Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- NineInchDCAPLS
- Optimization enabled
- true
- Compiler version
- v0.8.19+commit.7dd6d404
- Optimization runs
- 200
- EVM Version
- default
- Verified at
- 2024-02-01T18:46:56.628222Z
Constructor Arguments
0x00000000000000000000000099c2d4937756cf66d04f7db362b87604f4303969000000000000000000000000c73896721b68ce58dde039ef79e37fff164fd355000000000000000000000000c73896721b68ce58dde039ef79e37fff164fd355
Arg [0] (address) : 0x99c2d4937756cf66d04f7db362b87604f4303969
Arg [1] (address) : 0xc73896721b68ce58dde039ef79e37fff164fd355
Arg [2] (address) : 0xc73896721b68ce58dde039ef79e37fff164fd355
contracts/swap/NineInchDCAPLS.sol
// SPDX-License-Identifier: GPLv3
pragma solidity 0.8.19;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/math/SafeCast.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "./interfaces/INineInchRouter02.sol";
/**
* @title NineInchDCAPLS
* @notice It allows
*/
contract NineInchDCAPLS is ReentrancyGuard, Pausable, Ownable {
//---------- Libraries ----------//
using SafeMath for uint256;
using SafeCast for uint256;
using SafeERC20 for IERC20;
using EnumerableSet for EnumerableSet.Bytes32Set;
//---------- Contracts ----------//
INineInchRouter02 private nineInchRouter; // 9inchRouter Router contract.
address public keeper; // Address of the admin who can performKeep.
//---------- Storage -----------//
address feeWallet; // Address of the wallet that will receive the fee.
uint256 fee = 10; // 0.1% Fee to be charged for each swap.
struct Order {
// Amount of tokens to swap.
uint256 amountIn;
// Path to be performed by the swap.
address[] path;
// Address of the order maker.
address user;
// Swap interval.
uint256 interval;
// Date of the last swap.
uint256 lastSwapDate;
// How many "from" tokens there are left to swap
uint256 remaining;
// How many swaps left the position has to execute
uint8 swapsLeft;
// Number of orders to execute.
uint8 numOfOrders;
// Minimum price to execute the order.
uint256 minPrice;
// Maximum price to execute the order.
uint256 maxPrice;
}
mapping(bytes32 => Order) private orderBook; // Mapping from orderId to order.
EnumerableSet.Bytes32Set private orderIndex; // Mapping of ids of orders.
//---------- Events -----------//
event OrderCreated(
bytes32 indexed orderId,
uint256 amountIn,
address tokenIn,
address tokenOut,
address indexed user
);
event OrderCancelled(bytes32 indexed orderId);
event OrderFilled(bytes32 indexed orderId, uint256 executionPrice);
event OrderFailed(bytes32 indexed orderId);
//---------- Constructor ----------//
constructor(address routerAddress, address _keeper, address _feeWallet) {
nineInchRouter = INineInchRouter02(routerAddress);
keeper = _keeper;
feeWallet = _feeWallet;
}
//---------- Modifiers ----------//
/**
* @dev Reverts if keeper is not admin.
*/
modifier onlyKeeper() {
require(_msgSender() == keeper, "Only Node Admin");
_;
}
/**
* @dev Cancel a existent order.
* @param orderId Order Identity.
*/
function _deleteOrder(bytes32 orderId) private {
orderIndex.remove(orderId);
delete orderBook[orderId];
}
/**
* @dev Return funds if the order execution fails.
* @param amount Amount to return.
* @param token Address of the asset.
* @param user Address of the order maker.
*/
function _forceFail(uint256 amount, address token, address user) private {
//Interactions
if (token == address(nineInchRouter.WETH())) {
(bool success, ) = payable(user).call{value: amount}("");
require(success, "Transfer failed");
} else {
IERC20 _token = IERC20(token);
_token.safeTransfer(user, amount);
}
}
/**
* @dev Perform a swap once the target price is reached.
* @param orderId Order Identity
*/
function _performSwap(bytes32 orderId) private {
require(orderIndex.contains(orderId), "Order does not exist");
Order storage order = orderBook[orderId];
uint256 amountIn = order.amountIn / order.numOfOrders;
if (order.remaining < amountIn) amountIn = order.remaining;
address[] memory path = order.path;
address tokenIn = path[0];
address tokenOut = path[path.length - 1];
address user = order.user;
address WETH = nineInchRouter.WETH();
(bool success, uint256 price) = getPrice(amountIn, order.path);
uint256 amountOutMin = price.mul(10000 - 450).div(10000);
if (tokenIn == WETH) {
try
nineInchRouter.swapExactETHForTokens{value: amountIn}(
amountOutMin,
path,
user,
block.timestamp.add(300)
)
returns (uint256[] memory amounts) {
order.swapsLeft -= 1;
order.lastSwapDate = block.timestamp;
order.remaining -= amountIn;
if (order.swapsLeft == 0) {
_deleteOrder(orderId);
}
emit OrderFilled(orderId, amounts[path.length - 1]);
} catch {
_forceFail(amountIn, tokenIn, user);
emit OrderFailed(orderId);
}
} else if (tokenOut == WETH) {
IERC20(tokenIn).approve(address(nineInchRouter), amountIn);
try
nineInchRouter.swapExactTokensForETH(
amountIn,
amountOutMin,
path,
payable(user),
block.timestamp.add(300)
)
returns (uint256[] memory amounts) {
order.swapsLeft -= 1;
order.lastSwapDate = block.timestamp;
order.remaining -= amountIn;
if (order.swapsLeft == 0) {
_deleteOrder(orderId);
}
emit OrderFilled(orderId, amounts[path.length - 1]);
} catch {
_forceFail(amountIn, tokenIn, user);
emit OrderFailed(orderId);
}
} else {
IERC20(tokenIn).approve(address(nineInchRouter), amountIn);
try
nineInchRouter.swapExactTokensForTokens(
amountIn,
amountOutMin,
path,
user,
block.timestamp.add(300)
)
returns (uint256[] memory amounts) {
order.swapsLeft -= 1;
order.lastSwapDate = block.timestamp;
order.remaining -= amountIn;
if (order.swapsLeft == 0) {
_deleteOrder(orderId);
}
emit OrderFilled(orderId, amounts[path.length - 1]);
} catch {
_forceFail(amountIn, tokenIn, user);
emit OrderFailed(orderId);
}
}
}
/**
* @notice Show the amounts out of path.
* @param amountIn Amount to query.
* @param path Path to query.
* @return If exist and the amount out.
*/
function getPrice(
uint256 amountIn,
address[] memory path
) public view returns (bool, uint256) {
try nineInchRouter.getAmountsOut(amountIn, path) returns (
uint256[] memory result
) {
return (true, result[path.length - 1]);
} catch {
return (false, 0);
}
}
/**
* @dev Calculate the amount of digits in a number.
* @param number Number to check.
* @return uint256 amount of difits.
*/
function _numDigits(uint256 number) private pure returns (uint256) {
uint256 digits = 0;
while (number != 0) {
number /= 10;
digits++;
}
return digits;
}
/**
* @dev Calculate the number of pages in proportion to 100 orders per page.
* @return book_ amount of pages.
* @return digitpage_ difits of pages.
*/
function _getPagination()
private
view
returns (uint256 book_, uint256 digitpage_)
{
uint256 _book = orderIndex.length().div(100);
uint256 remainder = _book.mul(100);
_book = remainder < orderIndex.length() ? _book.add(1) : _book;
return (_book, _numDigits(_book));
}
//----------- External Functions -----------//
/**
* @notice Show the number of total open orders.
* @return The number of orders.
*/
function totalOrders() external view returns (uint256) {
return orderIndex.length();
}
/**
* @notice Show the order in the searched index.
* @param index Index number for query.
* @return The id of the order.
*/
function getOrderAt(uint256 index) external view returns (bytes32) {
return orderIndex.at(index);
}
/**
* @notice Show data of the order.
* @param orderId ID for query.
* @return The data of the order.
*/
function getOrder(bytes32 orderId) external view returns (Order memory) {
require(orderIndex.contains(orderId), "Query for nonexistent order");
return orderBook[orderId];
}
/**
* @notice Show the start and end index for the keeper query, these indexes change according to the block number.
* This function is implemented so that keepers can read all open orders and not have a reduced limit.
* @return start index to check.
* @return end index to check.
*/
function getBatch() public view returns (uint256 start, uint256 end) {
if (orderIndex.length() != 0) {
(uint256 pages, uint256 batchDigits) = _getPagination();
uint256 blockTens = block.number.div(10);
uint256 underBlock = blockTens.div(10 ** batchDigits);
uint256 overBlock = underBlock.mul(10 ** batchDigits);
uint256 result = blockTens.sub(overBlock);
result = result == 0 ? 1 : result;
while (result > pages) {
result -= pages;
}
uint256 start_ = result.sub(1).mul(100);
uint256 end_ = result.mul(100) > orderIndex.length()
? orderIndex.length()
: result.mul(100);
return (start_, end_);
}
return (0, 0);
}
/**
* @notice Create new order.
* @param amountIn_ Amount to swap.
* @param path_ Path to be performed by the swap.
*/
function createOrder(
uint256 amountIn_,
address[] calldata path_,
uint256 interval_,
uint8 numOfOrders_,
uint256[] memory priceRange_ // [minPrice, maxPrice]
) external payable whenNotPaused nonReentrant {
//Checks
require(amountIn_ != 0, "Zero amount in");
require(path_.length >= 2, "Invalid path");
require(interval_ >= 60 && interval_ <= 31556952, "Invalid interval");
require(numOfOrders_ <= 255, "Invalid num of orders");
if (priceRange_[0] != 0 && priceRange_[1] != 0) {
require(priceRange_[0] < priceRange_[1], "Invalid price range");
}
uint256 amountIn = amountIn_;
address[] calldata path = path_;
uint256 _interval = interval_;
address tokenIn = path[0];
address tokenOut = path[path_.length - 1];
address user = _msgSender();
require(
tokenIn != address(0x0) &&
tokenOut != address(0x0) &&
tokenIn != tokenOut,
"Invalid tokens"
);
if (tokenIn == address(nineInchRouter.WETH())) {
require(msg.value >= amountIn, "Insufficient eth value for swap");
// transfer fee to feeWallet
uint256 feeAmount = amountIn.mul(fee).div(10000);
(bool success, ) = payable(feeWallet).call{value: feeAmount}("");
require(success, "Transfer failed");
amountIn -= feeAmount;
} else {
IERC20 _token = IERC20(tokenIn);
require(
_token.allowance(user, address(this)) >= amountIn,
"Insufficient token allowance for swap"
);
_token.transferFrom(user, address(this), amountIn);
// transfer fee to feeWallet
uint256 feeAmount = amountIn.mul(fee).div(10000);
_token.safeTransfer(feeWallet, feeAmount);
amountIn -= feeAmount;
}
bytes32 orderId = keccak256(
abi.encodePacked(
amountIn,
tokenIn,
tokenOut,
user,
_interval,
numOfOrders_,
block.timestamp,
block.number
)
);
require(!orderIndex.contains(orderId), "Order id mistake");
//Create order
Order memory newOrder = Order(
amountIn,
path,
user,
_interval,
block.timestamp,
amountIn,
numOfOrders_,
numOfOrders_,
priceRange_[0],
priceRange_[1]
);
orderIndex.add(orderId);
orderBook[orderId] = newOrder;
//Interactions
emit OrderCreated(orderId, amountIn, user, tokenIn, tokenOut);
}
/**
* @notice Cancel a existent order.
* @param orderId Order identity.
*/
function cancelOrder(bytes32 orderId) external nonReentrant {
//Checks
require(orderIndex.contains(orderId), "Order does not exist");
Order memory order = orderBook[orderId];
require(order.user == _msgSender(), "Invalid access");
address tokenIn = order.path[0];
//Effects
_deleteOrder(orderId);
//Interactions
if (tokenIn == address(nineInchRouter.WETH())) {
(bool success, ) = payable(order.user).call{value: order.remaining}(
""
);
require(success, "Transfer failed");
} else {
IERC20 token = IERC20(tokenIn);
token.transfer(order.user, order.remaining);
}
emit OrderCancelled(orderId);
}
/**
* @notice Check if any order need to be execute.
* @param checkData default data of keeper.
* @return If need to be execute and the order id.
*/
function checkUpkeep(
bytes calldata checkData
) external view returns (bool, bytes memory) {
(uint256 start, uint256 end) = getBatch();
for (uint256 i = start; i < end; i++) {
bytes32 orderId = orderIndex.at(i);
Order memory order = orderBook[orderId];
uint256 amount = order.amountIn / order.numOfOrders;
// check if order is within the price range
// check if the minimum price is greater or equal than current price
if (order.minPrice != 0) {
(bool success, uint256 price) = getPrice(amount, order.path);
require(
success && price >= order.minPrice,
"Order price is below the minimum"
);
}
// check if the maximum price is lower or equal than current price
if (order.maxPrice != 0) {
(bool success, uint256 price) = getPrice(amount, order.path);
require(
success && price <= order.maxPrice,
"Order price is above the maximum"
);
}
// check if the order is ready to be executed, will be executed if the interval has passed,
// and if the remaining amount is greater than 0 and the number of swaps left is greater than 0
if (order.swapsLeft == order.numOfOrders) {
return (true, abi.encodePacked(orderId));
} else {
if (
order.remaining > 0 &&
order.swapsLeft > 0 &&
order.lastSwapDate + order.interval <= block.timestamp
) {
return (true, abi.encodePacked(orderId));
}
}
}
return (false, checkData);
}
/**
* @notice Execute an order, only keepers can do this execution.
* @param performData order id to execute.
*/
function performUpkeep(
bytes calldata performData
) external nonReentrant onlyKeeper {
bytes32 orderId = abi.decode(performData, (bytes32));
require(orderIndex.contains(orderId), "Order does not exist");
Order memory order = orderBook[orderId];
uint32 swapsLeft = order.swapsLeft;
uint256 remaining = order.remaining;
uint256 lastSwapDate = order.lastSwapDate;
uint256 amountIn = order.amountIn / order.numOfOrders;
if (order.remaining < amountIn) amountIn = order.remaining;
// check if order is within the price range
// check if the minimum price is greater or equal than current price
if (order.minPrice != 0) {
(bool success, uint256 price) = getPrice(amountIn, order.path);
require(
success && price >= order.minPrice,
"Order price is below the minimum"
);
}
// check if the maximum price is lower or equal than current price
if (order.maxPrice != 0) {
(bool success, uint256 price) = getPrice(amountIn, order.path);
require(
success && price <= order.maxPrice,
"Order price is above the maximum"
);
}
// check if the order is ready to be executed, will be executed if the interval has passed,
// and if the remaining amount is greater than 0 and the number of swaps left is greater than 0
if (swapsLeft != order.numOfOrders) {
require(
swapsLeft > 0 &&
remaining > 0 &&
lastSwapDate + order.interval <= block.timestamp,
"Target not reached"
);
}
//Interactions
_performSwap(orderId);
}
/**
* @notice Cancel a existent order by the contract owner.
* @param orderId_ Order identity.
*/
function forceCancelOrder(bytes32 orderId_) external onlyOwner {
//Checks
require(orderIndex.contains(orderId_), "Order does not exist");
Order memory order = orderBook[orderId_];
address tokenIn = order.path[0];
//Effects
_deleteOrder(orderId_);
//Interactions
if (tokenIn == address(nineInchRouter.WETH())) {
(bool success, ) = payable(order.user).call{value: order.remaining}(
""
);
require(success, "Transfer failed");
} else {
IERC20 token = IERC20(tokenIn);
token.transfer(order.user, order.remaining);
}
emit OrderCancelled(orderId_);
}
function updateKeeper(address _keeper) external onlyOwner {
keeper = _keeper;
}
function updateRouter(address _router) external onlyOwner {
nineInchRouter = INineInchRouter02(_router);
}
function updateFeeWallet(address _feeWallet) external onlyOwner {
feeWallet = _feeWallet;
}
function updateFee(uint256 _fee) external onlyOwner {
fee = _fee;
}
/**
* @notice Functions for pause and unpause the contract.
*/
function pause() external onlyOwner {
_pause();
}
function unpause() external onlyOwner {
_unpause();
}
}
@openzeppelin/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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 Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling 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);
}
}
@openzeppelin/contracts/security/Pausable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (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 Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
require(!paused(), "Pausable: paused");
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
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());
}
}
@openzeppelin/contracts/security/ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (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() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
}
@openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @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 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);
}
@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/IERC20Permit.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;
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
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));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
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");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @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");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
/**
* @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).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// 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 cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}
@openzeppelin/contracts/utils/Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [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://consensys.net/diligence/blog/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.8.0/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 functionCallWithValue(target, data, 0, "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");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, 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) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, 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) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or 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 {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// 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
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
@openzeppelin/contracts/utils/Context.sol
// 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;
}
}
@openzeppelin/contracts/utils/math/SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.0;
/**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such 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.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/
library SafeCast {
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toUint248(uint256 value) internal pure returns (uint248) {
require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toUint240(uint256 value) internal pure returns (uint240) {
require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toUint232(uint256 value) internal pure returns (uint232) {
require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*
* _Available since v4.2._
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toUint216(uint256 value) internal pure returns (uint216) {
require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toUint208(uint256 value) internal pure returns (uint208) {
require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toUint200(uint256 value) internal pure returns (uint200) {
require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toUint192(uint256 value) internal pure returns (uint192) {
require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toUint184(uint256 value) internal pure returns (uint184) {
require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toUint176(uint256 value) internal pure returns (uint176) {
require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toUint168(uint256 value) internal pure returns (uint168) {
require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toUint160(uint256 value) internal pure returns (uint160) {
require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toUint152(uint256 value) internal pure returns (uint152) {
require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toUint144(uint256 value) internal pure returns (uint144) {
require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toUint136(uint256 value) internal pure returns (uint136) {
require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v2.5._
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toUint120(uint256 value) internal pure returns (uint120) {
require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toUint112(uint256 value) internal pure returns (uint112) {
require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toUint104(uint256 value) internal pure returns (uint104) {
require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*
* _Available since v4.2._
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toUint88(uint256 value) internal pure returns (uint88) {
require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toUint80(uint256 value) internal pure returns (uint80) {
require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toUint72(uint256 value) internal pure returns (uint72) {
require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v2.5._
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toUint56(uint256 value) internal pure returns (uint56) {
require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toUint48(uint256 value) internal pure returns (uint48) {
require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toUint40(uint256 value) internal pure returns (uint40) {
require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v2.5._
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toUint24(uint256 value) internal pure returns (uint24) {
require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v2.5._
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*
* _Available since v2.5._
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*
* _Available since v3.0._
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*
* _Available since v4.7._
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*
* _Available since v4.7._
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*
* _Available since v3.0._
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
}
@openzeppelin/contracts/utils/math/SafeMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (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 subtraction 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;
}
}
}
@openzeppelin/contracts/utils/structs/EnumerableSet.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
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.
*
* ```solidity
* 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.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
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) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// 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;
/// @solidity memory-safe-assembly
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 in 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;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}
contracts/swap/interfaces/INineInchRouter01.sol
// SPDX-License-Identifier: GPLv3
pragma solidity 0.8.19;
interface INineInchRouter01 {
function factory() external view returns (address);
function WETH() external view 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);
}
contracts/swap/interfaces/INineInchRouter02.sol
// SPDX-License-Identifier: GPLv3
pragma solidity 0.8.19;
import "./INineInchRouter01.sol";
interface INineInchRouter02 is INineInchRouter01 {
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;
}
Compiler Settings
{"outputSelection":{"*":{"*":["abi","evm.bytecode","evm.deployedBytecode","evm.methodIdentifiers"]}},"optimizer":{"runs":200,"enabled":true},"libraries":{}}
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"routerAddress","internalType":"address"},{"type":"address","name":"_keeper","internalType":"address"},{"type":"address","name":"_feeWallet","internalType":"address"}]},{"type":"event","name":"OrderCancelled","inputs":[{"type":"bytes32","name":"orderId","internalType":"bytes32","indexed":true}],"anonymous":false},{"type":"event","name":"OrderCreated","inputs":[{"type":"bytes32","name":"orderId","internalType":"bytes32","indexed":true},{"type":"uint256","name":"amountIn","internalType":"uint256","indexed":false},{"type":"address","name":"tokenIn","internalType":"address","indexed":false},{"type":"address","name":"tokenOut","internalType":"address","indexed":false},{"type":"address","name":"user","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"OrderFailed","inputs":[{"type":"bytes32","name":"orderId","internalType":"bytes32","indexed":true}],"anonymous":false},{"type":"event","name":"OrderFilled","inputs":[{"type":"bytes32","name":"orderId","internalType":"bytes32","indexed":true},{"type":"uint256","name":"executionPrice","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"Paused","inputs":[{"type":"address","name":"account","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"Unpaused","inputs":[{"type":"address","name":"account","internalType":"address","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"cancelOrder","inputs":[{"type":"bytes32","name":"orderId","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"},{"type":"bytes","name":"","internalType":"bytes"}],"name":"checkUpkeep","inputs":[{"type":"bytes","name":"checkData","internalType":"bytes"}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"createOrder","inputs":[{"type":"uint256","name":"amountIn_","internalType":"uint256"},{"type":"address[]","name":"path_","internalType":"address[]"},{"type":"uint256","name":"interval_","internalType":"uint256"},{"type":"uint8","name":"numOfOrders_","internalType":"uint8"},{"type":"uint256[]","name":"priceRange_","internalType":"uint256[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"forceCancelOrder","inputs":[{"type":"bytes32","name":"orderId_","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"start","internalType":"uint256"},{"type":"uint256","name":"end","internalType":"uint256"}],"name":"getBatch","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"","internalType":"struct NineInchDCAPLS.Order","components":[{"type":"uint256","name":"amountIn","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"address","name":"user","internalType":"address"},{"type":"uint256","name":"interval","internalType":"uint256"},{"type":"uint256","name":"lastSwapDate","internalType":"uint256"},{"type":"uint256","name":"remaining","internalType":"uint256"},{"type":"uint8","name":"swapsLeft","internalType":"uint8"},{"type":"uint8","name":"numOfOrders","internalType":"uint8"},{"type":"uint256","name":"minPrice","internalType":"uint256"},{"type":"uint256","name":"maxPrice","internalType":"uint256"}]}],"name":"getOrder","inputs":[{"type":"bytes32","name":"orderId","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"getOrderAt","inputs":[{"type":"uint256","name":"index","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"},{"type":"uint256","name":"","internalType":"uint256"}],"name":"getPrice","inputs":[{"type":"uint256","name":"amountIn","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"keeper","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"pause","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"paused","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"performUpkeep","inputs":[{"type":"bytes","name":"performData","internalType":"bytes"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalOrders","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unpause","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateFee","inputs":[{"type":"uint256","name":"_fee","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateFeeWallet","inputs":[{"type":"address","name":"_feeWallet","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateKeeper","inputs":[{"type":"address","name":"_keeper","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateRouter","inputs":[{"type":"address","name":"_router","internalType":"address"}]}]
Contract Creation Code
0x6080604052600a6005553480156200001657600080fd5b50604051620038563803806200385683398101604081905262000039916200010d565b60016000819055805460ff19169055620000533362000096565b600280546001600160a01b039485166001600160a01b03199182161790915560038054938516938216939093179092556004805491909316911617905562000157565b600180546001600160a01b03838116610100818102610100600160a81b031985161790945560405193909204169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b80516001600160a01b03811681146200010857600080fd5b919050565b6000806000606084860312156200012357600080fd5b6200012e84620000f0565b92506200013e60208501620000f0565b91506200014e60408501620000f0565b90509250925092565b6136ef80620001676000396000f3fe60806040526004361061012a5760003560e01c8063715018a6116100ab5780639012c4a81161006f5780639012c4a81461034157806395048d46146103615780639779021714610381578063aced1661146103a1578063c851cc32146103c1578063f2fde38b146103e157600080fd5b8063715018a6146102a057806373a423d0146102b55780637489ec23146102d55780638456cb59146102f55780638da5cb5b1461030a57600080fd5b80634a6354ff116100f25780634a6354ff146101ef5780635778472a146102025780635c975abb1461022f57806366718524146102525780636e04ff0d1461027257600080fd5b80630c0fa81a1461012f5780631d8344091461016b5780633b1fee6c1461018e5780633f4ba83a146101b85780634585e33b146101cf575b600080fd5b34801561013b57600080fd5b5061014f61014a366004612f23565b610401565b6040805192151583526020830191909152015b60405180910390f35b34801561017757600080fd5b506101806104bb565b604051908152602001610162565b34801561019a57600080fd5b506101a36104cc565b60408051928352602083019190915201610162565b3480156101c457600080fd5b506101cd6105d2565b005b3480156101db57600080fd5b506101cd6101ea366004612fce565b6105e4565b6101cd6101fd3660046130bc565b610958565b34801561020e57600080fd5b5061022261021d366004613177565b6111fc565b60405161016291906131d4565b34801561023b57600080fd5b5060015460ff166040519015158152602001610162565b34801561025e57600080fd5b506101cd61026d366004613280565b61139d565b34801561027e57600080fd5b5061029261028d366004612fce565b6113c7565b6040516101629291906132ed565b3480156102ac57600080fd5b506101cd611704565b3480156102c157600080fd5b506101806102d0366004613177565b611716565b3480156102e157600080fd5b506101cd6102f0366004613177565b611729565b34801561030157600080fd5b506101cd611a89565b34801561031657600080fd5b5060015461010090046001600160a01b03165b6040516001600160a01b039091168152602001610162565b34801561034d57600080fd5b506101cd61035c366004613177565b611a99565b34801561036d57600080fd5b506101cd61037c366004613177565b611aa6565b34801561038d57600080fd5b506101cd61039c366004613280565b611dad565b3480156103ad57600080fd5b50600354610329906001600160a01b031681565b3480156103cd57600080fd5b506101cd6103dc366004613280565b611dd7565b3480156103ed57600080fd5b506101cd6103fc366004613280565b611e01565b60025460405163d06ca61f60e01b815260009182916001600160a01b039091169063d06ca61f906104389087908790600401613308565b600060405180830381865afa92505050801561047657506040513d6000823e601f3d908101601f191682016040526104739190810190613321565b60015b610485575060009050806104b4565b6001816001865161049691906133bd565b815181106104a6576104a66133d0565b602002602001015192509250505b9250929050565b60006104c76007611e77565b905090565b6000806104d96007611e77565b156105c9576000806104e9611e81565b909250905060006104fb43600a611edd565b9050600061051461050d84600a6134ca565b8390611edd565b9050600061052d61052685600a6134ca565b8390611ef0565b9050600061053b8483611efc565b90508015610549578061054c565b60015b90505b858111156105685761056186826133bd565b905061054f565b6000610580606461057a846001611efc565b90611ef0565b9050600061058e6007611e77565b610599846064611ef0565b116105ae576105a9836064611ef0565b6105b8565b6105b86007611e77565b919a91995090975050505050505050565b50600091829150565b6105da611f08565b6105e2611f68565b565b6105ec611fba565b6003546001600160a01b0316336001600160a01b0316146106465760405162461bcd60e51b815260206004820152600f60248201526e27b7363c902737b2329020b236b4b760891b60448201526064015b60405180910390fd5b600061065482840184613177565b9050610661600782612013565b61067d5760405162461bcd60e51b815260040161063d906134d6565b60008181526006602090815260408083208151610140810183528154815260018201805484518187028101870190955280855291949293858401939092908301828280156106f457602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116106d6575b505050918352505060028201546001600160a01b0316602082015260038201546040820152600482015460608201526005820154608080830191909152600683015460ff80821660a08086019190915261010092839004821660c080870191909152600787015460e08088019190915260089097015493909501929092529285015190850151918501519385015185519596509083169491939260009261079e9290911690613504565b9050808560a0015110156107b3575060a08401515b61010085015115610834576000806107cf838860200151610401565b915091508180156107e557508661010001518110155b6108315760405162461bcd60e51b815260206004820181905260248201527f4f726465722070726963652069732062656c6f7720746865206d696e696d756d604482015260640161063d565b50505b610120850151156108b557600080610850838860200151610401565b9150915081801561086657508661012001518111155b6108b25760405162461bcd60e51b815260206004820181905260248201527f4f726465722070726963652069732061626f766520746865206d6178696d756d604482015260640161063d565b50505b8460e0015160ff168463ffffffff161461093b5760008463ffffffff161180156108df5750600083115b80156108fa5750428560600151836108f79190613526565b11155b61093b5760405162461bcd60e51b815260206004820152601260248201527115185c99d95d081b9bdd081c995858da195960721b604482015260640161063d565b6109448661202b565b5050505050506109546001600055565b5050565b6109606126db565b610968611fba565b856000036109a95760405162461bcd60e51b815260206004820152600e60248201526d2d32b9379030b6b7bab73a1034b760911b604482015260640161063d565b60028410156109e95760405162461bcd60e51b815260206004820152600c60248201526b092dcecc2d8d2c840e0c2e8d60a31b604482015260640161063d565b603c83101580156109fe57506301e185588311155b610a3d5760405162461bcd60e51b815260206004820152601060248201526f125b9d985b1a59081a5b9d195c9d985b60821b604482015260640161063d565b60ff8260ff161115610a895760405162461bcd60e51b8152602060048201526015602482015274496e76616c6964206e756d206f66206f726465727360581b604482015260640161063d565b80600081518110610a9c57610a9c6133d0565b6020026020010151600014158015610acf575080600181518110610ac257610ac26133d0565b6020026020010151600014155b15610b4d5780600181518110610ae757610ae76133d0565b602002602001015181600081518110610b0257610b026133d0565b602002602001015110610b4d5760405162461bcd60e51b8152602060048201526013602482015272496e76616c69642070726963652072616e676560681b604482015260640161063d565b85858585600083838281610b6357610b636133d0565b9050602002016020810190610b789190613280565b905060008484610b8960018d6133bd565b818110610b9857610b986133d0565b9050602002016020810190610bad9190613280565b9050336001600160a01b03831615801590610bd057506001600160a01b03821615155b8015610bee5750816001600160a01b0316836001600160a01b031614155b610c2b5760405162461bcd60e51b815260206004820152600e60248201526d496e76616c696420746f6b656e7360901b604482015260640161063d565b600260009054906101000a90046001600160a01b03166001600160a01b031663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa158015610c7e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ca29190613539565b6001600160a01b0316836001600160a01b031603610db85786341015610d0a5760405162461bcd60e51b815260206004820152601f60248201527f496e73756666696369656e74206574682076616c756520666f72207377617000604482015260640161063d565b6000610d2d612710610d276005548b611ef090919063ffffffff16565b90611edd565b6004546040519192506000916001600160a01b039091169083908381818185875af1925050503d8060008114610d7f576040519150601f19603f3d011682016040523d82523d6000602084013e610d84565b606091505b5050905080610da55760405162461bcd60e51b815260040161063d90613556565b610daf828a6133bd565b98505050610f4b565b604051636eb1769f60e11b81526001600160a01b0382811660048301523060248301528491899183169063dd62ed3e90604401602060405180830381865afa158015610e08573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e2c919061357f565b1015610e885760405162461bcd60e51b815260206004820152602560248201527f496e73756666696369656e7420746f6b656e20616c6c6f77616e636520666f72604482015264020737761760dc1b606482015260840161063d565b6040516323b872dd60e01b81526001600160a01b038381166004830152306024830152604482018a90528216906323b872dd906064016020604051808303816000875af1158015610edd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f019190613598565b506000610f1f612710610d276005548c611ef090919063ffffffff16565b600454909150610f3c906001600160a01b03848116911683612721565b610f46818a6133bd565b985050505b6040805160208082018a90526bffffffffffffffffffffffff19606087811b82168486015286811b8216605485015285901b166068830152607c82018790526001600160f81b031960f88d901b16609c83015242609d8301524360bd808401919091528351808403909101815260dd9092019092528051910120610fd0600782612013565b156110105760405162461bcd60e51b815260206004820152601060248201526f4f72646572206964206d697374616b6560801b604482015260640161063d565b60006040518061014001604052808a815260200189898080602002602001604051908101604052809392919081815260200183836020028082843760009201829052509385525050506001600160a01b038616602083015260408201899052426060830152608082018c905260ff8e1660a0830181905260c08301528c5160e0909201918d91906110a3576110a36133d0565b602002602001015181526020018b6001815181106110c3576110c36133d0565b602002602001015181525090506110e482600761277890919063ffffffff16565b506000828152600660209081526040909120825181558183015180518493611113926001850192910190612e0f565b506040828101516002830180546001600160a01b039283166001600160a01b031990911617905560608085015160038501556080850151600485015560a0850151600585015560c085015160068501805460e088015160ff90811661010090810261ffff19909316919094161717905585015160078501556101209094015160089093019290925580518c815286831660208201528883168183015290519187169285927f1808ead687d1958acd9ebc3565c92ce7744d4ada02aeba135e4ed14b40e842bb9281900390910190a35050505050505050506111f46001600055565b505050505050565b611261604051806101400160405280600081526020016060815260200160006001600160a01b03168152602001600081526020016000815260200160008152602001600060ff168152602001600060ff16815260200160008152602001600081525090565b61126c600783612013565b6112b85760405162461bcd60e51b815260206004820152601b60248201527f517565727920666f72206e6f6e6578697374656e74206f726465720000000000604482015260640161063d565b600082815260066020908152604091829020825161014081018452815481526001820180548551818602810186019096528086529194929385810193929083018282801561132f57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611311575b505050918352505060028201546001600160a01b03166020820152600382015460408201526004820154606082015260058201546080820152600682015460ff80821660a0840152610100918290041660c0830152600783015460e083015260089092015491015292915050565b6113a5611f08565b600480546001600160a01b0319166001600160a01b0392909216919091179055565b600060606000806113d66104cc565b9092509050815b818110156116b95760006113f2600783612784565b905060006006600083815260200190815260200160002060405180610140016040529081600082015481526020016001820180548060200260200160405190810160405280929190818152602001828054801561147857602002820191906000526020600020905b81546001600160a01b0316815260019091019060200180831161145a575b505050918352505060028201546001600160a01b03166020820152600382015460408201526004820154606082015260058201546080820152600682015460ff80821660a084015261010091829004811660c0840152600784015460e0808501919091526008909401549190920152908201518251929350600092611501929190911690613504565b905081610100015160001461158657600080611521838560200151610401565b9150915081801561153757508361010001518110155b6115835760405162461bcd60e51b815260206004820181905260248201527f4f726465722070726963652069732062656c6f7720746865206d696e696d756d604482015260640161063d565b50505b61012082015115611607576000806115a2838560200151610401565b915091508180156115b857508361012001518111155b6116045760405162461bcd60e51b815260206004820181905260248201527f4f726465722070726963652069732061626f766520746865206d6178696d756d604482015260640161063d565b50505b8160e0015160ff168260c0015160ff160361164f5760018360405160200161163191815260200190565b604051602081830303815290604052975097505050505050506104b4565b60008260a0015111801561166a575060008260c0015160ff16115b8015611689575042826060015183608001516116869190613526565b11155b156116a35760018360405160200161163191815260200190565b50505080806116b1906135ba565b9150506113dd565b506000868681818080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250959c929b50919950505050505050505050565b61170c611f08565b6105e26000612790565b6000611723600783612784565b92915050565b611731611fba565b61173c600782612013565b6117585760405162461bcd60e51b815260040161063d906134d6565b60008181526006602090815260408083208151610140810183528154815260018201805484518187028101870190955280855291949293858401939092908301828280156117cf57602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116117b1575b505050918352505060028201546001600160a01b03166020820152600382015460408201526004820154606082015260058201546080820152600682015460ff80821660a0840152610100918290041660c0830152600783015460e08301526008909201549101529050336001600160a01b031681604001516001600160a01b03161461188f5760405162461bcd60e51b815260206004820152600e60248201526d496e76616c69642061636365737360901b604482015260640161063d565b600081602001516000815181106118a8576118a86133d0565b602002602001015190506118bb836127ea565b600260009054906101000a90046001600160a01b03166001600160a01b031663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa15801561190e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119329190613539565b6001600160a01b0316816001600160a01b0316036119cb57600082604001516001600160a01b03168360a0015160405160006040518083038185875af1925050503d806000811461199f576040519150601f19603f3d011682016040523d82523d6000602084013e6119a4565b606091505b50509050806119c55760405162461bcd60e51b815260040161063d90613556565b50611a4f565b60408281015160a0840151915163a9059cbb60e01b81526001600160a01b039182166004820152602481019290925282919082169063a9059cbb906044016020604051808303816000875af1158015611a28573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a4c9190613598565b50505b60405183907f5152abf959f6564662358c2e52b702259b78bac5ee7842a0f01937e670efcc7d90600090a25050611a866001600055565b50565b611a91611f08565b6105e261285c565b611aa1611f08565b600555565b611aae611f08565b611ab9600782612013565b611ad55760405162461bcd60e51b815260040161063d906134d6565b6000818152600660209081526040808320815161014081018352815481526001820180548451818702810187019095528085529194929385840193909290830182828015611b4c57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611b2e575b505050918352505060028201546001600160a01b0316602080830191909152600383015460408301526004830154606083015260058301546080830152600683015460ff80821660a0850152610100918290041660c0840152600784015460e0840152600890930154929091019190915281015180519192506000918290611bd657611bd66133d0565b60200260200101519050611be9836127ea565b600260009054906101000a90046001600160a01b03166001600160a01b031663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa158015611c3c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c609190613539565b6001600160a01b0316816001600160a01b031603611cf957600082604001516001600160a01b03168360a0015160405160006040518083038185875af1925050503d8060008114611ccd576040519150601f19603f3d011682016040523d82523d6000602084013e611cd2565b606091505b5050905080611cf35760405162461bcd60e51b815260040161063d90613556565b50611d7d565b60408281015160a0840151915163a9059cbb60e01b81526001600160a01b039182166004820152602481019290925282919082169063a9059cbb906044016020604051808303816000875af1158015611d56573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d7a9190613598565b50505b60405183907f5152abf959f6564662358c2e52b702259b78bac5ee7842a0f01937e670efcc7d90600090a2505050565b611db5611f08565b600380546001600160a01b0319166001600160a01b0392909216919091179055565b611ddf611f08565b600280546001600160a01b0319166001600160a01b0392909216919091179055565b611e09611f08565b6001600160a01b038116611e6e5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161063d565b611a8681612790565b6000611723825490565b6000806000611e956064610d276007611e77565b90506000611ea4826064611ef0565b9050611eb06007611e77565b8110611ebc5781611ec7565b611ec7826001612897565b915081611ed3836128a3565b9350935050509091565b6000611ee98284613504565b9392505050565b6000611ee982846135d3565b6000611ee982846133bd565b6001546001600160a01b036101009091041633146105e25760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161063d565b611f706128cc565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b60026000540361200c5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161063d565b6002600055565b60008181526001830160205260408120541515611ee9565b612036600782612013565b6120525760405162461bcd60e51b815260040161063d906134d6565b6000818152600660208190526040822090810154815491929161207d91610100900460ff1690613504565b90508082600501541015612092575060058101545b6000826001018054806020026020016040519081016040528092919081815260200182805480156120ec57602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116120ce575b50505050509050600081600081518110612108576121086133d0565b602002602001015190506000826001845161212391906133bd565b81518110612133576121336133d0565b6020908102919091018101516002808801549054604080516315ab88c960e31b815290519395506001600160a01b0392831694600094929093169263ad5c4648926004808401938290030181865afa158015612193573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121b79190613539565b9050600080612222888a60010180548060200260200160405190810160405280929190818152602001828054801561221857602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116121fa575b5050505050610401565b9092509050600061223b612710610d278461254e611ef0565b9050836001600160a01b0316876001600160a01b0316036123e8576002546001600160a01b0316637ff36ab58a838b896122774261012c612897565b6040518663ffffffff1660e01b815260040161229694939291906135ea565b60006040518083038185885af1935050505080156122d657506040513d6000823e601f3d908101601f191682016040526122d39190810190613321565b60015b612315576122e5898887612915565b6040518b907fe1bf2a28c083b93b502e4140fe14e357c3d973a7ec3d8517b6022a70bfd3562690600090a26126ce565b60068b0180546001919060009061233090849060ff1661361f565b92506101000a81548160ff021916908360ff160217905550428b60040181905550898b600501600082825461236591906133bd565b909155505060068b015460ff16600003612382576123828c6127ea565b8b7ffec331350fce78ba658e082a71da20ac9f8d798a99b3c79681c8440cbfe77e078260018c516123b391906133bd565b815181106123c3576123c36133d0565b60200260200101516040516123da91815260200190565b60405180910390a2506126ce565b836001600160a01b0316866001600160a01b0316036124f75760025460405163095ea7b360e01b81526001600160a01b039182166004820152602481018b90529088169063095ea7b3906044016020604051808303816000875af1158015612454573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124789190613598565b506002546001600160a01b03166318cbafe58a838b8961249a4261012c612897565b6040518663ffffffff1660e01b81526004016124ba959493929190613638565b6000604051808303816000875af19250505080156122d657506040513d6000823e601f3d908101601f191682016040526122d39190810190613321565b60025460405163095ea7b360e01b81526001600160a01b039182166004820152602481018b90529088169063095ea7b3906044016020604051808303816000875af115801561254a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061256e9190613598565b506002546001600160a01b03166338ed17398a838b896125904261012c612897565b6040518663ffffffff1660e01b81526004016125b0959493929190613638565b6000604051808303816000875af19250505080156125f057506040513d6000823e601f3d908101601f191682016040526125ed9190810190613321565b60015b6125ff576122e5898887612915565b60068b0180546001919060009061261a90849060ff1661361f565b92506101000a81548160ff021916908360ff160217905550428b60040181905550898b600501600082825461264f91906133bd565b909155505060068b015460ff1660000361266c5761266c8c6127ea565b8b7ffec331350fce78ba658e082a71da20ac9f8d798a99b3c79681c8440cbfe77e078260018c5161269d91906133bd565b815181106126ad576126ad6133d0565b60200260200101516040516126c491815260200190565b60405180910390a2505b5050505050505050505050565b60015460ff16156105e25760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015260640161063d565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052612773908490612a32565b505050565b6000611ee98383612b07565b6000611ee98383612b56565b600180546001600160a01b03838116610100818102610100600160a81b031985161790945560405193909204169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6127f5600782612b80565b506000818152600660205260408120818155906128156001830182612e74565b506002810180546001600160a01b0319169055600060038201819055600482018190556005820181905560068201805461ffff191690556007820181905560089091015550565b6128646126db565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25833611f9d565b6000611ee98284613526565b6000805b8215611723576128b8600a84613504565b9250806128c4816135ba565b9150506128a7565b60015460ff166105e25760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015260640161063d565b600260009054906101000a90046001600160a01b03166001600160a01b031663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa158015612968573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061298c9190613539565b6001600160a01b0316826001600160a01b031603612a1d576000816001600160a01b03168460405160006040518083038185875af1925050503d80600081146129f1576040519150601f19603f3d011682016040523d82523d6000602084013e6129f6565b606091505b5050905080612a175760405162461bcd60e51b815260040161063d90613556565b50505050565b81612a176001600160a01b0382168386612721565b6000612a87826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612b8c9092919063ffffffff16565b9050805160001480612aa8575080806020019051810190612aa89190613598565b6127735760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161063d565b6000818152600183016020526040812054612b4e57508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155611723565b506000611723565b6000826000018281548110612b6d57612b6d6133d0565b9060005260206000200154905092915050565b6000611ee98383612ba3565b6060612b9b8484600085612c96565b949350505050565b60008181526001830160205260408120548015612c8c576000612bc76001836133bd565b8554909150600090612bdb906001906133bd565b9050818114612c40576000866000018281548110612bfb57612bfb6133d0565b9060005260206000200154905080876000018481548110612c1e57612c1e6133d0565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080612c5157612c51613674565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050611723565b6000915050611723565b606082471015612cf75760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161063d565b600080866001600160a01b03168587604051612d13919061368a565b60006040518083038185875af1925050503d8060008114612d50576040519150601f19603f3d011682016040523d82523d6000602084013e612d55565b606091505b5091509150612d6687838387612d71565b979650505050505050565b60608315612de0578251600003612dd9576001600160a01b0385163b612dd95760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161063d565b5081612b9b565b612b9b8383815115612df55781518083602001fd5b8060405162461bcd60e51b815260040161063d91906136a6565b828054828255906000526020600020908101928215612e64579160200282015b82811115612e6457825182546001600160a01b0319166001600160a01b03909116178255602090920191600190910190612e2f565b50612e70929150612e8e565b5090565b5080546000825590600052602060002090810190611a8691905b5b80821115612e705760008155600101612e8f565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715612ee257612ee2612ea3565b604052919050565b600067ffffffffffffffff821115612f0457612f04612ea3565b5060051b60200190565b6001600160a01b0381168114611a8657600080fd5b60008060408385031215612f3657600080fd5b8235915060208084013567ffffffffffffffff811115612f5557600080fd5b8401601f81018613612f6657600080fd5b8035612f79612f7482612eea565b612eb9565b81815260059190911b82018301908381019088831115612f9857600080fd5b928401925b82841015612fbf578335612fb081612f0e565b82529284019290840190612f9d565b80955050505050509250929050565b60008060208385031215612fe157600080fd5b823567ffffffffffffffff80821115612ff957600080fd5b818501915085601f83011261300d57600080fd5b81358181111561301c57600080fd5b86602082850101111561302e57600080fd5b60209290920196919550909350505050565b803560ff8116811461305157600080fd5b919050565b600082601f83011261306757600080fd5b81356020613077612f7483612eea565b82815260059290921b8401810191818101908684111561309657600080fd5b8286015b848110156130b1578035835291830191830161309a565b509695505050505050565b60008060008060008060a087890312156130d557600080fd5b86359550602087013567ffffffffffffffff808211156130f457600080fd5b818901915089601f83011261310857600080fd5b81358181111561311757600080fd5b8a60208260051b850101111561312c57600080fd5b60208301975095506040890135945061314760608a01613040565b9350608089013591508082111561315d57600080fd5b5061316a89828a01613056565b9150509295509295509295565b60006020828403121561318957600080fd5b5035919050565b600081518084526020808501945080840160005b838110156131c95781516001600160a01b0316875295820195908201906001016131a4565b509495945050505050565b6020815281516020820152600060208301516101408060408501526131fd610160850183613190565b9150604085015161321960608601826001600160a01b03169052565b5060608501516080850152608085015160a085015260a085015160c085015260c085015161324c60e086018260ff169052565b5060e08501516101006132638187018360ff169052565b860151610120868101919091529095015193019290925250919050565b60006020828403121561329257600080fd5b8135611ee981612f0e565b60005b838110156132b85781810151838201526020016132a0565b50506000910152565b600081518084526132d981602086016020860161329d565b601f01601f19169290920160200192915050565b8215158152604060208201526000612b9b60408301846132c1565b828152604060208201526000612b9b6040830184613190565b6000602080838503121561333457600080fd5b825167ffffffffffffffff81111561334b57600080fd5b8301601f8101851361335c57600080fd5b805161336a612f7482612eea565b81815260059190911b8201830190838101908783111561338957600080fd5b928401925b82841015612d665783518252928401929084019061338e565b634e487b7160e01b600052601160045260246000fd5b81810381811115611723576117236133a7565b634e487b7160e01b600052603260045260246000fd5b600181815b80851115613421578160001904821115613407576134076133a7565b8085161561341457918102915b93841c93908002906133eb565b509250929050565b60008261343857506001611723565b8161344557506000611723565b816001811461345b576002811461346557613481565b6001915050611723565b60ff841115613476576134766133a7565b50506001821b611723565b5060208310610133831016604e8410600b84101617156134a4575081810a611723565b6134ae83836133e6565b80600019048211156134c2576134c26133a7565b029392505050565b6000611ee98383613429565b60208082526014908201527313dc99195c88191bd95cc81b9bdd08195e1a5cdd60621b604082015260600190565b60008261352157634e487b7160e01b600052601260045260246000fd5b500490565b80820180821115611723576117236133a7565b60006020828403121561354b57600080fd5b8151611ee981612f0e565b6020808252600f908201526e151c985b9cd9995c8819985a5b1959608a1b604082015260600190565b60006020828403121561359157600080fd5b5051919050565b6000602082840312156135aa57600080fd5b81518015158114611ee957600080fd5b6000600182016135cc576135cc6133a7565b5060010190565b8082028115828204841417611723576117236133a7565b8481526080602082015260006136036080830186613190565b6001600160a01b03949094166040830152506060015292915050565b60ff8281168282160390811115611723576117236133a7565b85815284602082015260a06040820152600061365760a0830186613190565b6001600160a01b0394909416606083015250608001529392505050565b634e487b7160e01b600052603160045260246000fd5b6000825161369c81846020870161329d565b9190910192915050565b602081526000611ee960208301846132c156fea264697066735822122090bb0747faf01df36c9ce80f3b393bc98d7e8b153a3ca48e7ad16e99e8d070ea64736f6c6343000813003300000000000000000000000099c2d4937756cf66d04f7db362b87604f4303969000000000000000000000000c73896721b68ce58dde039ef79e37fff164fd355000000000000000000000000c73896721b68ce58dde039ef79e37fff164fd355
Deployed ByteCode
0x60806040526004361061012a5760003560e01c8063715018a6116100ab5780639012c4a81161006f5780639012c4a81461034157806395048d46146103615780639779021714610381578063aced1661146103a1578063c851cc32146103c1578063f2fde38b146103e157600080fd5b8063715018a6146102a057806373a423d0146102b55780637489ec23146102d55780638456cb59146102f55780638da5cb5b1461030a57600080fd5b80634a6354ff116100f25780634a6354ff146101ef5780635778472a146102025780635c975abb1461022f57806366718524146102525780636e04ff0d1461027257600080fd5b80630c0fa81a1461012f5780631d8344091461016b5780633b1fee6c1461018e5780633f4ba83a146101b85780634585e33b146101cf575b600080fd5b34801561013b57600080fd5b5061014f61014a366004612f23565b610401565b6040805192151583526020830191909152015b60405180910390f35b34801561017757600080fd5b506101806104bb565b604051908152602001610162565b34801561019a57600080fd5b506101a36104cc565b60408051928352602083019190915201610162565b3480156101c457600080fd5b506101cd6105d2565b005b3480156101db57600080fd5b506101cd6101ea366004612fce565b6105e4565b6101cd6101fd3660046130bc565b610958565b34801561020e57600080fd5b5061022261021d366004613177565b6111fc565b60405161016291906131d4565b34801561023b57600080fd5b5060015460ff166040519015158152602001610162565b34801561025e57600080fd5b506101cd61026d366004613280565b61139d565b34801561027e57600080fd5b5061029261028d366004612fce565b6113c7565b6040516101629291906132ed565b3480156102ac57600080fd5b506101cd611704565b3480156102c157600080fd5b506101806102d0366004613177565b611716565b3480156102e157600080fd5b506101cd6102f0366004613177565b611729565b34801561030157600080fd5b506101cd611a89565b34801561031657600080fd5b5060015461010090046001600160a01b03165b6040516001600160a01b039091168152602001610162565b34801561034d57600080fd5b506101cd61035c366004613177565b611a99565b34801561036d57600080fd5b506101cd61037c366004613177565b611aa6565b34801561038d57600080fd5b506101cd61039c366004613280565b611dad565b3480156103ad57600080fd5b50600354610329906001600160a01b031681565b3480156103cd57600080fd5b506101cd6103dc366004613280565b611dd7565b3480156103ed57600080fd5b506101cd6103fc366004613280565b611e01565b60025460405163d06ca61f60e01b815260009182916001600160a01b039091169063d06ca61f906104389087908790600401613308565b600060405180830381865afa92505050801561047657506040513d6000823e601f3d908101601f191682016040526104739190810190613321565b60015b610485575060009050806104b4565b6001816001865161049691906133bd565b815181106104a6576104a66133d0565b602002602001015192509250505b9250929050565b60006104c76007611e77565b905090565b6000806104d96007611e77565b156105c9576000806104e9611e81565b909250905060006104fb43600a611edd565b9050600061051461050d84600a6134ca565b8390611edd565b9050600061052d61052685600a6134ca565b8390611ef0565b9050600061053b8483611efc565b90508015610549578061054c565b60015b90505b858111156105685761056186826133bd565b905061054f565b6000610580606461057a846001611efc565b90611ef0565b9050600061058e6007611e77565b610599846064611ef0565b116105ae576105a9836064611ef0565b6105b8565b6105b86007611e77565b919a91995090975050505050505050565b50600091829150565b6105da611f08565b6105e2611f68565b565b6105ec611fba565b6003546001600160a01b0316336001600160a01b0316146106465760405162461bcd60e51b815260206004820152600f60248201526e27b7363c902737b2329020b236b4b760891b60448201526064015b60405180910390fd5b600061065482840184613177565b9050610661600782612013565b61067d5760405162461bcd60e51b815260040161063d906134d6565b60008181526006602090815260408083208151610140810183528154815260018201805484518187028101870190955280855291949293858401939092908301828280156106f457602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116106d6575b505050918352505060028201546001600160a01b0316602082015260038201546040820152600482015460608201526005820154608080830191909152600683015460ff80821660a08086019190915261010092839004821660c080870191909152600787015460e08088019190915260089097015493909501929092529285015190850151918501519385015185519596509083169491939260009261079e9290911690613504565b9050808560a0015110156107b3575060a08401515b61010085015115610834576000806107cf838860200151610401565b915091508180156107e557508661010001518110155b6108315760405162461bcd60e51b815260206004820181905260248201527f4f726465722070726963652069732062656c6f7720746865206d696e696d756d604482015260640161063d565b50505b610120850151156108b557600080610850838860200151610401565b9150915081801561086657508661012001518111155b6108b25760405162461bcd60e51b815260206004820181905260248201527f4f726465722070726963652069732061626f766520746865206d6178696d756d604482015260640161063d565b50505b8460e0015160ff168463ffffffff161461093b5760008463ffffffff161180156108df5750600083115b80156108fa5750428560600151836108f79190613526565b11155b61093b5760405162461bcd60e51b815260206004820152601260248201527115185c99d95d081b9bdd081c995858da195960721b604482015260640161063d565b6109448661202b565b5050505050506109546001600055565b5050565b6109606126db565b610968611fba565b856000036109a95760405162461bcd60e51b815260206004820152600e60248201526d2d32b9379030b6b7bab73a1034b760911b604482015260640161063d565b60028410156109e95760405162461bcd60e51b815260206004820152600c60248201526b092dcecc2d8d2c840e0c2e8d60a31b604482015260640161063d565b603c83101580156109fe57506301e185588311155b610a3d5760405162461bcd60e51b815260206004820152601060248201526f125b9d985b1a59081a5b9d195c9d985b60821b604482015260640161063d565b60ff8260ff161115610a895760405162461bcd60e51b8152602060048201526015602482015274496e76616c6964206e756d206f66206f726465727360581b604482015260640161063d565b80600081518110610a9c57610a9c6133d0565b6020026020010151600014158015610acf575080600181518110610ac257610ac26133d0565b6020026020010151600014155b15610b4d5780600181518110610ae757610ae76133d0565b602002602001015181600081518110610b0257610b026133d0565b602002602001015110610b4d5760405162461bcd60e51b8152602060048201526013602482015272496e76616c69642070726963652072616e676560681b604482015260640161063d565b85858585600083838281610b6357610b636133d0565b9050602002016020810190610b789190613280565b905060008484610b8960018d6133bd565b818110610b9857610b986133d0565b9050602002016020810190610bad9190613280565b9050336001600160a01b03831615801590610bd057506001600160a01b03821615155b8015610bee5750816001600160a01b0316836001600160a01b031614155b610c2b5760405162461bcd60e51b815260206004820152600e60248201526d496e76616c696420746f6b656e7360901b604482015260640161063d565b600260009054906101000a90046001600160a01b03166001600160a01b031663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa158015610c7e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ca29190613539565b6001600160a01b0316836001600160a01b031603610db85786341015610d0a5760405162461bcd60e51b815260206004820152601f60248201527f496e73756666696369656e74206574682076616c756520666f72207377617000604482015260640161063d565b6000610d2d612710610d276005548b611ef090919063ffffffff16565b90611edd565b6004546040519192506000916001600160a01b039091169083908381818185875af1925050503d8060008114610d7f576040519150601f19603f3d011682016040523d82523d6000602084013e610d84565b606091505b5050905080610da55760405162461bcd60e51b815260040161063d90613556565b610daf828a6133bd565b98505050610f4b565b604051636eb1769f60e11b81526001600160a01b0382811660048301523060248301528491899183169063dd62ed3e90604401602060405180830381865afa158015610e08573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e2c919061357f565b1015610e885760405162461bcd60e51b815260206004820152602560248201527f496e73756666696369656e7420746f6b656e20616c6c6f77616e636520666f72604482015264020737761760dc1b606482015260840161063d565b6040516323b872dd60e01b81526001600160a01b038381166004830152306024830152604482018a90528216906323b872dd906064016020604051808303816000875af1158015610edd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f019190613598565b506000610f1f612710610d276005548c611ef090919063ffffffff16565b600454909150610f3c906001600160a01b03848116911683612721565b610f46818a6133bd565b985050505b6040805160208082018a90526bffffffffffffffffffffffff19606087811b82168486015286811b8216605485015285901b166068830152607c82018790526001600160f81b031960f88d901b16609c83015242609d8301524360bd808401919091528351808403909101815260dd9092019092528051910120610fd0600782612013565b156110105760405162461bcd60e51b815260206004820152601060248201526f4f72646572206964206d697374616b6560801b604482015260640161063d565b60006040518061014001604052808a815260200189898080602002602001604051908101604052809392919081815260200183836020028082843760009201829052509385525050506001600160a01b038616602083015260408201899052426060830152608082018c905260ff8e1660a0830181905260c08301528c5160e0909201918d91906110a3576110a36133d0565b602002602001015181526020018b6001815181106110c3576110c36133d0565b602002602001015181525090506110e482600761277890919063ffffffff16565b506000828152600660209081526040909120825181558183015180518493611113926001850192910190612e0f565b506040828101516002830180546001600160a01b039283166001600160a01b031990911617905560608085015160038501556080850151600485015560a0850151600585015560c085015160068501805460e088015160ff90811661010090810261ffff19909316919094161717905585015160078501556101209094015160089093019290925580518c815286831660208201528883168183015290519187169285927f1808ead687d1958acd9ebc3565c92ce7744d4ada02aeba135e4ed14b40e842bb9281900390910190a35050505050505050506111f46001600055565b505050505050565b611261604051806101400160405280600081526020016060815260200160006001600160a01b03168152602001600081526020016000815260200160008152602001600060ff168152602001600060ff16815260200160008152602001600081525090565b61126c600783612013565b6112b85760405162461bcd60e51b815260206004820152601b60248201527f517565727920666f72206e6f6e6578697374656e74206f726465720000000000604482015260640161063d565b600082815260066020908152604091829020825161014081018452815481526001820180548551818602810186019096528086529194929385810193929083018282801561132f57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611311575b505050918352505060028201546001600160a01b03166020820152600382015460408201526004820154606082015260058201546080820152600682015460ff80821660a0840152610100918290041660c0830152600783015460e083015260089092015491015292915050565b6113a5611f08565b600480546001600160a01b0319166001600160a01b0392909216919091179055565b600060606000806113d66104cc565b9092509050815b818110156116b95760006113f2600783612784565b905060006006600083815260200190815260200160002060405180610140016040529081600082015481526020016001820180548060200260200160405190810160405280929190818152602001828054801561147857602002820191906000526020600020905b81546001600160a01b0316815260019091019060200180831161145a575b505050918352505060028201546001600160a01b03166020820152600382015460408201526004820154606082015260058201546080820152600682015460ff80821660a084015261010091829004811660c0840152600784015460e0808501919091526008909401549190920152908201518251929350600092611501929190911690613504565b905081610100015160001461158657600080611521838560200151610401565b9150915081801561153757508361010001518110155b6115835760405162461bcd60e51b815260206004820181905260248201527f4f726465722070726963652069732062656c6f7720746865206d696e696d756d604482015260640161063d565b50505b61012082015115611607576000806115a2838560200151610401565b915091508180156115b857508361012001518111155b6116045760405162461bcd60e51b815260206004820181905260248201527f4f726465722070726963652069732061626f766520746865206d6178696d756d604482015260640161063d565b50505b8160e0015160ff168260c0015160ff160361164f5760018360405160200161163191815260200190565b604051602081830303815290604052975097505050505050506104b4565b60008260a0015111801561166a575060008260c0015160ff16115b8015611689575042826060015183608001516116869190613526565b11155b156116a35760018360405160200161163191815260200190565b50505080806116b1906135ba565b9150506113dd565b506000868681818080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250959c929b50919950505050505050505050565b61170c611f08565b6105e26000612790565b6000611723600783612784565b92915050565b611731611fba565b61173c600782612013565b6117585760405162461bcd60e51b815260040161063d906134d6565b60008181526006602090815260408083208151610140810183528154815260018201805484518187028101870190955280855291949293858401939092908301828280156117cf57602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116117b1575b505050918352505060028201546001600160a01b03166020820152600382015460408201526004820154606082015260058201546080820152600682015460ff80821660a0840152610100918290041660c0830152600783015460e08301526008909201549101529050336001600160a01b031681604001516001600160a01b03161461188f5760405162461bcd60e51b815260206004820152600e60248201526d496e76616c69642061636365737360901b604482015260640161063d565b600081602001516000815181106118a8576118a86133d0565b602002602001015190506118bb836127ea565b600260009054906101000a90046001600160a01b03166001600160a01b031663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa15801561190e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119329190613539565b6001600160a01b0316816001600160a01b0316036119cb57600082604001516001600160a01b03168360a0015160405160006040518083038185875af1925050503d806000811461199f576040519150601f19603f3d011682016040523d82523d6000602084013e6119a4565b606091505b50509050806119c55760405162461bcd60e51b815260040161063d90613556565b50611a4f565b60408281015160a0840151915163a9059cbb60e01b81526001600160a01b039182166004820152602481019290925282919082169063a9059cbb906044016020604051808303816000875af1158015611a28573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a4c9190613598565b50505b60405183907f5152abf959f6564662358c2e52b702259b78bac5ee7842a0f01937e670efcc7d90600090a25050611a866001600055565b50565b611a91611f08565b6105e261285c565b611aa1611f08565b600555565b611aae611f08565b611ab9600782612013565b611ad55760405162461bcd60e51b815260040161063d906134d6565b6000818152600660209081526040808320815161014081018352815481526001820180548451818702810187019095528085529194929385840193909290830182828015611b4c57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611b2e575b505050918352505060028201546001600160a01b0316602080830191909152600383015460408301526004830154606083015260058301546080830152600683015460ff80821660a0850152610100918290041660c0840152600784015460e0840152600890930154929091019190915281015180519192506000918290611bd657611bd66133d0565b60200260200101519050611be9836127ea565b600260009054906101000a90046001600160a01b03166001600160a01b031663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa158015611c3c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c609190613539565b6001600160a01b0316816001600160a01b031603611cf957600082604001516001600160a01b03168360a0015160405160006040518083038185875af1925050503d8060008114611ccd576040519150601f19603f3d011682016040523d82523d6000602084013e611cd2565b606091505b5050905080611cf35760405162461bcd60e51b815260040161063d90613556565b50611d7d565b60408281015160a0840151915163a9059cbb60e01b81526001600160a01b039182166004820152602481019290925282919082169063a9059cbb906044016020604051808303816000875af1158015611d56573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d7a9190613598565b50505b60405183907f5152abf959f6564662358c2e52b702259b78bac5ee7842a0f01937e670efcc7d90600090a2505050565b611db5611f08565b600380546001600160a01b0319166001600160a01b0392909216919091179055565b611ddf611f08565b600280546001600160a01b0319166001600160a01b0392909216919091179055565b611e09611f08565b6001600160a01b038116611e6e5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161063d565b611a8681612790565b6000611723825490565b6000806000611e956064610d276007611e77565b90506000611ea4826064611ef0565b9050611eb06007611e77565b8110611ebc5781611ec7565b611ec7826001612897565b915081611ed3836128a3565b9350935050509091565b6000611ee98284613504565b9392505050565b6000611ee982846135d3565b6000611ee982846133bd565b6001546001600160a01b036101009091041633146105e25760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161063d565b611f706128cc565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b60026000540361200c5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161063d565b6002600055565b60008181526001830160205260408120541515611ee9565b612036600782612013565b6120525760405162461bcd60e51b815260040161063d906134d6565b6000818152600660208190526040822090810154815491929161207d91610100900460ff1690613504565b90508082600501541015612092575060058101545b6000826001018054806020026020016040519081016040528092919081815260200182805480156120ec57602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116120ce575b50505050509050600081600081518110612108576121086133d0565b602002602001015190506000826001845161212391906133bd565b81518110612133576121336133d0565b6020908102919091018101516002808801549054604080516315ab88c960e31b815290519395506001600160a01b0392831694600094929093169263ad5c4648926004808401938290030181865afa158015612193573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121b79190613539565b9050600080612222888a60010180548060200260200160405190810160405280929190818152602001828054801561221857602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116121fa575b5050505050610401565b9092509050600061223b612710610d278461254e611ef0565b9050836001600160a01b0316876001600160a01b0316036123e8576002546001600160a01b0316637ff36ab58a838b896122774261012c612897565b6040518663ffffffff1660e01b815260040161229694939291906135ea565b60006040518083038185885af1935050505080156122d657506040513d6000823e601f3d908101601f191682016040526122d39190810190613321565b60015b612315576122e5898887612915565b6040518b907fe1bf2a28c083b93b502e4140fe14e357c3d973a7ec3d8517b6022a70bfd3562690600090a26126ce565b60068b0180546001919060009061233090849060ff1661361f565b92506101000a81548160ff021916908360ff160217905550428b60040181905550898b600501600082825461236591906133bd565b909155505060068b015460ff16600003612382576123828c6127ea565b8b7ffec331350fce78ba658e082a71da20ac9f8d798a99b3c79681c8440cbfe77e078260018c516123b391906133bd565b815181106123c3576123c36133d0565b60200260200101516040516123da91815260200190565b60405180910390a2506126ce565b836001600160a01b0316866001600160a01b0316036124f75760025460405163095ea7b360e01b81526001600160a01b039182166004820152602481018b90529088169063095ea7b3906044016020604051808303816000875af1158015612454573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124789190613598565b506002546001600160a01b03166318cbafe58a838b8961249a4261012c612897565b6040518663ffffffff1660e01b81526004016124ba959493929190613638565b6000604051808303816000875af19250505080156122d657506040513d6000823e601f3d908101601f191682016040526122d39190810190613321565b60025460405163095ea7b360e01b81526001600160a01b039182166004820152602481018b90529088169063095ea7b3906044016020604051808303816000875af115801561254a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061256e9190613598565b506002546001600160a01b03166338ed17398a838b896125904261012c612897565b6040518663ffffffff1660e01b81526004016125b0959493929190613638565b6000604051808303816000875af19250505080156125f057506040513d6000823e601f3d908101601f191682016040526125ed9190810190613321565b60015b6125ff576122e5898887612915565b60068b0180546001919060009061261a90849060ff1661361f565b92506101000a81548160ff021916908360ff160217905550428b60040181905550898b600501600082825461264f91906133bd565b909155505060068b015460ff1660000361266c5761266c8c6127ea565b8b7ffec331350fce78ba658e082a71da20ac9f8d798a99b3c79681c8440cbfe77e078260018c5161269d91906133bd565b815181106126ad576126ad6133d0565b60200260200101516040516126c491815260200190565b60405180910390a2505b5050505050505050505050565b60015460ff16156105e25760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015260640161063d565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052612773908490612a32565b505050565b6000611ee98383612b07565b6000611ee98383612b56565b600180546001600160a01b03838116610100818102610100600160a81b031985161790945560405193909204169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6127f5600782612b80565b506000818152600660205260408120818155906128156001830182612e74565b506002810180546001600160a01b0319169055600060038201819055600482018190556005820181905560068201805461ffff191690556007820181905560089091015550565b6128646126db565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25833611f9d565b6000611ee98284613526565b6000805b8215611723576128b8600a84613504565b9250806128c4816135ba565b9150506128a7565b60015460ff166105e25760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015260640161063d565b600260009054906101000a90046001600160a01b03166001600160a01b031663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa158015612968573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061298c9190613539565b6001600160a01b0316826001600160a01b031603612a1d576000816001600160a01b03168460405160006040518083038185875af1925050503d80600081146129f1576040519150601f19603f3d011682016040523d82523d6000602084013e6129f6565b606091505b5050905080612a175760405162461bcd60e51b815260040161063d90613556565b50505050565b81612a176001600160a01b0382168386612721565b6000612a87826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612b8c9092919063ffffffff16565b9050805160001480612aa8575080806020019051810190612aa89190613598565b6127735760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161063d565b6000818152600183016020526040812054612b4e57508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155611723565b506000611723565b6000826000018281548110612b6d57612b6d6133d0565b9060005260206000200154905092915050565b6000611ee98383612ba3565b6060612b9b8484600085612c96565b949350505050565b60008181526001830160205260408120548015612c8c576000612bc76001836133bd565b8554909150600090612bdb906001906133bd565b9050818114612c40576000866000018281548110612bfb57612bfb6133d0565b9060005260206000200154905080876000018481548110612c1e57612c1e6133d0565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080612c5157612c51613674565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050611723565b6000915050611723565b606082471015612cf75760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161063d565b600080866001600160a01b03168587604051612d13919061368a565b60006040518083038185875af1925050503d8060008114612d50576040519150601f19603f3d011682016040523d82523d6000602084013e612d55565b606091505b5091509150612d6687838387612d71565b979650505050505050565b60608315612de0578251600003612dd9576001600160a01b0385163b612dd95760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161063d565b5081612b9b565b612b9b8383815115612df55781518083602001fd5b8060405162461bcd60e51b815260040161063d91906136a6565b828054828255906000526020600020908101928215612e64579160200282015b82811115612e6457825182546001600160a01b0319166001600160a01b03909116178255602090920191600190910190612e2f565b50612e70929150612e8e565b5090565b5080546000825590600052602060002090810190611a8691905b5b80821115612e705760008155600101612e8f565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715612ee257612ee2612ea3565b604052919050565b600067ffffffffffffffff821115612f0457612f04612ea3565b5060051b60200190565b6001600160a01b0381168114611a8657600080fd5b60008060408385031215612f3657600080fd5b8235915060208084013567ffffffffffffffff811115612f5557600080fd5b8401601f81018613612f6657600080fd5b8035612f79612f7482612eea565b612eb9565b81815260059190911b82018301908381019088831115612f9857600080fd5b928401925b82841015612fbf578335612fb081612f0e565b82529284019290840190612f9d565b80955050505050509250929050565b60008060208385031215612fe157600080fd5b823567ffffffffffffffff80821115612ff957600080fd5b818501915085601f83011261300d57600080fd5b81358181111561301c57600080fd5b86602082850101111561302e57600080fd5b60209290920196919550909350505050565b803560ff8116811461305157600080fd5b919050565b600082601f83011261306757600080fd5b81356020613077612f7483612eea565b82815260059290921b8401810191818101908684111561309657600080fd5b8286015b848110156130b1578035835291830191830161309a565b509695505050505050565b60008060008060008060a087890312156130d557600080fd5b86359550602087013567ffffffffffffffff808211156130f457600080fd5b818901915089601f83011261310857600080fd5b81358181111561311757600080fd5b8a60208260051b850101111561312c57600080fd5b60208301975095506040890135945061314760608a01613040565b9350608089013591508082111561315d57600080fd5b5061316a89828a01613056565b9150509295509295509295565b60006020828403121561318957600080fd5b5035919050565b600081518084526020808501945080840160005b838110156131c95781516001600160a01b0316875295820195908201906001016131a4565b509495945050505050565b6020815281516020820152600060208301516101408060408501526131fd610160850183613190565b9150604085015161321960608601826001600160a01b03169052565b5060608501516080850152608085015160a085015260a085015160c085015260c085015161324c60e086018260ff169052565b5060e08501516101006132638187018360ff169052565b860151610120868101919091529095015193019290925250919050565b60006020828403121561329257600080fd5b8135611ee981612f0e565b60005b838110156132b85781810151838201526020016132a0565b50506000910152565b600081518084526132d981602086016020860161329d565b601f01601f19169290920160200192915050565b8215158152604060208201526000612b9b60408301846132c1565b828152604060208201526000612b9b6040830184613190565b6000602080838503121561333457600080fd5b825167ffffffffffffffff81111561334b57600080fd5b8301601f8101851361335c57600080fd5b805161336a612f7482612eea565b81815260059190911b8201830190838101908783111561338957600080fd5b928401925b82841015612d665783518252928401929084019061338e565b634e487b7160e01b600052601160045260246000fd5b81810381811115611723576117236133a7565b634e487b7160e01b600052603260045260246000fd5b600181815b80851115613421578160001904821115613407576134076133a7565b8085161561341457918102915b93841c93908002906133eb565b509250929050565b60008261343857506001611723565b8161344557506000611723565b816001811461345b576002811461346557613481565b6001915050611723565b60ff841115613476576134766133a7565b50506001821b611723565b5060208310610133831016604e8410600b84101617156134a4575081810a611723565b6134ae83836133e6565b80600019048211156134c2576134c26133a7565b029392505050565b6000611ee98383613429565b60208082526014908201527313dc99195c88191bd95cc81b9bdd08195e1a5cdd60621b604082015260600190565b60008261352157634e487b7160e01b600052601260045260246000fd5b500490565b80820180821115611723576117236133a7565b60006020828403121561354b57600080fd5b8151611ee981612f0e565b6020808252600f908201526e151c985b9cd9995c8819985a5b1959608a1b604082015260600190565b60006020828403121561359157600080fd5b5051919050565b6000602082840312156135aa57600080fd5b81518015158114611ee957600080fd5b6000600182016135cc576135cc6133a7565b5060010190565b8082028115828204841417611723576117236133a7565b8481526080602082015260006136036080830186613190565b6001600160a01b03949094166040830152506060015292915050565b60ff8281168282160390811115611723576117236133a7565b85815284602082015260a06040820152600061365760a0830186613190565b6001600160a01b0394909416606083015250608001529392505050565b634e487b7160e01b600052603160045260246000fd5b6000825161369c81846020870161329d565b9190910192915050565b602081526000611ee960208301846132c156fea264697066735822122090bb0747faf01df36c9ce80f3b393bc98d7e8b153a3ca48e7ad16e99e8d070ea64736f6c63430008130033