Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- Homunculi
- Optimization enabled
- true
- Compiler version
- v0.8.24+commit.e11b9ed9
- Optimization runs
- 200
- EVM Version
- paris
- Verified at
- 2024-11-19T18:12:39.519174Z
contracts/Homunculi.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/Base64.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "./lib/Pausable.sol";
contract Homunculi is
Initializable,
ERC721Upgradeable,
ERC721EnumerableUpgradeable,
Pausable
{
/*========================= STRUCTS =========================*/
struct NftDetails {
string name;
uint64 royalties;
uint64 tier;
string mediaType;
string collectionHash;
string[] tags;
}
/*========================= CONTRACT STATE =========================*/
bytes32 private constant EXPERIENCE_TYPEHASH =
keccak256(
"Experience(uint256 tokenId,uint256 newExperience,uint256 timestamp)"
);
address private signerAddress;
bytes32 private DOMAIN_SEPARATOR;
// Reserved storage slots for future upgrades
uint256[10] private __gap;
mapping(string => NftDetails) public nftDetails;
mapping(string => uint256) public idLastMintedIndex;
mapping(string => uint256) public maximumSupply;
mapping(string => uint256) public mintPrice;
mapping(uint256 => uint256) public experience;
mapping(uint256 => string) private _tokenIdToNftId;
mapping(uint256 => uint256) private _tokenIdToNftIndex;
mapping(uint256 => uint256) private _tokenIdToAssetIndex;
mapping(string => mapping(uint256 => uint256)) private _availableAssets;
/*============================ EVENTS ============================*/
event NFTMinted(address indexed to, uint256 tokenId, string id);
event ExperienceUpdated(
uint256 tokenId,
uint256 oldExperience,
uint256 newExperience
);
/*========================= PUBLIC API ===========================*/
function initialize() public initializer {
__ERC721_init("MPHomunculi", "MPHOM");
__Pausable_init();
__Homunculi__init_unchained();
}
function __Homunculi__init_unchained() internal onlyInitializing {
signerAddress = address(0);
DOMAIN_SEPARATOR = keccak256(
abi.encode(
keccak256(
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
),
keccak256(bytes("MPHomunculi")),
keccak256(bytes("1")),
block.chainid,
address(this)
)
);
}
function supportsInterface(
bytes4 interfaceId
)
public
view
override(ERC721Upgradeable, ERC721EnumerableUpgradeable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
function tokenURI(
uint256 _tokenId
) public view override(ERC721Upgradeable) returns (string memory) {
require(_ownerOf(_tokenId) != address(0), "Token does not exist");
string memory id = _tokenIdToNftId[_tokenId];
uint256 index = _tokenIdToNftIndex[_tokenId];
NftDetails memory details = nftDetails[id];
string memory name = string.concat(
details.name,
" #",
Strings.toString(index)
);
string memory image = string.concat(
"ipfs://",
details.collectionHash,
"/",
id,
"/",
Strings.toString(_tokenIdToAssetIndex[_tokenId]),
".",
details.mediaType
);
// Create the JSON metadata string
string memory json = Base64.encode(
bytes(
string.concat('{"name": "', name, '", "image": "', image, '"}')
)
);
return string(abi.encodePacked("data:application/json;base64,", json));
}
function setNftDetails(
string memory id,
string memory name,
string memory collectionHash,
string[] memory tags,
string memory mediaType,
uint256 maxLen,
uint64 royalties,
uint64 tier
) public onlyAdmin {
require(
bytes(nftDetails[id].name).length == 0,
"NFT details already set for this ID"
);
nftDetails[id] = NftDetails({
name: name,
royalties: royalties,
tier: tier,
mediaType: mediaType,
collectionHash: collectionHash,
tags: tags
});
idLastMintedIndex[id] = 0;
maximumSupply[id] = maxLen;
}
function updateNftDetails(
string memory id,
string memory name,
string memory collectionHash,
string[] memory tags,
string memory mediaType,
uint64 royalties,
uint64 tier
) public onlyAdmin {
require(
bytes(nftDetails[id].name).length > 0,
"NFT details not set for this ID"
);
nftDetails[id] = NftDetails({
name: name,
royalties: royalties,
tier: tier,
mediaType: mediaType,
collectionHash: collectionHash,
tags: tags
});
}
function getTags(string memory id) public view returns (string[] memory) {
return nftDetails[id].tags;
}
function setMintPrice(string memory id, uint256 price) public onlyAdmin {
require(
bytes(nftDetails[id].name).length > 0,
"NFT details not set for this ID"
);
mintPrice[id] = price;
}
function mint(string memory id) public payable whenNotPaused {
require(mintPrice[id] > 0, "Mint price not set for this ID");
require(
msg.value == mintPrice[id],
"Insufficient funds to mint this NFT"
);
_mintNft(id, msg.sender);
}
function freeMint(string memory id, address to) public onlyAdmin {
_mintNft(id, to);
}
function withdraw() public onlyAdmin {
payable(admin()).transfer(address(this).balance);
}
function setSignerAddress(address _signerAddress) public onlyAdmin {
signerAddress = _signerAddress;
}
function updateExperience(
uint256 tokenId,
uint256 newExperience,
uint256 timestamp,
bytes memory signature
) public whenNotPaused {
require(_ownerOf(tokenId) != address(0), "Token does not exist");
require(_ownerOf(tokenId) == msg.sender, "Not the owner of this token");
require(signerAddress != address(0), "Signer address not set");
require(timestamp >= block.timestamp - 120, "Invalid timestamp");
require(timestamp <= block.timestamp + 1500, "Signature expired");
uint256 oldExperience = experience[tokenId];
require(
newExperience > experience[tokenId],
"New experience is not greater than old experience"
);
bytes32 structHash = keccak256(
abi.encode(EXPERIENCE_TYPEHASH, tokenId, newExperience, timestamp)
);
bytes32 digest = keccak256(
abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR, structHash)
);
address recoveredAddress = ECDSA.recover(digest, signature);
require(recoveredAddress == signerAddress, "Invalid signature");
experience[tokenId] = newExperience;
emit ExperienceUpdated(tokenId, oldExperience, newExperience);
}
/*========================= PRIVATE API =========================*/
/**
* @dev See {ERC721-_beforeTokenTransfer}.
*/
function _increaseBalance(
address account,
uint128 value
)
internal
virtual
override(ERC721Upgradeable, ERC721EnumerableUpgradeable)
{
super._increaseBalance(account, value);
}
/**
* @dev See {ERC721-_beforeTokenTransfer}.
*/
function _update(
address to,
uint256 tokenId,
address auth
)
internal
virtual
override(ERC721Upgradeable, ERC721EnumerableUpgradeable)
returns (address)
{
return super._update(to, tokenId, auth);
}
function _useRandomAvailableAsset(
string memory id
) internal returns (uint256) {
uint256 randomNum = uint256(
keccak256(
abi.encode(
msg.sender,
tx.gasprice,
block.number,
block.timestamp,
blockhash(block.number - 1),
id
)
)
);
uint256 numAvailableTokens = maximumSupply[id] - idLastMintedIndex[id];
uint256 randomIndex = randomNum % numAvailableTokens;
return _useAvailableTokenAtIndex(id, randomIndex, numAvailableTokens);
}
function _useAvailableTokenAtIndex(
string memory id,
uint256 indexToUse,
uint256 numAvailableTokens
) internal returns (uint256) {
uint256 valAtIndex = _availableAssets[id][indexToUse];
uint256 result;
if (valAtIndex == 0) {
// This means the index itself is still an available token
result = indexToUse;
} else {
// This means the index itself is not an available token, but the val at that index is.
result = valAtIndex;
}
uint256 lastIndex = numAvailableTokens - 1;
if (indexToUse != lastIndex) {
// Replace the value at indexToUse, now that it's been used.
// Replace it with the data from the last index in the array, since we are going to decrease the array size afterwards.
uint256 lastValInArray = _availableAssets[id][lastIndex];
if (lastValInArray == 0) {
// This means the index itself is still an available token
_availableAssets[id][indexToUse] = lastIndex;
} else {
// This means the index itself is not an available token, but the val at that index is.
_availableAssets[id][indexToUse] = lastValInArray;
}
}
return result;
}
function _mintNft(string memory id, address to) internal {
require(
bytes(nftDetails[id].name).length > 0,
"NFT details not set for this ID"
);
require(
idLastMintedIndex[id] < maximumSupply[id],
"No more NFTs available to mint for this ID"
);
uint256 assetIndex = _useRandomAvailableAsset(id);
uint256 tokenId = totalSupply() + 1;
_safeMint(to, tokenId);
experience[tokenId] = 0;
idLastMintedIndex[id]++;
_tokenIdToNftId[tokenId] = id;
_tokenIdToAssetIndex[tokenId] = assetIndex;
_tokenIdToNftIndex[tokenId] = idLastMintedIndex[id];
emit NFTMinted(to, tokenId, id);
}
}
@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.20;
/**
* @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 Storage of the initializable contract.
*
* It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
* when using with upgradeable contracts.
*
* @custom:storage-location erc7201:openzeppelin.storage.Initializable
*/
struct InitializableStorage {
/**
* @dev Indicates that the contract has been initialized.
*/
uint64 _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool _initializing;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
/**
* @dev The contract is already initialized.
*/
error InvalidInitialization();
/**
* @dev The contract is not initializing.
*/
error NotInitializing();
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint64 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 in the context of a constructor an `initializer` may be invoked any
* number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
* production.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
// Cache values to avoid duplicated sloads
bool isTopLevelCall = !$._initializing;
uint64 initialized = $._initialized;
// Allowed calls:
// - initialSetup: the contract is not in the initializing state and no previous version was
// initialized
// - construction: the contract is initialized at version 1 (no reininitialization) and the
// current contract is just being deployed
bool initialSetup = initialized == 0 && isTopLevelCall;
bool construction = initialized == 1 && address(this).code.length == 0;
if (!initialSetup && !construction) {
revert InvalidInitialization();
}
$._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 2**64 - 1 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint64 version) {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing || $._initialized >= version) {
revert InvalidInitialization();
}
$._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() {
_checkInitializing();
_;
}
/**
* @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
*/
function _checkInitializing() internal view virtual {
if (!_isInitializing()) {
revert NotInitializing();
}
}
/**
* @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 {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing) {
revert InvalidInitialization();
}
if ($._initialized != type(uint64).max) {
$._initialized = type(uint64).max;
emit Initialized(type(uint64).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint64) {
return _getInitializableStorage()._initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _getInitializableStorage()._initializing;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
assembly {
$.slot := INITIALIZABLE_STORAGE
}
}
}
@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/ERC721.sol)
pragma solidity ^0.8.20;
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import {IERC721Metadata} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
import {ContextUpgradeable} from "../../utils/ContextUpgradeable.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {ERC165Upgradeable} from "../../utils/introspection/ERC165Upgradeable.sol";
import {IERC721Errors} from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
abstract contract ERC721Upgradeable is Initializable, ContextUpgradeable, ERC165Upgradeable, IERC721, IERC721Metadata, IERC721Errors {
using Strings for uint256;
/// @custom:storage-location erc7201:openzeppelin.storage.ERC721
struct ERC721Storage {
// Token name
string _name;
// Token symbol
string _symbol;
mapping(uint256 tokenId => address) _owners;
mapping(address owner => uint256) _balances;
mapping(uint256 tokenId => address) _tokenApprovals;
mapping(address owner => mapping(address operator => bool)) _operatorApprovals;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ERC721")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant ERC721StorageLocation = 0x80bb2b638cc20bc4d0a60d66940f3ab4a00c1d7b313497ca82fb0b4ab0079300;
function _getERC721Storage() private pure returns (ERC721Storage storage $) {
assembly {
$.slot := ERC721StorageLocation
}
}
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
function __ERC721_init(string memory name_, string memory symbol_) internal onlyInitializing {
__ERC721_init_unchained(name_, symbol_);
}
function __ERC721_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {
ERC721Storage storage $ = _getERC721Storage();
$._name = name_;
$._symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165Upgradeable, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual returns (uint256) {
ERC721Storage storage $ = _getERC721Storage();
if (owner == address(0)) {
revert ERC721InvalidOwner(address(0));
}
return $._balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual returns (address) {
return _requireOwned(tokenId);
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual returns (string memory) {
ERC721Storage storage $ = _getERC721Storage();
return $._name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual returns (string memory) {
ERC721Storage storage $ = _getERC721Storage();
return $._symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual returns (string memory) {
_requireOwned(tokenId);
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string.concat(baseURI, tokenId.toString()) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overridden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual {
_approve(to, tokenId, _msgSender());
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual returns (address) {
_requireOwned(tokenId);
return _getApproved(tokenId);
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual returns (bool) {
ERC721Storage storage $ = _getERC721Storage();
return $._operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(address from, address to, uint256 tokenId) public virtual {
if (to == address(0)) {
revert ERC721InvalidReceiver(address(0));
}
// Setting an "auth" arguments enables the `_isAuthorized` check which verifies that the token exists
// (from != 0). Therefore, it is not needed to verify that the return value is not 0 here.
address previousOwner = _update(to, tokenId, _msgSender());
if (previousOwner != from) {
revert ERC721IncorrectOwner(from, tokenId, previousOwner);
}
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual {
transferFrom(from, to, tokenId);
_checkOnERC721Received(from, to, tokenId, data);
}
/**
* @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist
*
* IMPORTANT: Any overrides to this function that add ownership of tokens not tracked by the
* core ERC721 logic MUST be matched with the use of {_increaseBalance} to keep balances
* consistent with ownership. The invariant to preserve is that for any address `a` the value returned by
* `balanceOf(a)` must be equal to the number of tokens such that `_ownerOf(tokenId)` is `a`.
*/
function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
ERC721Storage storage $ = _getERC721Storage();
return $._owners[tokenId];
}
/**
* @dev Returns the approved address for `tokenId`. Returns 0 if `tokenId` is not minted.
*/
function _getApproved(uint256 tokenId) internal view virtual returns (address) {
ERC721Storage storage $ = _getERC721Storage();
return $._tokenApprovals[tokenId];
}
/**
* @dev Returns whether `spender` is allowed to manage `owner`'s tokens, or `tokenId` in
* particular (ignoring whether it is owned by `owner`).
*
* WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this
* assumption.
*/
function _isAuthorized(address owner, address spender, uint256 tokenId) internal view virtual returns (bool) {
return
spender != address(0) &&
(owner == spender || isApprovedForAll(owner, spender) || _getApproved(tokenId) == spender);
}
/**
* @dev Checks if `spender` can operate on `tokenId`, assuming the provided `owner` is the actual owner.
* Reverts if `spender` does not have approval from the provided `owner` for the given token or for all its assets
* the `spender` for the specific `tokenId`.
*
* WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this
* assumption.
*/
function _checkAuthorized(address owner, address spender, uint256 tokenId) internal view virtual {
if (!_isAuthorized(owner, spender, tokenId)) {
if (owner == address(0)) {
revert ERC721NonexistentToken(tokenId);
} else {
revert ERC721InsufficientApproval(spender, tokenId);
}
}
}
/**
* @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override.
*
* NOTE: the value is limited to type(uint128).max. This protect against _balance overflow. It is unrealistic that
* a uint256 would ever overflow from increments when these increments are bounded to uint128 values.
*
* WARNING: Increasing an account's balance using this function tends to be paired with an override of the
* {_ownerOf} function to resolve the ownership of the corresponding tokens so that balances and ownership
* remain consistent with one another.
*/
function _increaseBalance(address account, uint128 value) internal virtual {
ERC721Storage storage $ = _getERC721Storage();
unchecked {
$._balances[account] += value;
}
}
/**
* @dev Transfers `tokenId` from its current owner to `to`, or alternatively mints (or burns) if the current owner
* (or `to`) is the zero address. Returns the owner of the `tokenId` before the update.
*
* The `auth` argument is optional. If the value passed is non 0, then this function will check that
* `auth` is either the owner of the token, or approved to operate on the token (by the owner).
*
* Emits a {Transfer} event.
*
* NOTE: If overriding this function in a way that tracks balances, see also {_increaseBalance}.
*/
function _update(address to, uint256 tokenId, address auth) internal virtual returns (address) {
ERC721Storage storage $ = _getERC721Storage();
address from = _ownerOf(tokenId);
// Perform (optional) operator check
if (auth != address(0)) {
_checkAuthorized(from, auth, tokenId);
}
// Execute the update
if (from != address(0)) {
// Clear approval. No need to re-authorize or emit the Approval event
_approve(address(0), tokenId, address(0), false);
unchecked {
$._balances[from] -= 1;
}
}
if (to != address(0)) {
unchecked {
$._balances[to] += 1;
}
}
$._owners[tokenId] = to;
emit Transfer(from, to, tokenId);
return from;
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal {
if (to == address(0)) {
revert ERC721InvalidReceiver(address(0));
}
address previousOwner = _update(to, tokenId, address(0));
if (previousOwner != address(0)) {
revert ERC721InvalidSender(address(0));
}
}
/**
* @dev Mints `tokenId`, transfers it to `to` and checks for `to` acceptance.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(address to, uint256 tokenId, bytes memory data) internal virtual {
_mint(to, tokenId);
_checkOnERC721Received(address(0), to, tokenId, data);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
* This is an internal function that does not check if the sender is authorized to operate on the token.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal {
address previousOwner = _update(address(0), tokenId, address(0));
if (previousOwner == address(0)) {
revert ERC721NonexistentToken(tokenId);
}
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(address from, address to, uint256 tokenId) internal {
if (to == address(0)) {
revert ERC721InvalidReceiver(address(0));
}
address previousOwner = _update(to, tokenId, address(0));
if (previousOwner == address(0)) {
revert ERC721NonexistentToken(tokenId);
} else if (previousOwner != from) {
revert ERC721IncorrectOwner(from, tokenId, previousOwner);
}
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking that contract recipients
* are aware of the ERC721 standard to prevent tokens from being forever locked.
*
* `data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is like {safeTransferFrom} in the sense that it invokes
* {IERC721Receiver-onERC721Received} on the receiver, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `tokenId` token must exist and be owned by `from`.
* - `to` cannot be the zero address.
* - `from` cannot be the zero address.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(address from, address to, uint256 tokenId) internal {
_safeTransfer(from, to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeTransfer-address-address-uint256-}[`_safeTransfer`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual {
_transfer(from, to, tokenId);
_checkOnERC721Received(from, to, tokenId, data);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* The `auth` argument is optional. If the value passed is non 0, then this function will check that `auth` is
* either the owner of the token, or approved to operate on all tokens held by this owner.
*
* Emits an {Approval} event.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address to, uint256 tokenId, address auth) internal {
_approve(to, tokenId, auth, true);
}
/**
* @dev Variant of `_approve` with an optional flag to enable or disable the {Approval} event. The event is not
* emitted in the context of transfers.
*/
function _approve(address to, uint256 tokenId, address auth, bool emitEvent) internal virtual {
ERC721Storage storage $ = _getERC721Storage();
// Avoid reading the owner unless necessary
if (emitEvent || auth != address(0)) {
address owner = _requireOwned(tokenId);
// We do not use _isAuthorized because single-token approvals should not be able to call approve
if (auth != address(0) && owner != auth && !isApprovedForAll(owner, auth)) {
revert ERC721InvalidApprover(auth);
}
if (emitEvent) {
emit Approval(owner, to, tokenId);
}
}
$._tokenApprovals[tokenId] = to;
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Requirements:
* - operator can't be the address zero.
*
* Emits an {ApprovalForAll} event.
*/
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
ERC721Storage storage $ = _getERC721Storage();
if (operator == address(0)) {
revert ERC721InvalidOperator(operator);
}
$._operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Reverts if the `tokenId` doesn't have a current owner (it hasn't been minted, or it has been burned).
* Returns the owner.
*
* Overrides to ownership logic should be done to {_ownerOf}.
*/
function _requireOwned(uint256 tokenId) internal view returns (address) {
address owner = _ownerOf(tokenId);
if (owner == address(0)) {
revert ERC721NonexistentToken(tokenId);
}
return owner;
}
/**
* @dev Private function to invoke {IERC721Receiver-onERC721Received} on a target address. This will revert if the
* recipient doesn't accept the token transfer. The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param data bytes optional data to send along with the call
*/
function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory data) private {
if (to.code.length > 0) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
if (retval != IERC721Receiver.onERC721Received.selector) {
revert ERC721InvalidReceiver(to);
}
} catch (bytes memory reason) {
if (reason.length == 0) {
revert ERC721InvalidReceiver(to);
} else {
/// @solidity memory-safe-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
}
}
}
@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/ERC721Enumerable.sol)
pragma solidity ^0.8.20;
import {ERC721Upgradeable} from "../ERC721Upgradeable.sol";
import {IERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {Initializable} from "../../../proxy/utils/Initializable.sol";
/**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds enumerability
* of all the token ids in the contract as well as all token ids owned by each account.
*
* CAUTION: `ERC721` extensions that implement custom `balanceOf` logic, such as `ERC721Consecutive`,
* interfere with enumerability and should not be used together with `ERC721Enumerable`.
*/
abstract contract ERC721EnumerableUpgradeable is Initializable, ERC721Upgradeable, IERC721Enumerable {
/// @custom:storage-location erc7201:openzeppelin.storage.ERC721Enumerable
struct ERC721EnumerableStorage {
mapping(address owner => mapping(uint256 index => uint256)) _ownedTokens;
mapping(uint256 tokenId => uint256) _ownedTokensIndex;
uint256[] _allTokens;
mapping(uint256 tokenId => uint256) _allTokensIndex;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ERC721Enumerable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant ERC721EnumerableStorageLocation = 0x645e039705490088daad89bae25049a34f4a9072d398537b1ab2425f24cbed00;
function _getERC721EnumerableStorage() private pure returns (ERC721EnumerableStorage storage $) {
assembly {
$.slot := ERC721EnumerableStorageLocation
}
}
/**
* @dev An `owner`'s token query was out of bounds for `index`.
*
* NOTE: The owner being `address(0)` indicates a global out of bounds index.
*/
error ERC721OutOfBoundsIndex(address owner, uint256 index);
/**
* @dev Batch mint is not allowed.
*/
error ERC721EnumerableForbiddenBatchMint();
function __ERC721Enumerable_init() internal onlyInitializing {
}
function __ERC721Enumerable_init_unchained() internal onlyInitializing {
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721Upgradeable) returns (bool) {
return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual returns (uint256) {
ERC721EnumerableStorage storage $ = _getERC721EnumerableStorage();
if (index >= balanceOf(owner)) {
revert ERC721OutOfBoundsIndex(owner, index);
}
return $._ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual returns (uint256) {
ERC721EnumerableStorage storage $ = _getERC721EnumerableStorage();
return $._allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index) public view virtual returns (uint256) {
ERC721EnumerableStorage storage $ = _getERC721EnumerableStorage();
if (index >= totalSupply()) {
revert ERC721OutOfBoundsIndex(address(0), index);
}
return $._allTokens[index];
}
/**
* @dev See {ERC721-_update}.
*/
function _update(address to, uint256 tokenId, address auth) internal virtual override returns (address) {
address previousOwner = super._update(to, tokenId, auth);
if (previousOwner == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (previousOwner != to) {
_removeTokenFromOwnerEnumeration(previousOwner, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (previousOwner != to) {
_addTokenToOwnerEnumeration(to, tokenId);
}
return previousOwner;
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
ERC721EnumerableStorage storage $ = _getERC721EnumerableStorage();
uint256 length = balanceOf(to) - 1;
$._ownedTokens[to][length] = tokenId;
$._ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
ERC721EnumerableStorage storage $ = _getERC721EnumerableStorage();
$._allTokensIndex[tokenId] = $._allTokens.length;
$._allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
ERC721EnumerableStorage storage $ = _getERC721EnumerableStorage();
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = balanceOf(from);
uint256 tokenIndex = $._ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = $._ownedTokens[from][lastTokenIndex];
$._ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
$._ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete $._ownedTokensIndex[tokenId];
delete $._ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
ERC721EnumerableStorage storage $ = _getERC721EnumerableStorage();
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = $._allTokens.length - 1;
uint256 tokenIndex = $._allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = $._allTokens[lastTokenIndex];
$._allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
$._allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete $._allTokensIndex[tokenId];
$._allTokens.pop();
}
/**
* See {ERC721-_increaseBalance}. We need that to account tokens that were minted in batch
*/
function _increaseBalance(address account, uint128 amount) internal virtual override {
if (amount > 0) {
revert ERC721EnumerableForbiddenBatchMint();
}
super._increaseBalance(account, amount);
}
}
@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
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;
}
}
@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165Upgradeable is Initializable, IERC165 {
function __ERC165_init() internal onlyInitializing {
}
function __ERC165_init_unchained() internal onlyInitializing {
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
@openzeppelin/contracts/interfaces/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";
@openzeppelin/contracts/interfaces/IERC4906.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC4906.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
import {IERC721} from "./IERC721.sol";
/// @title EIP-721 Metadata Update Extension
interface IERC4906 is IERC165, IERC721 {
/// @dev This event emits when the metadata of a token is changed.
/// So that the third-party platforms such as NFT market could
/// timely update the images and related attributes of the NFT.
event MetadataUpdate(uint256 _tokenId);
/// @dev This event emits when the metadata of a range of tokens is changed.
/// So that the third-party platforms such as NFT market could
/// timely update the images and related attributes of the NFTs.
event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId);
}
@openzeppelin/contracts/interfaces/IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC721.sol)
pragma solidity ^0.8.20;
import {IERC721} from "../token/ERC721/IERC721.sol";
@openzeppelin/contracts/interfaces/draft-IERC6093.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}
@openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` 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 value) external returns (bool);
}
@openzeppelin/contracts/token/ERC721/ERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/ERC721.sol)
pragma solidity ^0.8.20;
import {IERC721} from "./IERC721.sol";
import {IERC721Receiver} from "./IERC721Receiver.sol";
import {IERC721Metadata} from "./extensions/IERC721Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {Strings} from "../../utils/Strings.sol";
import {IERC165, ERC165} from "../../utils/introspection/ERC165.sol";
import {IERC721Errors} from "../../interfaces/draft-IERC6093.sol";
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Errors {
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
mapping(uint256 tokenId => address) private _owners;
mapping(address owner => uint256) private _balances;
mapping(uint256 tokenId => address) private _tokenApprovals;
mapping(address owner => mapping(address operator => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual returns (uint256) {
if (owner == address(0)) {
revert ERC721InvalidOwner(address(0));
}
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual returns (address) {
return _requireOwned(tokenId);
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual returns (string memory) {
_requireOwned(tokenId);
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string.concat(baseURI, tokenId.toString()) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overridden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual {
_approve(to, tokenId, _msgSender());
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual returns (address) {
_requireOwned(tokenId);
return _getApproved(tokenId);
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(address from, address to, uint256 tokenId) public virtual {
if (to == address(0)) {
revert ERC721InvalidReceiver(address(0));
}
// Setting an "auth" arguments enables the `_isAuthorized` check which verifies that the token exists
// (from != 0). Therefore, it is not needed to verify that the return value is not 0 here.
address previousOwner = _update(to, tokenId, _msgSender());
if (previousOwner != from) {
revert ERC721IncorrectOwner(from, tokenId, previousOwner);
}
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual {
transferFrom(from, to, tokenId);
_checkOnERC721Received(from, to, tokenId, data);
}
/**
* @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist
*
* IMPORTANT: Any overrides to this function that add ownership of tokens not tracked by the
* core ERC721 logic MUST be matched with the use of {_increaseBalance} to keep balances
* consistent with ownership. The invariant to preserve is that for any address `a` the value returned by
* `balanceOf(a)` must be equal to the number of tokens such that `_ownerOf(tokenId)` is `a`.
*/
function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
return _owners[tokenId];
}
/**
* @dev Returns the approved address for `tokenId`. Returns 0 if `tokenId` is not minted.
*/
function _getApproved(uint256 tokenId) internal view virtual returns (address) {
return _tokenApprovals[tokenId];
}
/**
* @dev Returns whether `spender` is allowed to manage `owner`'s tokens, or `tokenId` in
* particular (ignoring whether it is owned by `owner`).
*
* WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this
* assumption.
*/
function _isAuthorized(address owner, address spender, uint256 tokenId) internal view virtual returns (bool) {
return
spender != address(0) &&
(owner == spender || isApprovedForAll(owner, spender) || _getApproved(tokenId) == spender);
}
/**
* @dev Checks if `spender` can operate on `tokenId`, assuming the provided `owner` is the actual owner.
* Reverts if `spender` does not have approval from the provided `owner` for the given token or for all its assets
* the `spender` for the specific `tokenId`.
*
* WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this
* assumption.
*/
function _checkAuthorized(address owner, address spender, uint256 tokenId) internal view virtual {
if (!_isAuthorized(owner, spender, tokenId)) {
if (owner == address(0)) {
revert ERC721NonexistentToken(tokenId);
} else {
revert ERC721InsufficientApproval(spender, tokenId);
}
}
}
/**
* @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override.
*
* NOTE: the value is limited to type(uint128).max. This protect against _balance overflow. It is unrealistic that
* a uint256 would ever overflow from increments when these increments are bounded to uint128 values.
*
* WARNING: Increasing an account's balance using this function tends to be paired with an override of the
* {_ownerOf} function to resolve the ownership of the corresponding tokens so that balances and ownership
* remain consistent with one another.
*/
function _increaseBalance(address account, uint128 value) internal virtual {
unchecked {
_balances[account] += value;
}
}
/**
* @dev Transfers `tokenId` from its current owner to `to`, or alternatively mints (or burns) if the current owner
* (or `to`) is the zero address. Returns the owner of the `tokenId` before the update.
*
* The `auth` argument is optional. If the value passed is non 0, then this function will check that
* `auth` is either the owner of the token, or approved to operate on the token (by the owner).
*
* Emits a {Transfer} event.
*
* NOTE: If overriding this function in a way that tracks balances, see also {_increaseBalance}.
*/
function _update(address to, uint256 tokenId, address auth) internal virtual returns (address) {
address from = _ownerOf(tokenId);
// Perform (optional) operator check
if (auth != address(0)) {
_checkAuthorized(from, auth, tokenId);
}
// Execute the update
if (from != address(0)) {
// Clear approval. No need to re-authorize or emit the Approval event
_approve(address(0), tokenId, address(0), false);
unchecked {
_balances[from] -= 1;
}
}
if (to != address(0)) {
unchecked {
_balances[to] += 1;
}
}
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
return from;
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal {
if (to == address(0)) {
revert ERC721InvalidReceiver(address(0));
}
address previousOwner = _update(to, tokenId, address(0));
if (previousOwner != address(0)) {
revert ERC721InvalidSender(address(0));
}
}
/**
* @dev Mints `tokenId`, transfers it to `to` and checks for `to` acceptance.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(address to, uint256 tokenId, bytes memory data) internal virtual {
_mint(to, tokenId);
_checkOnERC721Received(address(0), to, tokenId, data);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
* This is an internal function that does not check if the sender is authorized to operate on the token.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal {
address previousOwner = _update(address(0), tokenId, address(0));
if (previousOwner == address(0)) {
revert ERC721NonexistentToken(tokenId);
}
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(address from, address to, uint256 tokenId) internal {
if (to == address(0)) {
revert ERC721InvalidReceiver(address(0));
}
address previousOwner = _update(to, tokenId, address(0));
if (previousOwner == address(0)) {
revert ERC721NonexistentToken(tokenId);
} else if (previousOwner != from) {
revert ERC721IncorrectOwner(from, tokenId, previousOwner);
}
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking that contract recipients
* are aware of the ERC721 standard to prevent tokens from being forever locked.
*
* `data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is like {safeTransferFrom} in the sense that it invokes
* {IERC721Receiver-onERC721Received} on the receiver, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `tokenId` token must exist and be owned by `from`.
* - `to` cannot be the zero address.
* - `from` cannot be the zero address.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(address from, address to, uint256 tokenId) internal {
_safeTransfer(from, to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeTransfer-address-address-uint256-}[`_safeTransfer`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual {
_transfer(from, to, tokenId);
_checkOnERC721Received(from, to, tokenId, data);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* The `auth` argument is optional. If the value passed is non 0, then this function will check that `auth` is
* either the owner of the token, or approved to operate on all tokens held by this owner.
*
* Emits an {Approval} event.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address to, uint256 tokenId, address auth) internal {
_approve(to, tokenId, auth, true);
}
/**
* @dev Variant of `_approve` with an optional flag to enable or disable the {Approval} event. The event is not
* emitted in the context of transfers.
*/
function _approve(address to, uint256 tokenId, address auth, bool emitEvent) internal virtual {
// Avoid reading the owner unless necessary
if (emitEvent || auth != address(0)) {
address owner = _requireOwned(tokenId);
// We do not use _isAuthorized because single-token approvals should not be able to call approve
if (auth != address(0) && owner != auth && !isApprovedForAll(owner, auth)) {
revert ERC721InvalidApprover(auth);
}
if (emitEvent) {
emit Approval(owner, to, tokenId);
}
}
_tokenApprovals[tokenId] = to;
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Requirements:
* - operator can't be the address zero.
*
* Emits an {ApprovalForAll} event.
*/
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
if (operator == address(0)) {
revert ERC721InvalidOperator(operator);
}
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Reverts if the `tokenId` doesn't have a current owner (it hasn't been minted, or it has been burned).
* Returns the owner.
*
* Overrides to ownership logic should be done to {_ownerOf}.
*/
function _requireOwned(uint256 tokenId) internal view returns (address) {
address owner = _ownerOf(tokenId);
if (owner == address(0)) {
revert ERC721NonexistentToken(tokenId);
}
return owner;
}
/**
* @dev Private function to invoke {IERC721Receiver-onERC721Received} on a target address. This will revert if the
* recipient doesn't accept the token transfer. The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param data bytes optional data to send along with the call
*/
function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory data) private {
if (to.code.length > 0) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
if (retval != IERC721Receiver.onERC721Received.selector) {
revert ERC721InvalidReceiver(to);
}
} catch (bytes memory reason) {
if (reason.length == 0) {
revert ERC721InvalidReceiver(to);
} else {
/// @solidity memory-safe-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
}
}
}
@openzeppelin/contracts/token/ERC721/IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* 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 address zero.
*
* 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/token/ERC721/IERC721Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.20;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be
* reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/ERC721URIStorage.sol)
pragma solidity ^0.8.20;
import {ERC721} from "../ERC721.sol";
import {Strings} from "../../../utils/Strings.sol";
import {IERC4906} from "../../../interfaces/IERC4906.sol";
import {IERC165} from "../../../interfaces/IERC165.sol";
/**
* @dev ERC721 token with storage based token URI management.
*/
abstract contract ERC721URIStorage is IERC4906, ERC721 {
using Strings for uint256;
// Interface ID as defined in ERC-4906. This does not correspond to a traditional interface ID as ERC-4906 only
// defines events and does not include any external function.
bytes4 private constant ERC4906_INTERFACE_ID = bytes4(0x49064906);
// Optional mapping for token URIs
mapping(uint256 tokenId => string) private _tokenURIs;
/**
* @dev See {IERC165-supportsInterface}
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, IERC165) returns (bool) {
return interfaceId == ERC4906_INTERFACE_ID || super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
_requireOwned(tokenId);
string memory _tokenURI = _tokenURIs[tokenId];
string memory base = _baseURI();
// If there is no base URI, return the token URI.
if (bytes(base).length == 0) {
return _tokenURI;
}
// If both are set, concatenate the baseURI and tokenURI (via string.concat).
if (bytes(_tokenURI).length > 0) {
return string.concat(base, _tokenURI);
}
return super.tokenURI(tokenId);
}
/**
* @dev Sets `_tokenURI` as the tokenURI of `tokenId`.
*
* Emits {MetadataUpdate}.
*/
function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {
_tokenURIs[tokenId] = _tokenURI;
emit MetadataUpdate(tokenId);
}
}
@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Enumerable.sol)
pragma solidity ^0.8.20;
import {IERC721} from "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Metadata.sol)
pragma solidity ^0.8.20;
import {IERC721} from "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
@openzeppelin/contracts/utils/math/SignedMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}
@openzeppelin/contracts/utils/Base64.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.2) (utils/Base64.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides a set of functions to operate with Base64 strings.
*/
library Base64 {
/**
* @dev Base64 Encoding/Decoding Table
*/
string internal constant _TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/**
* @dev Converts a `bytes` to its Bytes64 `string` representation.
*/
function encode(bytes memory data) internal pure returns (string memory) {
/**
* Inspired by Brecht Devos (Brechtpd) implementation - MIT licence
* https://github.com/Brechtpd/base64/blob/e78d9fd951e7b0977ddca77d92dc85183770daf4/base64.sol
*/
if (data.length == 0) return "";
// Loads the table into memory
string memory table = _TABLE;
// Encoding takes 3 bytes chunks of binary data from `bytes` data parameter
// and split into 4 numbers of 6 bits.
// The final Base64 length should be `bytes` data length multiplied by 4/3 rounded up
// - `data.length + 2` -> Round up
// - `/ 3` -> Number of 3-bytes chunks
// - `4 *` -> 4 characters for each chunk
string memory result = new string(4 * ((data.length + 2) / 3));
/// @solidity memory-safe-assembly
assembly {
// Prepare the lookup table (skip the first "length" byte)
let tablePtr := add(table, 1)
// Prepare result pointer, jump over length
let resultPtr := add(result, 0x20)
let dataPtr := data
let endPtr := add(data, mload(data))
// In some cases, the last iteration will read bytes after the end of the data. We cache the value, and
// set it to zero to make sure no dirty bytes are read in that section.
let afterPtr := add(endPtr, 0x20)
let afterCache := mload(afterPtr)
mstore(afterPtr, 0x00)
// Run over the input, 3 bytes at a time
for {
} lt(dataPtr, endPtr) {
} {
// Advance 3 bytes
dataPtr := add(dataPtr, 3)
let input := mload(dataPtr)
// To write each character, shift the 3 byte (24 bits) chunk
// 4 times in blocks of 6 bits for each character (18, 12, 6, 0)
// and apply logical AND with 0x3F to bitmask the least significant 6 bits.
// Use this as an index into the lookup table, mload an entire word
// so the desired character is in the least significant byte, and
// mstore8 this least significant byte into the result and continue.
mstore8(resultPtr, mload(add(tablePtr, and(shr(18, input), 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
mstore8(resultPtr, mload(add(tablePtr, and(shr(12, input), 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
mstore8(resultPtr, mload(add(tablePtr, and(shr(6, input), 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
mstore8(resultPtr, mload(add(tablePtr, and(input, 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
}
// Reset the value that was cached
mstore(afterPtr, afterCache)
// When data `bytes` is not exactly 3 bytes long
// it is padded with `=` characters at the end
switch mod(mload(data), 3)
case 1 {
mstore8(sub(resultPtr, 1), 0x3d)
mstore8(sub(resultPtr, 2), 0x3d)
}
case 2 {
mstore8(sub(resultPtr, 1), 0x3d)
}
}
return result;
}
}
@openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
@openzeppelin/contracts/utils/Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)
pragma solidity ^0.8.20;
import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
/**
* @dev The `value` string doesn't fit in the specified `length`.
*/
error StringsInsufficientHexLength(uint256 value, uint256 length);
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toStringSigned(int256 value) internal pure returns (string memory) {
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
uint256 localValue = value;
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = HEX_DIGITS[localValue & 0xf];
localValue >>= 4;
}
if (localValue != 0) {
revert StringsInsufficientHexLength(value, length);
}
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
* representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
}
}
@openzeppelin/contracts/utils/cryptography/ECDSA.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.20;
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS
}
/**
* @dev The signature derives the `address(0)`.
*/
error ECDSAInvalidSignature();
/**
* @dev The signature has an invalid length.
*/
error ECDSAInvalidSignatureLength(uint256 length);
/**
* @dev The signature has an S value that is in the upper half order.
*/
error ECDSAInvalidSignatureS(bytes32 s);
/**
* @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not
* return address(0) without also returning an error description. Errors are documented using an enum (error type)
* and a bytes32 providing additional information about the error.
*
* If no error is returned, then the address can be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
/// @solidity memory-safe-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*/
function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) {
unchecked {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
// We do not check for an overflow here since the shift operation results in 0 or 1.
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*/
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError, bytes32) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS, s);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature, bytes32(0));
}
return (signer, RecoverError.NoError, bytes32(0));
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.
*/
function _throwError(RecoverError error, bytes32 errorArg) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert ECDSAInvalidSignature();
} else if (error == RecoverError.InvalidSignatureLength) {
revert ECDSAInvalidSignatureLength(uint256(errorArg));
} else if (error == RecoverError.InvalidSignatureS) {
revert ECDSAInvalidSignatureS(errorArg);
}
}
}
@openzeppelin/contracts/utils/introspection/ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
@openzeppelin/contracts/utils/introspection/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
@openzeppelin/contracts/utils/math/Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Muldiv operation overflow.
*/
error MathOverflowedMulDiv();
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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 largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
return a / b;
}
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (denominator <= prod1) {
revert MathOverflowedMulDiv();
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}
contracts/access/AdminRole.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an admin) 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 {transferAdmin}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyAdmin`, which can be applied to your functions to restrict their use to
* the admin.
*/
abstract contract AdminRole is Initializable {
address private _admin;
event AdminRoleTransferred(
address indexed previousAdmin,
address indexed newAdmin
);
/**
* @dev Initializes the contract setting the deployer as the initial admin.
*/
function __AdminRole_init() internal onlyInitializing {
__AdminRole_init_unchained();
}
function __AdminRole_init_unchained() internal onlyInitializing {
address msgSender = msg.sender;
_admin = msgSender;
emit AdminRoleTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current admin.
*/
function admin() public view virtual returns (address) {
return _admin;
}
/**
* @dev Throws if called by any account other than the admin.
*/
modifier onlyAdmin() {
require(admin() == msg.sender, "Access Control: sender is not Admin");
_;
}
/**
* @dev Leaves the contract without admin. It will not be possible to call
* `onlyAdmin` functions anymore. Can only be called by the current admin.
*
* NOTE: Renouncing admin role will leave the contract without an admin,
* thereby removing any functionality that is only available to the admin.
*/
function renounceAdmin() public virtual onlyAdmin {
emit AdminRoleTransferred(_admin, address(0));
_admin = address(0);
}
/**
* @dev Transfers admin role of the contract to a new account (`newAdmin`).
* Can only be called by the current admin.
*/
function transferAdmin(address newAdmin) public virtual onlyAdmin {
require(
newAdmin != address(0),
"AdminRole: new admin is the zero address"
);
emit AdminRoleTransferred(_admin, newAdmin);
_admin = newAdmin;
}
}
contracts/lib/Pausable.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "../access/AdminRole.sol";
contract Pausable is Initializable, AdminRole {
bool private _paused;
event Pause(bool isPause);
/**
* @dev Initializes the contract in paused state.
*/
function __Pausable_init() internal onlyInitializing {
__AdminRole_init();
__Pausable_init_unchained();
}
function __Pausable_init_unchained() internal onlyInitializing {
_paused = true;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view returns (bool) {
return _paused;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
require(!paused(), "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
require(paused(), "Pausable: not paused");
_;
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function pause() external onlyAdmin {
_paused = true;
emit Pause(true);
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function unpause() external onlyAdmin {
_paused = false;
emit Pause(false);
}
}
Compiler Settings
{"outputSelection":{"*":{"*":["*"],"":["*"]}},"optimizer":{"runs":200,"enabled":true},"libraries":{},"evmVersion":"paris"}
Contract ABI
[{"type":"error","name":"ECDSAInvalidSignature","inputs":[]},{"type":"error","name":"ECDSAInvalidSignatureLength","inputs":[{"type":"uint256","name":"length","internalType":"uint256"}]},{"type":"error","name":"ECDSAInvalidSignatureS","inputs":[{"type":"bytes32","name":"s","internalType":"bytes32"}]},{"type":"error","name":"ERC721EnumerableForbiddenBatchMint","inputs":[]},{"type":"error","name":"ERC721IncorrectOwner","inputs":[{"type":"address","name":"sender","internalType":"address"},{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"address","name":"owner","internalType":"address"}]},{"type":"error","name":"ERC721InsufficientApproval","inputs":[{"type":"address","name":"operator","internalType":"address"},{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"error","name":"ERC721InvalidApprover","inputs":[{"type":"address","name":"approver","internalType":"address"}]},{"type":"error","name":"ERC721InvalidOperator","inputs":[{"type":"address","name":"operator","internalType":"address"}]},{"type":"error","name":"ERC721InvalidOwner","inputs":[{"type":"address","name":"owner","internalType":"address"}]},{"type":"error","name":"ERC721InvalidReceiver","inputs":[{"type":"address","name":"receiver","internalType":"address"}]},{"type":"error","name":"ERC721InvalidSender","inputs":[{"type":"address","name":"sender","internalType":"address"}]},{"type":"error","name":"ERC721NonexistentToken","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"error","name":"ERC721OutOfBoundsIndex","inputs":[{"type":"address","name":"owner","internalType":"address"},{"type":"uint256","name":"index","internalType":"uint256"}]},{"type":"error","name":"InvalidInitialization","inputs":[]},{"type":"error","name":"NotInitializing","inputs":[]},{"type":"event","name":"AdminRoleTransferred","inputs":[{"type":"address","name":"previousAdmin","internalType":"address","indexed":true},{"type":"address","name":"newAdmin","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"Approval","inputs":[{"type":"address","name":"owner","internalType":"address","indexed":true},{"type":"address","name":"approved","internalType":"address","indexed":true},{"type":"uint256","name":"tokenId","internalType":"uint256","indexed":true}],"anonymous":false},{"type":"event","name":"ApprovalForAll","inputs":[{"type":"address","name":"owner","internalType":"address","indexed":true},{"type":"address","name":"operator","internalType":"address","indexed":true},{"type":"bool","name":"approved","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"ExperienceUpdated","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256","indexed":false},{"type":"uint256","name":"oldExperience","internalType":"uint256","indexed":false},{"type":"uint256","name":"newExperience","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"Initialized","inputs":[{"type":"uint64","name":"version","internalType":"uint64","indexed":false}],"anonymous":false},{"type":"event","name":"NFTMinted","inputs":[{"type":"address","name":"to","internalType":"address","indexed":true},{"type":"uint256","name":"tokenId","internalType":"uint256","indexed":false},{"type":"string","name":"id","internalType":"string","indexed":false}],"anonymous":false},{"type":"event","name":"Pause","inputs":[{"type":"bool","name":"isPause","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"Transfer","inputs":[{"type":"address","name":"from","internalType":"address","indexed":true},{"type":"address","name":"to","internalType":"address","indexed":true},{"type":"uint256","name":"tokenId","internalType":"uint256","indexed":true}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"admin","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"approve","inputs":[{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"balanceOf","inputs":[{"type":"address","name":"owner","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"experience","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"freeMint","inputs":[{"type":"string","name":"id","internalType":"string"},{"type":"address","name":"to","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"getApproved","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"string[]","name":"","internalType":"string[]"}],"name":"getTags","inputs":[{"type":"string","name":"id","internalType":"string"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"idLastMintedIndex","inputs":[{"type":"string","name":"","internalType":"string"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isApprovedForAll","inputs":[{"type":"address","name":"owner","internalType":"address"},{"type":"address","name":"operator","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"maximumSupply","inputs":[{"type":"string","name":"","internalType":"string"}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"mint","inputs":[{"type":"string","name":"id","internalType":"string"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"mintPrice","inputs":[{"type":"string","name":"","internalType":"string"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"name","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"name","internalType":"string"},{"type":"uint64","name":"royalties","internalType":"uint64"},{"type":"uint64","name":"tier","internalType":"uint64"},{"type":"string","name":"mediaType","internalType":"string"},{"type":"string","name":"collectionHash","internalType":"string"}],"name":"nftDetails","inputs":[{"type":"string","name":"","internalType":"string"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"ownerOf","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"pause","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"paused","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceAdmin","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"safeTransferFrom","inputs":[{"type":"address","name":"from","internalType":"address"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"safeTransferFrom","inputs":[{"type":"address","name":"from","internalType":"address"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"bytes","name":"data","internalType":"bytes"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setApprovalForAll","inputs":[{"type":"address","name":"operator","internalType":"address"},{"type":"bool","name":"approved","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setMintPrice","inputs":[{"type":"string","name":"id","internalType":"string"},{"type":"uint256","name":"price","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setNftDetails","inputs":[{"type":"string","name":"id","internalType":"string"},{"type":"string","name":"name","internalType":"string"},{"type":"string","name":"collectionHash","internalType":"string"},{"type":"string[]","name":"tags","internalType":"string[]"},{"type":"string","name":"mediaType","internalType":"string"},{"type":"uint256","name":"maxLen","internalType":"uint256"},{"type":"uint64","name":"royalties","internalType":"uint64"},{"type":"uint64","name":"tier","internalType":"uint64"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setSignerAddress","inputs":[{"type":"address","name":"_signerAddress","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"supportsInterface","inputs":[{"type":"bytes4","name":"interfaceId","internalType":"bytes4"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"symbol","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"tokenByIndex","inputs":[{"type":"uint256","name":"index","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"tokenOfOwnerByIndex","inputs":[{"type":"address","name":"owner","internalType":"address"},{"type":"uint256","name":"index","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"tokenURI","inputs":[{"type":"uint256","name":"_tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalSupply","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferAdmin","inputs":[{"type":"address","name":"newAdmin","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferFrom","inputs":[{"type":"address","name":"from","internalType":"address"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unpause","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateExperience","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"uint256","name":"newExperience","internalType":"uint256"},{"type":"uint256","name":"timestamp","internalType":"uint256"},{"type":"bytes","name":"signature","internalType":"bytes"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateNftDetails","inputs":[{"type":"string","name":"id","internalType":"string"},{"type":"string","name":"name","internalType":"string"},{"type":"string","name":"collectionHash","internalType":"string"},{"type":"string[]","name":"tags","internalType":"string[]"},{"type":"string","name":"mediaType","internalType":"string"},{"type":"uint64","name":"royalties","internalType":"uint64"},{"type":"uint64","name":"tier","internalType":"uint64"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"withdraw","inputs":[]}]
Contract Creation Code
0x608060405234801561001057600080fd5b506141f5806100206000396000f3fe60806040526004361061021a5760003560e01c80635c975abb11610123578063a22cb465116100ab578063d85d3d271161006f578063d85d3d2714610674578063e8e6629f14610687578063e985e9c5146106a7578063f49526e3146106c7578063f851a440146106ff57600080fd5b8063a22cb465146105af578063b88d4fde146105cf578063bbe977c3146105ef578063c87b56dd14610627578063d3e971651461064757600080fd5b80638129fc1c116100f25780638129fc1c1461053b5780638456cb59146105505780638bad0c0a1461056557806395d89b411461057a578063a11b34951461058f57600080fd5b80635c975abb146104bc5780636352211e146104db57806370a08231146104fb57806375829def1461051b57600080fd5b80632f745c59116101a657806342842e0e1161017557806342842e0e146103f75780634920d1fb146104175780634f6ccce7146104375780634fbf4cb814610457578063566da8661461048f57600080fd5b80632f745c591461037c57806337245c941461039c5780633ccfd60b146103cd5780633f4ba83a146103e257600080fd5b8063081812fc116101ed578063081812fc146102b8578063095ea7b3146102f057806318160ddd1461031057806323b872dd1461033c578063282a63141461035c57600080fd5b806301ffc9a71461021f578063046dc1661461025457806304bcce131461027657806306fdde0314610296575b600080fd5b34801561022b57600080fd5b5061023f61023a36600461350c565b61071d565b60405190151581526020015b60405180910390f35b34801561026057600080fd5b5061027461026f36600461354c565b61072e565b005b34801561028257600080fd5b5061027461029136600461361c565b610792565b3480156102a257600080fd5b506102ab6107d9565b60405161024b91906136b9565b3480156102c457600080fd5b506102d86102d33660046136cc565b61087d565b6040516001600160a01b03909116815260200161024b565b3480156102fc57600080fd5b5061027461030b3660046136e5565b610892565b34801561031c57600080fd5b506000805160206141a0833981519152545b60405190815260200161024b565b34801561034857600080fd5b5061027461035736600461370f565b61089d565b34801561036857600080fd5b50610274610377366004613800565b610928565b34801561038857600080fd5b5061032e6103973660046136e5565b610aa3565b3480156103a857600080fd5b506103bc6103b73660046138f2565b610b17565b60405161024b959493929190613926565b3480156103d957600080fd5b50610274610cf9565b3480156103ee57600080fd5b50610274610d6f565b34801561040357600080fd5b5061027461041236600461370f565b610deb565b34801561042357600080fd5b50610274610432366004613976565b610e0b565b34801561044357600080fd5b5061032e6104523660046136cc565b6111bf565b34801561046357600080fd5b5061032e6104723660046138f2565b805160208183018101805160108252928201919093012091525481565b34801561049b57600080fd5b506104af6104aa3660046138f2565b611237565b60405161024b91906139cf565b3480156104c857600080fd5b50600054600160a01b900460ff1661023f565b3480156104e757600080fd5b506102d86104f63660046136cc565b611331565b34801561050757600080fd5b5061032e61051636600461354c565b61133c565b34801561052757600080fd5b5061027461053636600461354c565b611398565b34801561054757600080fd5b50610274611493565b34801561055c57600080fd5b506102746115f1565b34801561057157600080fd5b5061027461166e565b34801561058657600080fd5b506102ab6116f1565b34801561059b57600080fd5b506102746105aa366004613a33565b611730565b3480156105bb57600080fd5b506102746105ca366004613a77565b6117d9565b3480156105db57600080fd5b506102746105ea366004613ab3565b6117e4565b3480156105fb57600080fd5b5061032e61060a3660046138f2565b8051602081830181018051600e8252928201919093012091525481565b34801561063357600080fd5b506102ab6106423660046136cc565b6117fb565b34801561065357600080fd5b5061032e6106623660046136cc565b60116020526000908152604090205481565b6102746106823660046138f2565b611cbb565b34801561069357600080fd5b506102746106a2366004613b02565b611df9565b3480156106b357600080fd5b5061023f6106c2366004613bfe565b611ff5565b3480156106d357600080fd5b5061032e6106e23660046138f2565b8051602081830181018051600f8252928201919093012091525481565b34801561070b57600080fd5b506000546001600160a01b03166102d8565b600061072882612042565b92915050565b336107416000546001600160a01b031690565b6001600160a01b0316146107705760405162461bcd60e51b815260040161076790613c28565b60405180910390fd5b600180546001600160a01b0319166001600160a01b0392909216919091179055565b336107a56000546001600160a01b031690565b6001600160a01b0316146107cb5760405162461bcd60e51b815260040161076790613c28565b6107d58282612067565b5050565b60008051602061414083398151915280546060919081906107f990613c6b565b80601f016020809104026020016040519081016040528092919081815260200182805461082590613c6b565b80156108725780601f1061084757610100808354040283529160200191610872565b820191906000526020600020905b81548152906001019060200180831161085557829003601f168201915b505050505091505090565b600061088882612274565b50610728826122ac565b6107d58282336122e6565b6001600160a01b0382166108c757604051633250574960e11b815260006004820152602401610767565b60006108d48383336122f3565b9050836001600160a01b0316816001600160a01b031614610922576040516364283d7b60e01b81526001600160a01b0380861660048301526024820184905282166044820152606401610767565b50505050565b3361093b6000546001600160a01b031690565b6001600160a01b0316146109615760405162461bcd60e51b815260040161076790613c28565b6000600d886040516109739190613ca5565b908152604051908190036020019020805461098d90613c6b565b9050116109ac5760405162461bcd60e51b815260040161076790613cc1565b6040518060c00160405280878152602001836001600160401b03168152602001826001600160401b0316815260200184815260200186815260200185815250600d886040516109fb9190613ca5565b90815260405190819003602001902081518190610a189082613d48565b50602082015160018201805460408501516001600160401b03908116600160401b026001600160801b031990921693169290921791909117905560608201516002820190610a669082613d48565b5060808201516003820190610a7b9082613d48565b5060a08201518051610a97916004840191602090910190613439565b50505050505050505050565b6000600080516020614120833981519152610abd8461133c565b8310610aee5760405163295f44f760e21b81526001600160a01b038516600482015260248101849052604401610767565b6001600160a01b0384166000908152602091825260408082208583529092522054905092915050565b8051602081830181018051600d82529282019190930120915280548190610b3d90613c6b565b80601f0160208091040260200160405190810160405280929190818152602001828054610b6990613c6b565b8015610bb65780601f10610b8b57610100808354040283529160200191610bb6565b820191906000526020600020905b815481529060010190602001808311610b9957829003601f168201915b50505050600183015460028401805493946001600160401b0380841695600160401b90940416935091610be890613c6b565b80601f0160208091040260200160405190810160405280929190818152602001828054610c1490613c6b565b8015610c615780601f10610c3657610100808354040283529160200191610c61565b820191906000526020600020905b815481529060010190602001808311610c4457829003601f168201915b505050505090806003018054610c7690613c6b565b80601f0160208091040260200160405190810160405280929190818152602001828054610ca290613c6b565b8015610cef5780601f10610cc457610100808354040283529160200191610cef565b820191906000526020600020905b815481529060010190602001808311610cd257829003601f168201915b5050505050905085565b33610d0c6000546001600160a01b031690565b6001600160a01b031614610d325760405162461bcd60e51b815260040161076790613c28565b600080546040516001600160a01b03909116914780156108fc02929091818181858888f19350505050158015610d6c573d6000803e3d6000fd5b50565b33610d826000546001600160a01b031690565b6001600160a01b031614610da85760405162461bcd60e51b815260040161076790613c28565b6000805460ff60a01b191681556040519081527f9422424b175dda897495a07b091ef74a3ef715cf6d866fc972954c1c7f459304906020015b60405180910390a1565b610e06838383604051806020016040528060008152506117e4565b505050565b600054600160a01b900460ff1615610e585760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610767565b6000610e6385612308565b6001600160a01b031603610eb05760405162461bcd60e51b8152602060048201526014602482015273151bdad95b88191bd95cc81b9bdd08195e1a5cdd60621b6044820152606401610767565b33610eba85612308565b6001600160a01b031614610f105760405162461bcd60e51b815260206004820152601b60248201527f4e6f7420746865206f776e6572206f66207468697320746f6b656e00000000006044820152606401610767565b6001546001600160a01b0316610f615760405162461bcd60e51b815260206004820152601660248201527514da59db995c881859191c995cdcc81b9bdd081cd95d60521b6044820152606401610767565b610f6c607842613e1d565b821015610faf5760405162461bcd60e51b81526020600482015260116024820152700496e76616c69642074696d657374616d7607c1b6044820152606401610767565b610fbb426105dc613e30565b821115610ffe5760405162461bcd60e51b815260206004820152601160248201527014da59db985d1d5c9948195e1c1a5c9959607a1b6044820152606401610767565b6000848152601160205260409020548084116110765760405162461bcd60e51b815260206004820152603160248201527f4e657720657870657269656e6365206973206e6f742067726561746572207468604482015270616e206f6c6420657870657269656e636560781b6064820152608401610767565b604080517fc5206b8130dd430a7d168b076f15282d213164c7ba336000fc11e588dabe7b356020808301919091528183018890526060820187905260808083018790528351808403909101815260a08301845280519082012060025461190160f01b60c085015260c284015260e2808401829052845180850390910181526101029093019093528151910120600061110e8286612342565b6001549091506001600160a01b038083169116146111625760405162461bcd60e51b8152602060048201526011602482015270496e76616c6964207369676e617475726560781b6044820152606401610767565b60008881526011602090815260409182902089905581518a81529081018690529081018890527f0429eaad554f08c6da4698a2dc2dedbcd90732068f25ef611c9dea7f857e4ad89060600160405180910390a15050505050505050565b60006000805160206141208339815191526111e66000805160206141a08339815191525490565b831061120f5760405163295f44f760e21b81526000600482015260248101849052604401610767565b80600201838154811061122457611224613e43565b9060005260206000200154915050919050565b6060600d826040516112499190613ca5565b9081526020016040518091039020600401805480602002602001604051908101604052809291908181526020016000905b8282101561132657838290600052602060002001805461129990613c6b565b80601f01602080910402602001604051908101604052809291908181526020018280546112c590613c6b565b80156113125780601f106112e757610100808354040283529160200191611312565b820191906000526020600020905b8154815290600101906020018083116112f557829003601f168201915b50505050508152602001906001019061127a565b505050509050919050565b600061072882612274565b60006000805160206141408339815191526001600160a01b038316611377576040516322718ad960e21b815260006004820152602401610767565b6001600160a01b039092166000908152600390920160205250604090205490565b336113ab6000546001600160a01b031690565b6001600160a01b0316146113d15760405162461bcd60e51b815260040161076790613c28565b6001600160a01b0381166114385760405162461bcd60e51b815260206004820152602860248201527f41646d696e526f6c653a206e65772061646d696e20697320746865207a65726f604482015267206164647265737360c01b6064820152608401610767565b600080546040516001600160a01b03808516939216917fe379ac64de02d8184ca1a871ac486cb8137de77e485ede140e97057b9c765ffd91a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff1615906001600160401b03166000811580156114d85750825b90506000826001600160401b031660011480156114f45750303b155b905081158015611502575080155b156115205760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff19166001178555831561154a57845460ff60401b1916600160401b1785555b6115946040518060400160405280600b81526020016a4d50486f6d756e63756c6960a81b815250604051806040016040528060058152602001644d50484f4d60d81b81525061236c565b61159c61237e565b6115a4612398565b83156115ea57845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b5050505050565b336116046000546001600160a01b031690565b6001600160a01b03161461162a5760405162461bcd60e51b815260040161076790613c28565b6000805460ff60a01b1916600160a01b179055604051600181527f9422424b175dda897495a07b091ef74a3ef715cf6d866fc972954c1c7f45930490602001610de1565b336116816000546001600160a01b031690565b6001600160a01b0316146116a75760405162461bcd60e51b815260040161076790613c28565b600080546040516001600160a01b03909116907fe379ac64de02d8184ca1a871ac486cb8137de77e485ede140e97057b9c765ffd908390a3600080546001600160a01b0319169055565b7f80bb2b638cc20bc4d0a60d66940f3ab4a00c1d7b313497ca82fb0b4ab00793018054606091600080516020614140833981519152916107f990613c6b565b336117436000546001600160a01b031690565b6001600160a01b0316146117695760405162461bcd60e51b815260040161076790613c28565b6000600d8360405161177b9190613ca5565b908152604051908190036020019020805461179590613c6b565b9050116117b45760405162461bcd60e51b815260040161076790613cc1565b806010836040516117c59190613ca5565b908152604051908190036020019020555050565b6107d5338383612489565b6117ef84848461089d565b6109228484848461253a565b6060600061180883612308565b6001600160a01b0316036118555760405162461bcd60e51b8152602060048201526014602482015273151bdad95b88191bd95cc81b9bdd08195e1a5cdd60621b6044820152606401610767565b6000828152601260205260408120805461186e90613c6b565b80601f016020809104026020016040519081016040528092919081815260200182805461189a90613c6b565b80156118e75780601f106118bc576101008083540402835291602001916118e7565b820191906000526020600020905b8154815290600101906020018083116118ca57829003601f168201915b50505060008681526013602052604080822054905194955093909250600d9150611912908590613ca5565b90815260200160405180910390206040518060c001604052908160008201805461193b90613c6b565b80601f016020809104026020016040519081016040528092919081815260200182805461196790613c6b565b80156119b45780601f10611989576101008083540402835291602001916119b4565b820191906000526020600020905b81548152906001019060200180831161199757829003601f168201915b505050918352505060018201546001600160401b038082166020840152600160401b9091041660408201526002820180546060909201916119f490613c6b565b80601f0160208091040260200160405190810160405280929190818152602001828054611a2090613c6b565b8015611a6d5780601f10611a4257610100808354040283529160200191611a6d565b820191906000526020600020905b815481529060010190602001808311611a5057829003601f168201915b50505050508152602001600382018054611a8690613c6b565b80601f0160208091040260200160405190810160405280929190818152602001828054611ab290613c6b565b8015611aff5780601f10611ad457610100808354040283529160200191611aff565b820191906000526020600020905b815481529060010190602001808311611ae257829003601f168201915b5050505050815260200160048201805480602002602001604051908101604052809291908181526020016000905b82821015611bd9578382906000526020600020018054611b4c90613c6b565b80601f0160208091040260200160405190810160405280929190818152602001828054611b7890613c6b565b8015611bc55780601f10611b9a57610100808354040283529160200191611bc5565b820191906000526020600020905b815481529060010190602001808311611ba857829003601f168201915b505050505081526020019060010190611b2d565b505050915250508051909150600090611bf18461265c565b604051602001611c02929190613e59565b60405160208183030381529060405290506000826080015185611c37601460008b81526020019081526020016000205461265c565b8560600151604051602001611c4f9493929190613e96565b60405160208183030381529060405290506000611c8c8383604051602001611c78929190613f26565b6040516020818303038152906040526126ee565b905080604051602001611c9f9190613f94565b6040516020818303038152906040529650505050505050919050565b600054600160a01b900460ff1615611d085760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610767565b6000601082604051611d1a9190613ca5565b90815260200160405180910390205411611d765760405162461bcd60e51b815260206004820152601e60248201527f4d696e74207072696365206e6f742073657420666f72207468697320494400006044820152606401610767565b601081604051611d869190613ca5565b9081526020016040518091039020543414611def5760405162461bcd60e51b815260206004820152602360248201527f496e73756666696369656e742066756e647320746f206d696e7420746869732060448201526213919560ea1b6064820152608401610767565b610d6c8133612067565b33611e0c6000546001600160a01b031690565b6001600160a01b031614611e325760405162461bcd60e51b815260040161076790613c28565b600d88604051611e429190613ca5565b9081526040519081900360200190208054611e5c90613c6b565b159050611eb75760405162461bcd60e51b815260206004820152602360248201527f4e46542064657461696c7320616c72656164792073657420666f72207468697360448201526208125160ea1b6064820152608401610767565b6040518060c00160405280888152602001836001600160401b03168152602001826001600160401b0316815260200185815260200187815260200186815250600d89604051611f069190613ca5565b90815260405190819003602001902081518190611f239082613d48565b50602082015160018201805460408501516001600160401b03908116600160401b026001600160801b031990921693169290921791909117905560608201516002820190611f719082613d48565b5060808201516003820190611f869082613d48565b5060a08201518051611fa2916004840191602090910190613439565b509050506000600e89604051611fb89190613ca5565b90815260200160405180910390208190555082600f89604051611fdb9190613ca5565b908152604051908190036020019020555050505050505050565b6001600160a01b0391821660009081527f80bb2b638cc20bc4d0a60d66940f3ab4a00c1d7b313497ca82fb0b4ab00793056020908152604080832093909416825291909152205460ff1690565b60006001600160e01b0319821663780e9d6360e01b148061072857506107288261284d565b6000600d836040516120799190613ca5565b908152604051908190036020019020805461209390613c6b565b9050116120b25760405162461bcd60e51b815260040161076790613cc1565b600f826040516120c29190613ca5565b908152602001604051809103902054600e836040516120e19190613ca5565b908152602001604051809103902054106121505760405162461bcd60e51b815260206004820152602a60248201527f4e6f206d6f7265204e46547320617661696c61626c6520746f206d696e7420666044820152691bdc881d1a1a5cc8125160b21b6064820152608401610767565b600061215b8361289d565b905060006121756000805160206141a08339815191525490565b612180906001613e30565b905061218c838261294f565b6000818152601160205260408082209190915551600e906121ae908690613ca5565b90815260405190819003602001902080549060006121cb83613fd9565b909155505060008181526012602052604090206121e88582613d48565b506000818152601460205260409081902083905551600e9061220b908690613ca5565b9081526040805191829003602090810183205460008581526013909252919020556001600160a01b038416907fd35bb95e09c04b219e35047ce7b7b300e3384264ef84a40456943dbc0fc17c14906122669084908890613ff2565b60405180910390a250505050565b60008061228083612308565b90506001600160a01b03811661072857604051637e27328960e01b815260048101849052602401610767565b60009081527f80bb2b638cc20bc4d0a60d66940f3ab4a00c1d7b313497ca82fb0b4ab007930460205260409020546001600160a01b031690565b610e068383836001612969565b6000612300848484612a7f565b949350505050565b60009081527f80bb2b638cc20bc4d0a60d66940f3ab4a00c1d7b313497ca82fb0b4ab007930260205260409020546001600160a01b031690565b6000806000806123528686612b78565b9250925092506123628282612bc5565b5090949350505050565b612374612c7e565b6107d58282612cc7565b612386612c7e565b61238e612cf8565b612396612d08565b565b6123a0612c7e565b600180546001600160a01b0319168155604080518082018252600b81526a4d50486f6d756e63756c6960a81b60209182015281518083018352928352603160f81b9281019290925280517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f928101929092527f62b62e3f2f6d80b6e94244b98cec8bdfc818ee5f2a082448e6905de4bb8ee3d7908201527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a082015260c00160408051601f198184030181529190528051602090910120600255565b6000805160206141408339815191526001600160a01b0383166124ca57604051630b61174360e31b81526001600160a01b0384166004820152602401610767565b6001600160a01b038481166000818152600584016020908152604080832094881680845294825291829020805460ff191687151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a350505050565b6001600160a01b0383163b1561092257604051630a85bd0160e11b81526001600160a01b0384169063150b7a029061257c90339088908790879060040161400b565b6020604051808303816000875af19250505080156125b7575060408051601f3d908101601f191682019092526125b491810190614048565b60015b612620573d8080156125e5576040519150601f19603f3d011682016040523d82523d6000602084013e6125ea565b606091505b50805160000361261857604051633250574960e11b81526001600160a01b0385166004820152602401610767565b805181602001fd5b6001600160e01b03198116630a85bd0160e11b146115ea57604051633250574960e11b81526001600160a01b0385166004820152602401610767565b6060600061266983612d25565b60010190506000816001600160401b0381111561268857612688613567565b6040519080825280601f01601f1916602001820160405280156126b2576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a85049450846126bc57509392505050565b6060815160000361270d57505060408051602081019091526000815290565b6000604051806060016040528060408152602001614160604091399050600060038451600261273c9190613e30565b612746919061407b565b61275190600461408f565b6001600160401b0381111561276857612768613567565b6040519080825280601f01601f191660200182016040528015612792576020820181803683370190505b50905060018201602082018586518701602081018051600082525b82841015612808576003840193508351603f8160121c168701518653600186019550603f81600c1c168701518653600186019550603f8160061c168701518653600186019550603f81168701518653506001850194506127ad565b9052505085516003900660018114612827576002811461283a57612842565b603d6001830353603d6002830353612842565b603d60018303535b509195945050505050565b60006001600160e01b031982166380ac58cd60e01b148061287e57506001600160e01b03198216635b5e139f60e01b145b8061072857506301ffc9a760e01b6001600160e01b0319831614610728565b600080333a43426128af600183613e1d565b40876040516020016128c6969594939291906140a6565b6040516020818303038152906040528051906020012060001c90506000600e846040516128f39190613ca5565b908152602001604051809103902054600f856040516129129190613ca5565b90815260200160405180910390205461292b9190613e1d565b9050600061293982846140df565b9050612946858284612dfd565b95945050505050565b6107d5828260405180602001604052806000815250612efa565b600080516020614140833981519152818061298c57506001600160a01b03831615155b15612a4e57600061299c85612274565b90506001600160a01b038416158015906129c85750836001600160a01b0316816001600160a01b031614155b80156129db57506129d98185611ff5565b155b15612a045760405163a9fbf51f60e01b81526001600160a01b0385166004820152602401610767565b8215612a4c5784866001600160a01b0316826001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45b505b600093845260040160205250506040902080546001600160a01b0319166001600160a01b0392909216919091179055565b600080612a8d858585612f11565b90506001600160a01b038116612b1657612b11846000805160206141a0833981519152805460008381527f645e039705490088daad89bae25049a34f4a9072d398537b1ab2425f24cbed0360205260408120829055600182018355919091527fa42f15e5d656f8155fd7419d740a6073999f19cd6e061449ce4a257150545bf20155565b612b39565b846001600160a01b0316816001600160a01b031614612b3957612b39818561301b565b6001600160a01b038516612b5557612b50846130bf565b612300565b846001600160a01b0316816001600160a01b031614612300576123008585613196565b60008060008351604103612bb25760208401516040850151606086015160001a612ba4888285856131f1565b955095509550505050612bbe565b50508151600091506002905b9250925092565b6000826003811115612bd957612bd96140f3565b03612be2575050565b6001826003811115612bf657612bf66140f3565b03612c145760405163f645eedf60e01b815260040160405180910390fd5b6002826003811115612c2857612c286140f3565b03612c495760405163fce698f760e01b815260048101829052602401610767565b6003826003811115612c5d57612c5d6140f3565b036107d5576040516335e2f38360e21b815260048101829052602401610767565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff1661239657604051631afcd79f60e31b815260040160405180910390fd5b612ccf612c7e565b60008051602061414083398151915280612ce98482613d48565b50600181016109228382613d48565b612d00612c7e565b6123966132c0565b612d10612c7e565b6000805460ff60a01b1916600160a01b179055565b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b8310612d645772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef81000000008310612d90576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc100008310612dae57662386f26fc10000830492506010015b6305f5e1008310612dc6576305f5e100830492506008015b6127108310612dda57612710830492506004015b60648310612dec576064830492506002015b600a83106107285760010192915050565b600080601585604051612e109190613ca5565b9081526040805160209281900383019020600087815292528120549150818103612e3b575083612e3e565b50805b6000612e4b600186613e1d565b9050808614612ef0576000601588604051612e669190613ca5565b9081526020016040518091039020600083815260200190815260200160002054905080600003612ec15781601589604051612ea19190613ca5565b908152604080516020928190038301902060008b81529252902055612eee565b80601589604051612ed29190613ca5565b908152604080516020928190038301902060008b815292529020555b505b5095945050505050565b612f04838361330b565b610e06600084848461253a565b600060008051602061414083398151915281612f2c85612308565b90506001600160a01b03841615612f4857612f48818587613370565b6001600160a01b03811615612f8857612f65600086600080612969565b6001600160a01b0381166000908152600383016020526040902080546000190190555b6001600160a01b03861615612fb9576001600160a01b03861660009081526003830160205260409020805460010190555b600085815260028301602052604080822080546001600160a01b0319166001600160a01b038a811691821790925591518893918516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a495945050505050565b60008051602061412083398151915260006130358461133c565b600084815260018401602052604090205490915080821461308a576001600160a01b03851660009081526020848152604080832085845282528083205484845281842081905583526001860190915290208190555b50600092835260018201602090815260408085208590556001600160a01b039095168452918252838320908352905290812055565b6000805160206141a083398151915254600080516020614120833981519152906000906130ee90600190613e1d565b600084815260038401602052604081205460028501805493945090928490811061311a5761311a613e43565b906000526020600020015490508084600201838154811061313d5761313d613e43565b60009182526020808320909101929092558281526003860190915260408082208490558682528120556002840180548061317957613179614109565b600190038181906000526020600020016000905590555050505050565b600080516020614120833981519152600060016131b28561133c565b6131bc9190613e1d565b6001600160a01b0390941660009081526020838152604080832087845282528083208690559482526001909301909252502055565b600080807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a084111561322c57506000915060039050826132b6565b604080516000808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa158015613280573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166132ac575060009250600191508290506132b6565b9250600091508190505b9450945094915050565b6132c8612c7e565b600080546001600160a01b031916339081178255604051909182917fe379ac64de02d8184ca1a871ac486cb8137de77e485ede140e97057b9c765ffd908290a350565b6001600160a01b03821661333557604051633250574960e11b815260006004820152602401610767565b6000613343838360006122f3565b90506001600160a01b03811615610e06576040516339e3563760e11b815260006004820152602401610767565b61337b8383836133d4565b610e06576001600160a01b0383166133a957604051637e27328960e01b815260048101829052602401610767565b60405163177e802f60e01b81526001600160a01b038316600482015260248101829052604401610767565b60006001600160a01b038316158015906123005750826001600160a01b0316846001600160a01b0316148061340e575061340e8484611ff5565b806123005750826001600160a01b0316613427836122ac565b6001600160a01b031614949350505050565b82805482825590600052602060002090810192821561347f579160200282015b8281111561347f578251829061346f9082613d48565b5091602001919060010190613459565b5061348b92915061348f565b5090565b8082111561348b5760006134a382826134ac565b5060010161348f565b5080546134b890613c6b565b6000825580601f106134c8575050565b601f016020900490600052602060002090810190610d6c91905b8082111561348b57600081556001016134e2565b6001600160e01b031981168114610d6c57600080fd5b60006020828403121561351e57600080fd5b8135613529816134f6565b9392505050565b80356001600160a01b038116811461354757600080fd5b919050565b60006020828403121561355e57600080fd5b61352982613530565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b03811182821017156135a5576135a5613567565b604052919050565b600082601f8301126135be57600080fd5b81356001600160401b038111156135d7576135d7613567565b6135ea601f8201601f191660200161357d565b8181528460208386010111156135ff57600080fd5b816020850160208301376000918101602001919091529392505050565b6000806040838503121561362f57600080fd5b82356001600160401b0381111561364557600080fd5b613651858286016135ad565b92505061366060208401613530565b90509250929050565b60005b8381101561368457818101518382015260200161366c565b50506000910152565b600081518084526136a5816020860160208601613669565b601f01601f19169290920160200192915050565b602081526000613529602083018461368d565b6000602082840312156136de57600080fd5b5035919050565b600080604083850312156136f857600080fd5b61370183613530565b946020939093013593505050565b60008060006060848603121561372457600080fd5b61372d84613530565b925061373b60208501613530565b9150604084013590509250925092565b600082601f83011261375c57600080fd5b813560206001600160401b038083111561377857613778613567565b8260051b61378783820161357d565b93845285810183019383810190888611156137a157600080fd5b84880192505b858310156137dd578235848111156137bf5760008081fd5b6137cd8a87838c01016135ad565b83525091840191908401906137a7565b98975050505050505050565b80356001600160401b038116811461354757600080fd5b600080600080600080600060e0888a03121561381b57600080fd5b87356001600160401b038082111561383257600080fd5b61383e8b838c016135ad565b985060208a013591508082111561385457600080fd5b6138608b838c016135ad565b975060408a013591508082111561387657600080fd5b6138828b838c016135ad565b965060608a013591508082111561389857600080fd5b6138a48b838c0161374b565b955060808a01359150808211156138ba57600080fd5b506138c78a828b016135ad565b9350506138d660a089016137e9565b91506138e460c089016137e9565b905092959891949750929550565b60006020828403121561390457600080fd5b81356001600160401b0381111561391a57600080fd5b612300848285016135ad565b60a08152600061393960a083018861368d565b6001600160401b038781166020850152861660408401528281036060840152613962818661368d565b905082810360808401526137dd818561368d565b6000806000806080858703121561398c57600080fd5b84359350602085013592506040850135915060608501356001600160401b038111156139b757600080fd5b6139c3878288016135ad565b91505092959194509250565b600060208083016020845280855180835260408601915060408160051b87010192506020870160005b82811015613a2657603f19888603018452613a1485835161368d565b945092850192908501906001016139f8565b5092979650505050505050565b60008060408385031215613a4657600080fd5b82356001600160401b03811115613a5c57600080fd5b613a68858286016135ad565b95602094909401359450505050565b60008060408385031215613a8a57600080fd5b613a9383613530565b915060208301358015158114613aa857600080fd5b809150509250929050565b60008060008060808587031215613ac957600080fd5b613ad285613530565b9350613ae060208601613530565b92506040850135915060608501356001600160401b038111156139b757600080fd5b600080600080600080600080610100898b031215613b1f57600080fd5b88356001600160401b0380821115613b3657600080fd5b613b428c838d016135ad565b995060208b0135915080821115613b5857600080fd5b613b648c838d016135ad565b985060408b0135915080821115613b7a57600080fd5b613b868c838d016135ad565b975060608b0135915080821115613b9c57600080fd5b613ba88c838d0161374b565b965060808b0135915080821115613bbe57600080fd5b50613bcb8b828c016135ad565b94505060a08901359250613be160c08a016137e9565b9150613bef60e08a016137e9565b90509295985092959890939650565b60008060408385031215613c1157600080fd5b613c1a83613530565b915061366060208401613530565b60208082526023908201527f41636365737320436f6e74726f6c3a2073656e646572206973206e6f7420416460408201526236b4b760e91b606082015260800190565b600181811c90821680613c7f57607f821691505b602082108103613c9f57634e487b7160e01b600052602260045260246000fd5b50919050565b60008251613cb7818460208701613669565b9190910192915050565b6020808252601f908201527f4e46542064657461696c73206e6f742073657420666f72207468697320494400604082015260600190565b601f821115610e06576000816000526020600020601f850160051c81016020861015613d215750805b601f850160051c820191505b81811015613d4057828155600101613d2d565b505050505050565b81516001600160401b03811115613d6157613d61613567565b613d7581613d6f8454613c6b565b84613cf8565b602080601f831160018114613daa5760008415613d925750858301515b600019600386901b1c1916600185901b178555613d40565b600085815260208120601f198616915b82811015613dd957888601518255948401946001909101908401613dba565b5085821015613df75787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b634e487b7160e01b600052601160045260246000fd5b8181038181111561072857610728613e07565b8082018082111561072857610728613e07565b634e487b7160e01b600052603260045260246000fd5b60008351613e6b818460208801613669565b61202360f01b9083019081528351613e8a816002840160208801613669565b01600201949350505050565b66697066733a2f2f60c81b815260008551613eb8816007850160208a01613669565b8083019050602f60f81b8060078301528651613edb816008850160208b01613669565b60089201918201528451613ef6816009840160208901613669565b601760f91b600992909101918201528351613f1881600a840160208801613669565b01600a019695505050505050565b693d913730b6b2911d101160b11b81528251600090613f4c81600a850160208801613669565b6c1116101134b6b0b3b2911d101160991b600a918401918201528351613f79816017840160208801613669565b61227d60f01b60179290910191820152601901949350505050565b7f646174613a6170706c69636174696f6e2f6a736f6e3b6261736536342c000000815260008251613fcc81601d850160208701613669565b91909101601d0192915050565b600060018201613feb57613feb613e07565b5060010190565b828152604060208201526000612300604083018461368d565b6001600160a01b038581168252841660208201526040810183905260806060820181905260009061403e9083018461368d565b9695505050505050565b60006020828403121561405a57600080fd5b8151613529816134f6565b634e487b7160e01b600052601260045260246000fd5b60008261408a5761408a614065565b500490565b808202811582820484141761072857610728613e07565b60018060a01b038716815285602082015284604082015283606082015282608082015260c060a082015260006137dd60c083018461368d565b6000826140ee576140ee614065565b500690565b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052603160045260246000fdfe645e039705490088daad89bae25049a34f4a9072d398537b1ab2425f24cbed0080bb2b638cc20bc4d0a60d66940f3ab4a00c1d7b313497ca82fb0b4ab00793004142434445464748494a4b4c4d4e4f505152535455565758595a6162636465666768696a6b6c6d6e6f707172737475767778797a303132333435363738392b2f645e039705490088daad89bae25049a34f4a9072d398537b1ab2425f24cbed02a2646970667358221220501f7450f4c411a01c0d59bb9294baafd8efa5b2ffb8978f06dafe24d56c408b64736f6c63430008180033
Deployed ByteCode
0x60806040526004361061021a5760003560e01c80635c975abb11610123578063a22cb465116100ab578063d85d3d271161006f578063d85d3d2714610674578063e8e6629f14610687578063e985e9c5146106a7578063f49526e3146106c7578063f851a440146106ff57600080fd5b8063a22cb465146105af578063b88d4fde146105cf578063bbe977c3146105ef578063c87b56dd14610627578063d3e971651461064757600080fd5b80638129fc1c116100f25780638129fc1c1461053b5780638456cb59146105505780638bad0c0a1461056557806395d89b411461057a578063a11b34951461058f57600080fd5b80635c975abb146104bc5780636352211e146104db57806370a08231146104fb57806375829def1461051b57600080fd5b80632f745c59116101a657806342842e0e1161017557806342842e0e146103f75780634920d1fb146104175780634f6ccce7146104375780634fbf4cb814610457578063566da8661461048f57600080fd5b80632f745c591461037c57806337245c941461039c5780633ccfd60b146103cd5780633f4ba83a146103e257600080fd5b8063081812fc116101ed578063081812fc146102b8578063095ea7b3146102f057806318160ddd1461031057806323b872dd1461033c578063282a63141461035c57600080fd5b806301ffc9a71461021f578063046dc1661461025457806304bcce131461027657806306fdde0314610296575b600080fd5b34801561022b57600080fd5b5061023f61023a36600461350c565b61071d565b60405190151581526020015b60405180910390f35b34801561026057600080fd5b5061027461026f36600461354c565b61072e565b005b34801561028257600080fd5b5061027461029136600461361c565b610792565b3480156102a257600080fd5b506102ab6107d9565b60405161024b91906136b9565b3480156102c457600080fd5b506102d86102d33660046136cc565b61087d565b6040516001600160a01b03909116815260200161024b565b3480156102fc57600080fd5b5061027461030b3660046136e5565b610892565b34801561031c57600080fd5b506000805160206141a0833981519152545b60405190815260200161024b565b34801561034857600080fd5b5061027461035736600461370f565b61089d565b34801561036857600080fd5b50610274610377366004613800565b610928565b34801561038857600080fd5b5061032e6103973660046136e5565b610aa3565b3480156103a857600080fd5b506103bc6103b73660046138f2565b610b17565b60405161024b959493929190613926565b3480156103d957600080fd5b50610274610cf9565b3480156103ee57600080fd5b50610274610d6f565b34801561040357600080fd5b5061027461041236600461370f565b610deb565b34801561042357600080fd5b50610274610432366004613976565b610e0b565b34801561044357600080fd5b5061032e6104523660046136cc565b6111bf565b34801561046357600080fd5b5061032e6104723660046138f2565b805160208183018101805160108252928201919093012091525481565b34801561049b57600080fd5b506104af6104aa3660046138f2565b611237565b60405161024b91906139cf565b3480156104c857600080fd5b50600054600160a01b900460ff1661023f565b3480156104e757600080fd5b506102d86104f63660046136cc565b611331565b34801561050757600080fd5b5061032e61051636600461354c565b61133c565b34801561052757600080fd5b5061027461053636600461354c565b611398565b34801561054757600080fd5b50610274611493565b34801561055c57600080fd5b506102746115f1565b34801561057157600080fd5b5061027461166e565b34801561058657600080fd5b506102ab6116f1565b34801561059b57600080fd5b506102746105aa366004613a33565b611730565b3480156105bb57600080fd5b506102746105ca366004613a77565b6117d9565b3480156105db57600080fd5b506102746105ea366004613ab3565b6117e4565b3480156105fb57600080fd5b5061032e61060a3660046138f2565b8051602081830181018051600e8252928201919093012091525481565b34801561063357600080fd5b506102ab6106423660046136cc565b6117fb565b34801561065357600080fd5b5061032e6106623660046136cc565b60116020526000908152604090205481565b6102746106823660046138f2565b611cbb565b34801561069357600080fd5b506102746106a2366004613b02565b611df9565b3480156106b357600080fd5b5061023f6106c2366004613bfe565b611ff5565b3480156106d357600080fd5b5061032e6106e23660046138f2565b8051602081830181018051600f8252928201919093012091525481565b34801561070b57600080fd5b506000546001600160a01b03166102d8565b600061072882612042565b92915050565b336107416000546001600160a01b031690565b6001600160a01b0316146107705760405162461bcd60e51b815260040161076790613c28565b60405180910390fd5b600180546001600160a01b0319166001600160a01b0392909216919091179055565b336107a56000546001600160a01b031690565b6001600160a01b0316146107cb5760405162461bcd60e51b815260040161076790613c28565b6107d58282612067565b5050565b60008051602061414083398151915280546060919081906107f990613c6b565b80601f016020809104026020016040519081016040528092919081815260200182805461082590613c6b565b80156108725780601f1061084757610100808354040283529160200191610872565b820191906000526020600020905b81548152906001019060200180831161085557829003601f168201915b505050505091505090565b600061088882612274565b50610728826122ac565b6107d58282336122e6565b6001600160a01b0382166108c757604051633250574960e11b815260006004820152602401610767565b60006108d48383336122f3565b9050836001600160a01b0316816001600160a01b031614610922576040516364283d7b60e01b81526001600160a01b0380861660048301526024820184905282166044820152606401610767565b50505050565b3361093b6000546001600160a01b031690565b6001600160a01b0316146109615760405162461bcd60e51b815260040161076790613c28565b6000600d886040516109739190613ca5565b908152604051908190036020019020805461098d90613c6b565b9050116109ac5760405162461bcd60e51b815260040161076790613cc1565b6040518060c00160405280878152602001836001600160401b03168152602001826001600160401b0316815260200184815260200186815260200185815250600d886040516109fb9190613ca5565b90815260405190819003602001902081518190610a189082613d48565b50602082015160018201805460408501516001600160401b03908116600160401b026001600160801b031990921693169290921791909117905560608201516002820190610a669082613d48565b5060808201516003820190610a7b9082613d48565b5060a08201518051610a97916004840191602090910190613439565b50505050505050505050565b6000600080516020614120833981519152610abd8461133c565b8310610aee5760405163295f44f760e21b81526001600160a01b038516600482015260248101849052604401610767565b6001600160a01b0384166000908152602091825260408082208583529092522054905092915050565b8051602081830181018051600d82529282019190930120915280548190610b3d90613c6b565b80601f0160208091040260200160405190810160405280929190818152602001828054610b6990613c6b565b8015610bb65780601f10610b8b57610100808354040283529160200191610bb6565b820191906000526020600020905b815481529060010190602001808311610b9957829003601f168201915b50505050600183015460028401805493946001600160401b0380841695600160401b90940416935091610be890613c6b565b80601f0160208091040260200160405190810160405280929190818152602001828054610c1490613c6b565b8015610c615780601f10610c3657610100808354040283529160200191610c61565b820191906000526020600020905b815481529060010190602001808311610c4457829003601f168201915b505050505090806003018054610c7690613c6b565b80601f0160208091040260200160405190810160405280929190818152602001828054610ca290613c6b565b8015610cef5780601f10610cc457610100808354040283529160200191610cef565b820191906000526020600020905b815481529060010190602001808311610cd257829003601f168201915b5050505050905085565b33610d0c6000546001600160a01b031690565b6001600160a01b031614610d325760405162461bcd60e51b815260040161076790613c28565b600080546040516001600160a01b03909116914780156108fc02929091818181858888f19350505050158015610d6c573d6000803e3d6000fd5b50565b33610d826000546001600160a01b031690565b6001600160a01b031614610da85760405162461bcd60e51b815260040161076790613c28565b6000805460ff60a01b191681556040519081527f9422424b175dda897495a07b091ef74a3ef715cf6d866fc972954c1c7f459304906020015b60405180910390a1565b610e06838383604051806020016040528060008152506117e4565b505050565b600054600160a01b900460ff1615610e585760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610767565b6000610e6385612308565b6001600160a01b031603610eb05760405162461bcd60e51b8152602060048201526014602482015273151bdad95b88191bd95cc81b9bdd08195e1a5cdd60621b6044820152606401610767565b33610eba85612308565b6001600160a01b031614610f105760405162461bcd60e51b815260206004820152601b60248201527f4e6f7420746865206f776e6572206f66207468697320746f6b656e00000000006044820152606401610767565b6001546001600160a01b0316610f615760405162461bcd60e51b815260206004820152601660248201527514da59db995c881859191c995cdcc81b9bdd081cd95d60521b6044820152606401610767565b610f6c607842613e1d565b821015610faf5760405162461bcd60e51b81526020600482015260116024820152700496e76616c69642074696d657374616d7607c1b6044820152606401610767565b610fbb426105dc613e30565b821115610ffe5760405162461bcd60e51b815260206004820152601160248201527014da59db985d1d5c9948195e1c1a5c9959607a1b6044820152606401610767565b6000848152601160205260409020548084116110765760405162461bcd60e51b815260206004820152603160248201527f4e657720657870657269656e6365206973206e6f742067726561746572207468604482015270616e206f6c6420657870657269656e636560781b6064820152608401610767565b604080517fc5206b8130dd430a7d168b076f15282d213164c7ba336000fc11e588dabe7b356020808301919091528183018890526060820187905260808083018790528351808403909101815260a08301845280519082012060025461190160f01b60c085015260c284015260e2808401829052845180850390910181526101029093019093528151910120600061110e8286612342565b6001549091506001600160a01b038083169116146111625760405162461bcd60e51b8152602060048201526011602482015270496e76616c6964207369676e617475726560781b6044820152606401610767565b60008881526011602090815260409182902089905581518a81529081018690529081018890527f0429eaad554f08c6da4698a2dc2dedbcd90732068f25ef611c9dea7f857e4ad89060600160405180910390a15050505050505050565b60006000805160206141208339815191526111e66000805160206141a08339815191525490565b831061120f5760405163295f44f760e21b81526000600482015260248101849052604401610767565b80600201838154811061122457611224613e43565b9060005260206000200154915050919050565b6060600d826040516112499190613ca5565b9081526020016040518091039020600401805480602002602001604051908101604052809291908181526020016000905b8282101561132657838290600052602060002001805461129990613c6b565b80601f01602080910402602001604051908101604052809291908181526020018280546112c590613c6b565b80156113125780601f106112e757610100808354040283529160200191611312565b820191906000526020600020905b8154815290600101906020018083116112f557829003601f168201915b50505050508152602001906001019061127a565b505050509050919050565b600061072882612274565b60006000805160206141408339815191526001600160a01b038316611377576040516322718ad960e21b815260006004820152602401610767565b6001600160a01b039092166000908152600390920160205250604090205490565b336113ab6000546001600160a01b031690565b6001600160a01b0316146113d15760405162461bcd60e51b815260040161076790613c28565b6001600160a01b0381166114385760405162461bcd60e51b815260206004820152602860248201527f41646d696e526f6c653a206e65772061646d696e20697320746865207a65726f604482015267206164647265737360c01b6064820152608401610767565b600080546040516001600160a01b03808516939216917fe379ac64de02d8184ca1a871ac486cb8137de77e485ede140e97057b9c765ffd91a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff1615906001600160401b03166000811580156114d85750825b90506000826001600160401b031660011480156114f45750303b155b905081158015611502575080155b156115205760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff19166001178555831561154a57845460ff60401b1916600160401b1785555b6115946040518060400160405280600b81526020016a4d50486f6d756e63756c6960a81b815250604051806040016040528060058152602001644d50484f4d60d81b81525061236c565b61159c61237e565b6115a4612398565b83156115ea57845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b5050505050565b336116046000546001600160a01b031690565b6001600160a01b03161461162a5760405162461bcd60e51b815260040161076790613c28565b6000805460ff60a01b1916600160a01b179055604051600181527f9422424b175dda897495a07b091ef74a3ef715cf6d866fc972954c1c7f45930490602001610de1565b336116816000546001600160a01b031690565b6001600160a01b0316146116a75760405162461bcd60e51b815260040161076790613c28565b600080546040516001600160a01b03909116907fe379ac64de02d8184ca1a871ac486cb8137de77e485ede140e97057b9c765ffd908390a3600080546001600160a01b0319169055565b7f80bb2b638cc20bc4d0a60d66940f3ab4a00c1d7b313497ca82fb0b4ab00793018054606091600080516020614140833981519152916107f990613c6b565b336117436000546001600160a01b031690565b6001600160a01b0316146117695760405162461bcd60e51b815260040161076790613c28565b6000600d8360405161177b9190613ca5565b908152604051908190036020019020805461179590613c6b565b9050116117b45760405162461bcd60e51b815260040161076790613cc1565b806010836040516117c59190613ca5565b908152604051908190036020019020555050565b6107d5338383612489565b6117ef84848461089d565b6109228484848461253a565b6060600061180883612308565b6001600160a01b0316036118555760405162461bcd60e51b8152602060048201526014602482015273151bdad95b88191bd95cc81b9bdd08195e1a5cdd60621b6044820152606401610767565b6000828152601260205260408120805461186e90613c6b565b80601f016020809104026020016040519081016040528092919081815260200182805461189a90613c6b565b80156118e75780601f106118bc576101008083540402835291602001916118e7565b820191906000526020600020905b8154815290600101906020018083116118ca57829003601f168201915b50505060008681526013602052604080822054905194955093909250600d9150611912908590613ca5565b90815260200160405180910390206040518060c001604052908160008201805461193b90613c6b565b80601f016020809104026020016040519081016040528092919081815260200182805461196790613c6b565b80156119b45780601f10611989576101008083540402835291602001916119b4565b820191906000526020600020905b81548152906001019060200180831161199757829003601f168201915b505050918352505060018201546001600160401b038082166020840152600160401b9091041660408201526002820180546060909201916119f490613c6b565b80601f0160208091040260200160405190810160405280929190818152602001828054611a2090613c6b565b8015611a6d5780601f10611a4257610100808354040283529160200191611a6d565b820191906000526020600020905b815481529060010190602001808311611a5057829003601f168201915b50505050508152602001600382018054611a8690613c6b565b80601f0160208091040260200160405190810160405280929190818152602001828054611ab290613c6b565b8015611aff5780601f10611ad457610100808354040283529160200191611aff565b820191906000526020600020905b815481529060010190602001808311611ae257829003601f168201915b5050505050815260200160048201805480602002602001604051908101604052809291908181526020016000905b82821015611bd9578382906000526020600020018054611b4c90613c6b565b80601f0160208091040260200160405190810160405280929190818152602001828054611b7890613c6b565b8015611bc55780601f10611b9a57610100808354040283529160200191611bc5565b820191906000526020600020905b815481529060010190602001808311611ba857829003601f168201915b505050505081526020019060010190611b2d565b505050915250508051909150600090611bf18461265c565b604051602001611c02929190613e59565b60405160208183030381529060405290506000826080015185611c37601460008b81526020019081526020016000205461265c565b8560600151604051602001611c4f9493929190613e96565b60405160208183030381529060405290506000611c8c8383604051602001611c78929190613f26565b6040516020818303038152906040526126ee565b905080604051602001611c9f9190613f94565b6040516020818303038152906040529650505050505050919050565b600054600160a01b900460ff1615611d085760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610767565b6000601082604051611d1a9190613ca5565b90815260200160405180910390205411611d765760405162461bcd60e51b815260206004820152601e60248201527f4d696e74207072696365206e6f742073657420666f72207468697320494400006044820152606401610767565b601081604051611d869190613ca5565b9081526020016040518091039020543414611def5760405162461bcd60e51b815260206004820152602360248201527f496e73756666696369656e742066756e647320746f206d696e7420746869732060448201526213919560ea1b6064820152608401610767565b610d6c8133612067565b33611e0c6000546001600160a01b031690565b6001600160a01b031614611e325760405162461bcd60e51b815260040161076790613c28565b600d88604051611e429190613ca5565b9081526040519081900360200190208054611e5c90613c6b565b159050611eb75760405162461bcd60e51b815260206004820152602360248201527f4e46542064657461696c7320616c72656164792073657420666f72207468697360448201526208125160ea1b6064820152608401610767565b6040518060c00160405280888152602001836001600160401b03168152602001826001600160401b0316815260200185815260200187815260200186815250600d89604051611f069190613ca5565b90815260405190819003602001902081518190611f239082613d48565b50602082015160018201805460408501516001600160401b03908116600160401b026001600160801b031990921693169290921791909117905560608201516002820190611f719082613d48565b5060808201516003820190611f869082613d48565b5060a08201518051611fa2916004840191602090910190613439565b509050506000600e89604051611fb89190613ca5565b90815260200160405180910390208190555082600f89604051611fdb9190613ca5565b908152604051908190036020019020555050505050505050565b6001600160a01b0391821660009081527f80bb2b638cc20bc4d0a60d66940f3ab4a00c1d7b313497ca82fb0b4ab00793056020908152604080832093909416825291909152205460ff1690565b60006001600160e01b0319821663780e9d6360e01b148061072857506107288261284d565b6000600d836040516120799190613ca5565b908152604051908190036020019020805461209390613c6b565b9050116120b25760405162461bcd60e51b815260040161076790613cc1565b600f826040516120c29190613ca5565b908152602001604051809103902054600e836040516120e19190613ca5565b908152602001604051809103902054106121505760405162461bcd60e51b815260206004820152602a60248201527f4e6f206d6f7265204e46547320617661696c61626c6520746f206d696e7420666044820152691bdc881d1a1a5cc8125160b21b6064820152608401610767565b600061215b8361289d565b905060006121756000805160206141a08339815191525490565b612180906001613e30565b905061218c838261294f565b6000818152601160205260408082209190915551600e906121ae908690613ca5565b90815260405190819003602001902080549060006121cb83613fd9565b909155505060008181526012602052604090206121e88582613d48565b506000818152601460205260409081902083905551600e9061220b908690613ca5565b9081526040805191829003602090810183205460008581526013909252919020556001600160a01b038416907fd35bb95e09c04b219e35047ce7b7b300e3384264ef84a40456943dbc0fc17c14906122669084908890613ff2565b60405180910390a250505050565b60008061228083612308565b90506001600160a01b03811661072857604051637e27328960e01b815260048101849052602401610767565b60009081527f80bb2b638cc20bc4d0a60d66940f3ab4a00c1d7b313497ca82fb0b4ab007930460205260409020546001600160a01b031690565b610e068383836001612969565b6000612300848484612a7f565b949350505050565b60009081527f80bb2b638cc20bc4d0a60d66940f3ab4a00c1d7b313497ca82fb0b4ab007930260205260409020546001600160a01b031690565b6000806000806123528686612b78565b9250925092506123628282612bc5565b5090949350505050565b612374612c7e565b6107d58282612cc7565b612386612c7e565b61238e612cf8565b612396612d08565b565b6123a0612c7e565b600180546001600160a01b0319168155604080518082018252600b81526a4d50486f6d756e63756c6960a81b60209182015281518083018352928352603160f81b9281019290925280517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f928101929092527f62b62e3f2f6d80b6e94244b98cec8bdfc818ee5f2a082448e6905de4bb8ee3d7908201527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a082015260c00160408051601f198184030181529190528051602090910120600255565b6000805160206141408339815191526001600160a01b0383166124ca57604051630b61174360e31b81526001600160a01b0384166004820152602401610767565b6001600160a01b038481166000818152600584016020908152604080832094881680845294825291829020805460ff191687151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a350505050565b6001600160a01b0383163b1561092257604051630a85bd0160e11b81526001600160a01b0384169063150b7a029061257c90339088908790879060040161400b565b6020604051808303816000875af19250505080156125b7575060408051601f3d908101601f191682019092526125b491810190614048565b60015b612620573d8080156125e5576040519150601f19603f3d011682016040523d82523d6000602084013e6125ea565b606091505b50805160000361261857604051633250574960e11b81526001600160a01b0385166004820152602401610767565b805181602001fd5b6001600160e01b03198116630a85bd0160e11b146115ea57604051633250574960e11b81526001600160a01b0385166004820152602401610767565b6060600061266983612d25565b60010190506000816001600160401b0381111561268857612688613567565b6040519080825280601f01601f1916602001820160405280156126b2576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a85049450846126bc57509392505050565b6060815160000361270d57505060408051602081019091526000815290565b6000604051806060016040528060408152602001614160604091399050600060038451600261273c9190613e30565b612746919061407b565b61275190600461408f565b6001600160401b0381111561276857612768613567565b6040519080825280601f01601f191660200182016040528015612792576020820181803683370190505b50905060018201602082018586518701602081018051600082525b82841015612808576003840193508351603f8160121c168701518653600186019550603f81600c1c168701518653600186019550603f8160061c168701518653600186019550603f81168701518653506001850194506127ad565b9052505085516003900660018114612827576002811461283a57612842565b603d6001830353603d6002830353612842565b603d60018303535b509195945050505050565b60006001600160e01b031982166380ac58cd60e01b148061287e57506001600160e01b03198216635b5e139f60e01b145b8061072857506301ffc9a760e01b6001600160e01b0319831614610728565b600080333a43426128af600183613e1d565b40876040516020016128c6969594939291906140a6565b6040516020818303038152906040528051906020012060001c90506000600e846040516128f39190613ca5565b908152602001604051809103902054600f856040516129129190613ca5565b90815260200160405180910390205461292b9190613e1d565b9050600061293982846140df565b9050612946858284612dfd565b95945050505050565b6107d5828260405180602001604052806000815250612efa565b600080516020614140833981519152818061298c57506001600160a01b03831615155b15612a4e57600061299c85612274565b90506001600160a01b038416158015906129c85750836001600160a01b0316816001600160a01b031614155b80156129db57506129d98185611ff5565b155b15612a045760405163a9fbf51f60e01b81526001600160a01b0385166004820152602401610767565b8215612a4c5784866001600160a01b0316826001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45b505b600093845260040160205250506040902080546001600160a01b0319166001600160a01b0392909216919091179055565b600080612a8d858585612f11565b90506001600160a01b038116612b1657612b11846000805160206141a0833981519152805460008381527f645e039705490088daad89bae25049a34f4a9072d398537b1ab2425f24cbed0360205260408120829055600182018355919091527fa42f15e5d656f8155fd7419d740a6073999f19cd6e061449ce4a257150545bf20155565b612b39565b846001600160a01b0316816001600160a01b031614612b3957612b39818561301b565b6001600160a01b038516612b5557612b50846130bf565b612300565b846001600160a01b0316816001600160a01b031614612300576123008585613196565b60008060008351604103612bb25760208401516040850151606086015160001a612ba4888285856131f1565b955095509550505050612bbe565b50508151600091506002905b9250925092565b6000826003811115612bd957612bd96140f3565b03612be2575050565b6001826003811115612bf657612bf66140f3565b03612c145760405163f645eedf60e01b815260040160405180910390fd5b6002826003811115612c2857612c286140f3565b03612c495760405163fce698f760e01b815260048101829052602401610767565b6003826003811115612c5d57612c5d6140f3565b036107d5576040516335e2f38360e21b815260048101829052602401610767565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff1661239657604051631afcd79f60e31b815260040160405180910390fd5b612ccf612c7e565b60008051602061414083398151915280612ce98482613d48565b50600181016109228382613d48565b612d00612c7e565b6123966132c0565b612d10612c7e565b6000805460ff60a01b1916600160a01b179055565b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b8310612d645772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef81000000008310612d90576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc100008310612dae57662386f26fc10000830492506010015b6305f5e1008310612dc6576305f5e100830492506008015b6127108310612dda57612710830492506004015b60648310612dec576064830492506002015b600a83106107285760010192915050565b600080601585604051612e109190613ca5565b9081526040805160209281900383019020600087815292528120549150818103612e3b575083612e3e565b50805b6000612e4b600186613e1d565b9050808614612ef0576000601588604051612e669190613ca5565b9081526020016040518091039020600083815260200190815260200160002054905080600003612ec15781601589604051612ea19190613ca5565b908152604080516020928190038301902060008b81529252902055612eee565b80601589604051612ed29190613ca5565b908152604080516020928190038301902060008b815292529020555b505b5095945050505050565b612f04838361330b565b610e06600084848461253a565b600060008051602061414083398151915281612f2c85612308565b90506001600160a01b03841615612f4857612f48818587613370565b6001600160a01b03811615612f8857612f65600086600080612969565b6001600160a01b0381166000908152600383016020526040902080546000190190555b6001600160a01b03861615612fb9576001600160a01b03861660009081526003830160205260409020805460010190555b600085815260028301602052604080822080546001600160a01b0319166001600160a01b038a811691821790925591518893918516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a495945050505050565b60008051602061412083398151915260006130358461133c565b600084815260018401602052604090205490915080821461308a576001600160a01b03851660009081526020848152604080832085845282528083205484845281842081905583526001860190915290208190555b50600092835260018201602090815260408085208590556001600160a01b039095168452918252838320908352905290812055565b6000805160206141a083398151915254600080516020614120833981519152906000906130ee90600190613e1d565b600084815260038401602052604081205460028501805493945090928490811061311a5761311a613e43565b906000526020600020015490508084600201838154811061313d5761313d613e43565b60009182526020808320909101929092558281526003860190915260408082208490558682528120556002840180548061317957613179614109565b600190038181906000526020600020016000905590555050505050565b600080516020614120833981519152600060016131b28561133c565b6131bc9190613e1d565b6001600160a01b0390941660009081526020838152604080832087845282528083208690559482526001909301909252502055565b600080807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a084111561322c57506000915060039050826132b6565b604080516000808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa158015613280573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166132ac575060009250600191508290506132b6565b9250600091508190505b9450945094915050565b6132c8612c7e565b600080546001600160a01b031916339081178255604051909182917fe379ac64de02d8184ca1a871ac486cb8137de77e485ede140e97057b9c765ffd908290a350565b6001600160a01b03821661333557604051633250574960e11b815260006004820152602401610767565b6000613343838360006122f3565b90506001600160a01b03811615610e06576040516339e3563760e11b815260006004820152602401610767565b61337b8383836133d4565b610e06576001600160a01b0383166133a957604051637e27328960e01b815260048101829052602401610767565b60405163177e802f60e01b81526001600160a01b038316600482015260248101829052604401610767565b60006001600160a01b038316158015906123005750826001600160a01b0316846001600160a01b0316148061340e575061340e8484611ff5565b806123005750826001600160a01b0316613427836122ac565b6001600160a01b031614949350505050565b82805482825590600052602060002090810192821561347f579160200282015b8281111561347f578251829061346f9082613d48565b5091602001919060010190613459565b5061348b92915061348f565b5090565b8082111561348b5760006134a382826134ac565b5060010161348f565b5080546134b890613c6b565b6000825580601f106134c8575050565b601f016020900490600052602060002090810190610d6c91905b8082111561348b57600081556001016134e2565b6001600160e01b031981168114610d6c57600080fd5b60006020828403121561351e57600080fd5b8135613529816134f6565b9392505050565b80356001600160a01b038116811461354757600080fd5b919050565b60006020828403121561355e57600080fd5b61352982613530565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b03811182821017156135a5576135a5613567565b604052919050565b600082601f8301126135be57600080fd5b81356001600160401b038111156135d7576135d7613567565b6135ea601f8201601f191660200161357d565b8181528460208386010111156135ff57600080fd5b816020850160208301376000918101602001919091529392505050565b6000806040838503121561362f57600080fd5b82356001600160401b0381111561364557600080fd5b613651858286016135ad565b92505061366060208401613530565b90509250929050565b60005b8381101561368457818101518382015260200161366c565b50506000910152565b600081518084526136a5816020860160208601613669565b601f01601f19169290920160200192915050565b602081526000613529602083018461368d565b6000602082840312156136de57600080fd5b5035919050565b600080604083850312156136f857600080fd5b61370183613530565b946020939093013593505050565b60008060006060848603121561372457600080fd5b61372d84613530565b925061373b60208501613530565b9150604084013590509250925092565b600082601f83011261375c57600080fd5b813560206001600160401b038083111561377857613778613567565b8260051b61378783820161357d565b93845285810183019383810190888611156137a157600080fd5b84880192505b858310156137dd578235848111156137bf5760008081fd5b6137cd8a87838c01016135ad565b83525091840191908401906137a7565b98975050505050505050565b80356001600160401b038116811461354757600080fd5b600080600080600080600060e0888a03121561381b57600080fd5b87356001600160401b038082111561383257600080fd5b61383e8b838c016135ad565b985060208a013591508082111561385457600080fd5b6138608b838c016135ad565b975060408a013591508082111561387657600080fd5b6138828b838c016135ad565b965060608a013591508082111561389857600080fd5b6138a48b838c0161374b565b955060808a01359150808211156138ba57600080fd5b506138c78a828b016135ad565b9350506138d660a089016137e9565b91506138e460c089016137e9565b905092959891949750929550565b60006020828403121561390457600080fd5b81356001600160401b0381111561391a57600080fd5b612300848285016135ad565b60a08152600061393960a083018861368d565b6001600160401b038781166020850152861660408401528281036060840152613962818661368d565b905082810360808401526137dd818561368d565b6000806000806080858703121561398c57600080fd5b84359350602085013592506040850135915060608501356001600160401b038111156139b757600080fd5b6139c3878288016135ad565b91505092959194509250565b600060208083016020845280855180835260408601915060408160051b87010192506020870160005b82811015613a2657603f19888603018452613a1485835161368d565b945092850192908501906001016139f8565b5092979650505050505050565b60008060408385031215613a4657600080fd5b82356001600160401b03811115613a5c57600080fd5b613a68858286016135ad565b95602094909401359450505050565b60008060408385031215613a8a57600080fd5b613a9383613530565b915060208301358015158114613aa857600080fd5b809150509250929050565b60008060008060808587031215613ac957600080fd5b613ad285613530565b9350613ae060208601613530565b92506040850135915060608501356001600160401b038111156139b757600080fd5b600080600080600080600080610100898b031215613b1f57600080fd5b88356001600160401b0380821115613b3657600080fd5b613b428c838d016135ad565b995060208b0135915080821115613b5857600080fd5b613b648c838d016135ad565b985060408b0135915080821115613b7a57600080fd5b613b868c838d016135ad565b975060608b0135915080821115613b9c57600080fd5b613ba88c838d0161374b565b965060808b0135915080821115613bbe57600080fd5b50613bcb8b828c016135ad565b94505060a08901359250613be160c08a016137e9565b9150613bef60e08a016137e9565b90509295985092959890939650565b60008060408385031215613c1157600080fd5b613c1a83613530565b915061366060208401613530565b60208082526023908201527f41636365737320436f6e74726f6c3a2073656e646572206973206e6f7420416460408201526236b4b760e91b606082015260800190565b600181811c90821680613c7f57607f821691505b602082108103613c9f57634e487b7160e01b600052602260045260246000fd5b50919050565b60008251613cb7818460208701613669565b9190910192915050565b6020808252601f908201527f4e46542064657461696c73206e6f742073657420666f72207468697320494400604082015260600190565b601f821115610e06576000816000526020600020601f850160051c81016020861015613d215750805b601f850160051c820191505b81811015613d4057828155600101613d2d565b505050505050565b81516001600160401b03811115613d6157613d61613567565b613d7581613d6f8454613c6b565b84613cf8565b602080601f831160018114613daa5760008415613d925750858301515b600019600386901b1c1916600185901b178555613d40565b600085815260208120601f198616915b82811015613dd957888601518255948401946001909101908401613dba565b5085821015613df75787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b634e487b7160e01b600052601160045260246000fd5b8181038181111561072857610728613e07565b8082018082111561072857610728613e07565b634e487b7160e01b600052603260045260246000fd5b60008351613e6b818460208801613669565b61202360f01b9083019081528351613e8a816002840160208801613669565b01600201949350505050565b66697066733a2f2f60c81b815260008551613eb8816007850160208a01613669565b8083019050602f60f81b8060078301528651613edb816008850160208b01613669565b60089201918201528451613ef6816009840160208901613669565b601760f91b600992909101918201528351613f1881600a840160208801613669565b01600a019695505050505050565b693d913730b6b2911d101160b11b81528251600090613f4c81600a850160208801613669565b6c1116101134b6b0b3b2911d101160991b600a918401918201528351613f79816017840160208801613669565b61227d60f01b60179290910191820152601901949350505050565b7f646174613a6170706c69636174696f6e2f6a736f6e3b6261736536342c000000815260008251613fcc81601d850160208701613669565b91909101601d0192915050565b600060018201613feb57613feb613e07565b5060010190565b828152604060208201526000612300604083018461368d565b6001600160a01b038581168252841660208201526040810183905260806060820181905260009061403e9083018461368d565b9695505050505050565b60006020828403121561405a57600080fd5b8151613529816134f6565b634e487b7160e01b600052601260045260246000fd5b60008261408a5761408a614065565b500490565b808202811582820484141761072857610728613e07565b60018060a01b038716815285602082015284604082015283606082015282608082015260c060a082015260006137dd60c083018461368d565b6000826140ee576140ee614065565b500690565b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052603160045260246000fdfe645e039705490088daad89bae25049a34f4a9072d398537b1ab2425f24cbed0080bb2b638cc20bc4d0a60d66940f3ab4a00c1d7b313497ca82fb0b4ab00793004142434445464748494a4b4c4d4e4f505152535455565758595a6162636465666768696a6b6c6d6e6f707172737475767778797a303132333435363738392b2f645e039705490088daad89bae25049a34f4a9072d398537b1ab2425f24cbed02a2646970667358221220501f7450f4c411a01c0d59bb9294baafd8efa5b2ffb8978f06dafe24d56c408b64736f6c63430008180033