- Contract name:
- ShopAP
- Optimization enabled
- true
- Compiler version
- v0.8.2+commit.661d1103
- Optimization runs
- 999999
- Verified at
- 2023-12-22 04:30:06.561520Z
contracts/ShopAP.sol
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
import "./libraries/TransferHelper.sol";
import "@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/utils/ERC721HolderUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "./abtracts/OwnerOperator.sol";
contract ShopAP is ERC721HolderUpgradeable, OwnerOperator {
using CountersUpgradeable for CountersUpgradeable.Counter;
using SafeMathUpgradeable for uint256;
event CreateSellOrder(
uint256 _orderId,
address _seller,
uint256 _tokenId,
uint256 _price,
uint256 _adminFee,
address _currency,
address _tokenAddress,
string _type
);
event Buy(
uint256 _orderId,
address _buyer,
address seller,
uint256 _tokenId,
uint256 _price,
uint256 _adminFee,
address _currency,
address _tokenAddress
);
event CancelSellOrder(
uint256 _orderId,
address _seller,
uint256 _tokenId,
uint256 _price,
address _currency,
address _tokenAddress
);
event UpdateSellOrder(
uint256 _orderId,
address _seller,
uint256 _tokenId,
uint256 _oldPrice,
uint256 _newPrice,
address _currency,
address _tokenAddress
);
event AdminStatics(
address _tokenAddress,
uint256 _tokenId,
string _nameToken,
address _adminAddr,
uint256 _fee,
uint256 revenue
);
event BuyMerah(uint256 _orderId, address _seller, uint256 _tokenId);
struct Order {
address tokenAddress;
uint256 tokenId;
address owner;
uint256 price;
address currency;
string sellType;
}
struct SavedData {
address owner;
uint256 tokenId;
}
// orderID => order
mapping(uint256 => Order) public orders;
CountersUpgradeable.Counter private _orderIdCounter;
// addmin
address private _adminAddress;
// creator
// contract address => tokenId => Creator
mapping(address => address) private _creatorOf;
mapping(address => mapping(uint256 => uint256)) public isSellings;
// percent fee of admin and creator
uint256 private _adminFee;
uint256 private _creatorFee;
uint256[] sellingIds;
mapping(address => bool) public tokenAddresses;
mapping(address => bool) public currencyAddresses;
mapping(address => mapping(uint256 => SavedData)) public sellDatas;
mapping(address => mapping(uint256 => SavedData)) public buyDatas;
mapping(address => mapping(uint256 => SavedData)) public cancelDatas;
uint256 public decimal;
// orderID => AdminFee
mapping(uint256 => uint256) public adminFees;
function setTokenAddress(address _tokenaddress, bool _boolean) public onlyOperator {
tokenAddresses[_tokenaddress] = _boolean;
}
function setCurrencyAddress(address _currencyaddress, bool _boolean) public onlyOperator {
currencyAddresses[_currencyaddress] = _boolean;
}
function checkTokenAddress(address _tokenaddress) public view returns (bool) {
return tokenAddresses[_tokenaddress];
}
function checkCurrencyAddress(address _currencyaddress) public view returns (bool) {
return currencyAddresses[_currencyaddress];
}
function getAdminAdress() external view returns (address) {
return _adminAddress;
}
function getAdminFee() external view returns (uint256) {
return _adminFee;
}
function sell(
address _tokenAddress,
uint256 _tokenId,
uint256 _price,
address _currency,
string memory _type
) public returns (uint256 orderId) {
require(msg.sender == IERC721Upgradeable(_tokenAddress).ownerOf(_tokenId), "You are not the owner of NFT");
require(
checkTokenAddress(_tokenAddress) && checkCurrencyAddress(_currency),
"Your Token or Currency is not allowed"
);
require(
keccak256(abi.encodePacked((_type))) == keccak256(abi.encodePacked(("adil"))) ||
keccak256(abi.encodePacked((_type))) == keccak256(abi.encodePacked(("merah"))),
"Type of sell invalid"
);
// create order
_orderIdCounter.increment();
orderId = _orderIdCounter.current();
Order memory order = Order(_tokenAddress, _tokenId, msg.sender, _price, _currency, _type);
orders[orderId] = order;
adminFees[orderId] = _adminFee;
sellDatas[_tokenAddress][orderId] = SavedData({owner: msg.sender, tokenId: _tokenId});
IERC721Upgradeable(_tokenAddress).safeTransferFrom(msg.sender, address(this), _tokenId);
isSellings[_tokenAddress][_tokenId] = orderId;
sellingIds.push(_tokenId);
emit CreateSellOrder(
orderId,
order.owner,
order.tokenId,
order.price,
_adminFee,
order.currency,
order.tokenAddress,
_type
);
}
function sellBatch(
address _tokenAddress,
uint256[] memory tokenIds,
uint256 _price,
address _currency,
string memory _type
) public {
for (uint256 i = 0; i < tokenIds.length; i++) {
sell(_tokenAddress, tokenIds[i], _price, _currency, _type);
}
}
function buyUsingMERAH(address _TokenAddress, address _adddressTo, uint256 _TokenId) public onlyOperator {
uint256 _orderId = isSellings[_TokenAddress][_TokenId];
require(_orderId != 0, "OrderId does not exist");
IERC721Upgradeable(_TokenAddress).safeTransferFrom(address(this), _adddressTo, _TokenId);
buyDatas[_TokenAddress][_orderId] = SavedData({owner: _adddressTo, tokenId: _TokenId});
delete isSellings[_TokenAddress][_TokenId];
delete orders[_orderId];
emit BuyMerah(_orderId, _adddressTo, _TokenId);
}
function checktoken(address _tokenAddress, uint256 _tokenId) external view returns (uint256) {
return isSellings[_tokenAddress][_tokenId];
}
function buyNative(uint256 _orderId) external payable {
// check order status
require(orders[_orderId].owner != address(0), "Order does not exist or is deleted");
require(msg.value == orders[_orderId].price, "Buyer did not send correct ADIL amount");
require(
orders[_orderId].currency == address(0),
"Order requires being paid by erc20 currency, use buy() instead"
);
require(_adminAddress != address(0), "AdminFee is Unused or Mising AdminAddress");
require(
checkTokenAddress(orders[_orderId].tokenAddress) && checkCurrencyAddress(orders[_orderId].currency),
"Your Token or Currency is not allowed"
);
uint256 adminFee = 0;
uint256 currentAdminFee = adminFees[_orderId];
if (currentAdminFee != 0) {
adminFee = orders[_orderId].price.mul(currentAdminFee).div(decimal).div(100);
TransferHelper.safeTransferETH(_adminAddress, adminFee);
emit AdminStatics(
orders[_orderId].tokenAddress,
orders[_orderId].tokenId,
"ADIL",
_adminAddress,
_adminFee,
adminFee
);
}
buyDatas[orders[_orderId].tokenAddress][_orderId] = SavedData({
owner: msg.sender,
tokenId: orders[_orderId].tokenId
});
TransferHelper.safeTransferETH(orders[_orderId].owner, orders[_orderId].price - adminFee);
IERC721Upgradeable(orders[_orderId].tokenAddress).safeTransferFrom(
address(this),
msg.sender,
orders[_orderId].tokenId
);
emit Buy(
_orderId,
msg.sender,
orders[_orderId].owner,
orders[_orderId].tokenId,
orders[_orderId].price,
currentAdminFee,
orders[_orderId].currency,
orders[_orderId].tokenAddress
);
delete isSellings[orders[_orderId].tokenAddress][orders[_orderId].tokenId];
delete orders[_orderId];
}
function cancelSell(uint256 _orderId, address _tokenAddress) public {
require(orders[_orderId].owner != address(0), "Order does not exist");
require(orders[_orderId].owner == msg.sender, "Msg sender is not order 's owner");
require(
checkTokenAddress(orders[_orderId].tokenAddress) && checkCurrencyAddress(orders[_orderId].currency),
"Your Token or Currency is not allowed"
);
cancelDatas[orders[_orderId].tokenAddress][_orderId] = SavedData({
owner: msg.sender,
tokenId: orders[_orderId].tokenId
});
IERC721Upgradeable(_tokenAddress).safeTransferFrom(address(this), msg.sender, orders[_orderId].tokenId);
emit CancelSellOrder(
_orderId,
orders[_orderId].owner,
orders[_orderId].tokenId,
orders[_orderId].price,
orders[_orderId].currency,
orders[_orderId].tokenAddress
);
delete isSellings[orders[_orderId].tokenAddress][orders[_orderId].tokenId];
delete orders[_orderId];
}
function cancelSellBatch(address _tokenAddress, uint256[] memory _orderIds) public {
for (uint256 i = 0; i < _orderIds.length; i++) {
cancelSell(_orderIds[i], _tokenAddress);
}
}
// set address of admin
function setAdminAddress(address _admin) external onlyOperator {
_adminAddress = _admin;
}
// set admin fee
function setAdminFee(uint256 _fee) external onlyOperator {
_adminFee = _fee;
}
function updateOrder(uint256 _orderId, uint256 _newPrice) external {
require(orders[_orderId].owner != address(0), "Order does not exist");
require(orders[_orderId].owner == msg.sender, "Msg sender is not order 's owner");
require(
checkTokenAddress(orders[_orderId].tokenAddress) && checkCurrencyAddress(orders[_orderId].currency),
"Your Token or Currency is not allowed"
);
uint256 oldPrice = orders[_orderId].price;
orders[_orderId].price = _newPrice;
emit UpdateSellOrder(
_orderId,
orders[_orderId].owner,
orders[_orderId].tokenId,
oldPrice,
orders[_orderId].price,
orders[_orderId].currency,
orders[_orderId].tokenAddress
);
}
function setDecimal(uint256 _decimal) public onlyOperator {
decimal = _decimal;
}
}
@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
function __Ownable_init() internal onlyInitializing {
__Ownable_init_unchained();
}
function __Ownable_init_unchained() internal onlyInitializing {
_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);
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}
@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: setting the version to 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized != type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}
@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20Upgradeable.sol";
import "./extensions/IERC20MetadataUpgradeable.sol";
import "../../utils/ContextUpgradeable.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing {
__ERC20_init_unchained(name_, symbol_);
}
function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(address from, address to, uint256 amount) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
// Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
// Overflow not possible: amount <= accountBalance <= totalSupply.
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[45] private __gap;
}
@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.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 IERC20Upgradeable {
/**
* @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-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20Upgradeable.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20MetadataUpgradeable is IERC20Upgradeable {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
@openzeppelin/contracts-upgradeable/token/ERC721/IERC721ReceiverUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721ReceiverUpgradeable {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165Upgradeable.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721Upgradeable is IERC165Upgradeable {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
@openzeppelin/contracts-upgradeable/token/ERC721/utils/ERC721HolderUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/utils/ERC721Holder.sol)
pragma solidity ^0.8.0;
import "../IERC721ReceiverUpgradeable.sol";
import {Initializable} from "../../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the {IERC721Receiver} interface.
*
* Accepts all token transfers.
* Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or {IERC721-setApprovalForAll}.
*/
contract ERC721HolderUpgradeable is Initializable, IERC721ReceiverUpgradeable {
function __ERC721Holder_init() internal onlyInitializing {
}
function __ERC721Holder_init_unchained() internal onlyInitializing {
}
/**
* @dev See {IERC721Receiver-onERC721Received}.
*
* Always returns `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(address, address, uint256, bytes memory) public virtual override returns (bytes4) {
return this.onERC721Received.selector;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}
@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.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 AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* 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-upgradeable/utils/ContextUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)
pragma solidity ^0.8.0;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}
@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)
pragma solidity ^0.8.0;
/**
* @title Counters
* @author Matt Condon (@shrugs)
* @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
* of elements in a mapping, issuing ERC721 ids, or counting request ids.
*
* Include with `using Counters for Counters.Counter;`
*/
library CountersUpgradeable {
struct Counter {
// This variable should never be directly accessed by users of the library: interactions must be restricted to
// the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
// this feature: see https://github.com/ethereum/solidity/issues/4637
uint256 _value; // default: 0
}
function current(Counter storage counter) internal view returns (uint256) {
return counter._value;
}
function increment(Counter storage counter) internal {
unchecked {
counter._value += 1;
}
}
function decrement(Counter storage counter) internal {
uint256 value = counter._value;
require(value > 0, "Counter: decrement overflow");
unchecked {
counter._value = value - 1;
}
}
function reset(Counter storage counter) internal {
counter._value = 0;
}
}
@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165Upgradeable {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.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 SafeMathUpgradeable {
/**
* @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;
}
}
}
contracts/abtracts/OwnerOperator.sol
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
abstract contract OwnerOperator is OwnableUpgradeable {
mapping(address => bool) public operators;
function initialize() public initializer {
__Context_init_unchained();
__Ownable_init_unchained();
}
modifier operatorOrOwner() {
require(operators[msg.sender] || owner() == msg.sender, "OwnerOperator: !operator, !owner");
_;
}
modifier onlyOperator() {
require(operators[msg.sender], "OwnerOperator: !operator");
_;
}
function addOperator(address operator) external virtual onlyOwner {
require(operator != address(0), "OwnerOperator: operator is the zero address");
operators[operator] = true;
}
function removeOperator(address operator) external virtual onlyOwner {
require(operator != address(0), "OwnerOperator: operator is the zero address");
operators[operator] = false;
}
}
contracts/libraries/TransferHelper.sol
//SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;
// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
library TransferHelper {
function safeApprove(address token, address to, uint256 value) internal {
// bytes4(keccak256(bytes('approve(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
"TransferHelper::safeApprove: approve failed"
);
}
function safeTransfer(address token, address to, uint256 value) internal {
// bytes4(keccak256(bytes('transfer(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
"TransferHelper::safeTransfer: transfer failed"
);
}
function safeTransferFrom(address token, address from, address to, uint256 value) internal {
// bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
"TransferHelper::transferFrom: transferFrom failed"
);
}
function safeTransferETH(address to, uint256 value) internal {
(bool success, ) = to.call{value: value}(new bytes(0));
require(success, "TransferHelper::safeTransferETH: ETH transfer failed");
}
}
Contract ABI
[{"type":"event","name":"AdminStatics","inputs":[{"type":"address","name":"_tokenAddress","internalType":"address","indexed":false},{"type":"uint256","name":"_tokenId","internalType":"uint256","indexed":false},{"type":"string","name":"_nameToken","internalType":"string","indexed":false},{"type":"address","name":"_adminAddr","internalType":"address","indexed":false},{"type":"uint256","name":"_fee","internalType":"uint256","indexed":false},{"type":"uint256","name":"revenue","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"Buy","inputs":[{"type":"uint256","name":"_orderId","internalType":"uint256","indexed":false},{"type":"address","name":"_buyer","internalType":"address","indexed":false},{"type":"address","name":"seller","internalType":"address","indexed":false},{"type":"uint256","name":"_tokenId","internalType":"uint256","indexed":false},{"type":"uint256","name":"_price","internalType":"uint256","indexed":false},{"type":"uint256","name":"_adminFee","internalType":"uint256","indexed":false},{"type":"address","name":"_currency","internalType":"address","indexed":false},{"type":"address","name":"_tokenAddress","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"BuyMerah","inputs":[{"type":"uint256","name":"_orderId","internalType":"uint256","indexed":false},{"type":"address","name":"_seller","internalType":"address","indexed":false},{"type":"uint256","name":"_tokenId","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"CancelSellOrder","inputs":[{"type":"uint256","name":"_orderId","internalType":"uint256","indexed":false},{"type":"address","name":"_seller","internalType":"address","indexed":false},{"type":"uint256","name":"_tokenId","internalType":"uint256","indexed":false},{"type":"uint256","name":"_price","internalType":"uint256","indexed":false},{"type":"address","name":"_currency","internalType":"address","indexed":false},{"type":"address","name":"_tokenAddress","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"CreateSellOrder","inputs":[{"type":"uint256","name":"_orderId","internalType":"uint256","indexed":false},{"type":"address","name":"_seller","internalType":"address","indexed":false},{"type":"uint256","name":"_tokenId","internalType":"uint256","indexed":false},{"type":"uint256","name":"_price","internalType":"uint256","indexed":false},{"type":"uint256","name":"_adminFee","internalType":"uint256","indexed":false},{"type":"address","name":"_currency","internalType":"address","indexed":false},{"type":"address","name":"_tokenAddress","internalType":"address","indexed":false},{"type":"string","name":"_type","internalType":"string","indexed":false}],"anonymous":false},{"type":"event","name":"Initialized","inputs":[{"type":"uint8","name":"version","internalType":"uint8","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":"UpdateSellOrder","inputs":[{"type":"uint256","name":"_orderId","internalType":"uint256","indexed":false},{"type":"address","name":"_seller","internalType":"address","indexed":false},{"type":"uint256","name":"_tokenId","internalType":"uint256","indexed":false},{"type":"uint256","name":"_oldPrice","internalType":"uint256","indexed":false},{"type":"uint256","name":"_newPrice","internalType":"uint256","indexed":false},{"type":"address","name":"_currency","internalType":"address","indexed":false},{"type":"address","name":"_tokenAddress","internalType":"address","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addOperator","inputs":[{"type":"address","name":"operator","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"adminFees","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"owner","internalType":"address"},{"type":"uint256","name":"tokenId","internalType":"uint256"}],"name":"buyDatas","inputs":[{"type":"address","name":"","internalType":"address"},{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"buyNative","inputs":[{"type":"uint256","name":"_orderId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"buyUsingMERAH","inputs":[{"type":"address","name":"_TokenAddress","internalType":"address"},{"type":"address","name":"_adddressTo","internalType":"address"},{"type":"uint256","name":"_TokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"owner","internalType":"address"},{"type":"uint256","name":"tokenId","internalType":"uint256"}],"name":"cancelDatas","inputs":[{"type":"address","name":"","internalType":"address"},{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"cancelSell","inputs":[{"type":"uint256","name":"_orderId","internalType":"uint256"},{"type":"address","name":"_tokenAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"cancelSellBatch","inputs":[{"type":"address","name":"_tokenAddress","internalType":"address"},{"type":"uint256[]","name":"_orderIds","internalType":"uint256[]"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"checkCurrencyAddress","inputs":[{"type":"address","name":"_currencyaddress","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"checkTokenAddress","inputs":[{"type":"address","name":"_tokenaddress","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"checktoken","inputs":[{"type":"address","name":"_tokenAddress","internalType":"address"},{"type":"uint256","name":"_tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"currencyAddresses","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"decimal","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"getAdminAdress","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getAdminFee","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"isSellings","inputs":[{"type":"address","name":"","internalType":"address"},{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bytes4","name":"","internalType":"bytes4"}],"name":"onERC721Received","inputs":[{"type":"address","name":"","internalType":"address"},{"type":"address","name":"","internalType":"address"},{"type":"uint256","name":"","internalType":"uint256"},{"type":"bytes","name":"","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"operators","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"tokenAddress","internalType":"address"},{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"address","name":"owner","internalType":"address"},{"type":"uint256","name":"price","internalType":"uint256"},{"type":"address","name":"currency","internalType":"address"},{"type":"string","name":"sellType","internalType":"string"}],"name":"orders","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removeOperator","inputs":[{"type":"address","name":"operator","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"orderId","internalType":"uint256"}],"name":"sell","inputs":[{"type":"address","name":"_tokenAddress","internalType":"address"},{"type":"uint256","name":"_tokenId","internalType":"uint256"},{"type":"uint256","name":"_price","internalType":"uint256"},{"type":"address","name":"_currency","internalType":"address"},{"type":"string","name":"_type","internalType":"string"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"sellBatch","inputs":[{"type":"address","name":"_tokenAddress","internalType":"address"},{"type":"uint256[]","name":"tokenIds","internalType":"uint256[]"},{"type":"uint256","name":"_price","internalType":"uint256"},{"type":"address","name":"_currency","internalType":"address"},{"type":"string","name":"_type","internalType":"string"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"owner","internalType":"address"},{"type":"uint256","name":"tokenId","internalType":"uint256"}],"name":"sellDatas","inputs":[{"type":"address","name":"","internalType":"address"},{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setAdminAddress","inputs":[{"type":"address","name":"_admin","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setAdminFee","inputs":[{"type":"uint256","name":"_fee","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setCurrencyAddress","inputs":[{"type":"address","name":"_currencyaddress","internalType":"address"},{"type":"bool","name":"_boolean","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setDecimal","inputs":[{"type":"uint256","name":"_decimal","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setTokenAddress","inputs":[{"type":"address","name":"_tokenaddress","internalType":"address"},{"type":"bool","name":"_boolean","internalType":"bool"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"tokenAddresses","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateOrder","inputs":[{"type":"uint256","name":"_orderId","internalType":"uint256"},{"type":"uint256","name":"_newPrice","internalType":"uint256"}]}]
Deployed ByteCode
0x6080604052600436106102195760003560e01c80639870d7fe1161011d578063b6ea8d51116100b0578063d99c224f1161007f578063eab0b07f11610064578063eab0b07f146107f2578063eb909bbc1461084a578063f2fde38b1461086a57610219565b8063d99c224f14610762578063da7c6a46146107ba57610219565b8063b6ea8d51146106e2578063b90a866314610702578063ba45b7191461072f578063d148d23b1461074257610219565b8063ac8a584a116100ec578063ac8a584a14610652578063adbfdd7014610672578063b502daeb14610692578063b6d3385e146106b257610219565b80639870d7fe1461059a5780639c78aee8146105ba5780639f1a156c146105da578063a85c38ef1461062057610219565b80634a66b3df116101b057806376809ce31161017f5780638beb60b6116101645780638beb60b6146104cb5780638da5cb5b146104eb5780638ee2592e1461051657610219565b806376809ce3146104a05780638129fc1c146104b657610219565b80634a66b3df146103d5578063587b71a61461041b578063715018a61461043b578063722b60291461045057610219565b80632c1e816d116101ec5780632c1e816d146103195780632ee15214146103395780633ef7fec7146103695780634931bb92146103b557610219565b806313e7c9d81461021e578063150b7a02146102635780632a0b5e9e146102d85780632a905ccc146102fa575b600080fd5b34801561022a57600080fd5b5061024e610239366004612ea1565b60976020526000908152604090205460ff1681565b60405190151581526020015b60405180910390f35b34801561026f57600080fd5b506102a761027e366004612f19565b7f150b7a0200000000000000000000000000000000000000000000000000000000949350505050565b6040517fffffffff00000000000000000000000000000000000000000000000000000000909116815260200161025a565b3480156102e457600080fd5b506102f86102f3366004613076565b61088a565b005b34801561030657600080fd5b50609d545b60405190815260200161025a565b34801561032557600080fd5b506102f8610334366004612ea1565b61095e565b34801561034557600080fd5b5061024e610354366004612ea1565b60a16020526000908152604090205460ff1681565b34801561037557600080fd5b50609a5473ffffffffffffffffffffffffffffffffffffffff165b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200161025a565b3480156103c157600080fd5b506102f86103d0366004612ed9565b610a1e565b3480156103e157600080fd5b5061024e6103f0366004612ea1565b73ffffffffffffffffffffffffffffffffffffffff16600090815260a1602052604090205460ff1690565b34801561042757600080fd5b506102f8610436366004613180565b610ce8565b34801561044757600080fd5b506102f8610fab565b34801561045c57600080fd5b5061030b61046b3660046130b2565b73ffffffffffffffffffffffffffffffffffffffff919091166000908152609c60209081526040808320938352929052205490565b3480156104ac57600080fd5b5061030b60a55481565b3480156104c257600080fd5b506102f8610fbf565b3480156104d757600080fd5b506102f86104e6366004613144565b611159565b3480156104f757600080fd5b5060655473ffffffffffffffffffffffffffffffffffffffff16610390565b34801561052257600080fd5b5061056e6105313660046130b2565b60a36020908152600092835260408084209091529082529020805460019091015473ffffffffffffffffffffffffffffffffffffffff9091169082565b6040805173ffffffffffffffffffffffffffffffffffffffff909316835260208301919091520161025a565b3480156105a657600080fd5b506102f86105b5366004612ea1565b6111d7565b3480156105c657600080fd5b506102f86105d5366004612fe4565b6112d1565b3480156105e657600080fd5b5061024e6105f5366004612ea1565b73ffffffffffffffffffffffffffffffffffffffff16600090815260a0602052604090205460ff1690565b34801561062c57600080fd5b5061064061063b366004613144565b611345565b60405161025a96959493929190613207565b34801561065e57600080fd5b506102f861066d366004612ea1565b611421565b34801561067e57600080fd5b506102f861068d36600461315c565b611518565b34801561069e57600080fd5b5061030b6106ad3660046130dd565b611975565b3480156106be57600080fd5b5061024e6106cd366004612ea1565b60a06020526000908152604090205460ff1681565b3480156106ee57600080fd5b506102f86106fd366004613076565b611f81565b34801561070e57600080fd5b5061030b61071d366004613144565b60a66020526000908152604090205481565b6102f861073d366004613144565b612050565b34801561074e57600080fd5b506102f861075d366004612f96565b6127be565b34801561076e57600080fd5b5061056e61077d3660046130b2565b60a46020908152600092835260408084209091529082529020805460019091015473ffffffffffffffffffffffffffffffffffffffff9091169082565b3480156107c657600080fd5b5061030b6107d53660046130b2565b609c60209081526000928352604080842090915290825290205481565b3480156107fe57600080fd5b5061056e61080d3660046130b2565b60a26020908152600092835260408084209091529082529020805460019091015473ffffffffffffffffffffffffffffffffffffffff9091169082565b34801561085657600080fd5b506102f8610865366004613144565b61282b565b34801561087657600080fd5b506102f8610885366004612ea1565b6128a9565b3360009081526097602052604090205460ff16610908576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f4f776e65724f70657261746f723a20216f70657261746f72000000000000000060448201526064015b60405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff91909116600090815260a06020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016911515919091179055565b3360009081526097602052604090205460ff166109d7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f4f776e65724f70657261746f723a20216f70657261746f72000000000000000060448201526064016108ff565b609a80547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b3360009081526097602052604090205460ff16610a97576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f4f776e65724f70657261746f723a20216f70657261746f72000000000000000060448201526064016108ff565b73ffffffffffffffffffffffffffffffffffffffff83166000908152609c6020908152604080832084845290915290205480610b2f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4f72646572496420646f6573206e6f742065786973740000000000000000000060448201526064016108ff565b6040517f42842e0e00000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff8481166024830152604482018490528516906342842e0e90606401600060405180830381600087803b158015610ba557600080fd5b505af1158015610bb9573d6000803e3d6000fd5b505060408051808201825273ffffffffffffffffffffffffffffffffffffffff808816825260208083018881528a8316600081815260a384528681208a825284528681209551865495167fffffffffffffffffffffffff000000000000000000000000000000000000000095861617865591516001958601558152609c8252848120898252825284812081905587815260989091529283208054821681559182018390556002820180548216905560038201839055600482018054909116905592509050610c8a6005830182612cb5565b50506040805182815273ffffffffffffffffffffffffffffffffffffffff851660208201529081018390527f52cfeab2ceb43f5cf9b807db258b7bc20b9783500d7850a411bbe518224739a99060600160405180910390a150505050565b60008281526098602052604090206002015473ffffffffffffffffffffffffffffffffffffffff16610d76576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f4f7264657220646f6573206e6f7420657869737400000000000000000000000060448201526064016108ff565b60008281526098602052604090206002015473ffffffffffffffffffffffffffffffffffffffff163314610e06576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4d73672073656e646572206973206e6f74206f72646572202773206f776e657260448201526064016108ff565b60008281526098602090815260408083205473ffffffffffffffffffffffffffffffffffffffff16835260a090915290205460ff168015610e7b575060008281526098602090815260408083206004015473ffffffffffffffffffffffffffffffffffffffff16835260a190915290205460ff165b610f07576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602560248201527f596f757220546f6b656e206f722043757272656e6379206973206e6f7420616c60448201527f6c6f77656400000000000000000000000000000000000000000000000000000060648201526084016108ff565b600082815260986020908152604091829020600381018054908590556002820154600183015460048401549354865189815273ffffffffffffffffffffffffffffffffffffffff9384169681019690965295850152606084018290526080840186905291821660a0840152921660c08201527f6d1b2d95d9b5089c8adae070090fd2dde13c784e7ba3b57ef219dce142cc52709060e00160405180910390a1505050565b610fb361295d565b610fbd60006129de565b565b600054610100900460ff1615808015610fdf5750600054600160ff909116105b80610ff95750303b158015610ff9575060005460ff166001145b611085576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a656400000000000000000000000000000000000060648201526084016108ff565b600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600117905580156110e357600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff166101001790555b6110eb612a55565b6110f3612aec565b801561115657600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50565b3360009081526097602052604090205460ff166111d2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f4f776e65724f70657261746f723a20216f70657261746f72000000000000000060448201526064016108ff565b609d55565b6111df61295d565b73ffffffffffffffffffffffffffffffffffffffff8116611282576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f4f776e65724f70657261746f723a206f70657261746f7220697320746865207a60448201527f65726f206164647265737300000000000000000000000000000000000000000060648201526084016108ff565b73ffffffffffffffffffffffffffffffffffffffff16600090815260976020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055565b60005b845181101561133d5761132a8686838151811061131a577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6020026020010151868686611975565b508061133581613425565b9150506112d4565b505050505050565b60986020526000908152604090208054600182015460028301546003840154600485015460058601805473ffffffffffffffffffffffffffffffffffffffff968716979596948516959394909216929161139e906133d1565b80601f01602080910402602001604051908101604052809291908181526020018280546113ca906133d1565b80156114175780601f106113ec57610100808354040283529160200191611417565b820191906000526020600020905b8154815290600101906020018083116113fa57829003601f168201915b5050505050905086565b61142961295d565b73ffffffffffffffffffffffffffffffffffffffff81166114cc576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f4f776e65724f70657261746f723a206f70657261746f7220697320746865207a60448201527f65726f206164647265737300000000000000000000000000000000000000000060648201526084016108ff565b73ffffffffffffffffffffffffffffffffffffffff16600090815260976020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169055565b60008281526098602052604090206002015473ffffffffffffffffffffffffffffffffffffffff166115a6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f4f7264657220646f6573206e6f7420657869737400000000000000000000000060448201526064016108ff565b60008281526098602052604090206002015473ffffffffffffffffffffffffffffffffffffffff163314611636576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4d73672073656e646572206973206e6f74206f72646572202773206f776e657260448201526064016108ff565b60008281526098602090815260408083205473ffffffffffffffffffffffffffffffffffffffff16835260a090915290205460ff1680156116ab575060008281526098602090815260408083206004015473ffffffffffffffffffffffffffffffffffffffff16835260a190915290205460ff165b611737576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602560248201527f596f757220546f6b656e206f722043757272656e6379206973206e6f7420616c60448201527f6c6f77656400000000000000000000000000000000000000000000000000000060648201526084016108ff565b6040805180820182523380825260008581526098602081815285832060018082018054848901908152925473ffffffffffffffffffffffffffffffffffffffff908116875260a485528987208c8852855295899020975188547fffffffffffffffffffffffff000000000000000000000000000000000000000016908716178855915196019590955552915492517f42842e0e000000000000000000000000000000000000000000000000000000008152306004820152602481019190915260448101929092528216906342842e0e90606401600060405180830381600087803b15801561182457600080fd5b505af1158015611838573d6000803e3d6000fd5b5050506000838152609860209081526040918290206002810154600182015460038301546004840154935486518a815273ffffffffffffffffffffffffffffffffffffffff9485169681019690965285870192909252606085015291811660808401521660a082015290517fa2b96082ec456d01f350420a13d8bb79e3c1b9db557aa581c27ba50c58b8b50692509081900360c00190a16000828152609860208181526040808420805473ffffffffffffffffffffffffffffffffffffffff168552609c835281852060018201805487529084529185208590558685529290915281547fffffffffffffffffffffffff0000000000000000000000000000000000000000908116835590839055600282018054821690556003820183905560048201805490911690559061196f6005830182612cb5565b50505050565b6040517f6352211e0000000000000000000000000000000000000000000000000000000081526004810185905260009073ffffffffffffffffffffffffffffffffffffffff871690636352211e9060240160206040518083038186803b1580156119de57600080fd5b505afa1580156119f2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a169190612ebd565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614611aaa576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f596f7520617265206e6f7420746865206f776e6572206f66204e46540000000060448201526064016108ff565b73ffffffffffffffffffffffffffffffffffffffff8616600090815260a0602052604090205460ff168015611b04575073ffffffffffffffffffffffffffffffffffffffff8316600090815260a1602052604090205460ff165b611b90576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602560248201527f596f757220546f6b656e206f722043757272656e6379206973206e6f7420616c60448201527f6c6f77656400000000000000000000000000000000000000000000000000000060648201526084016108ff565b6040517f6164696c0000000000000000000000000000000000000000000000000000000060208201526024016040516020818303038152906040528051906020012082604051602001611be391906131eb565b604051602081830303815290604052805190602001201480611c6b57506040517f6d6572616800000000000000000000000000000000000000000000000000000060208201526025016040516020818303038152906040528051906020012082604051602001611c5391906131eb565b60405160208183030381529060405280519060200120145b611cd1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f54797065206f662073656c6c20696e76616c696400000000000000000000000060448201526064016108ff565b611cdf609980546001019055565b506099546040805160c08101825273ffffffffffffffffffffffffffffffffffffffff8881168252602080830189815233848601908152606085018a81528985166080870190815260a087018a815260008a81526098875298909820875181547fffffffffffffffffffffffff00000000000000000000000000000000000000009081169189169190911782559451600182015592516002840180548616918816919091179055905160038301555160048201805490931694169390931790559251805192938493611db79260058501920190612cf1565b5050609d54600084815260a6602090815260408083209390935582518084018452338082528183018c815273ffffffffffffffffffffffffffffffffffffffff8e811680875260a286528787208b885290955294869020925183547fffffffffffffffffffffffff0000000000000000000000000000000000000000169516949094178255925160019091015591517f42842e0e0000000000000000000000000000000000000000000000000000000081526004810191909152306024820152604481018990529091506342842e0e90606401600060405180830381600087803b158015611ea457600080fd5b505af1158015611eb8573d6000803e3d6000fd5b50505073ffffffffffffffffffffffffffffffffffffffff88166000908152609c602090815260408083208a84528252808320869055609f805460018101825593527f0bc14066c33013fe88f66e314e4cf150b0b2d4d6451a1a51dbbd1c27cd11de2890920189905583820151908401516060850151609d546080870151875195517feca15604e218289d749d34ecd2add3a59dded24f6a59ec9231c31109f1dd958e9750611f6f968a9695949392918c90613260565b60405180910390a15095945050505050565b3360009081526097602052604090205460ff16611ffa576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f4f776e65724f70657261746f723a20216f70657261746f72000000000000000060448201526064016108ff565b73ffffffffffffffffffffffffffffffffffffffff91909116600090815260a16020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016911515919091179055565b60008181526098602052604090206002015473ffffffffffffffffffffffffffffffffffffffff16612104576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602260248201527f4f7264657220646f6573206e6f74206578697374206f722069732064656c657460448201527f656400000000000000000000000000000000000000000000000000000000000060648201526084016108ff565b60008181526098602052604090206003015434146121a4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f427579657220646964206e6f742073656e6420636f7272656374204144494c2060448201527f616d6f756e74000000000000000000000000000000000000000000000000000060648201526084016108ff565b60008181526098602052604090206004015473ffffffffffffffffffffffffffffffffffffffff1615612259576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603e60248201527f4f72646572207265717569726573206265696e6720706169642062792065726360448201527f32302063757272656e63792c2075736520627579282920696e7374656164000060648201526084016108ff565b609a5473ffffffffffffffffffffffffffffffffffffffff166122fe576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602960248201527f41646d696e46656520697320556e75736564206f72204d6973696e672041646d60448201527f696e41646472657373000000000000000000000000000000000000000000000060648201526084016108ff565b60008181526098602090815260408083205473ffffffffffffffffffffffffffffffffffffffff16835260a090915290205460ff168015612373575060008181526098602090815260408083206004015473ffffffffffffffffffffffffffffffffffffffff16835260a190915290205460ff165b6123ff576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602560248201527f596f757220546f6b656e206f722043757272656e6379206973206e6f7420616c60448201527f6c6f77656400000000000000000000000000000000000000000000000000000060648201526084016108ff565b600081815260a6602052604081205480156125235760a5546000848152609860205260409020600301546124439160649161243d9190829086612b8c565b90612b9f565b609a549092506124699073ffffffffffffffffffffffffffffffffffffffff1683612bab565b6000838152609860209081526040918290208054600190910154609a54609d54855173ffffffffffffffffffffffffffffffffffffffff94851681529485019290925260c08486018190526004908501527f4144494c0000000000000000000000000000000000000000000000000000000060e0850152919091166060830152608082015260a0810184905290517f592b02a0b072e4346a94c8e0b35c4c5c58c88ee0cb2af8c562f9acf50ebf2dd9918190036101000190a15b604080518082018252338152600085815260986020818152848320600180820154838701908152825473ffffffffffffffffffffffffffffffffffffffff908116875260a385528887208c8852855297909520955186547fffffffffffffffffffffffff0000000000000000000000000000000000000000169088161786559351949093019390935590915260028101546003909101546125d39291909116906125ce90859061338e565b612bab565b60008381526098602052604090819020805460019091015491517f42842e0e000000000000000000000000000000000000000000000000000000008152306004820152336024820152604481019290925273ffffffffffffffffffffffffffffffffffffffff16906342842e0e90606401600060405180830381600087803b15801561265e57600080fd5b505af1158015612672573d6000803e3d6000fd5b5050506000848152609860209081526040918290206002810154600182015460038301546004840154935486518b8152339681019690965273ffffffffffffffffffffffffffffffffffffffff938416868801526060860192909252608085015260a0840187905291811660c08401521660e082015290517fe8b4a16b6f1e28e361a64b7ba73894ae53d38fb0cc7153cd42eafcd51bf7a39e9250908190036101000190a16000838152609860208181526040808420805473ffffffffffffffffffffffffffffffffffffffff168552609c835281852060018201805487529084529185208590558785529290915281547fffffffffffffffffffffffff000000000000000000000000000000000000000090811683559083905560028201805482169055600382018390556004820180549091169055906127b76005830182612cb5565b5050505050565b60005b815181101561282657612814828281518110612806577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001015184611518565b8061281e81613425565b9150506127c1565b505050565b3360009081526097602052604090205460ff166128a4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f4f776e65724f70657261746f723a20216f70657261746f72000000000000000060448201526064016108ff565b60a555565b6128b161295d565b73ffffffffffffffffffffffffffffffffffffffff8116612954576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f646472657373000000000000000000000000000000000000000000000000000060648201526084016108ff565b611156816129de565b60655473ffffffffffffffffffffffffffffffffffffffff163314610fbd576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016108ff565b6065805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600054610100900460ff16610fbd576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e6700000000000000000000000000000000000000000060648201526084016108ff565b600054610100900460ff16612b83576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e6700000000000000000000000000000000000000000060648201526084016108ff565b610fbd336129de565b6000612b988284613351565b9392505050565b6000612b988284613318565b6040805160008082526020820190925273ffffffffffffffffffffffffffffffffffffffff8416908390604051612be291906131eb565b60006040518083038185875af1925050503d8060008114612c1f576040519150601f19603f3d011682016040523d82523d6000602084013e612c24565b606091505b5050905080612826576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603460248201527f5472616e7366657248656c7065723a3a736166655472616e736665724554483a60448201527f20455448207472616e73666572206661696c656400000000000000000000000060648201526084016108ff565b508054612cc1906133d1565b6000825580601f10612cd35750611156565b601f0160209004906000526020600020908101906111569190612d75565b828054612cfd906133d1565b90600052602060002090601f016020900481019282612d1f5760008555612d65565b82601f10612d3857805160ff1916838001178555612d65565b82800160010185558215612d65579182015b82811115612d65578251825591602001919060010190612d4a565b50612d71929150612d75565b5090565b5b80821115612d715760008155600101612d76565b600067ffffffffffffffff831115612da457612da461348d565b612dd560207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f860116016132c9565b9050828152838383011115612de957600080fd5b828260208301376000602084830101529392505050565b600082601f830112612e10578081fd5b8135602067ffffffffffffffff821115612e2c57612e2c61348d565b808202612e3a8282016132c9565b838152828101908684018388018501891015612e54578687fd5b8693505b85841015612e76578035835260019390930192918401918401612e58565b50979650505050505050565b600082601f830112612e92578081fd5b612b9883833560208501612d8a565b600060208284031215612eb2578081fd5b8135612b98816134bc565b600060208284031215612ece578081fd5b8151612b98816134bc565b600080600060608486031215612eed578182fd5b8335612ef8816134bc565b92506020840135612f08816134bc565b929592945050506040919091013590565b60008060008060808587031215612f2e578081fd5b8435612f39816134bc565b93506020850135612f49816134bc565b925060408501359150606085013567ffffffffffffffff811115612f6b578182fd5b8501601f81018713612f7b578182fd5b612f8a87823560208401612d8a565b91505092959194509250565b60008060408385031215612fa8578182fd5b8235612fb3816134bc565b9150602083013567ffffffffffffffff811115612fce578182fd5b612fda85828601612e00565b9150509250929050565b600080600080600060a08688031215612ffb578081fd5b8535613006816134bc565b9450602086013567ffffffffffffffff80821115613022578283fd5b61302e89838a01612e00565b95506040880135945060608801359150613047826134bc565b9092506080870135908082111561305c578283fd5b5061306988828901612e82565b9150509295509295909350565b60008060408385031215613088578182fd5b8235613093816134bc565b9150602083013580151581146130a7578182fd5b809150509250929050565b600080604083850312156130c4578182fd5b82356130cf816134bc565b946020939093013593505050565b600080600080600060a086880312156130f4578081fd5b85356130ff816134bc565b94506020860135935060408601359250606086013561311d816134bc565b9150608086013567ffffffffffffffff811115613138578182fd5b61306988828901612e82565b600060208284031215613155578081fd5b5035919050565b6000806040838503121561316e578182fd5b8235915060208301356130a7816134bc565b60008060408385031215613192578182fd5b50508035926020909101359150565b600081518084526131b98160208601602086016133a5565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b600082516131fd8184602087016133a5565b9190910192915050565b600073ffffffffffffffffffffffffffffffffffffffff8089168352876020840152808716604084015285606084015280851660808401525060c060a083015261325460c08301846131a1565b98975050505050505050565b60006101008a835273ffffffffffffffffffffffffffffffffffffffff808b16602085015289604085015288606085015287608085015280871660a085015280861660c0850152508060e08401526132ba818401856131a1565b9b9a5050505050505050505050565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff811182821017156133105761331061348d565b604052919050565b60008261334c577f4e487b710000000000000000000000000000000000000000000000000000000081526012600452602481fd5b500490565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04831182151516156133895761338961345e565b500290565b6000828210156133a0576133a061345e565b500390565b60005b838110156133c05781810151838201526020016133a8565b8381111561196f5750506000910152565b6002810460018216806133e557607f821691505b6020821081141561341f577f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b50919050565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156134575761345761345e565b5060010190565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b73ffffffffffffffffffffffffffffffffffffffff8116811461115657600080fdfea2646970667358221220d08d5c67934894e62825163593ac8811b6afdf0ac4cee86f13b1f6e896ba754264736f6c63430008020033