ERC-721
Source Code
Overview
Max Total Supply
17,154 SHIP
Holders
10,581
Market
Volume (24H)
N/A
Min Price (24H)
N/A
Max Price (24H)
N/A
Other Info
Token Contract
Balance
1 SHIPLoading...
Loading
Loading...
Loading
Loading...
Loading
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0xF8098f7d...462436a8f The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
ShipNFT
Compiler Version
v0.8.13+commit.abaa5c0e
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT LICENSE
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/utils/Strings.sol";
import "../../deprecated/GameNFT.sol";
import {GENERATION_TRAIT_ID, LEVEL_TRAIT_ID, NAME_TRAIT_ID, IS_SHIP_TRAIT_ID, MINTER_ROLE, GAME_LOGIC_CONTRACT_ROLE} from "../../Constants.sol";
uint256 constant ID = uint256(keccak256("game.piratenation.shipnft"));
/** @title Pirate NFTs on L2 */
contract ShipNFT is GameNFT {
using Strings for uint256;
// 0 max supply = infinite
uint256 constant MAX_SUPPLY = 0;
constructor(address gameRegistryAddress)
GameNFT(MAX_SUPPLY, "Ship", "SHIP", gameRegistryAddress, ID)
{
_defaultDescription = "Take to the seas with your pirate crew! Explore the world and gather XP, loot, and untold riches in a race to become the world's greatest pirate captain! Play at https://piratenation.game";
_defaultImageURI = "ipfs://QmUeMG7QPySPiBp4hTc9u1FPcq5MKJzyYLgQh1t7FefECX?";
}
/** Initializes traits for the given tokenId */
function _initializeTraits(uint256 tokenId) internal override {
ITraitsProvider traitsProvider = _traitsProvider();
traitsProvider.setTraitBool(
address(this),
tokenId,
IS_SHIP_TRAIT_ID,
true
);
}
/** @return Token name for the given tokenId */
function tokenName(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
if (_hasTrait(tokenId, NAME_TRAIT_ID) == true) {
// If token has a name trait set, use that
return _getTraitString(tokenId, NAME_TRAIT_ID);
} else {
return string(abi.encodePacked("Ship #", tokenId.toString()));
}
}
/**
* Mints the ERC721 token
*
* @param to Recipient of the token
* @param id Id of token to mint
*/
function mint(address to, uint256 id)
external
onlyRole(MINTER_ROLE)
whenNotPaused
{
_safeMint(to, id);
}
/**
* Burn a token - any payment / game logic should be handled in the game contract.
*
* @param id Id of the token to burn
*/
function burn(uint256 id)
external
onlyRole(GAME_LOGIC_CONTRACT_ROLE)
whenNotPaused
{
_burn(id);
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;
/**
* @title The ERC-2771 Recipient Base Abstract Class - Declarations
*
* @notice A contract must implement this interface in order to support relayed transaction.
*
* @notice It is recommended that your contract inherits from the ERC2771Recipient contract.
*/
abstract contract IERC2771Recipient {
/**
* :warning: **Warning** :warning: The Forwarder can have a full control over your Recipient. Only trust verified Forwarder.
* @param forwarder The address of the Forwarder contract that is being used.
* @return isTrustedForwarder `true` if the Forwarder is trusted to forward relayed transactions by this Recipient.
*/
function isTrustedForwarder(address forwarder) public virtual view returns(bool);
/**
* @notice Use this method the contract anywhere instead of msg.sender to support relayed transactions.
* @return sender The real sender of this call.
* For a call that came through the Forwarder the real sender is extracted from the last 20 bytes of the `msg.data`.
* Otherwise simply returns `msg.sender`.
*/
function _msgSender() internal virtual view returns (address);
/**
* @notice Use this method in the contract instead of `msg.data` when difference matters (hashing, signature, etc.)
* @return data The real `msg.data` of this call.
* For a call that came through the Forwarder, the real sender address was appended as the last 20 bytes
* of the `msg.data` - so this method will strip those 20 bytes off.
* Otherwise (if the call was made directly and not through the forwarder) simply returns `msg.data`.
*/
function _msgData() internal virtual view returns (bytes calldata);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/ERC721.sol)
pragma solidity ^0.8.0;
import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/ERC165.sol";
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to owner address
mapping(uint256 => address) private _owners;
// Mapping owner address to token count
mapping(address => uint256) private _balances;
// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: address zero is not a valid owner");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _ownerOf(tokenId);
require(owner != address(0), "ERC721: invalid token ID");
return owner;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
_requireMinted(tokenId);
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be 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 override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not token owner or approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
_requireMinted(tokenId);
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory data
) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved");
_safeTransfer(from, to, tokenId, data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(
address from,
address to,
uint256 tokenId,
bytes memory data
) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist
*/
function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
return _owners[tokenId];
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _ownerOf(tokenId) != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == spender);
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(
address to,
uint256 tokenId,
bytes memory data
) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId, 1);
// Check that tokenId was not minted by `_beforeTokenTransfer` hook
require(!_exists(tokenId), "ERC721: token already minted");
unchecked {
// Will not overflow unless all 2**256 token ids are minted to the same owner.
// Given that tokens are minted one by one, it is impossible in practice that
// this ever happens. Might change if we allow batch minting.
// The ERC fails to describe this case.
_balances[to] += 1;
}
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
_afterTokenTransfer(address(0), to, tokenId, 1);
}
/**
* @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 virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId, 1);
// Update ownership in case tokenId was transferred by `_beforeTokenTransfer` hook
owner = ERC721.ownerOf(tokenId);
// Clear approvals
delete _tokenApprovals[tokenId];
unchecked {
// Cannot overflow, as that would require more tokens to be burned/transferred
// out than the owner initially received through minting and transferring in.
_balances[owner] -= 1;
}
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
_afterTokenTransfer(owner, address(0), tokenId, 1);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId, 1);
// Check that tokenId was not transferred by `_beforeTokenTransfer` hook
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
// Clear approvals from the previous owner
delete _tokenApprovals[tokenId];
unchecked {
// `_balances[from]` cannot overflow for the same reason as described in `_burn`:
// `from`'s balance is the number of token held, which is at least one before the current
// transfer.
// `_balances[to]` could overflow in the conditions described in `_mint`. That would require
// all 2**256 token ids to be minted, which in practice is impossible.
_balances[from] -= 1;
_balances[to] += 1;
}
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
_afterTokenTransfer(from, to, tokenId, 1);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits an {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Emits an {ApprovalForAll} event.
*/
function _setApprovalForAll(
address owner,
address operator,
bool approved
) internal virtual {
require(owner != operator, "ERC721: approve to caller");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Reverts if the `tokenId` has not been minted yet.
*/
function _requireMinted(uint256 tokenId) internal view virtual {
require(_exists(tokenId), "ERC721: invalid token ID");
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory data
) private returns (bool) {
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
return retval == IERC721Receiver.onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
/// @solidity memory-safe-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting and burning. If {ERC721Consecutive} is
* used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s tokens will be transferred to `to`.
* - When `from` is zero, the tokens will be minted for `to`.
* - When `to` is zero, ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
* - `batchSize` is non-zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256, /* firstTokenId */
uint256 batchSize
) internal virtual {
if (batchSize > 1) {
if (from != address(0)) {
_balances[from] -= batchSize;
}
if (to != address(0)) {
_balances[to] += batchSize;
}
}
}
/**
* @dev Hook that is called after any token transfer. This includes minting and burning. If {ERC721Consecutive} is
* used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s tokens were transferred to `to`.
* - When `from` is zero, the tokens were minted for `to`.
* - When `to` is zero, ``from``'s tokens were burned.
* - `from` and `to` are never both zero.
* - `batchSize` is non-zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize
) internal virtual {}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/extensions/ERC721Enumerable.sol)
pragma solidity ^0.8.0;
import "../ERC721.sol";
import "./IERC721Enumerable.sol";
/**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
return _allTokens[index];
}
/**
* @dev See {ERC721-_beforeTokenTransfer}.
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize
) internal virtual override {
super._beforeTokenTransfer(from, to, firstTokenId, batchSize);
if (batchSize > 1) {
// Will only trigger during construction. Batch transferring (minting) is not available afterwards.
revert("ERC721Enumerable: consecutive transfers not supported");
}
uint256 tokenId = firstTokenId;
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface 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);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @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 up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (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; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1);
///////////////////////////////////////////////
// 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.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
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 (rounding == Rounding.Up && 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 down.
*
* 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 + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* 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 + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* 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 + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* 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 10, 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 + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.0;
/**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/
library SafeCast {
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toUint248(uint256 value) internal pure returns (uint248) {
require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toUint240(uint256 value) internal pure returns (uint240) {
require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toUint232(uint256 value) internal pure returns (uint232) {
require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*
* _Available since v4.2._
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toUint216(uint256 value) internal pure returns (uint216) {
require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toUint208(uint256 value) internal pure returns (uint208) {
require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toUint200(uint256 value) internal pure returns (uint200) {
require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toUint192(uint256 value) internal pure returns (uint192) {
require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toUint184(uint256 value) internal pure returns (uint184) {
require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toUint176(uint256 value) internal pure returns (uint176) {
require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toUint168(uint256 value) internal pure returns (uint168) {
require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toUint160(uint256 value) internal pure returns (uint160) {
require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toUint152(uint256 value) internal pure returns (uint152) {
require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toUint144(uint256 value) internal pure returns (uint144) {
require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toUint136(uint256 value) internal pure returns (uint136) {
require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v2.5._
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toUint120(uint256 value) internal pure returns (uint120) {
require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toUint112(uint256 value) internal pure returns (uint112) {
require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toUint104(uint256 value) internal pure returns (uint104) {
require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*
* _Available since v4.2._
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toUint88(uint256 value) internal pure returns (uint88) {
require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toUint80(uint256 value) internal pure returns (uint80) {
require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toUint72(uint256 value) internal pure returns (uint72) {
require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v2.5._
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toUint56(uint256 value) internal pure returns (uint56) {
require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toUint48(uint256 value) internal pure returns (uint48) {
require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toUint40(uint256 value) internal pure returns (uint40) {
require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v2.5._
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toUint24(uint256 value) internal pure returns (uint24) {
require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v2.5._
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*
* _Available since v2.5._
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*
* _Available since v3.0._
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*
* _Available since v4.7._
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*
* _Available since v4.7._
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*
* _Available since v3.0._
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/Math.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @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), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @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) {
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] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
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);
}
}// SPDX-License-Identifier: MIT LICENSE
pragma solidity ^0.8.9;
// Used for calculating decimal-point percentages (10000 = 100%)
uint256 constant PERCENTAGE_RANGE = 10000;
// Pauser Role - Can pause the game
bytes32 constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
// Minter Role - Can mint items, NFTs, and ERC20 currency
bytes32 constant MINTER_ROLE = keccak256("MINTER_ROLE");
// Manager Role - Can manage the shop, loot tables, and other game data
bytes32 constant MANAGER_ROLE = keccak256("MANAGER_ROLE");
// Game Logic Contract - Contract that executes game logic and accesses other systems
bytes32 constant GAME_LOGIC_CONTRACT_ROLE = keccak256(
"GAME_LOGIC_CONTRACT_ROLE"
);
// Game Currency Contract - Allowlisted currency ERC20 contract
bytes32 constant GAME_CURRENCY_CONTRACT_ROLE = keccak256(
"GAME_CURRENCY_CONTRACT_ROLE"
);
// Game NFT Contract - Allowlisted game NFT ERC721 contract
bytes32 constant GAME_NFT_CONTRACT_ROLE = keccak256("GAME_NFT_CONTRACT_ROLE");
// Game Items Contract - Allowlist game items ERC1155 contract
bytes32 constant GAME_ITEMS_CONTRACT_ROLE = keccak256(
"GAME_ITEMS_CONTRACT_ROLE"
);
// Depositor role - used by Polygon bridge to mint on child chain
bytes32 constant DEPOSITOR_ROLE = keccak256("DEPOSITOR_ROLE");
// Randomizer role - Used by the randomizer contract to callback
bytes32 constant RANDOMIZER_ROLE = keccak256("RANDOMIZER_ROLE");
// Trusted forwarder role - Used by meta transactions to verify trusted forwader(s)
bytes32 constant TRUSTED_FORWARDER_ROLE = keccak256("TRUSTED_FORWARDER_ROLE");
// =====
// All of the possible traits in the system
// =====
/// @dev Trait that points to another token/template id
uint256 constant TEMPLATE_ID_TRAIT_ID = uint256(keccak256("template_id"));
// Generation of a token
uint256 constant GENERATION_TRAIT_ID = uint256(keccak256("generation"));
// XP for a token
uint256 constant XP_TRAIT_ID = uint256(keccak256("xp"));
// Current level of a token
uint256 constant LEVEL_TRAIT_ID = uint256(keccak256("level"));
// Whether or not a token is a pirate
uint256 constant IS_PIRATE_TRAIT_ID = uint256(keccak256("is_pirate"));
// Whether or not a token is a ship
uint256 constant IS_SHIP_TRAIT_ID = uint256(keccak256("is_ship"));
// Whether or not an item is equippable on ships
uint256 constant EQUIPMENT_TYPE_TRAIT_ID = uint256(keccak256("equipment_type"));
// Item slots
uint256 constant ITEM_SLOTS_TRAIT_ID = uint256(keccak256("item_slots"));
// Rank of the ship
uint256 constant SHIP_RANK_TRAIT_ID = uint256(keccak256("ship_rank"));
// Current Health trait
uint256 constant CURRENT_HEALTH_TRAIT_ID = uint256(keccak256("current_health"));
// Health trait
uint256 constant HEALTH_TRAIT_ID = uint256(keccak256("health"));
// Damage trait
uint256 constant DAMAGE_TRAIT_ID = uint256(keccak256("damage"));
// Speed trait
uint256 constant SPEED_TRAIT_ID = uint256(keccak256("speed"));
// Accuracy trait
uint256 constant ACCURACY_TRAIT_ID = uint256(keccak256("accuracy"));
// Evasion trait
uint256 constant EVASION_TRAIT_ID = uint256(keccak256("evasion"));
// Image hash of token's image, used for verifiable / fair drops
uint256 constant IMAGE_HASH_TRAIT_ID = uint256(keccak256("image_hash"));
// Name of a token
uint256 constant NAME_TRAIT_ID = uint256(keccak256("name_trait"));
// Description of a token
uint256 constant DESCRIPTION_TRAIT_ID = uint256(keccak256("description_trait"));
// General rarity for a token (corresponds to IGameRarity)
uint256 constant RARITY_TRAIT_ID = uint256(keccak256("rarity"));
// The character's affinity for a specific element
uint256 constant ELEMENTAL_AFFINITY_TRAIT_ID = uint256(
keccak256("affinity_id")
);
// Boss start time trait
uint256 constant BOSS_START_TIME_TRAIT_ID = uint256(
keccak256("boss_start_time")
);
// Boss end time trait
uint256 constant BOSS_END_TIME_TRAIT_ID = uint256(keccak256("boss_end_time"));
// Boss type trait
uint256 constant BOSS_TYPE_TRAIT_ID = uint256(keccak256("boss_type"));
// The character's dice rolls
uint256 constant DICE_ROLL_1_TRAIT_ID = uint256(keccak256("dice_roll_1"));
uint256 constant DICE_ROLL_2_TRAIT_ID = uint256(keccak256("dice_roll_2"));
// The character's star sign (astrology)
uint256 constant STAR_SIGN_TRAIT_ID = uint256(keccak256("star_sign"));
// Image for the token
uint256 constant IMAGE_TRAIT_ID = uint256(keccak256("image_trait"));
// How much energy the token provides if used
uint256 constant ENERGY_PROVIDED_TRAIT_ID = uint256(
keccak256("energy_provided")
);
// Whether a given token is soulbound, meaning it is unable to be transferred
uint256 constant SOULBOUND_TRAIT_ID = uint256(keccak256("soulbound"));
// ------
// Avatar Profile Picture related traits
// If an avatar is a 1 of 1, this is their only trait
uint256 constant PROFILE_IS_LEGENDARY_TRAIT_ID = uint256(
keccak256("profile_is_legendary")
);
// Avatar's archetype -- possible values: Human (including Druid, Mage, Berserker, Crusty), Robot, Animal, Zombie, Vampire, Ghost
uint256 constant PROFILE_CHARACTER_TYPE = uint256(
keccak256("profile_character_type")
);
// Avatar's profile picture's background image
uint256 constant PROFILE_BACKGROUND_TRAIT_ID = uint256(
keccak256("profile_background")
);
// Avatar's eye style
uint256 constant PROFILE_EYES_TRAIT_ID = uint256(keccak256("profile_eyes"));
// Avatar's facial hair type
uint256 constant PROFILE_FACIAL_HAIR_TRAIT_ID = uint256(
keccak256("profile_facial_hair")
);
// Avatar's hair style
uint256 constant PROFILE_HAIR_TRAIT_ID = uint256(keccak256("profile_hair"));
// Avatar's skin color
uint256 constant PROFILE_SKIN_TRAIT_ID = uint256(keccak256("profile_skin"));
// Avatar's coat color
uint256 constant PROFILE_COAT_TRAIT_ID = uint256(keccak256("profile_coat"));
// Avatar's earring(s) type
uint256 constant PROFILE_EARRING_TRAIT_ID = uint256(
keccak256("profile_facial_hair")
);
// Avatar's eye covering
uint256 constant PROFILE_EYE_COVERING_TRAIT_ID = uint256(
keccak256("profile_eye_covering")
);
// Avatar's headwear
uint256 constant PROFILE_HEADWEAR_TRAIT_ID = uint256(
keccak256("profile_headwear")
);
// Avatar's (Mages only) gem color
uint256 constant PROFILE_MAGE_GEM_TRAIT_ID = uint256(
keccak256("profile_mage_gem")
);// SPDX-License-Identifier: MIT LICENSE
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "./IERC721BridgableChild.sol";
/// @notice This contract implements the Matic/Polygon bridging logic to allow tokens to be bridged back to mainnet
abstract contract ERC721BridgableChild is
ERC721Enumerable,
IERC721BridgableChild
{
// Max batch size
uint256 public constant BATCH_LIMIT = 20;
/** EVENTS **/
// Emitted when a token is deposited
event DepositFromBridge(address indexed to, uint256 indexed tokenId);
// @notice this event needs to be like this and unchanged so that the L1 can pick up the changes
// @dev We don't use this event, everything is a single withdraw so metadata is always transferred
// event WithdrawnBatch(address indexed user, uint256[] tokenIds);
// @notice this event needs to be like this and unchanged so that the L1 can pick up the changes
event TransferWithMetadata(
address indexed from,
address indexed to,
uint256 indexed tokenId,
bytes metaData
);
/** ERRORS **/
/// @notice Call was not made by owner
error NotOwner();
/// @notice Tried to withdraw too many tokens at once
error ExceedsBatchLimit();
/** EXTERNAL **/
/**
* @notice called when to wants to withdraw token back to root chain
* @dev Should burn to's token. This transaction will be verified when exiting on root chain
* @param tokenId tokenId to withdraw
*/
function withdraw(uint256 tokenId) external {
_withdrawWithMetadata(tokenId);
}
/**
* @notice called when to wants to withdraw multiple tokens back to root chain
* @dev Should burn to's tokens. This transaction will be verified when exiting on root chain
* @param tokenIds tokenId list to withdraw
*/
function withdrawBatch(uint256[] calldata tokenIds) external {
uint256 length = tokenIds.length;
if (length > BATCH_LIMIT) {
revert ExceedsBatchLimit();
}
for (uint256 i; i < length; ++i) {
uint256 tokenId = tokenIds[i];
_withdrawWithMetadata(tokenId);
}
}
/**
* @notice called when to wants to withdraw token back to root chain with arbitrary metadata
* @dev Should handle withraw by burning to's token.
*
* This transaction will be verified when exiting on root chain
*
* @param tokenId tokenId to withdraw
*/
function withdrawWithMetadata(uint256 tokenId) external {
_withdrawWithMetadata(tokenId);
}
/**
* @notice This method is supposed to be called by client when withdrawing token with metadata
* and pass return value of this function as second paramter of `withdrawWithMetadata` method
*
* It can be overridden by clients to encode data in a different form, which needs to
* be decoded back by them correctly during exiting
*
* @param tokenId Token for which URI to be fetched
*/
function encodeTokenMetadata(uint256 tokenId)
external
view
virtual
returns (bytes memory)
{
// You're always free to change this default implementation
// and pack more data in byte array which can be decoded back
// in L1
return abi.encode(tokenURI(tokenId));
}
/** @return Whether or not the given tokenId has been minted/exists */
function exists(uint256 tokenId) external view override returns (bool) {
return _exists(tokenId);
}
/**
* @inheritdoc IERC165
*/
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC721Enumerable, IERC165)
returns (bool)
{
return
interfaceId == type(IERC721BridgableChild).interfaceId ||
ERC721Enumerable.supportsInterface(interfaceId);
}
/** INTERNAL **/
/// @dev executes the withdraw
function _withdrawWithMetadata(uint256 tokenId) internal {
if (_msgSender() != ownerOf(tokenId)) {
revert NotOwner();
}
// Encoding metadata associated with tokenId & emitting event
// This event needs to be exactly like this for the bridge to work
emit TransferWithMetadata(
_msgSender(),
address(0),
tokenId,
this.encodeTokenMetadata(tokenId)
);
_burn(tokenId);
}
/**
* @notice called when token is deposited on root chain
* @dev Should be callable only by ChildChainManager
* Should handle deposit by minting the required tokenId for to
* Make sure minting is done only by this function
* @param to address for whom deposit is being done
* @param depositData abi encoded tokenId
*/
function _deposit(address to, bytes calldata depositData) internal virtual {
// deposit single
if (depositData.length == 32) {
uint256 tokenId = abi.decode(depositData, (uint256));
_safeMint(to, tokenId);
emit DepositFromBridge(to, tokenId);
} else {
// deposit batch
uint256[] memory tokenIds = abi.decode(depositData, (uint256[]));
uint256 length = tokenIds.length;
for (uint256 i; i < length; ++i) {
_safeMint(to, tokenIds[i]);
emit DepositFromBridge(to, tokenIds[i]);
}
}
}
}// SPDX-License-Identifier: MIT LICENSE
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {IGameNFT} from "./IGameNFT.sol";
import {DEPOSITOR_ROLE} from "../Constants.sol";
import {ITraitsProvider} from "../interfaces/ITraitsProvider.sol";
import {SafeCast, ITraitsConsumer, TraitsConsumer, GameRegistryConsumer} from "../TraitsConsumer.sol";
import {IERC721BeforeTokenTransferHandler} from "../tokens/IERC721BeforeTokenTransferHandler.sol";
import "./ERC721BridgableChild.sol";
/** @title NFT base contract for all game NFTs. Exposes traits for the NFT and respects GameRegistry/Soulbound/LockingSystem access control */
contract GameNFT is IERC165, TraitsConsumer, IGameNFT, ERC721BridgableChild {
/// @notice Whether or not the token has had its traits initialized. Prevents re-initialization when bridging
mapping(uint256 => bool) private _traitsInitialized;
/// @notice Max supply for this NFT. If zero, it is unlimited supply.
uint256 private immutable _maxSupply;
/// @notice The amount of time a token has been held by a given account
mapping(uint256 => mapping(address => uint32)) private _timeHeld;
/// @notice Last transfer time for the token
mapping(uint256 => uint32) public lastTransfer;
/// @notice Current contract metadata URI for this collection
string private _contractURI;
/// @notice Handler for before token transfer events
address public beforeTokenTransferHandler;
/** EVENTS **/
/// @notice Emitted when contractURI has changed
event ContractURIUpdated(string uri);
/** ERRORS **/
/// @notice Account must be non-null
error InvalidAccountAddress();
/// @notice Token id is not valid
error InvalidTokenId();
/// @notice tokenId exceeds max supply for this NFT
error TokenIdExceedsMaxSupply();
/// @notice Amount to mint exceeds max supply
error NotEnoughSupply(uint256 needed, uint256 actual);
/** SETUP **/
constructor(
uint256 tokenMaxSupply,
string memory name,
string memory symbol,
address gameRegistryAddress,
uint256 id
) ERC721(name, symbol) TraitsConsumer(gameRegistryAddress, id) {
_maxSupply = tokenMaxSupply;
}
/**
* Sets the current contractURI for the contract
*
* @param _uri New contract URI
*/
function setContractURI(string calldata _uri) public onlyOwner {
_contractURI = _uri;
emit ContractURIUpdated(_uri);
}
/**
* @return Contract metadata URI for the NFT contract, used by NFT marketplaces to display collection inf
*/
function contractURI() public view returns (string memory) {
return _contractURI;
}
/**
* @notice called when token is deposited on root chain
* @dev Should be callable only by DEPOSITOR_ROLE and call _deposit
*/
function deposit(
address to,
bytes calldata depositData
) external override onlyRole(DEPOSITOR_ROLE) {
_deposit(to, depositData);
}
/** @return Max supply for this token */
function maxSupply() external view returns (uint256) {
return _maxSupply;
}
/**
* @return Generates a dynamic tokenURI based on the traits associated with the given token
*/
function tokenURI(
uint256 tokenId
) public view override returns (string memory) {
// Make sure this still errors according to ERC721 spec
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
return _tokenURI(tokenId);
}
/**
* @param account Account to check hold time of
* @param tokenId Id of the token
* @return The time in seconds a given account has held a token
*/
function getTimeHeld(
address account,
uint256 tokenId
) external view returns (uint32) {
address owner = ownerOf(tokenId);
if (account == address(0)) {
revert InvalidAccountAddress();
}
uint32 totalTime = _timeHeld[tokenId][account];
if (owner == account) {
uint32 lastTransferTime = lastTransfer[tokenId];
uint32 currentTime = SafeCast.toUint32(block.timestamp);
totalTime += (currentTime - lastTransferTime);
}
return totalTime;
}
/**
* Sets the before token transfer handler
*
* @param handlerAddress Address to the transfer hook handler contract
*/
function setBeforeTokenTransferHandler(
address handlerAddress
) external onlyOwner {
beforeTokenTransferHandler = handlerAddress;
}
/**
* @inheritdoc IERC165
*/
function supportsInterface(
bytes4 interfaceId
)
public
view
virtual
override(IERC165, TraitsConsumer, ERC721BridgableChild)
returns (bool)
{
return
interfaceId == type(IGameNFT).interfaceId ||
ERC721BridgableChild.supportsInterface(interfaceId) ||
TraitsConsumer.supportsInterface(interfaceId);
}
/** INTERNAL **/
/** Initializes traits for the given tokenId */
function _initializeTraits(uint256 tokenId) internal virtual {
// Do nothing by default
}
/**
* Mint token to recipient
*
* @param to The recipient of the token
* @param tokenId Id of the token to mint
*/
function _safeMint(address to, uint256 tokenId) internal override {
if (_maxSupply != 0 && tokenId > _maxSupply) {
revert TokenIdExceedsMaxSupply();
}
if (tokenId == 0) {
revert InvalidTokenId();
}
super._safeMint(to, tokenId);
// Conditionally initialize traits
if (_traitsInitialized[tokenId] == false) {
_initializeTraits(tokenId);
_traitsInitialized[tokenId] = true;
}
}
/**
* @notice Checks for soulbound status before transfer
* @inheritdoc ERC721
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize
) internal virtual override {
if (beforeTokenTransferHandler != address(0)) {
IERC721BeforeTokenTransferHandler handlerRef = IERC721BeforeTokenTransferHandler(
beforeTokenTransferHandler
);
handlerRef.beforeTokenTransfer(
address(this),
_msgSender(),
from,
to,
firstTokenId,
batchSize
);
}
// Track hold time
for (uint256 idx = 0; idx < batchSize; idx++) {
uint256 tokenId = firstTokenId + idx;
uint32 lastTransferTime = lastTransfer[tokenId];
uint32 currentTime = SafeCast.toUint32(block.timestamp);
if (lastTransferTime > 0) {
_timeHeld[tokenId][from] += (currentTime - lastTransferTime);
}
lastTransfer[tokenId] = currentTime;
}
super._beforeTokenTransfer(from, to, firstTokenId, batchSize);
}
/**
* Message sender override to get Context to work with meta transactions
*
*/
function _msgSender()
internal
view
override(Context, GameRegistryConsumer)
returns (address)
{
return GameRegistryConsumer._msgSender();
}
/**
* Message data override to get Context to work with meta transactions
*
*/
function _msgData()
internal
view
override(Context, GameRegistryConsumer)
returns (bytes memory)
{
return GameRegistryConsumer._msgData();
}
function getLastTransfer(uint256 tokenId) external view returns (uint32) {
return lastTransfer[tokenId];
}
}// SPDX-License-Identifier: MIT LICENSE
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
// @notice Interface for Polygon bridgable NFTs on L2-chain
interface IERC721BridgableChild is IERC721Enumerable {
/**
* @notice called when token is deposited on root chain
* @dev Should be callable only by ChildChainManager and call _deposit
*
* @param to Address being deposited to
* @param depositData ABI encoded ids being deposited
*/
function deposit(address to, bytes calldata depositData) external;
/** @return Whether or not the given tokenId has been minted/exists */
function exists(uint256 tokenId) external view returns (bool);
}// SPDX-License-Identifier: MIT LICENSE
pragma solidity ^0.8.9;
import {IERC721BridgableChild} from "./IERC721BridgableChild.sol";
import {IHoldingConsumer} from "../interfaces/IHoldingConsumer.sol";
/**
* @title Interface for game NFTs that have stats and other properties
*/
interface IGameNFT is IHoldingConsumer, IERC721BridgableChild {
}// SPDX-License-Identifier: MIT LICENSE
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@opengsn/contracts/src/interfaces/IERC2771Recipient.sol";
import {IGameRegistry} from "./interfaces/IGameRegistry.sol";
import {ISystem} from "./interfaces/ISystem.sol";
import {TRUSTED_FORWARDER_ROLE} from "./Constants.sol";
import {ITraitsProvider, ID as TRAITS_PROVIDER_ID} from "./interfaces/ITraitsProvider.sol";
import {ILockingSystem, ID as LOCKING_SYSTEM_ID} from "./locking/ILockingSystem.sol";
import {IRandomizer, IRandomizerCallback, ID as RANDOMIZER_ID} from "./randomizer/IRandomizer.sol";
import {ILootSystem, ID as LOOT_SYSTEM_ID} from "./loot/ILootSystem.sol";
/** @title Contract that lets a child contract access the GameRegistry contract */
abstract contract GameRegistryConsumer is
ISystem,
Ownable,
IERC2771Recipient,
IRandomizerCallback
{
/// @notice Whether or not the contract is paused
bool private _paused;
/// @notice Id for the system/component
uint256 private _id;
/// @notice Read access contract
IGameRegistry private _gameRegistry;
/** EVENTS **/
/// @dev Emitted when the pause is triggered by `account`.
event Paused(address account);
/// @dev Emitted when the pause is lifted by `account`.
event Unpaused(address account);
/** ERRORS **/
/// @notice Not authorized to perform action
error MissingRole(address account, bytes32 expectedRole);
/** MODIFIERS **/
// Modifier to verify a user has the appropriate role to call a given function
modifier onlyRole(bytes32 role) {
_checkRole(role, _msgSender());
_;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/** ERRORS **/
/// @notice gameRegistryAddress does not implement IGameRegistry
error InvalidGameRegistry();
/** SETUP **/
/** Sets the GameRegistry contract address for this contract */
constructor(address gameRegistryAddress, uint256 id) {
_gameRegistry = IGameRegistry(gameRegistryAddress);
_id = id;
if (gameRegistryAddress == address(0)) {
revert InvalidGameRegistry();
}
_paused = true;
}
/** EXTERNAL **/
/** @return ID for this system */
function getId() public view override returns (uint256) {
return _id;
}
/**
* Pause/Unpause the contract
*
* @param shouldPause Whether or pause or unpause
*/
function setPaused(bool shouldPause) external onlyOwner {
if (shouldPause) {
_pause();
} else {
_unpause();
}
}
/**
* @dev Returns true if the contract OR the GameRegistry is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused || _gameRegistry.paused();
}
/**
* Sets the GameRegistry contract address for this contract
*
* @param gameRegistryAddress Address for the GameRegistry contract
*/
function setGameRegistry(address gameRegistryAddress) external onlyOwner {
_gameRegistry = IGameRegistry(gameRegistryAddress);
if (gameRegistryAddress == address(0)) {
revert InvalidGameRegistry();
}
}
/** @return GameRegistry contract for this contract */
function getGameRegistry() external view returns (IGameRegistry) {
return _gameRegistry;
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function _hasAccessRole(bytes32 role, address account)
internal
view
returns (bool)
{
return _gameRegistry.hasAccessRole(role, account);
}
/**
* @dev Revert with a standard message if `account` is missing `role`.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*/
function _checkRole(bytes32 role, address account) virtual internal view {
if (!_gameRegistry.hasAccessRole(role, account)) {
revert MissingRole(account, role);
}
}
/** Returns the traits provider for this contract */
function _traitsProvider() internal view returns (ITraitsProvider) {
return ITraitsProvider(_getSystem(TRAITS_PROVIDER_ID));
}
/** @return Interface to the LockingSystem */
function _lockingSystem() internal view returns (ILockingSystem) {
return ILockingSystem(_gameRegistry.getSystem(LOCKING_SYSTEM_ID));
}
/** @return Interface to the LootSystem */
function _lootSystem() internal view returns (ILootSystem) {
return ILootSystem(_gameRegistry.getSystem(LOOT_SYSTEM_ID));
}
/** @return Interface to the Randomizer */
function _randomizer() internal view returns (IRandomizer) {
return IRandomizer(_gameRegistry.getSystem(RANDOMIZER_ID));
}
/** @return Address for a given system */
function _getSystem(uint256 systemId) internal view returns (address) {
return _gameRegistry.getSystem(systemId);
}
/**
* Requests randomness from the game's Randomizer contract
*
* @param numWords Number of words to request from the VRF
*
* @return Id of the randomness request
*/
function _requestRandomWords(uint32 numWords) internal returns (uint256) {
return
_randomizer().requestRandomWords(
IRandomizerCallback(this),
numWords
);
}
/**
* Callback for when a random number request has returned with random words
*
* @param requestId Id of the request
* @param randomWords Random words
*/
function fulfillRandomWordsCallback(
uint256 requestId,
uint256[] memory randomWords
) external virtual override {
// Do nothing by default
}
/**
* Returns the Player address for the Operator account
* @param operatorAccount address of the Operator account to retrieve the player for
*/
function _getPlayerAccount(address operatorAccount)
internal
view
returns (address playerAccount)
{
return _gameRegistry.getPlayerAccount(operatorAccount);
}
/// @inheritdoc IERC2771Recipient
function isTrustedForwarder(address forwarder)
public
view
virtual
override
returns (bool)
{
return
address(_gameRegistry) != address(0) &&
_hasAccessRole(TRUSTED_FORWARDER_ROLE, forwarder);
}
/** INTERNAL **/
/// @inheritdoc IERC2771Recipient
function _msgSender()
internal
view
virtual
override(Context, IERC2771Recipient)
returns (address ret)
{
if (msg.data.length >= 20 && isTrustedForwarder(msg.sender)) {
assembly {
ret := shr(96, calldataload(sub(calldatasize(), 20)))
}
} else {
ret = msg.sender;
}
}
/// @inheritdoc IERC2771Recipient
function _msgData()
internal
view
virtual
override(Context, IERC2771Recipient)
returns (bytes calldata ret)
{
if (msg.data.length >= 20 && isTrustedForwarder(msg.sender)) {
return msg.data[0:msg.data.length - 20];
} else {
return msg.data;
}
}
/** PAUSABLE **/
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
require(!paused(), "Pausable: paused");
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
require(paused(), "Pausable: not paused");
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual {
require(_paused == false, "Pausable: not paused");
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual {
require(_paused == true, "Pausable: not paused");
_paused = false;
emit Unpaused(_msgSender());
}
}// SPDX-License-Identifier: MIT LICENSE
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
// @title Interface the game's ACL / Management Layer
interface IGameRegistry is IERC165 {
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasAccessRole(bytes32 role, address account)
external
view
returns (bool);
/** @return Whether or not the registry is paused */
function paused() external view returns (bool);
/**
* Registers a system by id
*
* @param systemId Id of the system
* @param systemAddress Address of the system contract
*/
function registerSystem(uint256 systemId, address systemAddress) external;
/** @return System based on an id */
function getSystem(uint256 systemId) external view returns (address);
/** @return Authorized Player account for an address
* @param operatorAddress Address of the Operator account
*/
function getPlayerAccount(address operatorAddress)
external
view
returns (address);
}// SPDX-License-Identifier: MIT LICENSE
pragma solidity ^0.8.9;
interface IHoldingConsumer {
/**
* @param account Account to check hold time of
* @param tokenId Id of the token
* @return The time in seconds a given account has held a token
*/
function getTimeHeld(
address account,
uint256 tokenId
) external view returns (uint32);
/**
* @param tokenId Id of the token
* @return The time in seconds a given account has held the token
*/
function getLastTransfer(uint256 tokenId) external view returns (uint32);
}// SPDX-License-Identifier: MIT LICENSE
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
/**
* Defines a system the game engine
*/
interface ISystem {
/** @return The ID for the system. Ex: a uint256 casted keccak256 hash */
function getId() external view returns (uint256);
}// SPDX-License-Identifier: MIT LICENSE
pragma solidity ^0.8.9;
import {ITraitsProvider} from "./ITraitsProvider.sol";
/** @title Consumer of traits, exposes functions to get traits for this contract */
interface ITraitsConsumer {
/** @return Token name for the given tokenId */
function tokenName(uint256 tokenId) external view returns (string memory);
/** @return Token name for the given tokenId */
function tokenDescription(uint256 tokenId)
external
view
returns (string memory);
/** @return Image URI for the given tokenId */
function imageURI(uint256 tokenId) external view returns (string memory);
/** @return External URI for the given tokenId */
function externalURI(uint256 tokenId) external view returns (string memory);
}// SPDX-License-Identifier: MIT LICENSE
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
uint256 constant ID = uint256(keccak256("game.piratenation.traitsprovider"));
// Enum describing how the trait can be modified
enum TraitBehavior {
NOT_INITIALIZED, // Trait has not been initialized
UNRESTRICTED, // Trait can be changed unrestricted
IMMUTABLE, // Trait can only be set once and then never changed
INCREMENT_ONLY, // Trait can only be incremented
DECREMENT_ONLY // Trait can only be decremented
}
// Type of data to allow in the trait
enum TraitDataType {
NOT_INITIALIZED, // Trait has not been initialized
INT, // int256 data type
UINT, // uint256 data type
BOOL, // bool data type
STRING, // string data type
INT_ARRAY, // int256 array data type
UINT_ARRAY // uint256 array data type
}
// Holds metadata for a given trait type
struct TraitMetadata {
// Name of the trait, used in tokenURIs
string name;
// How the trait can be modified
TraitBehavior behavior;
// Trait type
TraitDataType dataType;
// Whether or not the trait is a top-level property and should not be in the attribute array
bool isTopLevelProperty;
// Whether or not the trait should be hidden from end-users
bool hidden;
}
// Used to pass traits around for URI generation
struct TokenURITrait {
string name;
bytes value;
TraitDataType dataType;
bool isTopLevelProperty;
bool hidden;
}
/** @title Provides a set of traits to a set of ERC721/ERC1155 contracts */
interface ITraitsProvider is IERC165 {
/**
* Sets the value for the string trait of a token, also checks to make sure trait can be modified
*
* @param tokenContract Address of the token's contract
* @param tokenId NFT tokenId or ERC1155 token type id
* @param traitId Id of the trait to modify
* @param value New value for the given trait
*/
function setTraitString(
address tokenContract,
uint256 tokenId,
uint256 traitId,
string calldata value
) external;
/**
* Sets several string traits for a given token
*
* @param tokenContract Address of the token's contract
* @param tokenIds Ids of the token to set traits for
* @param traitIds Ids of traits to set
* @param values Values of traits to set
*/
function batchSetTraitString(
address tokenContract,
uint256[] calldata tokenIds,
uint256[] calldata traitIds,
string[] calldata values
) external;
/**
* Sets the value for the uint256 trait of a token, also checks to make sure trait can be modified
*
* @param tokenContract Address of the token's contract
* @param tokenId NFT tokenId or ERC1155 token type id
* @param traitId Id of the trait to modify
* @param value New value for the given trait
*/
function setTraitUint256(
address tokenContract,
uint256 tokenId,
uint256 traitId,
uint256 value
) external;
/**
* Sets several uint256 traits for a given token
*
* @param tokenContract Address of the token's contract
* @param tokenIds Ids of the token to set traits for
* @param traitIds Ids of traits to set
* @param values Values of traits to set
*/
function batchSetTraitUint256(
address tokenContract,
uint256[] calldata tokenIds,
uint256[] calldata traitIds,
uint256[] calldata values
) external;
/**
* Sets the value for the int256 trait of a token, also checks to make sure trait can be modified
*
* @param tokenContract Address of the token's contract
* @param tokenId NFT tokenId or ERC1155 token type id
* @param traitId Id of the trait to modify
* @param value New value for the given trait
*/
function setTraitInt256(
address tokenContract,
uint256 tokenId,
uint256 traitId,
int256 value
) external;
/**
* Sets several int256 traits for a given token
*
* @param tokenContract Address of the token's contract
* @param tokenIds Ids of the token to set traits for
* @param traitIds Ids of traits to set
* @param values Values of traits to set
*/
function batchSetTraitInt256(
address tokenContract,
uint256[] calldata tokenIds,
uint256[] calldata traitIds,
int256[] calldata values
) external;
/**
* Sets the value for the int256[] trait of a token, also checks to make sure trait can be modified
*
* @param tokenContract Address of the token's contract
* @param tokenId NFT tokenId or ERC1155 token type id
* @param traitId Id of the trait to modify
* @param value New value for the given trait
*/
function setTraitInt256Array(
address tokenContract,
uint256 tokenId,
uint256 traitId,
int256[] calldata value
) external;
/**
* Sets the value for the uint256[] trait of a token, also checks to make sure trait can be modified
*
* @param tokenContract Address of the token's contract
* @param tokenId NFT tokenId or ERC1155 token type id
* @param traitId Id of the trait to modify
* @param value New value for the given trait
*/
function setTraitUint256Array(
address tokenContract,
uint256 tokenId,
uint256 traitId,
uint256[] calldata value
) external;
/**
* Sets the value for the bool trait of a token, also checks to make sure trait can be modified
*
* @param tokenContract Address of the token's contract
* @param tokenId NFT tokenId or ERC1155 token type id
* @param traitId Id of the trait to modify
* @param value New value for the given trait
*/
function setTraitBool(
address tokenContract,
uint256 tokenId,
uint256 traitId,
bool value
) external;
/**
* Sets several bool traits for a given token
*
* @param tokenContract Address of the token's contract
* @param tokenIds Ids of the token to set traits for
* @param traitIds Ids of traits to set
* @param values Values of traits to set
*/
function batchSetTraitBool(
address tokenContract,
uint256[] calldata tokenIds,
uint256[] calldata traitIds,
bool[] calldata values
) external;
/**
* Increments the trait for a token by the given amount
*
* @param tokenContract Address of the token's contract
* @param tokenId NFT tokenId or ERC1155 token type id
* @param traitId Id of the trait to modify
* @param amount Amount to increment trait by
*/
function incrementTrait(
address tokenContract,
uint256 tokenId,
uint256 traitId,
uint256 amount
) external;
/**
* Decrements the trait for a token by the given amount
*
* @param tokenContract Address of the token's contract
* @param tokenId NFT tokenId or ERC1155 token type id
* @param traitId Id of the trait to modify
* @param amount Amount to decrement trait by
*/
function decrementTrait(
address tokenContract,
uint256 tokenId,
uint256 traitId,
uint256 amount
) external;
/**
* Returns the trait data for a given token
*
* @param tokenContract Address of the token's contract
* @param tokenId NFT tokenId or ERC1155 token type id
*
* @return A struct containing all traits for the token
*/
function getTraitIds(
address tokenContract,
uint256 tokenId
) external view returns (uint256[] memory);
/**
* Retrieves a raw abi-encoded byte data for the given trait
*
* @param tokenContract Token contract (ERC721 or ERC1155)
* @param tokenId Id of the NFT or token type
* @param traitId Id of the trait to retrieve
*
* @return The value of the trait if it exists, reverts if the trait has not been set or is of a different type.
*/
function getTraitBytes(
address tokenContract,
uint256 tokenId,
uint256 traitId
) external view returns (bytes memory);
/**
* Retrieves a int256 trait for the given token
*
* @param tokenContract Token contract (ERC721 or ERC1155)
* @param tokenId Id of the NFT or token type
* @param traitId Id of the trait to retrieve
*
* @return The value of the trait if it exists, reverts if the trait has not been set or is of a different type.
*/
function getTraitInt256(
address tokenContract,
uint256 tokenId,
uint256 traitId
) external view returns (int256);
/**
* Retrieves a int256 array trait for the given token
*
* @param tokenContract Token contract (ERC721 or ERC1155)
* @param tokenId Id of the NFT or token type
* @param traitId Id of the trait to retrieve
*
* @return The value of the trait if it exists, reverts if the trait has not been set or is of a different type.
*/
function getTraitInt256Array(
address tokenContract,
uint256 tokenId,
uint256 traitId
) external view returns (int256[] memory);
/**
* Retrieves a uint256 trait for the given token
*
* @param tokenContract Token contract (ERC721 or ERC1155)
* @param tokenId Id of the NFT or token type
* @param traitId Id of the trait to retrieve
*
* @return The value of the trait if it exists, reverts if the trait has not been set or is of a different type.
*/
function getTraitUint256(
address tokenContract,
uint256 tokenId,
uint256 traitId
) external view returns (uint256);
/**
* Retrieves a uint256 array trait for the given token
*
* @param tokenContract Token contract (ERC721 or ERC1155)
* @param tokenId Id of the NFT or token type
* @param traitId Id of the trait to retrieve
*
* @return The value of the trait if it exists, reverts if the trait has not been set or is of a different type.
*/
function getTraitUint256Array(
address tokenContract,
uint256 tokenId,
uint256 traitId
) external view returns (uint256[] memory);
/**
* Retrieves a bool trait for the given token
*
* @param tokenContract Token contract (ERC721 or ERC1155)
* @param tokenId Id of the NFT or token type
* @param traitId Id of the trait to retrieve
*
* @return The value of the trait if it exists, reverts if the trait has not been set or is of a different type.
*/
function getTraitBool(
address tokenContract,
uint256 tokenId,
uint256 traitId
) external view returns (bool);
/**
* Retrieves a string trait for the given token
*
* @param tokenContract Token contract (ERC721 or ERC1155)
* @param tokenId Id of the NFT or token type
* @param traitId Id of the trait to retrieve
*
* @return The value of the trait if it exists, reverts if the trait has not been set or is of a different type.
*/
function getTraitString(
address tokenContract,
uint256 tokenId,
uint256 traitId
) external view returns (string memory);
/**
* Returns whether or not the given token has a trait
*
* @param tokenContract Address of the token's contract
* @param tokenId NFT tokenId or ERC1155 token type id
* @param traitId Id of the trait to retrieve
*
* @return Whether or not the token has the trait
*/
function hasTrait(
address tokenContract,
uint256 tokenId,
uint256 traitId
) external view returns (bool);
/**
* @param traitId Id of the trait to get metadata for
* @return Metadata for the given trait
*/
function getTraitMetadata(
uint256 traitId
) external view returns (TraitMetadata memory);
/**
* Generate a tokenURI based on a set of global properties and traits
*
* @param tokenContract Address of the token contract
* @param tokenId Id of the token to generate traits for
*
* @return base64-encoded fully-formed tokenURI
*/
function generateTokenURI(
address tokenContract,
uint256 tokenId,
TokenURITrait[] memory extraTraits
) external view returns (string memory);
}// SPDX-License-Identifier: MIT LICENSE
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
uint256 constant ID = uint256(keccak256("game.piratenation.lockingsystem"));
/// @title Interface for the LockingSystem that allows tokens to be locked by the game to prevent transfer
interface ILockingSystem is IERC165 {
/**
* Whether or not an NFT is locked
*
* @param tokenContract Token contract address
* @param tokenId Id of the token
*/
function isNFTLocked(address tokenContract, uint256 tokenId)
external
view
returns (bool);
/**
* Amount of token locked in the system by a given owner
*
* @param account Token owner
* @param tokenContract Token contract address
* @param tokenId Id of the token
*
* @return Number of tokens locked
*/
function itemAmountLocked(
address account,
address tokenContract,
uint256 tokenId
) external view returns (uint256);
/**
* Amount of tokens available for unlock
*
* @param account Token owner
* @param tokenContract Token contract address
* @param tokenId Id of the token
*
* @return Number of tokens locked
*/
function itemAmountUnlocked(
address account,
address tokenContract,
uint256 tokenId
) external view returns (uint256);
/**
* Whether or not the given items can be transferred
*
* @param account Token owner
* @param tokenContract Token contract address
* @param ids Ids of the tokens
* @param amounts Amounts of the tokens
*
* @return Whether or not the given items can be transferred
*/
function canTransferItems(
address account,
address tokenContract,
uint256[] memory ids,
uint256[] memory amounts
) external view returns (bool);
/**
* Lets the game add a reservation to a given NFT, this prevents the NFT from being unlocked
*
* @param tokenContract Token contract address
* @param tokenId Token id to reserve
* @param exclusive Whether or not the reservation is exclusive. Exclusive reservations prevent other reservations from using the tokens by removing them from the pool.
* @param data Data determined by the reserver, can be used to identify the source of the reservation for display in UI
*/
function addNFTReservation(
address tokenContract,
uint256 tokenId,
bool exclusive,
uint32 data
) external returns (uint32);
/**
* Lets the game remove a reservation from a given token
*
* @param tokenContract Token contract
* @param tokenId Id of the token
* @param reservationId Id of the reservation to remove
*/
function removeNFTReservation(
address tokenContract,
uint256 tokenId,
uint32 reservationId
) external;
/**
* Lets the game add a reservation to a given token, this prevents the token from being unlocked
*
* @param account Owner of the token to reserver
* @param tokenContract Token contract address
* @param tokenId Token id to reserve
* @param amount Number of tokens to reserve (1 for NFTs, >=1 for ERC1155)
* @param exclusive Whether or not the reservation is exclusive. Exclusive reservations prevent other reservations from using the tokens by removing them from the pool.
* @param data Data determined by the reserver, can be used to identify the source of the reservation for display in UI
*/
function addItemReservation(
address account,
address tokenContract,
uint256 tokenId,
uint256 amount,
bool exclusive,
uint32 data
) external returns (uint32);
/**
* Lets the game remove a reservation from a given token
*
* @param account Owner to remove reservation from
* @param tokenContract Token contract
* @param tokenId Id of the token
* @param reservationId Id of the reservation to remove
*/
function removeItemReservation(
address account,
address tokenContract,
uint256 tokenId,
uint32 reservationId
) external;
}// SPDX-License-Identifier: MIT LICENSE
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
uint256 constant ID = uint256(keccak256("game.piratenation.lootsystem"));
/// @title Interface for the LootSystem that gives player loot (tokens, XP, etc) for playing the game
interface ILootSystem is IERC165 {
// Type of loot
enum LootType {
UNDEFINED,
ERC20,
ERC721,
ERC1155,
LOOT_TABLE,
CALLBACK
}
// Individual loot to grant
struct Loot {
// Type of fulfillment (ERC721, ERC1155, ERC20, LOOT_TABLE)
LootType lootType;
// Contract to grant tokens from
address tokenContract;
// Id of the token to grant (ERC1155/LOOT TABLE/CALLBACK types only)
uint256 lootId;
// Amount of token to grant (XP, ERC20, ERC1155)
uint256 amount;
}
/**
* Grants the given user loot(s), calls VRF to ensure it's truly random
*
* @param to Address to grant loot to
* @param loots Loots to grant
*/
function grantLoot(address to, Loot[] calldata loots) external;
/**
* Grants the given user loot(s), calls VRF to ensure it's truly random
*
* @param to Address to grant loot to
* @param loots Loots to grant
* @param randomWord Optional random word to skip VRF callback if we already have words generated / are in a VRF callback
*/
function grantLootWithRandomWord(
address to,
Loot[] calldata loots,
uint256 randomWord
) external;
/**
* Grants the given user loot(s) in batches. Presumes no randomness or loot tables
*
* @param to Address to grant loot to
* @param loots Loots to grant
* @param amount Amount of each loot to grant
*/
function batchGrantLootWithoutRandomness(
address to,
Loot[] calldata loots,
uint8 amount
) external;
/**
* Validate that loots are properly formed. Reverts if the loots are not valid
*
* @param loots Loots to validate
* @return needsVRF Whether or not the loots specified require VRF to generate
*/
function validateLoots(
Loot[] calldata loots
) external view returns (bool needsVRF);
}// SPDX-License-Identifier: MIT LICENSE
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {IRandomizerCallback} from "./IRandomizerCallback.sol";
uint256 constant ID = uint256(keccak256("game.piratenation.randomizer"));
interface IRandomizer is IERC165 {
/**
* Starts a VRF random number request
*
* @param callbackAddress Address to callback with the random numbers
* @param numWords Number of words to request from VRF
*
* @return requestId for the random number, will be passed to the callback contract
*/
function requestRandomWords(
IRandomizerCallback callbackAddress,
uint32 numWords
) external returns (uint256);
}// SPDX-License-Identifier: MIT LICENSE
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
interface IRandomizerCallback {
/**
* Callback for when the Chainlink request returns
*
* @param requestId Id of the random word request
* @param randomWords Random words that were generated by the VRF
*/
function fulfillRandomWordsCallback(
uint256 requestId,
uint256[] memory randomWords
) external;
}// SPDX-License-Identifier: MIT LICENSE
pragma solidity ^0.8.9;
interface IERC721BeforeTokenTransferHandler {
/**
* Before transfer hook for NFTs. Performs any trait checks needed before transfer
*
* @param tokenContract Address of the token contract
* @param tokenId Id of the token to generate traits for
* @param from From address
* @param to To address
* @param operator Operator address
*/
function beforeTokenTransfer(
address tokenContract,
address operator,
address from,
address to,
uint256 tokenId,
uint256 batchSize
) external;
}// SPDX-License-Identifier: MIT LICENSE
pragma solidity ^0.8.9;
interface ITokenURIHandler {
/**
* Generates the TokenURI for a given token
*
* @param operator Sender requesting the tokenURI
* @param tokenContract TokenContract to get URI for
* @param tokenId Id of the token to get URI for
*
* @return TokenURI for the given token
*/
function tokenURI(
address operator,
address tokenContract,
uint256 tokenId
) external view returns (string memory);
}// SPDX-License-Identifier: MIT LICENSE
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/utils/math/SafeCast.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {GAME_LOGIC_CONTRACT_ROLE, NAME_TRAIT_ID, DESCRIPTION_TRAIT_ID, IMAGE_TRAIT_ID} from "./Constants.sol";
import {ITraitsConsumer} from "./interfaces/ITraitsConsumer.sol";
import {ITokenURIHandler} from "./tokens/ITokenURIHandler.sol";
import {GameRegistryConsumer} from "./GameRegistryConsumer.sol";
/** @title Contract that lets a child contract access the TraitsProvider contract */
abstract contract TraitsConsumer is
ITraitsConsumer,
GameRegistryConsumer,
IERC165
{
using Strings for uint256;
/// @notice Override URI for the NFT contract. If not set, on-chain data is used instead
string public _overrideURI;
/// @notice Pointer to the handler for TokenURI calls
address public tokenURIHandler;
/// @notice Base URI for images, tokenId is appended to make final uri
string public _baseImageURI;
/// @notice Base URI for external link, tokenId is appended to make final uri
string public _baseExternalURI;
/// @notice Default image URI for the token
/// @dev Should be set in the constructor
string public _defaultImageURI;
/// @notice Default description for the token
string public _defaultDescription;
/** ERRORS */
/// @notice traitsProviderAddress does not implement ITraitsProvvider
error InvalidTraitsProvider();
/** SETUP **/
/** Set game registry */
constructor(address _gameRegistryAddress, uint256 _id)
GameRegistryConsumer(_gameRegistryAddress, _id)
{}
/** Sets the override URI for the tokens */
function setURI(string calldata newURI) external onlyOwner {
_overrideURI = newURI;
}
/** Sets base image URI for the tokens */
function setBaseImageURI(string calldata newURI) external onlyOwner {
_baseImageURI = newURI;
}
/** Sets base external URI for the tokens */
function setBaseExternalURI(string calldata newURI) external onlyOwner {
_baseExternalURI = newURI;
}
/** @return Token name for the given tokenId */
function tokenName(uint256 tokenId)
external
view
virtual
override
returns (string memory)
{
if (_hasTrait(tokenId, NAME_TRAIT_ID)) {
// If token has a name trait set, use that
return _getTraitString(tokenId, NAME_TRAIT_ID);
} else {
return string(abi.encodePacked("#", tokenId.toString()));
}
}
/** @return Token name for the given tokenId */
function tokenDescription(uint256 tokenId)
external
view
virtual
override
returns (string memory)
{
if (_hasTrait(tokenId, DESCRIPTION_TRAIT_ID)) {
// If token has a description trait set, use that
return _getTraitString(tokenId, DESCRIPTION_TRAIT_ID);
}
return _defaultDescription;
}
/** @return Image URI for the given tokenId */
function imageURI(uint256 tokenId)
external
view
virtual
override
returns (string memory)
{
if (_hasTrait(tokenId, IMAGE_TRAIT_ID)) {
// If token has a description trait set, use that
return _getTraitString(tokenId, IMAGE_TRAIT_ID);
}
if (bytes(_baseImageURI).length > 0) {
return string(abi.encodePacked(_baseImageURI, tokenId.toString()));
}
return _defaultImageURI;
}
/** @return External URI for the given tokenId */
function externalURI(uint256 tokenId)
external
view
virtual
override
returns (string memory)
{
if (bytes(_baseExternalURI).length > 0) {
return
string(abi.encodePacked(_baseExternalURI, tokenId.toString()));
}
return "";
}
/**
* Sets the tokenURI handler for this token
*
* @param handler Address of the handler contract to use
*/
function setTokenURIHandler(address handler) external onlyOwner {
tokenURIHandler = handler;
}
/** INTERNAL **/
/**
* @param tokenId Id of the token to get a trait value for
* @param traitId Id of the trait to get the value for
*
* @return Trait int256 value for the given token and trait
*/
function _getTraitInt256(uint256 tokenId, uint256 traitId)
internal
view
returns (int256)
{
return
_traitsProvider().getTraitInt256(address(this), tokenId, traitId);
}
/**
* @param tokenId Id of the token to get a trait value for
* @param traitId Id of the trait to get the value for
*
* @return Trait string value for the given token and trait
*/
function _getTraitString(uint256 tokenId, uint256 traitId)
internal
view
returns (string memory)
{
return
_traitsProvider().getTraitString(address(this), tokenId, traitId);
}
/**
* @param tokenId NFT tokenId or ERC1155 token type id
* @param traitId Id of the trait to retrieve
*
* @return Whether or not the token has the trait
*/
function _hasTrait(uint256 tokenId, uint256 traitId)
internal
view
returns (bool)
{
return _traitsProvider().hasTrait(address(this), tokenId, traitId);
}
/**
* Sets the int256 trait value for this token
*
* @param tokenId Id of the token to set trait for
* @param traitId Id of the trait to set
* @param value New value of the trait
*/
function _setTraitInt256(
uint256 tokenId,
uint256 traitId,
int256 value
) internal {
_traitsProvider().setTraitInt256(
address(this),
tokenId,
traitId,
value
);
}
/**
* Sets the string trait value for this token
*
* @param tokenId Id of the token to set trait for
* @param traitId Id of the trait to set
* @param value New value of the trait
*/
function _setTraitString(
uint256 tokenId,
uint256 traitId,
string memory value
) internal {
_traitsProvider().setTraitString(
address(this),
tokenId,
traitId,
value
);
}
/**
* @notice Generates metadata for the given tokenId
* @param tokenId Token to generate metadata for
* @return A base64 encoded JSON metadata string
*/
function _tokenURI(uint256 tokenId)
internal
view
virtual
returns (string memory)
{
// If override URI is set, return the URI with tokenId appended instead of on-chain data
if (bytes(_overrideURI).length > 0) {
return string(abi.encodePacked(_overrideURI, tokenId.toString()));
}
if (tokenURIHandler == address(0)) {
return "";
}
return
ITokenURIHandler(tokenURIHandler).tokenURI(
_msgSender(),
address(this),
tokenId
);
}
/**
* @inheritdoc IERC165
*/
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override
returns (bool)
{
return
interfaceId == type(ITraitsConsumer).interfaceId ||
interfaceId == type(IERC165).interfaceId;
}
}{
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"metadata": {
"useLiteralContent": true
},
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"gameRegistryAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ExceedsBatchLimit","type":"error"},{"inputs":[],"name":"InvalidAccountAddress","type":"error"},{"inputs":[],"name":"InvalidGameRegistry","type":"error"},{"inputs":[],"name":"InvalidTokenId","type":"error"},{"inputs":[],"name":"InvalidTraitsProvider","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"expectedRole","type":"bytes32"}],"name":"MissingRole","type":"error"},{"inputs":[{"internalType":"uint256","name":"needed","type":"uint256"},{"internalType":"uint256","name":"actual","type":"uint256"}],"name":"NotEnoughSupply","type":"error"},{"inputs":[],"name":"NotOwner","type":"error"},{"inputs":[],"name":"TokenIdExceedsMaxSupply","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"uri","type":"string"}],"name":"ContractURIUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"DepositFromBridge","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"metaData","type":"bytes"}],"name":"TransferWithMetadata","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[],"name":"BATCH_LIMIT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_baseExternalURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_baseImageURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_defaultDescription","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_defaultImageURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_overrideURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"beforeTokenTransferHandler","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"contractURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"bytes","name":"depositData","type":"bytes"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"encodeTokenMetadata","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"exists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"externalURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"requestId","type":"uint256"},{"internalType":"uint256[]","name":"randomWords","type":"uint256[]"}],"name":"fulfillRandomWordsCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getGameRegistry","outputs":[{"internalType":"contract IGameRegistry","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getLastTransfer","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getTimeHeld","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"imageURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"forwarder","type":"address"}],"name":"isTrustedForwarder","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"lastTransfer","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"newURI","type":"string"}],"name":"setBaseExternalURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"newURI","type":"string"}],"name":"setBaseImageURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"handlerAddress","type":"address"}],"name":"setBeforeTokenTransferHandler","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_uri","type":"string"}],"name":"setContractURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"gameRegistryAddress","type":"address"}],"name":"setGameRegistry","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"shouldPause","type":"bool"}],"name":"setPaused","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"handler","type":"address"}],"name":"setTokenURIHandler","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"newURI","type":"string"}],"name":"setURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenDescription","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenName","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenURIHandler","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"name":"withdrawBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"withdrawWithMetadata","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
0x60a06040523480156200001157600080fd5b5060405162003cef38038062003cef8339810160408190526200003491620003c0565b6000604051806040016040528060048152602001630536869760e41b815250604051806040016040528060048152602001630534849560e41b815250837faeca1b630a909fd2c24c10ed836dbecc723968d7724ecc7c4d13aa36a4e4300860001c838383838181620000b5620000af620001b160201b60201c565b620001cd565b600280546001600160a01b0319166001600160a01b0384169081179091556001829055620000f65760405163a4b9148160e01b815260040160405180910390fd5b50506000805460ff60a01b1916600160a01b17905550508151620001229060099060208501906200031a565b5080516200013890600a9060208401906200031a565b505050846080818152505050505050506040518060e0016040528060bb815260200162003bfe60bb9139805162000178916008916020909101906200031a565b5060405180606001604052806036815260200162003cb9603691398051620001a9916007916020909101906200031a565b50506200044b565b6000620001c86200021d60201b620015091760201c565b905090565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60006014361080159062000237575062000237336200024f565b156200024a575060131936013560601c90565b503390565b6002546000906001600160a01b031615801590620002945750620002947fd3df22cd6a774f62b0ae21ffd602cc92e7f3390518eee8b33307fc70380da7d2836200029a565b92915050565b6002546040516361b6ebf560e11b8152600481018490526001600160a01b038381166024830152600092169063c36dd7ea90604401602060405180830381865afa158015620002ed573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620003139190620003eb565b9392505050565b82805462000328906200040f565b90600052602060002090601f0160209004810192826200034c576000855562000397565b82601f106200036757805160ff191683800117855562000397565b8280016001018555821562000397579182015b82811115620003975782518255916020019190600101906200037a565b50620003a5929150620003a9565b5090565b5b80821115620003a55760008155600101620003aa565b600060208284031215620003d357600080fd5b81516001600160a01b03811681146200031357600080fd5b600060208284031215620003fe57600080fd5b815180151581146200031357600080fd5b600181811c908216806200042457607f821691505b6020821081036200044557634e487b7160e01b600052602260045260246000fd5b50919050565b60805161378962000475600039600081816106b801528181611bfa0152611c2401526137896000f3fe608060405234801561001057600080fd5b50600436106103835760003560e01c806374ca4283116101de578063ce6225ce1161010f578063e8a3d485116100ad578063ed022ebd1161007c578063ed022ebd1461077c578063f0e56f0d1461078d578063f2fde38b146107b3578063f803f410146107c657600080fd5b8063e8a3d4851461071d578063e985e9c514610725578063eab7e15514610761578063eb0c3a151461076957600080fd5b8063dd898b2f116100e9578063dd898b2f146106dc578063e41f84f4146106ef578063e725f877146106f7578063e7277dd71461070a57600080fd5b8063ce6225ce1461069b578063cf2c52cb146106a3578063d5abeb01146106b657600080fd5b80639c8d41561161017c578063a5e584dc11610156578063a5e584dc14610490578063a6c038f71461066d578063b88d4fde14610675578063c87b56dd1461068857600080fd5b80639c8d415614610634578063a0c6d53714610647578063a22cb4651461065a57600080fd5b80638f742d16116101b85780638f742d16146105fe578063938e3d7b146106115780639559c0bd1461062457806395d89b411461062c57600080fd5b806374ca4283146105c75780638647ca76146105da5780638da5cb5b146105ed57600080fd5b806340c10f19116102b8578063572b6c05116102565780636352211e116102305780636352211e146105865780636838c0621461059957806370a08231146105ac578063715018a6146105bf57600080fd5b8063572b6c05146105635780635c975abb146105765780635d1ca6311461057e57600080fd5b806342966c681161029257806342966c68146105175780634dbf9a731461052a5780634f558e791461053d5780634f6ccce71461055057600080fd5b806340c10f19146104b65780634139493e146104c957806342842e0e1461050457600080fd5b80631653c39a1161032557806323b872dd116102ff57806323b872dd146104755780632aa0324d146104885780632e1a7d4d146104905780632f745c59146104a357600080fd5b80631653c39a1461043d57806316c38b3c1461045057806318160ddd1461046357600080fd5b806306fdde031161036157806306fdde03146103d7578063081812fc146103ec578063095ea7b3146104175780630dacaa081461042a57600080fd5b806301ffc9a71461038857806302fe5305146103b057806306c1cb91146103c5575b600080fd5b61039b610396366004612df1565b6107d9565b60405190151581526020015b60405180910390f35b6103c36103be366004612e57565b61080b565b005b6103c36103d3366004612f60565b5050565b6103df610824565b6040516103a79190612fff565b6103ff6103fa366004613012565b6108b6565b6040516001600160a01b0390911681526020016103a7565b6103c3610425366004613040565b6108dd565b6004546103ff906001600160a01b031681565b6103df61044b366004613012565b610a04565b6103c361045e36600461307a565b610a35565b6011545b6040519081526020016103a7565b6103c3610483366004613097565b610a56565b6103df610a8e565b6103c361049e366004613012565b610b1c565b6104676104b1366004613040565b610b25565b6103c36104c4366004613040565b610bbb565b6104ef6104d7366004613012565b60156020526000908152604090205463ffffffff1681565b60405163ffffffff90911681526020016103a7565b6103c3610512366004613097565b610bff565b6103c3610525366004613012565b610c1a565b6103c36105383660046130d8565b610c58565b61039b61054b366004613012565b610c82565b61046761055e366004613012565b610ca1565b61039b6105713660046130d8565b610d34565b61039b610d76565b600154610467565b6103ff610594366004613012565b610e06565b6017546103ff906001600160a01b031681565b6104676105ba3660046130d8565b610e66565b6103c3610eec565b6103df6105d5366004613012565b610f00565b6103c36105e8366004612e57565b610f49565b6000546001600160a01b03166103ff565b6103df61060c366004613012565b610f5d565b6103c361061f366004612e57565b61106c565b610467601481565b6103df6110be565b6103c36106423660046130f5565b6110cd565b6103df610655366004613012565b611138565b6103c361066836600461316a565b6111a0565b6103df6111b2565b6103c36106833660046131cb565b6111bf565b6103df610696366004613012565b6111f8565b6103df611280565b6103c36106b136600461327a565b61128d565b7f0000000000000000000000000000000000000000000000000000000000000000610467565b6103c36106ea3660046130d8565b6112c5565b6103df611308565b6103df610705366004613012565b611315565b6104ef610718366004613040565b61138d565b6103df611439565b61039b6107333660046132cf565b6001600160a01b039182166000908152600e6020908152604080832093909416825291909152205460ff1690565b6103df611448565b6103c36107773660046130d8565b611455565b6002546001600160a01b03166103ff565b6104ef61079b366004613012565b60009081526015602052604090205463ffffffff1690565b6103c36107c13660046130d8565b61147f565b6103c36107d4366004612e57565b6114f5565b60006001600160e01b0319821615806107f657506107f682611537565b8061080557506108058261155c565b92915050565b610813611592565b61081f60038383612d4b565b505050565b606060098054610833906132fd565b80601f016020809104026020016040519081016040528092919081815260200182805461085f906132fd565b80156108ac5780601f10610881576101008083540402835291602001916108ac565b820191906000526020600020905b81548152906001019060200180831161088f57829003601f168201915b5050505050905090565b60006108c18261160b565b506000908152600d60205260409020546001600160a01b031690565b60006108e882610e06565b9050806001600160a01b0316836001600160a01b03160361095a5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b60648201526084015b60405180910390fd5b806001600160a01b031661096c61166a565b6001600160a01b0316148061098857506109888161073361166a565b6109fa5760405162461bcd60e51b815260206004820152603d60248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f7420746f60448201527f6b656e206f776e6572206f7220617070726f76656420666f7220616c6c0000006064820152608401610951565b61081f8383611674565b6060610a0f826111f8565b604051602001610a1f9190612fff565b6040516020818303038152906040529050919050565b610a3d611592565b8015610a4e57610a4b6116e2565b50565b610a4b61178c565b610a67610a6161166a565b82611817565b610a835760405162461bcd60e51b815260040161095190613337565b61081f838383611895565b60088054610a9b906132fd565b80601f0160208091040260200160405190810160405280929190818152602001828054610ac7906132fd565b8015610b145780601f10610ae957610100808354040283529160200191610b14565b820191906000526020600020905b815481529060010190602001808311610af757829003601f168201915b505050505081565b610a4b81611a06565b6000610b3083610e66565b8210610b925760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b6064820152608401610951565b506001600160a01b03919091166000908152600f60209081526040808320938352929052205490565b7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6610bed81610be861166a565b611b0d565b610bf5611bb0565b61081f8383611bf8565b61081f838383604051806020016040528060008152506111bf565b7fd3dc2a3a14cbd0cdbf3069fc3927e48506f271b9dda2c21625b93e6a99d3eb53610c4781610be861166a565b610c4f611bb0565b6103d382611ccf565b610c60611592565b600480546001600160a01b0319166001600160a01b0392909216919091179055565b6000818152600b60205260408120546001600160a01b03161515610805565b6000610cac60115490565b8210610d0f5760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b6064820152608401610951565b60118281548110610d2257610d22613384565b90600052602060002001549050919050565b6002546000906001600160a01b03161580159061080557506108057fd3df22cd6a774f62b0ae21ffd602cc92e7f3390518eee8b33307fc70380da7d283611d72565b60008054600160a01b900460ff1680610e015750600260009054906101000a90046001600160a01b03166001600160a01b0316635c975abb6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ddd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e01919061339a565b905090565b6000818152600b60205260408120546001600160a01b0316806108055760405162461bcd60e51b8152602060048201526018602482015277115490cdcc8c4e881a5b9d985b1a59081d1bdad95b88125160421b6044820152606401610951565b60006001600160a01b038216610ed05760405162461bcd60e51b815260206004820152602960248201527f4552433732313a2061646472657373207a65726f206973206e6f7420612076616044820152683634b21037bbb732b960b91b6064820152608401610951565b506001600160a01b03166000908152600c602052604090205490565b610ef4611592565b610efe6000611df0565b565b6060600060068054610f11906132fd565b90501115610f35576006610f2483611e40565b604051602001610a1f9291906133d3565b505060408051602081019091526000815290565b610f51611592565b61081f60058383612d4b565b6060610f89827fdd8c1d6d2c9a745d80261bb0d7b0c6ba96f1ea6479fc4ab1935153a72f28db1f611ed3565b15610fb857610805827fdd8c1d6d2c9a745d80261bb0d7b0c6ba96f1ea6479fc4ab1935153a72f28db1f611f19565b600060058054610fc7906132fd565b90501115610fda576005610f2483611e40565b60078054610fe7906132fd565b80601f0160208091040260200160405190810160405280929190818152602001828054611013906132fd565b80156110605780601f1061103557610100808354040283529160200191611060565b820191906000526020600020905b81548152906001019060200180831161104357829003601f168201915b50505050509050919050565b611074611592565b61108060168383612d4b565b507f905d981207a7d0b6c62cc46ab0be2a076d0298e4a86d0ab79882dbd01ac3737882826040516110b2929190613479565b60405180910390a15050565b6060600a8054610833906132fd565b8060148111156110f0576040516368ebde9160e11b815260040160405180910390fd5b60005b8181101561113257600084848381811061110f5761110f613384565b90506020020135905061112181611a06565b5061112b816134be565b90506110f3565b50505050565b6060611164827f7452e56ec9dd836d15d444262499c5f01e617174be1abe27bc773c8a8890b9cb611ed3565b1561119357610805827f7452e56ec9dd836d15d444262499c5f01e617174be1abe27bc773c8a8890b9cb611f19565b60088054610fe7906132fd565b6103d36111ab61166a565b8383611f9f565b60058054610a9b906132fd565b6111d06111ca61166a565b83611817565b6111ec5760405162461bcd60e51b815260040161095190613337565b6111328484848461206d565b6000818152600b60205260409020546060906001600160a01b03166112775760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b6064820152608401610951565b610805826120a0565b60038054610a9b906132fd565b7f8f4f2da22e8ac8f11e15f9fc141cddbb5deea8800186560abb6e68c5496619a96112ba81610be861166a565b61113284848461217a565b6112cd611592565b600280546001600160a01b0319166001600160a01b038316908117909155610a4b5760405163a4b9148160e01b815260040160405180910390fd5b60078054610a9b906132fd565b6060611341827fb5e7e7e737f64f2b9cbe8f990b1f427fc2a03b47e93daeea99b83c32061778a7611ed3565b151560010361137457610805827fb5e7e7e737f64f2b9cbe8f990b1f427fc2a03b47e93daeea99b83c32061778a7611f19565b61137d82611e40565b604051602001610a1f91906134d7565b60008061139983610e06565b90506001600160a01b0384166113c25760405163200db56f60e11b815260040160405180910390fd5b60008381526014602090815260408083206001600160a01b038089168086529190935292205463ffffffff1691908316036114315760008481526015602052604081205463ffffffff169061141642612282565b90506114228282613505565b61142c908461352a565b925050505b949350505050565b606060168054610833906132fd565b60068054610a9b906132fd565b61145d611592565b601780546001600160a01b0319166001600160a01b0392909216919091179055565b611487611592565b6001600160a01b0381166114ec5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610951565b610a4b81611df0565b6114fd611592565b61081f60068383612d4b565b600060143610801590611520575061152033610d34565b15611532575060131936013560601c90565b503390565b60006001600160e01b0319821663403cee5960e11b14806108055750610805826122eb565b60006001600160e01b0319821663bc5d42d560e01b148061080557506001600160e01b031982166301ffc9a760e01b1492915050565b61159a61166a565b6001600160a01b03166115b56000546001600160a01b031690565b6001600160a01b031614610efe5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610951565b6000818152600b60205260409020546001600160a01b0316610a4b5760405162461bcd60e51b8152602060048201526018602482015277115490cdcc8c4e881a5b9d985b1a59081d1bdad95b88125160421b6044820152606401610951565b6000610e01611509565b6000818152600d6020526040902080546001600160a01b0319166001600160a01b03841690811790915581906116a982610e06565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b600054600160a01b900460ff16156117335760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610951565b6000805460ff60a01b1916600160a01b1790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861176f61166a565b6040516001600160a01b03909116815260200160405180910390a1565b600054600160a01b900460ff1615156001146117e15760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610951565b6000805460ff60a01b191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa61176f61166a565b60008061182383610e06565b9050806001600160a01b0316846001600160a01b0316148061186a57506001600160a01b038082166000908152600e602090815260408083209388168352929052205460ff165b806114315750836001600160a01b0316611883846108b6565b6001600160a01b031614949350505050565b826001600160a01b03166118a882610e06565b6001600160a01b0316146118ce5760405162461bcd60e51b815260040161095190613552565b6001600160a01b0382166119305760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610951565b61193d8383836001612310565b826001600160a01b031661195082610e06565b6001600160a01b0316146119765760405162461bcd60e51b815260040161095190613552565b6000818152600d6020908152604080832080546001600160a01b03199081169091556001600160a01b03878116808652600c8552838620805460001901905590871680865283862080546001019055868652600b90945282852080549092168417909155905184937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b611a0f81610e06565b6001600160a01b0316611a2061166a565b6001600160a01b031614611a47576040516330cd747160e01b815260040160405180910390fd5b806000611a5261166a565b6001600160a01b03167ff94915c6d1fd521cee85359239227480c7e8776d7caf1fc3bacad5c269b66a14306001600160a01b0316631653c39a866040518263ffffffff1660e01b8152600401611aaa91815260200190565b600060405180830381865afa158015611ac7573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611aef91908101906135c7565b604051611afc9190612fff565b60405180910390a4610a4b81611ccf565b6002546040516361b6ebf560e11b8152600481018490526001600160a01b0383811660248301529091169063c36dd7ea90604401602060405180830381865afa158015611b5e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b82919061339a565b6103d35760405162b0d32560e11b81526001600160a01b038216600482015260248101839052604401610951565b611bb8610d76565b15610efe5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610951565b7f000000000000000000000000000000000000000000000000000000000000000015801590611c4657507f000000000000000000000000000000000000000000000000000000000000000081115b15611c6457604051636454417160e01b815260040160405180910390fd5b80600003611c85576040516307ed98ed60e31b815260040160405180910390fd5b611c8f82826124ae565b60008181526013602052604081205460ff16151590036103d357611cb2816124c8565b6000818152601360205260409020805460ff191660011790555050565b6000611cda82610e06565b9050611cea816000846001612310565b611cf382610e06565b6000838152600d6020908152604080832080546001600160a01b03199081169091556001600160a01b038516808552600c84528285208054600019019055878552600b909352818420805490911690555192935084927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b6002546040516361b6ebf560e11b8152600481018490526001600160a01b038381166024830152600092169063c36dd7ea906044015b602060405180830381865afa158015611dc5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611de9919061339a565b9392505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60606000611e4d8361255e565b600101905060008167ffffffffffffffff811115611e6d57611e6d612e99565b6040519080825280601f01601f191660200182016040528015611e97576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a8504945084611ea157509392505050565b6000611edd612636565b604051639b9a15b360e01b815230600482015260248101859052604481018490526001600160a01b039190911690639b9a15b390606401611da8565b6060611f23612636565b604051631b9db23d60e21b815230600482015260248101859052604481018490526001600160a01b039190911690636e76c8f490606401600060405180830381865afa158015611f77573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611de991908101906135c7565b816001600160a01b0316836001600160a01b0316036120005760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610951565b6001600160a01b038381166000818152600e6020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b612078848484611895565b61208484848484612661565b6111325760405162461bcd60e51b815260040161095190613610565b60606000600380546120b1906132fd565b905011156120c4576003610f2483611e40565b6004546001600160a01b03166120e857505060408051602081019091526000815290565b6004546001600160a01b031663f4bef99c61210161166a565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015230602482015260448101859052606401600060405180830381865afa158015612152573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261080591908101906135c7565b60208190036121d957600061219182840184613012565b905061219d8482611bf8565b60405181906001600160a01b038616907fc153eb6ad0186f7ea3e5f9572267cff685b50c83b6ad973546e592349686fdfe90600090a350505050565b60006121e782840184613662565b805190915060005b8181101561227a5761221a8684838151811061220d5761220d613384565b6020026020010151611bf8565b82818151811061222c5761222c613384565b6020026020010151866001600160a01b03167fc153eb6ad0186f7ea3e5f9572267cff685b50c83b6ad973546e592349686fdfe60405160405180910390a3612273816134be565b90506121ef565b505050505050565b600063ffffffff8211156122e75760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203360448201526532206269747360d01b6064820152608401610951565b5090565b60006001600160e01b0319821663780e9d6360e01b1480610805575061080582612769565b6017546001600160a01b0316156123bd576017546001600160a01b0316806374c916863061233c61166a565b6040516001600160e01b031960e085901b1681526001600160a01b0392831660048201529082166024820152818916604482015290871660648201526084810186905260a4810185905260c401600060405180830381600087803b1580156123a357600080fd5b505af11580156123b7573d6000803e3d6000fd5b50505050505b60005b818110156124a15760006123d48285613697565b60008181526015602052604081205491925063ffffffff909116906123f842612282565b905063ffffffff821615612467576124108282613505565b60008481526014602090815260408083206001600160a01b038d1684529091528120805490919061244890849063ffffffff1661352a565b92506101000a81548163ffffffff021916908363ffffffff1602179055505b600092835260156020526040909220805463ffffffff191663ffffffff909316929092179091555080612499816134be565b9150506123c0565b50611132848484846127b9565b6103d38282604051806020016040528060008152506128f9565b60006124d2612636565b604051631d0795a560e01b8152306004820152602481018490527ff98ab89115ec445bbd2dc50976d3a259c6f8143547281cdb262347c645f1ac836044820152600160648201529091506001600160a01b03821690631d0795a590608401600060405180830381600087803b15801561254a57600080fd5b505af115801561227a573d6000803e3d6000fd5b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b831061259d5772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef810000000083106125c9576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc1000083106125e757662386f26fc10000830492506010015b6305f5e10083106125ff576305f5e100830492506008015b612710831061261357612710830492506004015b60648310612625576064830492506002015b600a83106108055760010192915050565b6000610e017f01f158cde3348caf657c186dba8f4f8ad98b974273df8754bfbbcf30386dabba61292c565b60006001600160a01b0384163b1561275e57836001600160a01b031663150b7a0261268a61166a565b8786866040518563ffffffff1660e01b81526004016126ac94939291906136af565b6020604051808303816000875af19250505080156126e7575060408051601f3d908101601f191682019092526126e4918101906136ec565b60015b612744573d808015612715576040519150601f19603f3d011682016040523d82523d6000602084013e61271a565b606091505b50805160000361273c5760405162461bcd60e51b815260040161095190613610565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611431565b506001949350505050565b60006001600160e01b031982166380ac58cd60e01b148061279a57506001600160e01b03198216635b5e139f60e01b145b8061080557506301ffc9a760e01b6001600160e01b0319831614610805565b6127c58484848461299a565b60018111156128345760405162461bcd60e51b815260206004820152603560248201527f455243373231456e756d657261626c653a20636f6e7365637574697665207472604482015274185b9cd9995c9cc81b9bdd081cdd5c1c1bdc9d1959605a1b6064820152608401610951565b816001600160a01b0385166128905761288b81601180546000838152601260205260408120829055600182018355919091527f31ecc21a745e3968a04e9570e4425bc18fa8019c68028196b546d1669c200c680155565b6128b3565b836001600160a01b0316856001600160a01b0316146128b3576128b38582612a22565b6001600160a01b0384166128cf576128ca81612abf565b6128f2565b846001600160a01b0316846001600160a01b0316146128f2576128f28482612b6e565b5050505050565b6129038383612bb2565b6129106000848484612661565b61081f5760405162461bcd60e51b815260040161095190613610565b6002546040516329f20e0f60e11b8152600481018390526000916001600160a01b0316906353e41c1e90602401602060405180830381865afa158015612976573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108059190613709565b6001811115611132576001600160a01b038416156129e0576001600160a01b0384166000908152600c6020526040812080548392906129da908490613726565b90915550505b6001600160a01b03831615611132576001600160a01b0383166000908152600c602052604081208054839290612a17908490613697565b909155505050505050565b60006001612a2f84610e66565b612a399190613726565b600083815260106020526040902054909150808214612a8c576001600160a01b0384166000908152600f602090815260408083208584528252808320548484528184208190558352601090915290208190555b5060009182526010602090815260408084208490556001600160a01b039094168352600f81528383209183525290812055565b601154600090612ad190600190613726565b60008381526012602052604081205460118054939450909284908110612af957612af9613384565b906000526020600020015490508060118381548110612b1a57612b1a613384565b6000918252602080832090910192909255828152601290915260408082208490558582528120556011805480612b5257612b5261373d565b6001900381819060005260206000200160009055905550505050565b6000612b7983610e66565b6001600160a01b039093166000908152600f60209081526040808320868452825280832085905593825260109052919091209190915550565b6001600160a01b038216612c085760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610951565b6000818152600b60205260409020546001600160a01b031615612c6d5760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610951565b612c7b600083836001612310565b6000818152600b60205260409020546001600160a01b031615612ce05760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610951565b6001600160a01b0382166000818152600c6020908152604080832080546001019055848352600b90915280822080546001600160a01b0319168417905551839291907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b828054612d57906132fd565b90600052602060002090601f016020900481019282612d795760008555612dbf565b82601f10612d925782800160ff19823516178555612dbf565b82800160010185558215612dbf579182015b82811115612dbf578235825591602001919060010190612da4565b506122e79291505b808211156122e75760008155600101612dc7565b6001600160e01b031981168114610a4b57600080fd5b600060208284031215612e0357600080fd5b8135611de981612ddb565b60008083601f840112612e2057600080fd5b50813567ffffffffffffffff811115612e3857600080fd5b602083019150836020828501011115612e5057600080fd5b9250929050565b60008060208385031215612e6a57600080fd5b823567ffffffffffffffff811115612e8157600080fd5b612e8d85828601612e0e565b90969095509350505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715612ed857612ed8612e99565b604052919050565b600082601f830112612ef157600080fd5b8135602067ffffffffffffffff821115612f0d57612f0d612e99565b8160051b612f1c828201612eaf565b9283528481018201928281019087851115612f3657600080fd5b83870192505b84831015612f5557823582529183019190830190612f3c565b979650505050505050565b60008060408385031215612f7357600080fd5b82359150602083013567ffffffffffffffff811115612f9157600080fd5b612f9d85828601612ee0565b9150509250929050565b60005b83811015612fc2578181015183820152602001612faa565b838111156111325750506000910152565b60008151808452612feb816020860160208601612fa7565b601f01601f19169290920160200192915050565b602081526000611de96020830184612fd3565b60006020828403121561302457600080fd5b5035919050565b6001600160a01b0381168114610a4b57600080fd5b6000806040838503121561305357600080fd5b823561305e8161302b565b946020939093013593505050565b8015158114610a4b57600080fd5b60006020828403121561308c57600080fd5b8135611de98161306c565b6000806000606084860312156130ac57600080fd5b83356130b78161302b565b925060208401356130c78161302b565b929592945050506040919091013590565b6000602082840312156130ea57600080fd5b8135611de98161302b565b6000806020838503121561310857600080fd5b823567ffffffffffffffff8082111561312057600080fd5b818501915085601f83011261313457600080fd5b81358181111561314357600080fd5b8660208260051b850101111561315857600080fd5b60209290920196919550909350505050565b6000806040838503121561317d57600080fd5b82356131888161302b565b915060208301356131988161306c565b809150509250929050565b600067ffffffffffffffff8211156131bd576131bd612e99565b50601f01601f191660200190565b600080600080608085870312156131e157600080fd5b84356131ec8161302b565b935060208501356131fc8161302b565b925060408501359150606085013567ffffffffffffffff81111561321f57600080fd5b8501601f8101871361323057600080fd5b803561324361323e826131a3565b612eaf565b81815288602083850101111561325857600080fd5b8160208401602083013760006020838301015280935050505092959194509250565b60008060006040848603121561328f57600080fd5b833561329a8161302b565b9250602084013567ffffffffffffffff8111156132b657600080fd5b6132c286828701612e0e565b9497909650939450505050565b600080604083850312156132e257600080fd5b82356132ed8161302b565b915060208301356131988161302b565b600181811c9082168061331157607f821691505b60208210810361333157634e487b7160e01b600052602260045260246000fd5b50919050565b6020808252602d908201527f4552433732313a2063616c6c6572206973206e6f7420746f6b656e206f776e6560408201526c1c881bdc88185c1c1c9bdd9959609a1b606082015260800190565b634e487b7160e01b600052603260045260246000fd5b6000602082840312156133ac57600080fd5b8151611de98161306c565b600081516133c9818560208601612fa7565b9290920192915050565b600080845481600182811c9150808316806133ef57607f831692505b6020808410820361340e57634e487b7160e01b86526022600452602486fd5b818015613422576001811461343357613460565b60ff19861689528489019650613460565b60008b81526020902060005b868110156134585781548b82015290850190830161343f565b505084890196505b50505050505061347081856133b7565b95945050505050565b60208152816020820152818360408301376000818301604090810191909152601f909201601f19160101919050565b634e487b7160e01b600052601160045260246000fd5b6000600182016134d0576134d06134a8565b5060010190565b6553686970202360d01b8152600082516134f8816006850160208701612fa7565b9190910160060192915050565b600063ffffffff83811690831681811015613522576135226134a8565b039392505050565b600063ffffffff808316818516808303821115613549576135496134a8565b01949350505050565b60208082526025908201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060408201526437bbb732b960d91b606082015260800190565b60006135a561323e846131a3565b90508281528383830111156135b957600080fd5b611de9836020830184612fa7565b6000602082840312156135d957600080fd5b815167ffffffffffffffff8111156135f057600080fd5b8201601f8101841361360157600080fd5b61143184825160208401613597565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b60006020828403121561367457600080fd5b813567ffffffffffffffff81111561368b57600080fd5b61143184828501612ee0565b600082198211156136aa576136aa6134a8565b500190565b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906136e290830184612fd3565b9695505050505050565b6000602082840312156136fe57600080fd5b8151611de981612ddb565b60006020828403121561371b57600080fd5b8151611de98161302b565b600082821015613738576137386134a8565b500390565b634e487b7160e01b600052603160045260246000fdfea264697066735822122091041d93de47daae3f89eb8dcb9f55658346895568ca5a439a4deb5297ca8a4164736f6c634300080d003354616b6520746f207468652073656173207769746820796f757220706972617465206372657721204578706c6f72652074686520776f726c6420616e64206761746865722058502c206c6f6f742c20616e6420756e746f6c642072696368657320696e2061207261636520746f206265636f6d652074686520776f726c64277320677265617465737420706972617465206361707461696e2120506c61792061742068747470733a2f2f7069726174656e6174696f6e2e67616d65697066733a2f2f516d55654d473751507953506942703468546339753146506371354d4b4a7a79594c6751683174374665664543583f00000000000000000000000033acb3c515f09967feb55cece0381d7efee58d39
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106103835760003560e01c806374ca4283116101de578063ce6225ce1161010f578063e8a3d485116100ad578063ed022ebd1161007c578063ed022ebd1461077c578063f0e56f0d1461078d578063f2fde38b146107b3578063f803f410146107c657600080fd5b8063e8a3d4851461071d578063e985e9c514610725578063eab7e15514610761578063eb0c3a151461076957600080fd5b8063dd898b2f116100e9578063dd898b2f146106dc578063e41f84f4146106ef578063e725f877146106f7578063e7277dd71461070a57600080fd5b8063ce6225ce1461069b578063cf2c52cb146106a3578063d5abeb01146106b657600080fd5b80639c8d41561161017c578063a5e584dc11610156578063a5e584dc14610490578063a6c038f71461066d578063b88d4fde14610675578063c87b56dd1461068857600080fd5b80639c8d415614610634578063a0c6d53714610647578063a22cb4651461065a57600080fd5b80638f742d16116101b85780638f742d16146105fe578063938e3d7b146106115780639559c0bd1461062457806395d89b411461062c57600080fd5b806374ca4283146105c75780638647ca76146105da5780638da5cb5b146105ed57600080fd5b806340c10f19116102b8578063572b6c05116102565780636352211e116102305780636352211e146105865780636838c0621461059957806370a08231146105ac578063715018a6146105bf57600080fd5b8063572b6c05146105635780635c975abb146105765780635d1ca6311461057e57600080fd5b806342966c681161029257806342966c68146105175780634dbf9a731461052a5780634f558e791461053d5780634f6ccce71461055057600080fd5b806340c10f19146104b65780634139493e146104c957806342842e0e1461050457600080fd5b80631653c39a1161032557806323b872dd116102ff57806323b872dd146104755780632aa0324d146104885780632e1a7d4d146104905780632f745c59146104a357600080fd5b80631653c39a1461043d57806316c38b3c1461045057806318160ddd1461046357600080fd5b806306fdde031161036157806306fdde03146103d7578063081812fc146103ec578063095ea7b3146104175780630dacaa081461042a57600080fd5b806301ffc9a71461038857806302fe5305146103b057806306c1cb91146103c5575b600080fd5b61039b610396366004612df1565b6107d9565b60405190151581526020015b60405180910390f35b6103c36103be366004612e57565b61080b565b005b6103c36103d3366004612f60565b5050565b6103df610824565b6040516103a79190612fff565b6103ff6103fa366004613012565b6108b6565b6040516001600160a01b0390911681526020016103a7565b6103c3610425366004613040565b6108dd565b6004546103ff906001600160a01b031681565b6103df61044b366004613012565b610a04565b6103c361045e36600461307a565b610a35565b6011545b6040519081526020016103a7565b6103c3610483366004613097565b610a56565b6103df610a8e565b6103c361049e366004613012565b610b1c565b6104676104b1366004613040565b610b25565b6103c36104c4366004613040565b610bbb565b6104ef6104d7366004613012565b60156020526000908152604090205463ffffffff1681565b60405163ffffffff90911681526020016103a7565b6103c3610512366004613097565b610bff565b6103c3610525366004613012565b610c1a565b6103c36105383660046130d8565b610c58565b61039b61054b366004613012565b610c82565b61046761055e366004613012565b610ca1565b61039b6105713660046130d8565b610d34565b61039b610d76565b600154610467565b6103ff610594366004613012565b610e06565b6017546103ff906001600160a01b031681565b6104676105ba3660046130d8565b610e66565b6103c3610eec565b6103df6105d5366004613012565b610f00565b6103c36105e8366004612e57565b610f49565b6000546001600160a01b03166103ff565b6103df61060c366004613012565b610f5d565b6103c361061f366004612e57565b61106c565b610467601481565b6103df6110be565b6103c36106423660046130f5565b6110cd565b6103df610655366004613012565b611138565b6103c361066836600461316a565b6111a0565b6103df6111b2565b6103c36106833660046131cb565b6111bf565b6103df610696366004613012565b6111f8565b6103df611280565b6103c36106b136600461327a565b61128d565b7f0000000000000000000000000000000000000000000000000000000000000000610467565b6103c36106ea3660046130d8565b6112c5565b6103df611308565b6103df610705366004613012565b611315565b6104ef610718366004613040565b61138d565b6103df611439565b61039b6107333660046132cf565b6001600160a01b039182166000908152600e6020908152604080832093909416825291909152205460ff1690565b6103df611448565b6103c36107773660046130d8565b611455565b6002546001600160a01b03166103ff565b6104ef61079b366004613012565b60009081526015602052604090205463ffffffff1690565b6103c36107c13660046130d8565b61147f565b6103c36107d4366004612e57565b6114f5565b60006001600160e01b0319821615806107f657506107f682611537565b8061080557506108058261155c565b92915050565b610813611592565b61081f60038383612d4b565b505050565b606060098054610833906132fd565b80601f016020809104026020016040519081016040528092919081815260200182805461085f906132fd565b80156108ac5780601f10610881576101008083540402835291602001916108ac565b820191906000526020600020905b81548152906001019060200180831161088f57829003601f168201915b5050505050905090565b60006108c18261160b565b506000908152600d60205260409020546001600160a01b031690565b60006108e882610e06565b9050806001600160a01b0316836001600160a01b03160361095a5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b60648201526084015b60405180910390fd5b806001600160a01b031661096c61166a565b6001600160a01b0316148061098857506109888161073361166a565b6109fa5760405162461bcd60e51b815260206004820152603d60248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f7420746f60448201527f6b656e206f776e6572206f7220617070726f76656420666f7220616c6c0000006064820152608401610951565b61081f8383611674565b6060610a0f826111f8565b604051602001610a1f9190612fff565b6040516020818303038152906040529050919050565b610a3d611592565b8015610a4e57610a4b6116e2565b50565b610a4b61178c565b610a67610a6161166a565b82611817565b610a835760405162461bcd60e51b815260040161095190613337565b61081f838383611895565b60088054610a9b906132fd565b80601f0160208091040260200160405190810160405280929190818152602001828054610ac7906132fd565b8015610b145780601f10610ae957610100808354040283529160200191610b14565b820191906000526020600020905b815481529060010190602001808311610af757829003601f168201915b505050505081565b610a4b81611a06565b6000610b3083610e66565b8210610b925760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b6064820152608401610951565b506001600160a01b03919091166000908152600f60209081526040808320938352929052205490565b7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6610bed81610be861166a565b611b0d565b610bf5611bb0565b61081f8383611bf8565b61081f838383604051806020016040528060008152506111bf565b7fd3dc2a3a14cbd0cdbf3069fc3927e48506f271b9dda2c21625b93e6a99d3eb53610c4781610be861166a565b610c4f611bb0565b6103d382611ccf565b610c60611592565b600480546001600160a01b0319166001600160a01b0392909216919091179055565b6000818152600b60205260408120546001600160a01b03161515610805565b6000610cac60115490565b8210610d0f5760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b6064820152608401610951565b60118281548110610d2257610d22613384565b90600052602060002001549050919050565b6002546000906001600160a01b03161580159061080557506108057fd3df22cd6a774f62b0ae21ffd602cc92e7f3390518eee8b33307fc70380da7d283611d72565b60008054600160a01b900460ff1680610e015750600260009054906101000a90046001600160a01b03166001600160a01b0316635c975abb6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ddd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e01919061339a565b905090565b6000818152600b60205260408120546001600160a01b0316806108055760405162461bcd60e51b8152602060048201526018602482015277115490cdcc8c4e881a5b9d985b1a59081d1bdad95b88125160421b6044820152606401610951565b60006001600160a01b038216610ed05760405162461bcd60e51b815260206004820152602960248201527f4552433732313a2061646472657373207a65726f206973206e6f7420612076616044820152683634b21037bbb732b960b91b6064820152608401610951565b506001600160a01b03166000908152600c602052604090205490565b610ef4611592565b610efe6000611df0565b565b6060600060068054610f11906132fd565b90501115610f35576006610f2483611e40565b604051602001610a1f9291906133d3565b505060408051602081019091526000815290565b610f51611592565b61081f60058383612d4b565b6060610f89827fdd8c1d6d2c9a745d80261bb0d7b0c6ba96f1ea6479fc4ab1935153a72f28db1f611ed3565b15610fb857610805827fdd8c1d6d2c9a745d80261bb0d7b0c6ba96f1ea6479fc4ab1935153a72f28db1f611f19565b600060058054610fc7906132fd565b90501115610fda576005610f2483611e40565b60078054610fe7906132fd565b80601f0160208091040260200160405190810160405280929190818152602001828054611013906132fd565b80156110605780601f1061103557610100808354040283529160200191611060565b820191906000526020600020905b81548152906001019060200180831161104357829003601f168201915b50505050509050919050565b611074611592565b61108060168383612d4b565b507f905d981207a7d0b6c62cc46ab0be2a076d0298e4a86d0ab79882dbd01ac3737882826040516110b2929190613479565b60405180910390a15050565b6060600a8054610833906132fd565b8060148111156110f0576040516368ebde9160e11b815260040160405180910390fd5b60005b8181101561113257600084848381811061110f5761110f613384565b90506020020135905061112181611a06565b5061112b816134be565b90506110f3565b50505050565b6060611164827f7452e56ec9dd836d15d444262499c5f01e617174be1abe27bc773c8a8890b9cb611ed3565b1561119357610805827f7452e56ec9dd836d15d444262499c5f01e617174be1abe27bc773c8a8890b9cb611f19565b60088054610fe7906132fd565b6103d36111ab61166a565b8383611f9f565b60058054610a9b906132fd565b6111d06111ca61166a565b83611817565b6111ec5760405162461bcd60e51b815260040161095190613337565b6111328484848461206d565b6000818152600b60205260409020546060906001600160a01b03166112775760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b6064820152608401610951565b610805826120a0565b60038054610a9b906132fd565b7f8f4f2da22e8ac8f11e15f9fc141cddbb5deea8800186560abb6e68c5496619a96112ba81610be861166a565b61113284848461217a565b6112cd611592565b600280546001600160a01b0319166001600160a01b038316908117909155610a4b5760405163a4b9148160e01b815260040160405180910390fd5b60078054610a9b906132fd565b6060611341827fb5e7e7e737f64f2b9cbe8f990b1f427fc2a03b47e93daeea99b83c32061778a7611ed3565b151560010361137457610805827fb5e7e7e737f64f2b9cbe8f990b1f427fc2a03b47e93daeea99b83c32061778a7611f19565b61137d82611e40565b604051602001610a1f91906134d7565b60008061139983610e06565b90506001600160a01b0384166113c25760405163200db56f60e11b815260040160405180910390fd5b60008381526014602090815260408083206001600160a01b038089168086529190935292205463ffffffff1691908316036114315760008481526015602052604081205463ffffffff169061141642612282565b90506114228282613505565b61142c908461352a565b925050505b949350505050565b606060168054610833906132fd565b60068054610a9b906132fd565b61145d611592565b601780546001600160a01b0319166001600160a01b0392909216919091179055565b611487611592565b6001600160a01b0381166114ec5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610951565b610a4b81611df0565b6114fd611592565b61081f60068383612d4b565b600060143610801590611520575061152033610d34565b15611532575060131936013560601c90565b503390565b60006001600160e01b0319821663403cee5960e11b14806108055750610805826122eb565b60006001600160e01b0319821663bc5d42d560e01b148061080557506001600160e01b031982166301ffc9a760e01b1492915050565b61159a61166a565b6001600160a01b03166115b56000546001600160a01b031690565b6001600160a01b031614610efe5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610951565b6000818152600b60205260409020546001600160a01b0316610a4b5760405162461bcd60e51b8152602060048201526018602482015277115490cdcc8c4e881a5b9d985b1a59081d1bdad95b88125160421b6044820152606401610951565b6000610e01611509565b6000818152600d6020526040902080546001600160a01b0319166001600160a01b03841690811790915581906116a982610e06565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b600054600160a01b900460ff16156117335760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610951565b6000805460ff60a01b1916600160a01b1790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861176f61166a565b6040516001600160a01b03909116815260200160405180910390a1565b600054600160a01b900460ff1615156001146117e15760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610951565b6000805460ff60a01b191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa61176f61166a565b60008061182383610e06565b9050806001600160a01b0316846001600160a01b0316148061186a57506001600160a01b038082166000908152600e602090815260408083209388168352929052205460ff165b806114315750836001600160a01b0316611883846108b6565b6001600160a01b031614949350505050565b826001600160a01b03166118a882610e06565b6001600160a01b0316146118ce5760405162461bcd60e51b815260040161095190613552565b6001600160a01b0382166119305760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610951565b61193d8383836001612310565b826001600160a01b031661195082610e06565b6001600160a01b0316146119765760405162461bcd60e51b815260040161095190613552565b6000818152600d6020908152604080832080546001600160a01b03199081169091556001600160a01b03878116808652600c8552838620805460001901905590871680865283862080546001019055868652600b90945282852080549092168417909155905184937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b611a0f81610e06565b6001600160a01b0316611a2061166a565b6001600160a01b031614611a47576040516330cd747160e01b815260040160405180910390fd5b806000611a5261166a565b6001600160a01b03167ff94915c6d1fd521cee85359239227480c7e8776d7caf1fc3bacad5c269b66a14306001600160a01b0316631653c39a866040518263ffffffff1660e01b8152600401611aaa91815260200190565b600060405180830381865afa158015611ac7573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611aef91908101906135c7565b604051611afc9190612fff565b60405180910390a4610a4b81611ccf565b6002546040516361b6ebf560e11b8152600481018490526001600160a01b0383811660248301529091169063c36dd7ea90604401602060405180830381865afa158015611b5e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b82919061339a565b6103d35760405162b0d32560e11b81526001600160a01b038216600482015260248101839052604401610951565b611bb8610d76565b15610efe5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610951565b7f000000000000000000000000000000000000000000000000000000000000000015801590611c4657507f000000000000000000000000000000000000000000000000000000000000000081115b15611c6457604051636454417160e01b815260040160405180910390fd5b80600003611c85576040516307ed98ed60e31b815260040160405180910390fd5b611c8f82826124ae565b60008181526013602052604081205460ff16151590036103d357611cb2816124c8565b6000818152601360205260409020805460ff191660011790555050565b6000611cda82610e06565b9050611cea816000846001612310565b611cf382610e06565b6000838152600d6020908152604080832080546001600160a01b03199081169091556001600160a01b038516808552600c84528285208054600019019055878552600b909352818420805490911690555192935084927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b6002546040516361b6ebf560e11b8152600481018490526001600160a01b038381166024830152600092169063c36dd7ea906044015b602060405180830381865afa158015611dc5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611de9919061339a565b9392505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60606000611e4d8361255e565b600101905060008167ffffffffffffffff811115611e6d57611e6d612e99565b6040519080825280601f01601f191660200182016040528015611e97576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a8504945084611ea157509392505050565b6000611edd612636565b604051639b9a15b360e01b815230600482015260248101859052604481018490526001600160a01b039190911690639b9a15b390606401611da8565b6060611f23612636565b604051631b9db23d60e21b815230600482015260248101859052604481018490526001600160a01b039190911690636e76c8f490606401600060405180830381865afa158015611f77573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611de991908101906135c7565b816001600160a01b0316836001600160a01b0316036120005760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610951565b6001600160a01b038381166000818152600e6020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b612078848484611895565b61208484848484612661565b6111325760405162461bcd60e51b815260040161095190613610565b60606000600380546120b1906132fd565b905011156120c4576003610f2483611e40565b6004546001600160a01b03166120e857505060408051602081019091526000815290565b6004546001600160a01b031663f4bef99c61210161166a565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015230602482015260448101859052606401600060405180830381865afa158015612152573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261080591908101906135c7565b60208190036121d957600061219182840184613012565b905061219d8482611bf8565b60405181906001600160a01b038616907fc153eb6ad0186f7ea3e5f9572267cff685b50c83b6ad973546e592349686fdfe90600090a350505050565b60006121e782840184613662565b805190915060005b8181101561227a5761221a8684838151811061220d5761220d613384565b6020026020010151611bf8565b82818151811061222c5761222c613384565b6020026020010151866001600160a01b03167fc153eb6ad0186f7ea3e5f9572267cff685b50c83b6ad973546e592349686fdfe60405160405180910390a3612273816134be565b90506121ef565b505050505050565b600063ffffffff8211156122e75760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203360448201526532206269747360d01b6064820152608401610951565b5090565b60006001600160e01b0319821663780e9d6360e01b1480610805575061080582612769565b6017546001600160a01b0316156123bd576017546001600160a01b0316806374c916863061233c61166a565b6040516001600160e01b031960e085901b1681526001600160a01b0392831660048201529082166024820152818916604482015290871660648201526084810186905260a4810185905260c401600060405180830381600087803b1580156123a357600080fd5b505af11580156123b7573d6000803e3d6000fd5b50505050505b60005b818110156124a15760006123d48285613697565b60008181526015602052604081205491925063ffffffff909116906123f842612282565b905063ffffffff821615612467576124108282613505565b60008481526014602090815260408083206001600160a01b038d1684529091528120805490919061244890849063ffffffff1661352a565b92506101000a81548163ffffffff021916908363ffffffff1602179055505b600092835260156020526040909220805463ffffffff191663ffffffff909316929092179091555080612499816134be565b9150506123c0565b50611132848484846127b9565b6103d38282604051806020016040528060008152506128f9565b60006124d2612636565b604051631d0795a560e01b8152306004820152602481018490527ff98ab89115ec445bbd2dc50976d3a259c6f8143547281cdb262347c645f1ac836044820152600160648201529091506001600160a01b03821690631d0795a590608401600060405180830381600087803b15801561254a57600080fd5b505af115801561227a573d6000803e3d6000fd5b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b831061259d5772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef810000000083106125c9576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc1000083106125e757662386f26fc10000830492506010015b6305f5e10083106125ff576305f5e100830492506008015b612710831061261357612710830492506004015b60648310612625576064830492506002015b600a83106108055760010192915050565b6000610e017f01f158cde3348caf657c186dba8f4f8ad98b974273df8754bfbbcf30386dabba61292c565b60006001600160a01b0384163b1561275e57836001600160a01b031663150b7a0261268a61166a565b8786866040518563ffffffff1660e01b81526004016126ac94939291906136af565b6020604051808303816000875af19250505080156126e7575060408051601f3d908101601f191682019092526126e4918101906136ec565b60015b612744573d808015612715576040519150601f19603f3d011682016040523d82523d6000602084013e61271a565b606091505b50805160000361273c5760405162461bcd60e51b815260040161095190613610565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611431565b506001949350505050565b60006001600160e01b031982166380ac58cd60e01b148061279a57506001600160e01b03198216635b5e139f60e01b145b8061080557506301ffc9a760e01b6001600160e01b0319831614610805565b6127c58484848461299a565b60018111156128345760405162461bcd60e51b815260206004820152603560248201527f455243373231456e756d657261626c653a20636f6e7365637574697665207472604482015274185b9cd9995c9cc81b9bdd081cdd5c1c1bdc9d1959605a1b6064820152608401610951565b816001600160a01b0385166128905761288b81601180546000838152601260205260408120829055600182018355919091527f31ecc21a745e3968a04e9570e4425bc18fa8019c68028196b546d1669c200c680155565b6128b3565b836001600160a01b0316856001600160a01b0316146128b3576128b38582612a22565b6001600160a01b0384166128cf576128ca81612abf565b6128f2565b846001600160a01b0316846001600160a01b0316146128f2576128f28482612b6e565b5050505050565b6129038383612bb2565b6129106000848484612661565b61081f5760405162461bcd60e51b815260040161095190613610565b6002546040516329f20e0f60e11b8152600481018390526000916001600160a01b0316906353e41c1e90602401602060405180830381865afa158015612976573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108059190613709565b6001811115611132576001600160a01b038416156129e0576001600160a01b0384166000908152600c6020526040812080548392906129da908490613726565b90915550505b6001600160a01b03831615611132576001600160a01b0383166000908152600c602052604081208054839290612a17908490613697565b909155505050505050565b60006001612a2f84610e66565b612a399190613726565b600083815260106020526040902054909150808214612a8c576001600160a01b0384166000908152600f602090815260408083208584528252808320548484528184208190558352601090915290208190555b5060009182526010602090815260408084208490556001600160a01b039094168352600f81528383209183525290812055565b601154600090612ad190600190613726565b60008381526012602052604081205460118054939450909284908110612af957612af9613384565b906000526020600020015490508060118381548110612b1a57612b1a613384565b6000918252602080832090910192909255828152601290915260408082208490558582528120556011805480612b5257612b5261373d565b6001900381819060005260206000200160009055905550505050565b6000612b7983610e66565b6001600160a01b039093166000908152600f60209081526040808320868452825280832085905593825260109052919091209190915550565b6001600160a01b038216612c085760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610951565b6000818152600b60205260409020546001600160a01b031615612c6d5760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610951565b612c7b600083836001612310565b6000818152600b60205260409020546001600160a01b031615612ce05760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610951565b6001600160a01b0382166000818152600c6020908152604080832080546001019055848352600b90915280822080546001600160a01b0319168417905551839291907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b828054612d57906132fd565b90600052602060002090601f016020900481019282612d795760008555612dbf565b82601f10612d925782800160ff19823516178555612dbf565b82800160010185558215612dbf579182015b82811115612dbf578235825591602001919060010190612da4565b506122e79291505b808211156122e75760008155600101612dc7565b6001600160e01b031981168114610a4b57600080fd5b600060208284031215612e0357600080fd5b8135611de981612ddb565b60008083601f840112612e2057600080fd5b50813567ffffffffffffffff811115612e3857600080fd5b602083019150836020828501011115612e5057600080fd5b9250929050565b60008060208385031215612e6a57600080fd5b823567ffffffffffffffff811115612e8157600080fd5b612e8d85828601612e0e565b90969095509350505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715612ed857612ed8612e99565b604052919050565b600082601f830112612ef157600080fd5b8135602067ffffffffffffffff821115612f0d57612f0d612e99565b8160051b612f1c828201612eaf565b9283528481018201928281019087851115612f3657600080fd5b83870192505b84831015612f5557823582529183019190830190612f3c565b979650505050505050565b60008060408385031215612f7357600080fd5b82359150602083013567ffffffffffffffff811115612f9157600080fd5b612f9d85828601612ee0565b9150509250929050565b60005b83811015612fc2578181015183820152602001612faa565b838111156111325750506000910152565b60008151808452612feb816020860160208601612fa7565b601f01601f19169290920160200192915050565b602081526000611de96020830184612fd3565b60006020828403121561302457600080fd5b5035919050565b6001600160a01b0381168114610a4b57600080fd5b6000806040838503121561305357600080fd5b823561305e8161302b565b946020939093013593505050565b8015158114610a4b57600080fd5b60006020828403121561308c57600080fd5b8135611de98161306c565b6000806000606084860312156130ac57600080fd5b83356130b78161302b565b925060208401356130c78161302b565b929592945050506040919091013590565b6000602082840312156130ea57600080fd5b8135611de98161302b565b6000806020838503121561310857600080fd5b823567ffffffffffffffff8082111561312057600080fd5b818501915085601f83011261313457600080fd5b81358181111561314357600080fd5b8660208260051b850101111561315857600080fd5b60209290920196919550909350505050565b6000806040838503121561317d57600080fd5b82356131888161302b565b915060208301356131988161306c565b809150509250929050565b600067ffffffffffffffff8211156131bd576131bd612e99565b50601f01601f191660200190565b600080600080608085870312156131e157600080fd5b84356131ec8161302b565b935060208501356131fc8161302b565b925060408501359150606085013567ffffffffffffffff81111561321f57600080fd5b8501601f8101871361323057600080fd5b803561324361323e826131a3565b612eaf565b81815288602083850101111561325857600080fd5b8160208401602083013760006020838301015280935050505092959194509250565b60008060006040848603121561328f57600080fd5b833561329a8161302b565b9250602084013567ffffffffffffffff8111156132b657600080fd5b6132c286828701612e0e565b9497909650939450505050565b600080604083850312156132e257600080fd5b82356132ed8161302b565b915060208301356131988161302b565b600181811c9082168061331157607f821691505b60208210810361333157634e487b7160e01b600052602260045260246000fd5b50919050565b6020808252602d908201527f4552433732313a2063616c6c6572206973206e6f7420746f6b656e206f776e6560408201526c1c881bdc88185c1c1c9bdd9959609a1b606082015260800190565b634e487b7160e01b600052603260045260246000fd5b6000602082840312156133ac57600080fd5b8151611de98161306c565b600081516133c9818560208601612fa7565b9290920192915050565b600080845481600182811c9150808316806133ef57607f831692505b6020808410820361340e57634e487b7160e01b86526022600452602486fd5b818015613422576001811461343357613460565b60ff19861689528489019650613460565b60008b81526020902060005b868110156134585781548b82015290850190830161343f565b505084890196505b50505050505061347081856133b7565b95945050505050565b60208152816020820152818360408301376000818301604090810191909152601f909201601f19160101919050565b634e487b7160e01b600052601160045260246000fd5b6000600182016134d0576134d06134a8565b5060010190565b6553686970202360d01b8152600082516134f8816006850160208701612fa7565b9190910160060192915050565b600063ffffffff83811690831681811015613522576135226134a8565b039392505050565b600063ffffffff808316818516808303821115613549576135496134a8565b01949350505050565b60208082526025908201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060408201526437bbb732b960d91b606082015260800190565b60006135a561323e846131a3565b90508281528383830111156135b957600080fd5b611de9836020830184612fa7565b6000602082840312156135d957600080fd5b815167ffffffffffffffff8111156135f057600080fd5b8201601f8101841361360157600080fd5b61143184825160208401613597565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b60006020828403121561367457600080fd5b813567ffffffffffffffff81111561368b57600080fd5b61143184828501612ee0565b600082198211156136aa576136aa6134a8565b500190565b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906136e290830184612fd3565b9695505050505050565b6000602082840312156136fe57600080fd5b8151611de981612ddb565b60006020828403121561371b57600080fd5b8151611de98161302b565b600082821015613738576137386134a8565b500390565b634e487b7160e01b600052603160045260246000fdfea264697066735822122091041d93de47daae3f89eb8dcb9f55658346895568ca5a439a4deb5297ca8a4164736f6c634300080d0033
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A token is a representation of an on-chain or off-chain asset. The token page shows information such as price, total supply, holders, transfers and social links. Learn more about this page in our Knowledge Base.