Overview
ETH Balance
0 ETH
ETH Value
$0.00More Info
Private Name Tags
ContractCreator
Latest 1 from a total of 1 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Initialize | 1301081 | 17 days ago | IN | 0 ETH | 0.00000351 |
Latest 1 internal transaction
Parent Transaction Hash | Block | From | To | |||
---|---|---|---|---|---|---|
1300785 | 17 days ago | Contract Creation | 0 ETH |
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Source Code Verified (Exact Match)
Contract Name:
GigaNameNFTBeforeUpdateHandler
Compiler Version
v0.8.28+commit.7893614a
ZkSolc Version
v1.5.7
Optimization Enabled:
Yes with Mode 3
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.9; import {IERC721UpdateHandler} from "../IERC721UpdateHandler.sol"; import {GameRegistryConsumer} from "../../core/GameRegistryConsumer.sol"; import {IAccountSystem, ID as ACCOUNT_SYSTEM_ID} from "../../accountsystem/IAccountSystem.sol"; import {IGigaNameNFT, ID as GIGA_NAME_NFT_ID} from "./GigaNameNFT.sol"; uint256 constant ID = uint256(keccak256("game.gigaverse.updateHandler.giganamenft")); contract GigaNameNFTBeforeUpdateHandler is IERC721UpdateHandler, GameRegistryConsumer { constructor(address gameRegistryAddress) GameRegistryConsumer(gameRegistryAddress, ID) {} /** * Before transfer hook for NFTs. Performs any trait checks needed before transfer */ function update( address /*from*/, address to, uint256 tokenId ) external override { address registeredSystem = _gameRegistry.getSystem(GIGA_NAME_NFT_ID); require(registeredSystem != address(0), "GigaNameNFT not registered"); require(registeredSystem == msg.sender, "Incorrect token contract"); IAccountSystem accountSystem = IAccountSystem(_gameRegistry.getSystem(ACCOUNT_SYSTEM_ID)); IGigaNameNFT gigaNameNFT = IGigaNameNFT(registeredSystem); if (gigaNameNFT.exists(tokenId)) { address prevOwner = gigaNameNFT.ownerOf(tokenId); if (prevOwner != address(0) && accountSystem.getPlayerUsernameId(prevOwner) == tokenId) { accountSystem.removeUsername(prevOwner); } } if (to != address(0) && accountSystem.getPlayerUsernameId(to) == 0 ) { accountSystem.setUsername(to, tokenId); } } }
// SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.9; interface IERC721UpdateHandler { /** * Before transfer hook for NFTs. Performs any trait checks needed before transfer * */ function update( address from, address to, uint256 tokenId ) external; }
// SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.13; import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import {PAUSER_ROLE, MANAGER_ROLE} from "../constants/RoleConstants.sol"; import {ISystem} from "./ISystem.sol"; import {IGameRegistry, IERC165} from "./IGameRegistry.sol"; import {IDataStore, ID as DATA_STORE_ID} from "../db/IDataStore.sol"; import {DEPLOYER_ROLE} from "../constants/RoleConstants.sol"; /** @title Contract that lets a child contract access the GameRegistry contract */ abstract contract GameRegistryConsumer is ReentrancyGuard, ISystem { /// @notice Whether or not the contract is paused bool private _paused; /// @notice Reference to the game registry that this contract belongs to IGameRegistry internal _gameRegistry; /// @notice Id for the system/component uint256 private _id; /** 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 **/ /// @notice Modifier to verify a user has the appropriate role to call a given function modifier onlyRole(bytes32 role) { _checkRole(role, msg.sender); _; } /** * @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 Error if the game registry specified is invalid error InvalidGameRegistry(); /** SETUP **/ /** @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 onlyRole(PAUSER_ROLE) { 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 onlyRole(MANAGER_ROLE) { _gameRegistry = IGameRegistry(gameRegistryAddress); if (gameRegistryAddress == address(0)) { revert InvalidGameRegistry(); } } /** @return GameRegistry contract for this contract */ function getGameRegistry() external view returns (IGameRegistry) { return _gameRegistry; } /** INTERNAL **/ /** * @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) internal view virtual { if (!_gameRegistry.hasAccessRole(role, account)) { revert MissingRole(account, role); } } /** @return Returns the dataStore for this contract */ function _dataStore() internal view returns (IDataStore) { return IDataStore(_getSystem(DATA_STORE_ID)); } /** @return Address for a given system */ function _getSystem(uint256 systemId) internal view returns (address) { return _gameRegistry.getSystem(systemId); } /** 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(msg.sender); } /** * @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(msg.sender); } function initialize() external virtual onlyRole(DEPLOYER_ROLE) { } /** * Constructor for this contract * * @param gameRegistryAddress Address of the GameRegistry contract * @param id Id of the system/component */ constructor( address gameRegistryAddress, uint256 id ) { _gameRegistry = IGameRegistry(gameRegistryAddress); if (gameRegistryAddress == address(0)) { revert InvalidGameRegistry(); } _paused = true; _id = id; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; uint256 constant ID = uint256(keccak256("game.gigaverse.system.account")); interface IAccountSystem is IERC165 { function setPrice(uint256 _price, uint256 _redeemableTokenId) external; function mintWithEth(string memory _username, bytes memory signature) external payable; function mintWithGameItem(string memory _username, bytes memory signature) external; function getPlayerUsernameId(address player) external view returns (uint256); function getPlayerNoobId(address player) external view returns (uint256); function mintPrice() external view returns (uint256); function setUsername(address to, uint256 tokenId) external; function setPlayerNoob(address to, uint256 tokenId) external; function removeUsername(address player) external; function changeUsername(uint256 tokenId) external; function setMintPrice(uint256 newPrice) external; function withdraw() external; }
// SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.9; import "@openzeppelin/contracts/utils/Strings.sol"; import {GameNFT} from "../gamenft/GameNFT.sol"; import {NAME_CID, ETH_MINT_PRICE_CID, IS_GIGA_NAME_CID, ID_CID, INITIALIZED_CID, ADDRESS_CID} from "../../constants/ColumnConstants.sol"; import {MINTER_ROLE, GAME_LOGIC_CONTRACT_ROLE, MANAGER_ROLE} from "../../constants/RoleConstants.sol"; import { IGigaNameNFT, ID } from "./IGigaNameNFT.sol"; import {DEPLOYER_ROLE} from "../../constants/RoleConstants.sol"; import "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol"; /** @title GigaName NFTs on L2 */ contract GigaNameNFT is GameNFT, IGigaNameNFT { using Strings for uint256; // 0 max supply = infinite uint256 constant MAX_SUPPLY = 0; /** SETUP */ constructor(address gameRegistryAddress, address royaltyRecipient, uint96 feeNumerator) GameNFT(MAX_SUPPLY, "NAME", "NAME", "Name #", gameRegistryAddress, ID, royaltyRecipient, feeNumerator) {} function initialize() external override onlyRole(DEPLOYER_ROLE) { initializeTable("GigaNameNFT", ID); _initialize(); } function validateUsername(string memory username) public pure returns (bool) { bytes memory usernameBytes = bytes(username); // Check length if (usernameBytes.length < 4 || usernameBytes.length > 15) { return false; } // Check first character is not underscore if (usernameBytes[0] == '_') { return false; } // Check each character for (uint i = 0; i < usernameBytes.length; i++) { bytes1 char = usernameBytes[i]; if (!( (char >= 'a' && char <= 'z') || (char >= '0' && char <= '9') || char == '_' )) { return false; } } return true; } function mintByManager(address to, string memory username) external onlyRole(MANAGER_ROLE) { _confirmMint(to, username); } function mintUsernameByMinterContract(address to, string memory username, bytes memory signature) external onlyRole(MINTER_ROLE) returns (uint256) { return _confirmMintWithSignature(to, username, signature); } function mintUsername(address to, string memory username, bytes memory signature) external payable { uint256 price = getMintPrice(); require(price > 0, "Mint price not set"); require(msg.value >= price, "Insufficient payment"); _confirmMintWithSignature(to, username, signature); uint256 excess = msg.value - price; if (excess > 0) { (bool success, ) = payable(msg.sender).call{value: excess}(""); require(success, "Failed to return excess ETH"); } } function setMintPrice(uint256 price) external onlyRole(MANAGER_ROLE) { _setTableUint256Value(ETH_MINT_PRICE_CID, price); } function getMintPrice() public view returns (uint256) { return getTableUint256Value(ETH_MINT_PRICE_CID); } /** * Burn a token - any payment / game logic should be handled in the game contract. * * @param id Id of the token to burn */ function burnByGameContract( uint256 id ) external onlyRole(GAME_LOGIC_CONTRACT_ROLE) whenNotPaused { _burn(id); } /** Initializes traits for the given tokenId */ function _initializeTraits(uint256 tokenId, string memory username) internal { require(validateUsername(username), "Invalid username"); require(tokenId == uint256(keccak256(abi.encodePacked(username))), "Token ID does not match name"); _setDocBoolValue(tokenId, IS_GIGA_NAME_CID, true); validateUsername(username); _setDocStringValue(tokenId, NAME_CID, username); } function _confirmMintWithSignature(address to, string memory username, bytes memory signature) internal returns (uint256) { bytes32 messageHash = keccak256(abi.encodePacked(username, to)); require(verifySignature(messageHash, signature), "Invalid signature"); return _confirmMint(to, username); } function _confirmMint(address to, string memory username) internal returns (uint256) { uint256 tokenId = uint256(keccak256(abi.encodePacked(username))); _initializeTraits(tokenId, username); _safeMint(to, tokenId); return tokenId; } function _cleanupAfterBurn(uint256 tokenId) override internal { super._cleanupAfterBurn(tokenId); _setDocBoolValue(tokenId, IS_GIGA_NAME_CID, false); _setDocStringValue(tokenId, NAME_CID, ""); } function setSignerAddress(address newSigner) external onlyRole(MANAGER_ROLE) { _setDocAddressValue(_getSignerDocId(), ADDRESS_CID, newSigner); } function _getSignerDocId() private pure returns (uint256) { return uint256(keccak256("signer")); } function getSignerAddress() public view returns (address) { return getDocAddressValue(_getSignerDocId(), ADDRESS_CID); } // Add new helper function for signature verification function verifySignature(bytes32 messageHash, bytes memory signature) public view returns (bool) { bytes32 ethSignedMessageHash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", messageHash)); address signer = getSignerAddress(); require(signer != address(0), "Signer not set"); return SignatureChecker.isValidSignatureNow( signer, ethSignedMessageHash, signature ); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor() { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { _nonReentrantBefore(); _; _nonReentrantAfter(); } function _nonReentrantBefore() private { // On the first call to nonReentrant, _status will be _NOT_ENTERED require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; } function _nonReentrantAfter() private { // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } }
// SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.9; // 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"); // Depoloyer Role - Can Deploy new Systems bytes32 constant DEPLOYER_ROLE = keccak256("DEPLOYER_ROLE"); // Game Logic Contract - Contract that executes game logic and accesses other systems bytes32 constant GAME_LOGIC_CONTRACT_ROLE = keccak256("GAME_LOGIC_CONTRACT_ROLE"); // For functions callable from game server bytes32 constant SERVER_JUDGE_ROLE = keccak256("SERVER_JUDGE_ROLE");
// 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); function initialize() external; }
// 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`. * @param role The role to query * @param account The address to query */ 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, bool isGameLogicContract) external; /** * @param systemId Id of the system * @return System based on an id */ function getSystem(uint256 systemId) external view returns (address); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; uint256 constant ID = uint256(keccak256("game.gigaverse.datastore")); interface IDataStore { enum ColumnType { NONE, UINT256, INT256, BOOL, ADDRESS, BYTES32, STRING, UINT256_ARRAY } event ValueSet(uint256 indexed tableId, uint256 indexed docId, uint256 indexed colId, bytes32 value); event StringValueSet(uint256 indexed tableId, uint256 indexed docId, uint256 indexed colId, string value); event ArrayValueSet(uint256 indexed tableId, uint256 indexed docId, uint256 indexed colId, bytes32[] value); event ColumnTypeSet(uint256 indexed colId, ColumnType columnType); function setValue(uint256 tableId, uint256 docId, uint256 colId, bytes32 value) external; function getValue(uint256 tableId, uint256 docId, uint256 colId) external view returns (bytes32); function setColumnType(uint256 colId, ColumnType columnType) external; function getColumnType(uint256 colId) external view returns (ColumnType); // Type-specific setters function setUint256(uint256 tableId, uint256 docId, uint256 colId, uint256 value) external; function setInt256(uint256 tableId, uint256 docId, uint256 colId, int256 value) external; function setBool(uint256 tableId, uint256 docId, uint256 colId, bool value) external; function setAddress(uint256 tableId, uint256 docId, uint256 colId, address value) external; function setBytes32(uint256 tableId, uint256 docId, uint256 colId, bytes32 value) external; function setString(uint256 tableId, uint256 docId, uint256 colId, string memory value) external; // Type-specific getters function getUint256(uint256 tableId, uint256 docId, uint256 colId) external view returns (uint256); function getInt256(uint256 tableId, uint256 docId, uint256 colId) external view returns (int256); function getBool(uint256 tableId, uint256 docId, uint256 colId) external view returns (bool); function getAddress(uint256 tableId, uint256 docId, uint256 colId) external view returns (address); function getBytes32(uint256 tableId, uint256 docId, uint256 colId) external view returns (bytes32); function getString(uint256 tableId, uint256 docId, uint256 colId) external view returns (string memory); function deleteValue(uint256 tableId, uint256 docId, uint256 colId) external; function hasValue(uint256 tableId, uint256 docId, uint256 colId) external view returns (bool); }
// 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/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; import "@openzeppelin/contracts/utils/math/SafeCast.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; import {IGameNFT} from "./IGameNFT.sol"; import {MANAGER_ROLE, DEPLOYER_ROLE} from "../../constants/RoleConstants.sol"; import {BALANCE_CID, UNLOCKED_CID, CONTRACT_URI_CID, NAME_CID, MINT_COUNT_CID, BURN_COUNT_CID,ADDRESS_CID, MAX_SUPPLY_CID, IS_SOULBOUND_CID, INITIALIZED_CID, OWNER_CID, BASE_NAME_CID, BASE_URI_CID, LAST_TRANSFER_TIME_CID, OWNER_CID} from "../../constants/ColumnConstants.sol"; import {DataTable} from "../../db/DataTable.sol"; import {IERC721UpdateHandler} from "../IERC721UpdateHandler.sol"; import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol"; import {ERC721C} from "@creator-token-standards/erc721c/ERC721C.sol"; import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import {BasicRoyalties} from "@creator-token-standards/programmable-royalties/BasicRoyalties.sol"; import {ERC721OpenZeppelin} from "@creator-token-standards/token/erc721/ERC721OpenZeppelin.sol"; import {OwnableBasic} from "@creator-token-standards/access/OwnableBasic.sol"; import {ERC721OpenZeppelinBase, ERC721OpenZeppelin} from "@creator-token-standards/token/erc721/ERC721OpenZeppelin.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import {ERC2981} from "@openzeppelin/contracts/token/common/ERC2981.sol"; /** @title NFT base contract for all game NFTs. Exposes traits for the NFT and respects GameRegistry/Soulbound access control */ abstract contract GameNFT is ERC721C, DataTable, IGameNFT, BasicRoyalties, OwnableBasic { using Strings for uint256; address public beforeUpdateHandler; address public afterUpdateHandler; /** ERRORS **/ /// @notice Account must be non-null error InvalidAccountAddress(); /// @notice Token id is not valid error InvalidTokenId(); /// @notice Exceeds max supply error ExceedsMaxSupply(); /// @notice Trading is locked error TradingLocked(); /** EVENTS **/ /// @notice Emitted when time held time is updated event TimeHeldSet(uint256 tokenId, address account, uint32 timeHeld); /// @notice Emitted when last transfer time is updated event LastTransferSet(uint256 tokenId, uint32 lastTransferTime); /// @notice Emitted when contractURI has changed event ContractURIUpdated(string uri); uint256 private _tokenMaxSupply; string private _baseTokenName; /** SETUP **/ constructor(uint256 tokenMaxSupply, string memory nameToSet, string memory symbol, string memory baseTokenName, address gameRegistryAddress, uint256 id, address royaltyRecipient, uint96 feeNumerator) DataTable(gameRegistryAddress, id) ERC721OpenZeppelin(nameToSet, symbol) BasicRoyalties(royaltyRecipient, feeNumerator) { _tokenMaxSupply = tokenMaxSupply; _baseTokenName = baseTokenName; } function _initialize() internal { _setTableUint256Value(MAX_SUPPLY_CID, _tokenMaxSupply); _setTableStringValue(BASE_NAME_CID, _baseTokenName); } /** * @param tokenId token id to check * @return Whether or not the given tokenId has been minted */ function exists(uint256 tokenId) public view returns (bool) { return _ownerOf(tokenId) != address(0); } function owner() public view override(DataTable, Ownable) returns (address) { return super.owner(); } function name() public view override(DataTable, ERC721OpenZeppelinBase) returns (string memory) { return DataTable.name(); } function setBaseURI(string memory uri) external onlyRole(MANAGER_ROLE) { _setTableStringValue(BASE_URI_CID, uri); } function withdraw(uint256 amount) external nonReentrant onlyRole(MANAGER_ROLE) { (bool success, ) = payable(msg.sender).call{value: amount}(""); require(success, "Transfer failed"); } /** * @param tokenId token id to check * @return Whether or not the given tokenId has had its traits initialized */ /** * @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 super.tokenURI(tokenId); } function _baseURI() internal override view returns (string memory) { return getTableStringValue(BASE_URI_CID); } /** * @dev a method that bulk sets initialized imported NFTs * @param tokenIds List of TokenIds to be initialized */ function setTraitsInitialized( uint256[] calldata tokenIds ) external onlyRole(MANAGER_ROLE) { for (uint256 i = 0; i < tokenIds.length; i++) { _setDocBoolValue(tokenIds[i], INITIALIZED_CID, true); } } function getAccountKey(address account) internal pure returns (uint256) { return uint256(keccak256(abi.encode(account))); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address walletAddress) public view override(IERC721, ERC721) returns (uint256) { return getDocUint256Value(getAccountKey(walletAddress), BALANCE_CID); } function setDefaultRoyalty(address receiver, uint96 feeNumerator) external onlyRole(MANAGER_ROLE) { _setDefaultRoyalty(receiver, feeNumerator); } function setTokenRoyalty(uint256 tokenId, address receiver, uint96 feeNumerator) external onlyRole(MANAGER_ROLE) { _setTokenRoyalty(tokenId, receiver, feeNumerator); } function deleteDefaultRoyalty() external onlyRole(MANAGER_ROLE) { _deleteDefaultRoyalty(); } /** * @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist * * IMPORTANT: Any overrides to this function that add ownership of tokens not tracked by the * core ERC721 logic MUST be matched with the use of {_increaseBalance} to keep balances * consistent with ownership. The invariant to preserve is that for any address `a` the value returned by * `balanceOf(a)` must be equal to the number of tokens such that `_ownerOf(tokenId)` is `a`. */ function _ownerOf(uint256 tokenId) internal view override returns (address) { return getDocAddressValue(tokenId, OWNER_CID); } /** * @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 override returns (uint32) { address ownerOfToken = ownerOf(tokenId); if (account == address(0)) { revert InvalidAccountAddress(); } if (ownerOfToken == account) { uint32 lastTransferTime = uint32(getDocUint256Value(tokenId, LAST_TRANSFER_TIME_CID)); uint32 currentTime = SafeCast.toUint32(block.timestamp); return currentTime - lastTransferTime; } return 0; } /** @return Token name for the given tokenId */ function tokenName( uint256 tokenId ) public view virtual returns (string memory) { if (hasDocStringValue(tokenId, NAME_CID)) { // If token has a name trait set, use that return getDocStringValue(tokenId, NAME_CID); } else { return string(abi.encodePacked(getTableStringValue(BASE_NAME_CID), tokenId.toString())); } } /** * @inheritdoc IERC165 */ function supportsInterface( bytes4 interfaceId ) public view virtual override( ERC721C, IERC165, ERC2981 ) returns (bool) { return interfaceId == type(IGameNFT).interfaceId || ERC721C.supportsInterface(interfaceId) || ERC2981.supportsInterface(interfaceId); } /** * Sets the before token transfer handler * * @param handlerAddress Address to the transfer hook handler contract */ function setUpdateHandler( address handlerAddress, bool before ) external onlyRole(MANAGER_ROLE) { if (before) { beforeUpdateHandler = handlerAddress; } else { afterUpdateHandler = handlerAddress; } } /** INTERNAL **/ /** Initializes traits for the given tokenId */ function _initializeTraits(uint256 tokenId) internal virtual { _setDocBoolValue(tokenId, INITIALIZED_CID, true); } function maxSupply() public view returns (uint256) { return getTableUint256Value(MAX_SUPPLY_CID); } /** * Sets the current contractURI for the contract * * @param _uri New contract URI */ function setContractURI(string calldata _uri) public onlyRole(MANAGER_ROLE) { _setTableStringValue(CONTRACT_URI_CID, _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 getTableStringValue(CONTRACT_URI_CID); } /** * 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, bytes memory data) internal override { uint256 _maxSupply = maxSupply(); if (_maxSupply != 0 && getTotalSupply() >= _maxSupply) { revert ExceedsMaxSupply(); } if (tokenId == 0) { revert InvalidTokenId(); } super._safeMint(to, tokenId, data); // Conditionally initialize traits if (getDocBoolValue(tokenId, INITIALIZED_CID) == false) { _initializeTraits(tokenId); } } /** * @notice Checks for soulbound status before transfer * @inheritdoc ERC721C */ function _beforeTokenTransfer( address from, address to, uint256 firstTokenId, uint256 batchSize ) internal virtual override( ERC721C ) { if (from != address(0) && to != address(0)) { if (isTradingLocked()) { revert TradingLocked(); } } for (uint256 i = 0; i < batchSize; i++) { uint256 tokenId = firstTokenId + i; if (beforeUpdateHandler != address(0)) { IERC721UpdateHandler( beforeUpdateHandler ).update( from, to, firstTokenId ); } _setDocUint256Value(tokenId, LAST_TRANSFER_TIME_CID, SafeCast.toUint32(block.timestamp)); require(!getTableBoolValue(IS_SOULBOUND_CID) || from == address(0) || to == address(0), "GameNFT: Token is soulbound"); super._beforeTokenTransfer(from, to, tokenId, batchSize); } } function _afterTokenTransfer( address from, address to, uint256 firstTokenId, uint256 batchSize ) internal override(ERC721C) { for (uint256 i = 0; i < batchSize; i++) { uint256 tokenId = firstTokenId + i; if (afterUpdateHandler != address(0)) { IERC721UpdateHandler( afterUpdateHandler ).update( from, to, tokenId ); } if (from != address(0)) { _decrementAmount(getAccountKey(from), BALANCE_CID, 1); } else { _incrementAmount(0, MINT_COUNT_CID, 1); } _setDocAddressValue(tokenId, OWNER_CID, to); if (to == address(0)) { _incrementAmount(0, BURN_COUNT_CID, 1); _cleanupAfterBurn(tokenId); } else { _incrementAmount(getAccountKey(to), BALANCE_CID, 1); } super._afterTokenTransfer(from, to, tokenId, batchSize); } } function getLastTransfer( uint256 tokenId ) external view returns (uint32) { return uint32(getDocUint256Value(tokenId, LAST_TRANSFER_TIME_CID)); } function mintBatch(address /*to*/, uint256 /*amount*/) pure external returns (uint256[] memory) { return new uint256[](0); } function setSoulbound(bool soulbound) external onlyRole(MANAGER_ROLE) { _setTableBoolValue(IS_SOULBOUND_CID, soulbound); } function isSoulbound() public view returns (bool) { return getTableBoolValue(IS_SOULBOUND_CID); } function _cleanupAfterBurn(uint256 tokenId) virtual internal { _setDocBoolValue(tokenId, INITIALIZED_CID, false); } function getTotalMinted() public view returns (uint256) { return getTableUint256Value(MINT_COUNT_CID); } function getTotalBurned() public view returns (uint256) { return getTableUint256Value(BURN_COUNT_CID); } function getTotalSupply() public view returns (uint256) { return getTotalMinted() - getTotalBurned(); } function burn(uint256 tokenId) external { require(ownerOf(tokenId) == msg.sender, "You are not the owner of this token"); _burn(tokenId); } function isTradingLocked() public view returns (bool) { return !getTableBoolValue(UNLOCKED_CID); } function setTradingLocked(bool locked) external onlyRole(MANAGER_ROLE) { _setTableBoolValue(UNLOCKED_CID, !locked); } }
// SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.9; uint256 constant NAME_CID = uint256(keccak256("name")); uint256 constant DESCRIPTION_CID = uint256(keccak256("description")); uint256 constant LEVEL_CID = uint256(keccak256("level")); uint256 constant IS_NOOB_CID = uint256(keccak256("is_noob")); uint256 constant NOOB_TOKEN_CID = uint256(keccak256("noob_tokend_id")); uint256 constant GIGA_NAME_TOKENDID_CID = uint256(keccak256("giganame_tokend_id")); uint256 constant IS_GIGA_NAME_CID = uint256(keccak256("is_giga_name")); uint256 constant GAME_ITEM_ID_CID = uint256(keccak256("game_item_id")); uint256 constant UINT256_CID = uint256(keccak256("int256")); uint256 constant ETH_MINT_PRICE_CID = uint256(keccak256("eth_mint_price")); uint256 constant NEXT_DOCID_CID = uint256(keccak256("next_token_id")); uint256 constant ID_CID = uint256(keccak256("id")); uint256 constant BASE_NAME_CID = uint256(keccak256("base_name")); uint256 constant BASE_URI_CID = uint256(keccak256("base_uri")); uint256 constant LAST_TRANSFER_TIME_CID = uint256(keccak256("last_transfer_time")); uint256 constant OWNER_CID = uint256(keccak256("owner")); uint256 constant INITIALIZED_CID = uint256(keccak256("initialized")); uint256 constant MAX_SUPPLY_CID = uint256(keccak256("max_supply")); uint256 constant ADDRESS_CID = uint256(keccak256("address")); uint256 constant IS_SOULBOUND_CID = uint256(keccak256("soulbound")); uint256 constant TIME_BETWEEN_CID = uint256(keccak256("time_between")); uint256 constant TIMESTAMP_CID = uint256(keccak256("timestamp")); uint256 constant IMG_URL_CID = uint256(keccak256("img_url")); uint256 constant PLAYER_CID = uint256(keccak256("player")); uint256 constant MINT_COUNT_CID = uint256(keccak256("mint_count")); uint256 constant CONTRACT_URI_CID = uint256(keccak256("contract_uri")); uint256 constant IS_RECYCLABLE_CID = uint256(keccak256("is_recyclable")); uint256 constant BURN_COUNT_CID = uint256(keccak256("burn_count")); uint256 constant BALANCE_CID = uint256(keccak256("balance")); uint256 constant ICON_URL_CID = uint256(keccak256("icon_url")); uint256 constant DUNGEON_ID_CID = uint256(keccak256("dungeon_id")); uint256 constant ENERGY_CID = uint256(keccak256("energy")); uint256 constant IS_CANCELLED_CID = uint256(keccak256("is_cancelled")); uint256 constant SPRITE_SHEET_URL_CID = uint256(keccak256("sprite_sheet_url")); uint256 constant IMPORT_AMOUNT_CID = uint256(keccak256("import_amount")); uint256 constant EXPORT_AMOUNT_CID = uint256(keccak256("export_amount")); uint256 constant EXPORT_LICENSE_CID = uint256(keccak256("export_license")); uint256 constant UNLOCKED_CID = uint256(keccak256("unlocked"));
// SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.9; import {IGameNFT} from "../gamenft/IGameNFT.sol"; uint256 constant ID = uint256(keccak256("game.gigaverse.giganamenft")); interface IGigaNameNFT is IGameNFT { function mintUsernameByMinterContract(address to, string memory username, bytes memory signature) external returns (uint256); function burnByGameContract(uint256 id) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/SignatureChecker.sol) pragma solidity ^0.8.0; import "./ECDSA.sol"; import "../Address.sol"; import "../../interfaces/IERC1271.sol"; /** * @dev Signature verification helper that can be used instead of `ECDSA.recover` to seamlessly support both ECDSA * signatures from externally owned accounts (EOAs) as well as ERC1271 signatures from smart contract wallets like * Argent and Gnosis Safe. * * _Available since v4.1._ */ library SignatureChecker { /** * @dev Checks if a signature is valid for a given signer and data hash. If the signer is a smart contract, the * signature is validated against that smart contract using ERC1271, otherwise it's validated using `ECDSA.recover`. * * NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus * change through time. It could return true at block N and false at block N+1 (or the opposite). */ function isValidSignatureNow( address signer, bytes32 hash, bytes memory signature ) internal view returns (bool) { (address recovered, ECDSA.RecoverError error) = ECDSA.tryRecover(hash, signature); if (error == ECDSA.RecoverError.NoError && recovered == signer) { return true; } (bool success, bytes memory result) = signer.staticcall( abi.encodeWithSelector(IERC1271.isValidSignature.selector, hash, signature) ); return (success && result.length == 32 && abi.decode(result, (bytes32)) == bytes32(IERC1271.isValidSignature.selector)); } }
// 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 LICENSE pragma solidity ^0.8.13; import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol"; /** * @title Interface for game NFTs that have stats and other properties */ interface IGameNFT is IERC721 { /** * @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); function getLastTransfer( uint256 tokenId ) external view returns (uint32); /** * Mints a batch of ERC721 token * * @param to Recipient of the token * @param amount Quantity of token to mint */ function mintBatch(address to, uint256 amount) external returns (uint256[] memory); function exists(uint256 tokenId) external view returns (bool); function isTradingLocked() external view returns (bool); }
// SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.9; import {DataStore, ID as DATA_STORE_ID} from "./DataStore.sol"; import {DEPLOYER_ROLE} from "../constants/RoleConstants.sol"; import {NAME_CID, ADDRESS_CID, ID_CID, NEXT_DOCID_CID, OWNER_CID} from "../constants/ColumnConstants.sol"; import {GameRegistryConsumer} from "../core/GameRegistryConsumer.sol"; contract DataTable is GameRegistryConsumer { error AlreadyInitialized(); bool private _initialized; constructor(address gameRegistryAddress, uint256 ID) GameRegistryConsumer(gameRegistryAddress, ID) {} function owner() public view virtual returns (address) { return getTableAddressValue(OWNER_CID); } function name() public view virtual returns (string memory) { return getTableStringValue(NAME_CID); } function initializeTable(string memory nameToSet, uint256 id) internal { if (_initialized) { revert AlreadyInitialized(); } _setTableAddressValue(ADDRESS_CID, address(this)); _setTableAddressValue(OWNER_CID, msg.sender); _setTableStringValue(NAME_CID, nameToSet); _setTableUint256Value(ID_CID, id); _initialized = true; } function getTableId() public virtual view returns (uint256) { return getId(); } function _getAndIncrementAutoIncId() internal returns (uint256) { uint256 currentId = getTableUint256Value(NEXT_DOCID_CID); _setTableUint256Value(NEXT_DOCID_CID, currentId + 1); return currentId + 1; } function _incrementAmount(uint256 docId, uint256 columnId, uint256 amount) internal { uint256 currentAmount = getDocUint256Value(docId, columnId); _setDocUint256Value(docId, columnId, currentAmount + amount); } function _decrementAmount(uint256 docId, uint256 columnId, uint256 amount) internal { uint256 currentAmount = getDocUint256Value(docId, columnId); _setDocUint256Value(docId, columnId, currentAmount - amount); } function _setTableStringValue(uint256 columnId, string memory value) internal { DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).setString(getTableId(), 0, columnId, value); } function _setTableUint256Value(uint256 columnId, uint256 value) internal { DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).setUint256(getTableId(), 0, columnId, value); } function _setTableAddressValue(uint256 columnId, address value) internal { DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).setAddress(getTableId(), 0, columnId, value); } function _setTableBoolValue(uint256 columnId, bool value) internal { DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).setBool(getTableId(), 0, columnId, value); } function _setTableAdddressValue(uint256 columnId, address value) internal { DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).setAddress(getTableId(), 0, columnId, value); } function _setTableUint256ArrayValue(uint256 columnId, uint256[] memory value) internal { DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).setUint256ArrayValue(getTableId(), 0, columnId, value); } function _setTableBoolArrayValue(uint256 columnId, bool[] memory value) internal { DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).setBoolArrayValue(getTableId(), 0, columnId, value); } function _setTableAddressArrayValue(uint256 columnId, address[] memory value) internal { DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).setAddressArrayValue(getTableId(), 0, columnId, value); } function _setDocAddressArrayValue(uint256 docId, uint256 columnId, address[] memory value) internal { DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).setAddressArrayValue(getTableId(), docId, columnId, value); } function _setDocBoolArrayValue(uint256 docId, uint256 columnId, bool[] memory value) internal { DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).setBoolArrayValue(getTableId(), docId, columnId, value); } function _setDocStringValue(uint256 docId, uint256 columnId, string memory value) internal { DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).setString(getTableId(), docId, columnId, value); } function _setDocUint256Value(uint256 docId, uint256 columnId, uint256 value) internal { DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).setUint256(getTableId(), docId, columnId, value); } function _setDocUint256ArrayValue(uint256 docId, uint256 columnId, uint256[] memory value) internal { DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).setUint256ArrayValue(getTableId(), docId, columnId, value); } function _setDocBoolValue(uint256 docId, uint256 columnId, bool value) internal { DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).setBool(getTableId(), docId, columnId, value); } function _setDocAddressValue(uint256 docId, uint256 columnId, address value) internal { DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).setAddress(getTableId(), docId, columnId, value); } function getTableBoolValue(uint256 columnId) public view returns (bool) { return DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).getBool(getTableId(), 0, columnId); } function getTableUint256Value(uint256 columnId) public view returns (uint256) { return DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).getUint256(getTableId(), 0, columnId); } function getTableStringValue(uint256 columnId) public view returns (string memory) { return DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).getString(getTableId(), 0, columnId); } function getTableAddressValue(uint256 columnId) public view returns (address) { return DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).getAddress(getTableId(), 0, columnId); } function getTableUint256ArrayValue(uint256 columnId) public view returns (uint256[] memory) { return DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).getUint256Array(getTableId(), 0, columnId); } function getDocUint256ArrayValue(uint256 docId, uint256 columnId) public view returns (uint256[] memory) { return DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).getUint256Array(getTableId(), docId, columnId); } function getDocStringValue(uint256 docId, uint256 columnId) public view returns (string memory) { return DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).getString(getTableId(), docId, columnId); } function getDocUint256Value(uint256 docId, uint256 columnId) public view returns (uint256) { return DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).getUint256(getTableId(), docId, columnId); } function getDocBoolValue(uint256 docId, uint256 columnId) public view returns (bool) { return DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).getBool(getTableId(), docId, columnId); } function getDocAddressValue(uint256 docId, uint256 columnId) public view returns (address) { return DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).getAddress(getTableId(), docId, columnId); } function hasDocStringValue(uint256 docId, uint256 columnId) public view returns (bool) { return DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).hasStringValue(getTableId(), docId, columnId); } function hasDocValue(uint256 docId, uint256 columnId) public view returns (bool) { return DataStore(_gameRegistry.getSystem(DATA_STORE_ID)).hasValue(getTableId(), docId, columnId); } function getPlayerDocId(address player) public pure returns (uint256) { return uint256(uint160(player)); } }
// 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 pragma solidity ^0.8.4; import "../utils/AutomaticValidatorTransferApproval.sol"; import "../utils/CreatorTokenBase.sol"; import "../token/erc721/ERC721OpenZeppelin.sol"; import "../interfaces/ITransferValidatorSetTokenType.sol"; import {TOKEN_TYPE_ERC721} from "@limitbreak/permit-c/Constants.sol"; /** * @title ERC721C * @author Limit Break, Inc. * @notice Extends OpenZeppelin's ERC721 implementation with Creator Token functionality, which * allows the contract owner to update the transfer validation logic by managing a security policy in * an external transfer validation security policy registry. See {CreatorTokenTransferValidator}. */ abstract contract ERC721C is ERC721OpenZeppelin, CreatorTokenBase, AutomaticValidatorTransferApproval { /** * @notice Overrides behavior of isApprovedFor all such that if an operator is not explicitly approved * for all, the contract owner can optionally auto-approve the 721-C transfer validator for transfers. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool isApproved) { isApproved = super.isApprovedForAll(owner, operator); if (!isApproved) { if (autoApproveTransfersFromValidator) { isApproved = operator == address(getTransferValidator()); } } } /** * @notice Indicates whether the contract implements the specified interface. * @dev Overrides supportsInterface in ERC165. * @param interfaceId The interface id * @return true if the contract implements the specified interface, false otherwise */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(ICreatorToken).interfaceId || interfaceId == type(ICreatorTokenLegacy).interfaceId || super.supportsInterface(interfaceId); } /** * @notice Returns the function selector for the transfer validator's validation function to be called * @notice for transaction simulation. */ function getTransferValidationFunction() external pure returns (bytes4 functionSignature, bool isViewFunction) { functionSignature = bytes4(keccak256("validateTransfer(address,address,address,uint256)")); isViewFunction = true; } /// @dev Ties the open-zeppelin _beforeTokenTransfer hook to more granular transfer validation logic function _beforeTokenTransfer( address from, address to, uint256 firstTokenId, uint256 batchSize) internal virtual override { for (uint256 i = 0; i < batchSize;) { _validateBeforeTransfer(from, to, firstTokenId + i); unchecked { ++i; } } } /// @dev Ties the open-zeppelin _afterTokenTransfer hook to more granular transfer validation logic function _afterTokenTransfer( address from, address to, uint256 firstTokenId, uint256 batchSize) internal virtual override { for (uint256 i = 0; i < batchSize;) { _validateAfterTransfer(from, to, firstTokenId + i); unchecked { ++i; } } } function _tokenType() internal pure override returns(uint16) { return uint16(TOKEN_TYPE_ERC721); } } /** * @title ERC721CInitializable * @author Limit Break, Inc. * @notice Initializable implementation of ERC721C to allow for EIP-1167 proxy clones. */ abstract contract ERC721CInitializable is ERC721OpenZeppelinInitializable, CreatorTokenBase, AutomaticValidatorTransferApproval { function initializeERC721(string memory name_, string memory symbol_) public override { super.initializeERC721(name_, symbol_); _emitDefaultTransferValidator(); _registerTokenType(getTransferValidator()); } /** * @notice Overrides behavior of isApprovedFor all such that if an operator is not explicitly approved * for all, the contract owner can optionally auto-approve the 721-C transfer validator for transfers. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool isApproved) { isApproved = super.isApprovedForAll(owner, operator); if (!isApproved) { if (autoApproveTransfersFromValidator) { isApproved = operator == address(getTransferValidator()); } } } /** * @notice Indicates whether the contract implements the specified interface. * @dev Overrides supportsInterface in ERC165. * @param interfaceId The interface id * @return true if the contract implements the specified interface, false otherwise */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(ICreatorToken).interfaceId || interfaceId == type(ICreatorTokenLegacy).interfaceId || super.supportsInterface(interfaceId); } /** * @notice Returns the function selector for the transfer validator's validation function to be called * @notice for transaction simulation. */ function getTransferValidationFunction() external pure returns (bytes4 functionSignature, bool isViewFunction) { functionSignature = bytes4(keccak256("validateTransfer(address,address,address,uint256)")); isViewFunction = true; } /// @dev Ties the open-zeppelin _beforeTokenTransfer hook to more granular transfer validation logic function _beforeTokenTransfer( address from, address to, uint256 firstTokenId, uint256 batchSize) internal virtual override { for (uint256 i = 0; i < batchSize;) { _validateBeforeTransfer(from, to, firstTokenId + i); unchecked { ++i; } } } /// @dev Ties the open-zeppelin _afterTokenTransfer hook to more granular transfer validation logic function _afterTokenTransfer( address from, address to, uint256 firstTokenId, uint256 batchSize) internal virtual override { for (uint256 i = 0; i < batchSize;) { _validateAfterTransfer(from, to, firstTokenId + i); unchecked { ++i; } } } function _tokenType() internal pure override returns(uint16) { return uint16(TOKEN_TYPE_ERC721); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.2) (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 {} /** * @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 {} /** * @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override. * * WARNING: Anyone calling this MUST ensure that the balances remain consistent with the ownership. The invariant * being that for any address `a` the value returned by `balanceOf(a)` must be equal to the number of tokens such * that `ownerOf(tokenId)` is `a`. */ // solhint-disable-next-line func-name-mixedcase function __unsafe_increaseBalance(address account, uint256 amount) internal { _balances[account] += amount; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import "@openzeppelin/contracts/token/common/ERC2981.sol"; /** * @title BasicRoyaltiesBase * @author Limit Break, Inc. * @dev Base functionality of an NFT mix-in contract implementing the most basic form of programmable royalties. */ abstract contract BasicRoyaltiesBase is ERC2981 { event DefaultRoyaltySet(address indexed receiver, uint96 feeNumerator); event TokenRoyaltySet(uint256 indexed tokenId, address indexed receiver, uint96 feeNumerator); function _setDefaultRoyalty(address receiver, uint96 feeNumerator) internal virtual override { super._setDefaultRoyalty(receiver, feeNumerator); emit DefaultRoyaltySet(receiver, feeNumerator); } function _setTokenRoyalty(uint256 tokenId, address receiver, uint96 feeNumerator) internal virtual override { super._setTokenRoyalty(tokenId, receiver, feeNumerator); emit TokenRoyaltySet(tokenId, receiver, feeNumerator); } } /** * @title BasicRoyalties * @author Limit Break, Inc. * @notice Constructable BasicRoyalties Contract implementation. */ abstract contract BasicRoyalties is BasicRoyaltiesBase { constructor(address receiver, uint96 feeNumerator) { _setDefaultRoyalty(receiver, feeNumerator); } } /** * @title BasicRoyaltiesInitializable * @author Limit Break, Inc. * @notice Initializable BasicRoyalties Contract implementation to allow for EIP-1167 clones. */ abstract contract BasicRoyaltiesInitializable is BasicRoyaltiesBase {}
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import "../../access/OwnablePermissions.sol"; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; abstract contract ERC721OpenZeppelinBase is ERC721 { // Token name string internal _contractName; // Token symbol string internal _contractSymbol; function name() public view virtual override returns (string memory) { return _contractName; } function symbol() public view virtual override returns (string memory) { return _contractSymbol; } function _setNameAndSymbol(string memory name_, string memory symbol_) internal { _contractName = name_; _contractSymbol = symbol_; } } abstract contract ERC721OpenZeppelin is ERC721OpenZeppelinBase { constructor(string memory name_, string memory symbol_) ERC721("", "") { _setNameAndSymbol(name_, symbol_); } } abstract contract ERC721OpenZeppelinInitializable is OwnablePermissions, ERC721OpenZeppelinBase { error ERC721OpenZeppelinInitializable__AlreadyInitializedERC721(); /// @notice Specifies whether or not the contract is initialized bool private _erc721Initialized; /// @dev Initializes parameters of ERC721 tokens. /// These cannot be set in the constructor because this contract is optionally compatible with EIP-1167. function initializeERC721(string memory name_, string memory symbol_) public virtual { _requireCallerIsContractOwner(); if(_erc721Initialized) { revert ERC721OpenZeppelinInitializable__AlreadyInitializedERC721(); } _erc721Initialized = true; _setNameAndSymbol(name_, symbol_); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import "./OwnablePermissions.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; abstract contract OwnableBasic is OwnablePermissions, Ownable { function _requireCallerIsContractOwner() internal view virtual override { _checkOwner(); } }
// 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.7.0) (token/common/ERC2981.sol) pragma solidity ^0.8.0; import "../../interfaces/IERC2981.sol"; import "../../utils/introspection/ERC165.sol"; /** * @dev Implementation of the NFT Royalty Standard, a standardized way to retrieve royalty payment information. * * Royalty information can be specified globally for all token ids via {_setDefaultRoyalty}, and/or individually for * specific token ids via {_setTokenRoyalty}. The latter takes precedence over the first. * * Royalty is specified as a fraction of sale price. {_feeDenominator} is overridable but defaults to 10000, meaning the * fee is specified in basis points by default. * * IMPORTANT: ERC-2981 only specifies a way to signal royalty information and does not enforce its payment. See * https://eips.ethereum.org/EIPS/eip-2981#optional-royalty-payments[Rationale] in the EIP. Marketplaces are expected to * voluntarily pay royalties together with sales, but note that this standard is not yet widely supported. * * _Available since v4.5._ */ abstract contract ERC2981 is IERC2981, ERC165 { struct RoyaltyInfo { address receiver; uint96 royaltyFraction; } RoyaltyInfo private _defaultRoyaltyInfo; mapping(uint256 => RoyaltyInfo) private _tokenRoyaltyInfo; /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) { return interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId); } /** * @inheritdoc IERC2981 */ function royaltyInfo(uint256 _tokenId, uint256 _salePrice) public view virtual override returns (address, uint256) { RoyaltyInfo memory royalty = _tokenRoyaltyInfo[_tokenId]; if (royalty.receiver == address(0)) { royalty = _defaultRoyaltyInfo; } uint256 royaltyAmount = (_salePrice * royalty.royaltyFraction) / _feeDenominator(); return (royalty.receiver, royaltyAmount); } /** * @dev The denominator with which to interpret the fee set in {_setTokenRoyalty} and {_setDefaultRoyalty} as a * fraction of the sale price. Defaults to 10000 so fees are expressed in basis points, but may be customized by an * override. */ function _feeDenominator() internal pure virtual returns (uint96) { return 10000; } /** * @dev Sets the royalty information that all ids in this contract will default to. * * Requirements: * * - `receiver` cannot be the zero address. * - `feeNumerator` cannot be greater than the fee denominator. */ function _setDefaultRoyalty(address receiver, uint96 feeNumerator) internal virtual { require(feeNumerator <= _feeDenominator(), "ERC2981: royalty fee will exceed salePrice"); require(receiver != address(0), "ERC2981: invalid receiver"); _defaultRoyaltyInfo = RoyaltyInfo(receiver, feeNumerator); } /** * @dev Removes default royalty information. */ function _deleteDefaultRoyalty() internal virtual { delete _defaultRoyaltyInfo; } /** * @dev Sets the royalty information for a specific token id, overriding the global default. * * Requirements: * * - `receiver` cannot be the zero address. * - `feeNumerator` cannot be greater than the fee denominator. */ function _setTokenRoyalty( uint256 tokenId, address receiver, uint96 feeNumerator ) internal virtual { require(feeNumerator <= _feeDenominator(), "ERC2981: royalty fee will exceed salePrice"); require(receiver != address(0), "ERC2981: Invalid parameters"); _tokenRoyaltyInfo[tokenId] = RoyaltyInfo(receiver, feeNumerator); } /** * @dev Resets royalty information for the token id back to the global default. */ function _resetTokenRoyalty(uint256 tokenId) internal virtual { delete _tokenRoyaltyInfo[tokenId]; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/ECDSA.sol) pragma solidity ^0.8.0; import "../Strings.sol"; /** * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations. * * These functions can be used to verify that a message was signed by the holder * of the private keys of a given address. */ library ECDSA { enum RecoverError { NoError, InvalidSignature, InvalidSignatureLength, InvalidSignatureS, InvalidSignatureV // Deprecated in v4.8 } function _throwError(RecoverError error) private pure { if (error == RecoverError.NoError) { return; // no error: do nothing } else if (error == RecoverError.InvalidSignature) { revert("ECDSA: invalid signature"); } else if (error == RecoverError.InvalidSignatureLength) { revert("ECDSA: invalid signature length"); } else if (error == RecoverError.InvalidSignatureS) { revert("ECDSA: invalid signature 's' value"); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature` or error string. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. * * Documentation for signature generation: * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js] * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers] * * _Available since v4.3._ */ function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) { if (signature.length == 65) { bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. /// @solidity memory-safe-assembly assembly { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return tryRecover(hash, v, r, s); } else { return (address(0), RecoverError.InvalidSignatureLength); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, signature); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately. * * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures] * * _Available since v4.3._ */ function tryRecover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address, RecoverError) { bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); uint8 v = uint8((uint256(vs) >> 255) + 27); return tryRecover(hash, v, r, s); } /** * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately. * * _Available since v4.2._ */ function recover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, r, vs); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `v`, * `r` and `s` signature fields separately. * * _Available since v4.3._ */ function tryRecover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address, RecoverError) { // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most // signatures from current libraries generate a unique signature with an s-value in the lower half order. // // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept // these malleable signatures as well. if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) { return (address(0), RecoverError.InvalidSignatureS); } // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); if (signer == address(0)) { return (address(0), RecoverError.InvalidSignature); } return (signer, RecoverError.NoError); } /** * @dev Overload of {ECDSA-recover} that receives the `v`, * `r` and `s` signature fields separately. */ function recover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, v, r, s); _throwError(error); return recovered; } /** * @dev Returns an Ethereum Signed Message, created from a `hash`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) { // 32 is the length in bytes of hash, // enforced by the type signature above return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)); } /** * @dev Returns an Ethereum Signed Message, created from `s`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s)); } /** * @dev Returns an Ethereum Signed Typed Data, created from a * `domainSeparator` and a `structHash`. This produces hash corresponding * to the one signed with the * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] * JSON-RPC method as part of EIP-712. * * See {recover}. */ function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (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 (interfaces/IERC1271.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC1271 standard signature validation method for * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271]. * * _Available since v4.1._ */ interface IERC1271 { /** * @dev Should return whether the signature provided is valid for the provided data * @param hash Hash of the data to be signed * @param signature Signature byte array associated with _data */ function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./DataTypes.sol"; import {IDataStore, ID} from "./IDataStore.sol"; import {GameRegistryConsumer} from "../core/GameRegistryConsumer.sol"; import {GAME_LOGIC_CONTRACT_ROLE} from "../constants/RoleConstants.sol"; contract DataStore is IDataStore, GameRegistryConsumer { using DataTypes for *; mapping(uint256 => mapping(uint256 => bytes32)) public datastore; mapping(uint256 => mapping(uint256 => bytes32[])) public arrayStore; mapping(uint256 => mapping(uint256 => string)) private stringStore; mapping(uint256 => bytes32) public columnTypes; constructor(address gameRegistryAddress) GameRegistryConsumer(gameRegistryAddress, ID) {} function generateKey(uint256 docId, uint256 colId) public pure returns (uint256) { return uint256(keccak256(abi.encodePacked(docId, colId))); } function generateArrayKey (uint256 docId, uint256 colId) public pure returns (uint256) { return uint256(keccak256(abi.encodePacked(docId, colId, "__array"))); } function setValue(uint256 tableId, uint256 docId, uint256 colId, bytes32 value) public onlyRole(GAME_LOGIC_CONTRACT_ROLE) { datastore[tableId][uint256(keccak256(abi.encodePacked(docId, colId)))] = value; emit ValueSet(tableId, docId, colId, value); } function setArrayValue(uint256 tableId, uint256 docId, uint256 colId, bytes32[] memory value) public onlyRole(GAME_LOGIC_CONTRACT_ROLE) { arrayStore[tableId][generateArrayKey(docId, colId)] = value; emit ArrayValueSet(tableId, docId, colId, value); } function setUint256ArrayValue(uint256 tableId, uint256 docId, uint256 colId, uint256[] memory value) public onlyRole(GAME_LOGIC_CONTRACT_ROLE) { require (getColumnType(colId) == IDataStore.ColumnType.UINT256, "Column is not UINT256ARRAY"); bytes32[] memory packedValues = new bytes32[](value.length); for (uint256 i = 0; i < value.length; i++) { packedValues[i] = value[i].packUint256(); } setArrayValue(tableId, docId, colId, packedValues); } function setBoolArrayValue(uint256 tableId, uint256 docId, uint256 colId, bool[] memory value) public onlyRole(GAME_LOGIC_CONTRACT_ROLE) { require (getColumnType(colId) == IDataStore.ColumnType.BOOL, "Column is not BOOLARRAY"); bytes32[] memory packedValues = new bytes32[](value.length); for (uint256 i = 0; i < value.length; i++) { packedValues[i] = value[i].packBool(); } setArrayValue(tableId, docId, colId, packedValues); } function setAddressArrayValue(uint256 tableId, uint256 docId, uint256 colId, address[] memory value) public onlyRole(GAME_LOGIC_CONTRACT_ROLE) { require (getColumnType(colId) == IDataStore.ColumnType.ADDRESS, "Column is not ADDRESSARRAY"); bytes32[] memory packedValues = new bytes32[](value.length); for (uint256 i = 0; i < value.length; i++) { packedValues[i] = value[i].packAddress(); } setArrayValue(tableId, docId, colId, packedValues); } function getUint256Array(uint256 tableId, uint256 docId, uint256 colId) public view returns (uint256[] memory) { require (getColumnType(colId) == IDataStore.ColumnType.UINT256, "Column is not UINT256"); bytes32[] memory byteArray = arrayStore[tableId][generateArrayKey(docId, colId)]; uint256[] memory uintArray = new uint256[](byteArray.length); for (uint256 i = 0; i < byteArray.length; i++) { uintArray[i] = byteArray[i].unpackUint256(); } return uintArray; } function getBoolArray(uint256 tableId, uint256 docId, uint256 colId) public view returns (bool[] memory) { require (getColumnType(colId) == IDataStore.ColumnType.BOOL, "Column is not BOOL"); bytes32[] memory byteArray = arrayStore[tableId][generateArrayKey(docId, colId)]; bool[] memory boolArray = new bool[](byteArray.length); for (uint256 i = 0; i < byteArray.length; i++) { boolArray[i] = byteArray[i].unpackBool(); } return boolArray; } function getAddressArray(uint256 tableId, uint256 docId, uint256 colId) public view returns (address[] memory) { require (getColumnType(colId) == IDataStore.ColumnType.ADDRESS, "Column is not ADDRESS"); bytes32[] memory byteArray = arrayStore[tableId][generateArrayKey(docId, colId)]; address[] memory addressArray = new address[](byteArray.length); for (uint256 i = 0; i < byteArray.length; i++) { addressArray[i] = byteArray[i].unpackAddress(); } return addressArray; } function getValue(uint256 tableId, uint256 docId, uint256 colId) public view returns (bytes32) { return datastore[tableId][uint256(keccak256(abi.encodePacked(docId, colId)))]; } function setColumnType(uint256 colId, IDataStore.ColumnType columnType) public onlyRole(GAME_LOGIC_CONTRACT_ROLE) { require(!isColumnTypeSet(colId), "Column type already set"); columnTypes[colId] = bytes32(uint256(columnType)); emit ColumnTypeSet(colId, columnType); } function isColumnTypeSet(uint256 colId) public view returns (bool) { return columnTypes[colId] != bytes32(0); } function getColumnType(uint256 colId) public view returns (IDataStore.ColumnType) { bytes32 typeValue = columnTypes[colId]; require(typeValue != bytes32(0), "Column type not set"); return IDataStore.ColumnType(uint8(uint256(typeValue))); } // Type-specific setters function setUint256(uint256 tableId, uint256 docId, uint256 colId, uint256 value) public onlyRole(GAME_LOGIC_CONTRACT_ROLE){ require(getColumnType(colId) == IDataStore.ColumnType.UINT256, "Column is not UINT256"); setValue(tableId, docId, colId, value.packUint256()); } function setInt256(uint256 tableId, uint256 docId, uint256 colId, int256 value) public onlyRole(GAME_LOGIC_CONTRACT_ROLE){ require(getColumnType(colId) == IDataStore.ColumnType.INT256, "Column is not INT256"); setValue(tableId, docId, colId, value.packInt256()); } function setBool(uint256 tableId, uint256 docId, uint256 colId, bool value) public onlyRole(GAME_LOGIC_CONTRACT_ROLE){ require(getColumnType(colId) == IDataStore.ColumnType.BOOL, "Column is not BOOL"); setValue(tableId, docId, colId, value.packBool()); } function setAddress(uint256 tableId, uint256 docId, uint256 colId, address value) public onlyRole(GAME_LOGIC_CONTRACT_ROLE){ require(getColumnType(colId) == IDataStore.ColumnType.ADDRESS, "Column is not ADDRESS"); setValue(tableId, docId, colId, value.packAddress()); } function setBytes32(uint256 tableId, uint256 docId, uint256 colId, bytes32 value) public onlyRole(GAME_LOGIC_CONTRACT_ROLE){ require(getColumnType(colId) == IDataStore.ColumnType.BYTES32, "Column is not BYTES32"); setValue(tableId, docId, colId, value); } function setString(uint256 tableId, uint256 docId, uint256 colId, string memory value) public onlyRole(GAME_LOGIC_CONTRACT_ROLE){ require(getColumnType(colId) == IDataStore.ColumnType.STRING, "Column is not STRING"); uint256 key = generateKey(docId, colId); stringStore[tableId][key] = value; emit StringValueSet(tableId, docId, colId, value); } function deleteValue(uint256 tableId, uint256 docId, uint256 colId) public onlyRole(GAME_LOGIC_CONTRACT_ROLE){ uint256 key = generateKey(docId, colId); delete datastore[tableId][key]; } // Type-specific getters function getUint256(uint256 tableId, uint256 docId, uint256 colId) public view returns (uint256) { require(getColumnType(colId) == IDataStore.ColumnType.UINT256, "Column is not UINT256"); return getValue(tableId, docId, colId).unpackUint256(); } function getInt256(uint256 tableId, uint256 docId, uint256 colId) public view returns (int256) { require(getColumnType(colId) == IDataStore.ColumnType.INT256, "Column is not INT256"); return getValue(tableId, docId, colId).unpackInt256(); } function getBool(uint256 tableId, uint256 docId, uint256 colId) public view returns (bool) { require(getColumnType(colId) == IDataStore.ColumnType.BOOL, "Column is not BOOL"); return getValue(tableId, docId, colId).unpackBool(); } function getAddress(uint256 tableId, uint256 docId, uint256 colId) public view returns (address) { require(getColumnType(colId) == IDataStore.ColumnType.ADDRESS, "Column is not ADDRESS"); return getValue(tableId, docId, colId).unpackAddress(); } function getBytes32(uint256 tableId, uint256 docId, uint256 colId) public view returns (bytes32) { require(getColumnType(colId) == IDataStore.ColumnType.BYTES32, "Column is not BYTES32"); return getValue(tableId, docId, colId); } function getString(uint256 tableId, uint256 docId, uint256 colId) public view returns (string memory) { require(getColumnType(colId) == IDataStore.ColumnType.STRING, "Column is not STRING"); uint256 key = generateKey(docId, colId); return stringStore[tableId][key]; } function hasValue(uint256 tableId, uint256 docId, uint256 colId) public view returns (bool) { uint256 key = generateKey(docId, colId); return datastore[tableId][key] != bytes32(0); } function hasStringValue(uint256 tableId, uint256 docId, uint256 colId) public view returns (bool) { uint256 key = generateKey(docId, colId); return keccak256(bytes(stringStore[tableId][key])) != keccak256(bytes("")); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import "../access/OwnablePermissions.sol"; /** * @title AutomaticValidatorTransferApproval * @author Limit Break, Inc. * @notice Base contract mix-in that provides boilerplate code giving the contract owner the * option to automatically approve a 721-C transfer validator implementation for transfers. */ abstract contract AutomaticValidatorTransferApproval is OwnablePermissions { /// @dev Emitted when the automatic approval flag is modified by the creator. event AutomaticApprovalOfTransferValidatorSet(bool autoApproved); /// @dev If true, the collection's transfer validator is automatically approved to transfer holder's tokens. bool public autoApproveTransfersFromValidator; /** * @notice Sets if the transfer validator is automatically approved as an operator for all token owners. * * @dev Throws when the caller is not the contract owner. * * @param autoApprove If true, the collection's transfer validator will be automatically approved to * transfer holder's tokens. */ function setAutomaticApprovalOfTransfersFromValidator(bool autoApprove) external { _requireCallerIsContractOwner(); autoApproveTransfersFromValidator = autoApprove; emit AutomaticApprovalOfTransferValidatorSet(autoApprove); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import "../access/OwnablePermissions.sol"; import "../interfaces/ICreatorToken.sol"; import "../interfaces/ICreatorTokenLegacy.sol"; import "../interfaces/ITransferValidator.sol"; import "./TransferValidation.sol"; import "../interfaces/ITransferValidatorSetTokenType.sol"; /** * @title CreatorTokenBase * @author Limit Break, Inc. * @notice CreatorTokenBaseV3 is an abstract contract that provides basic functionality for managing token * transfer policies through an implementation of ICreatorTokenTransferValidator/ICreatorTokenTransferValidatorV2/ICreatorTokenTransferValidatorV3. * This contract is intended to be used as a base for creator-specific token contracts, enabling customizable transfer * restrictions and security policies. * * <h4>Features:</h4> * <ul>Ownable: This contract can have an owner who can set and update the transfer validator.</ul> * <ul>TransferValidation: Implements the basic token transfer validation interface.</ul> * * <h4>Benefits:</h4> * <ul>Provides a flexible and modular way to implement custom token transfer restrictions and security policies.</ul> * <ul>Allows creators to enforce policies such as account and codehash blacklists, whitelists, and graylists.</ul> * <ul>Can be easily integrated into other token contracts as a base contract.</ul> * * <h4>Intended Usage:</h4> * <ul>Use as a base contract for creator token implementations that require advanced transfer restrictions and * security policies.</ul> * <ul>Set and update the ICreatorTokenTransferValidator implementation contract to enforce desired policies for the * creator token.</ul> * * <h4>Compatibility:</h4> * <ul>Backward and Forward Compatible - V1/V2/V3 Creator Token Base will work with V1/V2/V3 Transfer Validators.</ul> */ abstract contract CreatorTokenBase is OwnablePermissions, TransferValidation, ICreatorToken { /// @dev Thrown when setting a transfer validator address that has no deployed code. error CreatorTokenBase__InvalidTransferValidatorContract(); /// @dev The default transfer validator that will be used if no transfer validator has been set by the creator. address public constant DEFAULT_TRANSFER_VALIDATOR = address(0x721C002B0059009a671D00aD1700c9748146cd1B); /// @dev Used to determine if the default transfer validator is applied. /// @dev Set to true when the creator sets a transfer validator address. bool private isValidatorInitialized; /// @dev Address of the transfer validator to apply to transactions. address private transferValidator; constructor() { _emitDefaultTransferValidator(); _registerTokenType(DEFAULT_TRANSFER_VALIDATOR); } /** * @notice Sets the transfer validator for the token contract. * * @dev Throws when provided validator contract is not the zero address and does not have code. * @dev Throws when the caller is not the contract owner. * * @dev <h4>Postconditions:</h4> * 1. The transferValidator address is updated. * 2. The `TransferValidatorUpdated` event is emitted. * * @param transferValidator_ The address of the transfer validator contract. */ function setTransferValidator(address transferValidator_) public { _requireCallerIsContractOwner(); bool isValidTransferValidator = transferValidator_.code.length > 0; if(transferValidator_ != address(0) && !isValidTransferValidator) { revert CreatorTokenBase__InvalidTransferValidatorContract(); } emit TransferValidatorUpdated(address(getTransferValidator()), transferValidator_); isValidatorInitialized = true; transferValidator = transferValidator_; _registerTokenType(transferValidator_); } /** * @notice Returns the transfer validator contract address for this token contract. */ function getTransferValidator() public view override returns (address validator) { validator = transferValidator; if (validator == address(0)) { if (!isValidatorInitialized) { validator = DEFAULT_TRANSFER_VALIDATOR; } } } /** * @dev Pre-validates a token transfer, reverting if the transfer is not allowed by this token's security policy. * Inheriting contracts are responsible for overriding the _beforeTokenTransfer function, or its equivalent * and calling _validateBeforeTransfer so that checks can be properly applied during token transfers. * * @dev Be aware that if the msg.sender is the transfer validator, the transfer is automatically permitted, as the * transfer validator is expected to pre-validate the transfer. * * @dev Throws when the transfer doesn't comply with the collection's transfer policy, if the transferValidator is * set to a non-zero address. * * @param caller The address of the caller. * @param from The address of the sender. * @param to The address of the receiver. * @param tokenId The token id being transferred. */ function _preValidateTransfer( address caller, address from, address to, uint256 tokenId, uint256 /*value*/) internal virtual override { address validator = getTransferValidator(); if (validator != address(0)) { if (msg.sender == validator) { return; } ITransferValidator(validator).validateTransfer(caller, from, to, tokenId); } } /** * @dev Pre-validates a token transfer, reverting if the transfer is not allowed by this token's security policy. * Inheriting contracts are responsible for overriding the _beforeTokenTransfer function, or its equivalent * and calling _validateBeforeTransfer so that checks can be properly applied during token transfers. * * @dev Be aware that if the msg.sender is the transfer validator, the transfer is automatically permitted, as the * transfer validator is expected to pre-validate the transfer. * * @dev Used for ERC20 and ERC1155 token transfers which have an amount value to validate in the transfer validator. * @dev The `tokenId` for ERC20 tokens should be set to `0`. * * @dev Throws when the transfer doesn't comply with the collection's transfer policy, if the transferValidator is * set to a non-zero address. * * @param caller The address of the caller. * @param from The address of the sender. * @param to The address of the receiver. * @param tokenId The token id being transferred. * @param amount The amount of token being transferred. */ function _preValidateTransfer( address caller, address from, address to, uint256 tokenId, uint256 amount, uint256 /*value*/) internal virtual override { address validator = getTransferValidator(); if (validator != address(0)) { if (msg.sender == validator) { return; } ITransferValidator(validator).validateTransfer(caller, from, to, tokenId, amount); } } function _tokenType() internal virtual pure returns(uint16); function _registerTokenType(address validator) internal { if (validator != address(0)) { uint256 validatorCodeSize; assembly { validatorCodeSize := extcodesize(validator) } if(validatorCodeSize > 0) { try ITransferValidatorSetTokenType(validator).setTokenTypeOfCollection(address(this), _tokenType()) { } catch { } } } } /** * @dev Used during contract deployment for constructable and cloneable creator tokens * @dev to emit the `TransferValidatorUpdated` event signaling the validator for the contract * @dev is the default transfer validator. */ function _emitDefaultTransferValidator() internal { emit TransferValidatorUpdated(address(0), DEFAULT_TRANSFER_VALIDATOR); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; interface ITransferValidatorSetTokenType { function setTokenTypeOfCollection(address collection, uint16 tokenType) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @dev Constant bytes32 value of 0x000...000 bytes32 constant ZERO_BYTES32 = bytes32(0); /// @dev Constant value of 0 uint256 constant ZERO = 0; /// @dev Constant value of 1 uint256 constant ONE = 1; /// @dev Constant value representing an open order in storage uint8 constant ORDER_STATE_OPEN = 0; /// @dev Constant value representing a filled order in storage uint8 constant ORDER_STATE_FILLED = 1; /// @dev Constant value representing a cancelled order in storage uint8 constant ORDER_STATE_CANCELLED = 2; /// @dev Constant value representing the ERC721 token type for signatures and transfer hooks uint256 constant TOKEN_TYPE_ERC721 = 721; /// @dev Constant value representing the ERC1155 token type for signatures and transfer hooks uint256 constant TOKEN_TYPE_ERC1155 = 1155; /// @dev Constant value representing the ERC20 token type for signatures and transfer hooks uint256 constant TOKEN_TYPE_ERC20 = 20; /// @dev Constant value to mask the upper bits of a signature that uses a packed `vs` value to extract `s` bytes32 constant UPPER_BIT_MASK = 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff; /// @dev EIP-712 typehash used for validating signature based stored approvals bytes32 constant UPDATE_APPROVAL_TYPEHASH = keccak256("UpdateApprovalBySignature(uint256 tokenType,address token,uint256 id,uint256 amount,uint256 nonce,address operator,uint256 approvalExpiration,uint256 sigDeadline,uint256 masterNonce)"); /// @dev EIP-712 typehash used for validating a single use permit without additional data bytes32 constant SINGLE_USE_PERMIT_TYPEHASH = keccak256("PermitTransferFrom(uint256 tokenType,address token,uint256 id,uint256 amount,uint256 nonce,address operator,uint256 expiration,uint256 masterNonce)"); /// @dev EIP-712 typehash used for validating a single use permit with additional data string constant SINGLE_USE_PERMIT_TRANSFER_ADVANCED_TYPEHASH_STUB = "PermitTransferFromWithAdditionalData(uint256 tokenType,address token,uint256 id,uint256 amount,uint256 nonce,address operator,uint256 expiration,uint256 masterNonce,"; /// @dev EIP-712 typehash used for validating an order permit that updates storage as it fills string constant PERMIT_ORDER_ADVANCED_TYPEHASH_STUB = "PermitOrderWithAdditionalData(uint256 tokenType,address token,uint256 id,uint256 amount,uint256 salt,address operator,uint256 expiration,uint256 masterNonce,"; /// @dev Pausable flag for stored approval transfers of ERC721 assets uint256 constant PAUSABLE_APPROVAL_TRANSFER_FROM_ERC721 = 1 << 0; /// @dev Pausable flag for stored approval transfers of ERC1155 assets uint256 constant PAUSABLE_APPROVAL_TRANSFER_FROM_ERC1155 = 1 << 1; /// @dev Pausable flag for stored approval transfers of ERC20 assets uint256 constant PAUSABLE_APPROVAL_TRANSFER_FROM_ERC20 = 1 << 2; /// @dev Pausable flag for single use permit transfers of ERC721 assets uint256 constant PAUSABLE_PERMITTED_TRANSFER_FROM_ERC721 = 1 << 3; /// @dev Pausable flag for single use permit transfers of ERC1155 assets uint256 constant PAUSABLE_PERMITTED_TRANSFER_FROM_ERC1155 = 1 << 4; /// @dev Pausable flag for single use permit transfers of ERC20 assets uint256 constant PAUSABLE_PERMITTED_TRANSFER_FROM_ERC20 = 1 << 5; /// @dev Pausable flag for order fill transfers of ERC1155 assets uint256 constant PAUSABLE_ORDER_TRANSFER_FROM_ERC1155 = 1 << 6; /// @dev Pausable flag for order fill transfers of ERC20 assets uint256 constant PAUSABLE_ORDER_TRANSFER_FROM_ERC20 = 1 << 7;
// 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 v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol) pragma solidity ^0.8.0; import "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (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 pragma solidity ^0.8.4; import "@openzeppelin/contracts/utils/Context.sol"; abstract contract OwnablePermissions is Context { function _requireCallerIsContractOwner() internal view virtual; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (interfaces/IERC2981.sol) pragma solidity ^0.8.0; import "../utils/introspection/IERC165.sol"; /** * @dev Interface for the NFT Royalty Standard. * * A standardized way to retrieve royalty payment information for non-fungible tokens (NFTs) to enable universal * support for royalty payments across all NFT marketplaces and ecosystem participants. * * _Available since v4.5._ */ interface IERC2981 is IERC165 { /** * @dev Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of * exchange. The royalty amount is denominated and should be paid in that same unit of exchange. */ function royaltyInfo(uint256 tokenId, uint256 salePrice) external view returns (address receiver, uint256 royaltyAmount); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.9; library DataTypes { // Pack and unpack uint256 function packUint256(uint256 value) internal pure returns (bytes32) { return bytes32(value); } function unpackUint256(bytes32 packed) internal pure returns (uint256) { return uint256(packed); } // Pack and unpack int256 function packInt256(int256 value) internal pure returns (bytes32) { return bytes32(uint256(value)); } function unpackInt256(bytes32 packed) internal pure returns (int256) { return int256(uint256(packed)); } // Pack and unpack address function packAddress(address value) internal pure returns (bytes32) { return bytes32(uint256(uint160(value))); } function unpackAddress(bytes32 packed) internal pure returns (address) { return address(uint160(uint256(packed))); } // Pack and unpack bool function packBool(bool value) internal pure returns (bytes32) { return bytes32(uint256(value ? 1 : 0)); } function unpackBool(bytes32 packed) internal pure returns (bool) { return uint256(packed) == 1; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; interface ICreatorToken { event TransferValidatorUpdated(address oldValidator, address newValidator); function getTransferValidator() external view returns (address validator); function setTransferValidator(address validator) external; function getTransferValidationFunction() external view returns (bytes4 functionSignature, bool isViewFunction); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; interface ICreatorTokenLegacy { event TransferValidatorUpdated(address oldValidator, address newValidator); function getTransferValidator() external view returns (address validator); function setTransferValidator(address validator) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; interface ITransferValidator { function applyCollectionTransferPolicy(address caller, address from, address to) external view; function validateTransfer(address caller, address from, address to) external view; function validateTransfer(address caller, address from, address to, uint256 tokenId) external view; function validateTransfer(address caller, address from, address to, uint256 tokenId, uint256 amount) external; function beforeAuthorizedTransfer(address operator, address token, uint256 tokenId) external; function afterAuthorizedTransfer(address token, uint256 tokenId) external; function beforeAuthorizedTransfer(address operator, address token) external; function afterAuthorizedTransfer(address token) external; function beforeAuthorizedTransfer(address token, uint256 tokenId) external; function beforeAuthorizedTransferWithAmount(address token, uint256 tokenId, uint256 amount) external; function afterAuthorizedTransferWithAmount(address token, uint256 tokenId) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import "@openzeppelin/contracts/utils/Context.sol"; /** * @title TransferValidation * @author Limit Break, Inc. * @notice A mix-in that can be combined with ERC-721 contracts to provide more granular hooks. * Openzeppelin's ERC721 contract only provides hooks for before and after transfer. This allows * developers to validate or customize transfers within the context of a mint, a burn, or a transfer. */ abstract contract TransferValidation is Context { /// @dev Thrown when the from and to address are both the zero address. error ShouldNotMintToBurnAddress(); /*************************************************************************/ /* Transfers Without Amounts */ /*************************************************************************/ /// @dev Inheriting contracts should call this function in the _beforeTokenTransfer function to get more granular hooks. function _validateBeforeTransfer(address from, address to, uint256 tokenId) internal virtual { bool fromZeroAddress = from == address(0); bool toZeroAddress = to == address(0); if(fromZeroAddress && toZeroAddress) { revert ShouldNotMintToBurnAddress(); } else if(fromZeroAddress) { _preValidateMint(_msgSender(), to, tokenId, msg.value); } else if(toZeroAddress) { _preValidateBurn(_msgSender(), from, tokenId, msg.value); } else { _preValidateTransfer(_msgSender(), from, to, tokenId, msg.value); } } /// @dev Inheriting contracts should call this function in the _afterTokenTransfer function to get more granular hooks. function _validateAfterTransfer(address from, address to, uint256 tokenId) internal virtual { bool fromZeroAddress = from == address(0); bool toZeroAddress = to == address(0); if(fromZeroAddress && toZeroAddress) { revert ShouldNotMintToBurnAddress(); } else if(fromZeroAddress) { _postValidateMint(_msgSender(), to, tokenId, msg.value); } else if(toZeroAddress) { _postValidateBurn(_msgSender(), from, tokenId, msg.value); } else { _postValidateTransfer(_msgSender(), from, to, tokenId, msg.value); } } /// @dev Optional validation hook that fires before a mint function _preValidateMint(address caller, address to, uint256 tokenId, uint256 value) internal virtual {} /// @dev Optional validation hook that fires after a mint function _postValidateMint(address caller, address to, uint256 tokenId, uint256 value) internal virtual {} /// @dev Optional validation hook that fires before a burn function _preValidateBurn(address caller, address from, uint256 tokenId, uint256 value) internal virtual {} /// @dev Optional validation hook that fires after a burn function _postValidateBurn(address caller, address from, uint256 tokenId, uint256 value) internal virtual {} /// @dev Optional validation hook that fires before a transfer function _preValidateTransfer(address caller, address from, address to, uint256 tokenId, uint256 value) internal virtual {} /// @dev Optional validation hook that fires after a transfer function _postValidateTransfer(address caller, address from, address to, uint256 tokenId, uint256 value) internal virtual {} /*************************************************************************/ /* Transfers With Amounts */ /*************************************************************************/ /// @dev Inheriting contracts should call this function in the _beforeTokenTransfer function to get more granular hooks. function _validateBeforeTransfer(address from, address to, uint256 tokenId, uint256 amount) internal virtual { bool fromZeroAddress = from == address(0); bool toZeroAddress = to == address(0); if(fromZeroAddress && toZeroAddress) { revert ShouldNotMintToBurnAddress(); } else if(fromZeroAddress) { _preValidateMint(_msgSender(), to, tokenId, amount, msg.value); } else if(toZeroAddress) { _preValidateBurn(_msgSender(), from, tokenId, amount, msg.value); } else { _preValidateTransfer(_msgSender(), from, to, tokenId, amount, msg.value); } } /// @dev Inheriting contracts should call this function in the _afterTokenTransfer function to get more granular hooks. function _validateAfterTransfer(address from, address to, uint256 tokenId, uint256 amount) internal virtual { bool fromZeroAddress = from == address(0); bool toZeroAddress = to == address(0); if(fromZeroAddress && toZeroAddress) { revert ShouldNotMintToBurnAddress(); } else if(fromZeroAddress) { _postValidateMint(_msgSender(), to, tokenId, amount, msg.value); } else if(toZeroAddress) { _postValidateBurn(_msgSender(), from, tokenId, amount, msg.value); } else { _postValidateTransfer(_msgSender(), from, to, tokenId, amount, msg.value); } } /// @dev Optional validation hook that fires before a mint function _preValidateMint(address caller, address to, uint256 tokenId, uint256 amount, uint256 value) internal virtual {} /// @dev Optional validation hook that fires after a mint function _postValidateMint(address caller, address to, uint256 tokenId, uint256 amount, uint256 value) internal virtual {} /// @dev Optional validation hook that fires before a burn function _preValidateBurn(address caller, address from, uint256 tokenId, uint256 amount, uint256 value) internal virtual {} /// @dev Optional validation hook that fires after a burn function _postValidateBurn(address caller, address from, uint256 tokenId, uint256 amount, uint256 value) internal virtual {} /// @dev Optional validation hook that fires before a transfer function _preValidateTransfer(address caller, address from, address to, uint256 tokenId, uint256 amount, uint256 value) internal virtual {} /// @dev Optional validation hook that fires after a transfer function _postValidateTransfer(address caller, address from, address to, uint256 tokenId, uint256 amount, uint256 value) internal virtual {} }
{ "viaIR": false, "codegen": "yul", "remappings": [ "@limitbreak/creator-token-standards/=lib/creator-token-standards/", "@openzeppelin/=lib/openzeppelin-contracts/", "ds-test/=lib/forge-std/lib/ds-test/src/", "forge-std/=lib/forge-std/src/", "murky/=lib/murky/src/", "erc721a/=lib/ERC721A/", "@creator-token-standards/=lib/creator-token-standards/src/", "@limitbreak/permit-c/=lib/creator-token-standards/lib/PermitC/src/", "@opensea/tstorish/=lib/creator-token-standards/lib/tstorish/src/", "@rari-capital/solmate/=lib/creator-token-standards/lib/PermitC/lib/solmate/", "ERC721A/=lib/ERC721A/contracts/", "PermitC/=lib/creator-token-standards/lib/PermitC/", "creator-token-standards/=lib/creator-token-standards/", "erc4626-tests/=lib/murky/lib/openzeppelin-contracts/lib/erc4626-tests/", "forge-gas-metering/=lib/creator-token-standards/lib/PermitC/lib/forge-gas-metering/", "forge-zksync-std/=lib/forge-zksync-std/src/", "openzeppelin-contracts/=lib/openzeppelin-contracts/", "openzeppelin/=lib/creator-token-standards/lib/PermitC/lib/openzeppelin-contracts/contracts/", "solady/=lib/creator-token-standards/lib/PermitC/lib/forge-gas-metering/lib/solady/", "solmate/=lib/creator-token-standards/lib/PermitC/lib/solmate/src/", "tstorish/=lib/creator-token-standards/lib/tstorish/src/" ], "evmVersion": "cancun", "outputSelection": { "*": { "*": [ "abi", "metadata" ], "": [ "ast" ] } }, "optimizer": { "enabled": true, "mode": "3", "fallback_to_optimizing_for_size": false, "disable_system_request_memoization": true }, "metadata": {}, "libraries": {}, "enableEraVMExtensions": false, "forceEVMLA": false }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"gameRegistryAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidGameRegistry","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"expectedRole","type":"bytes32"}],"name":"MissingRole","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"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":[],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","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":"","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"update","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
9c4d535b000000000000000000000000000000000000000000000000000000000000000001000175c1c9c8ad7ccf19e4ebafe609d5c31bd569ca87813c5066ad2f1a9b7e0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000002000000000000000000000000074eb92b33f2400eb14f6d6725b14f76078d5e731
Deployed Bytecode
0x0001000000000002000600000000000200000060031002700000013c033001970000000100200190000000330000c13d0000008002000039000000400020043f000000040030008c000000560000413d000000000201043b000000e002200270000001440020009c000000580000a13d000001450020009c000000660000213d000001480020009c0000007c0000613d000001490020009c000000560000c13d000000640030008c000000560000413d0000000002000416000000000002004b000000560000c13d0000000402100370000000000202043b0000013f0020009c000000560000213d0000002402100370000000000602043b0000013f0060009c000000560000213d0000004401100370000000000501043b0000000101000039000000000201041a0000015601000041000000800010043f0000015701000041000000840010043f000000000100041400000008022002700000013f02200197000000040020008c000001e30000c13d0000000003000031000000200030008c000000200400003900000000040340190000020d0000013d0000000002000416000000000002004b000000560000c13d0000001f023000390000013d022001970000008002200039000000400020043f0000001f0430018f0000013e053001980000008002500039000000440000613d0000008006000039000000000701034f000000007807043c0000000006860436000000000026004b000000400000c13d000000000004004b000000510000613d000000000151034f0000000304400210000000000502043300000000054501cf000000000545022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f0000000000120435000000200030008c000000560000413d000000800100043d0000013f0010009c000000740000a13d0000000001000019000004ec000104300000014a0020009c000000910000613d0000014b0020009c000000af0000613d0000014c0020009c000000560000c13d0000000001000416000000000001004b000000560000c13d0000000201000039000000000101041a000000800010043f0000014d01000041000004eb0001042e000001460020009c000000c20000613d000001470020009c000000560000c13d0000000001000416000000000001004b000000560000c13d0000000101000039000000000101041a00000008011002700000013f01100197000000800010043f0000014d01000041000004eb0001042e0000000102000039000000000020041b000000000001004b000000dd0000c13d0000015201000041000000000010043f0000015301000041000004ec000104300000000001000416000000000001004b000000560000c13d0000000101000039000000000201041a0000014e01000041000000800010043f0000016901000041000000840010043f0000000005000411000000a40050043f000000000100041400000008022002700000013f02200197000000040020008c000000ec0000c13d0000000003000031000000200030008c00000020040000390000000004034019000001110000013d000000240030008c000000560000413d0000000002000416000000000002004b000000560000c13d0000000401100370000000000701043b000000000007004b0000000001000039000000010100c039000000000017004b000000560000c13d0000000103000039000000000203041a0000014e01000041000000800010043f0000016d01000041000000840010043f0000000006000411000000a40060043f000000000100041400000008022002700000013f02200197000000040020008c0000012c0000c13d000000000b0000310000002000b0008c000000200400003900000000040b4019000001540000013d0000000001000416000000000001004b000000560000c13d0000000102000039000000000302041a000000ff00300190000001260000c13d0000016a01000041000000800010043f000000000100041400000008023002700000013f02200197000000040020008c000001690000c13d0000000003000031000000200030008c000000200400003900000000040340190000018d0000013d000000240030008c000000560000413d0000000002000416000000000002004b000000560000c13d0000000401100370000000000501043b0000013f0050009c000000560000213d0000000106000039000000000206041a0000014e01000041000000800010043f0000014f01000041000000840010043f0000000007000411000000a40070043f000000000100041400000008022002700000013f02200197000000040020008c0000019a0000c13d0000000003000031000000200030008c00000020040000390000000004034019000001c20000013d000000000302041a000001400330019700000008011002100000014101100197000000000131019f00000001011001bf000000000012041b00000142010000410000000202000039000000000012041b0000002001000039000001000010044300000120000004430000014301000041000004eb0001042e0000013c0010009c0000013c01008041000000c00110021000000150011001c704ea04e50000040f00000060031002700000013c03300197000000200030008c000000200400003900000000040340190000001f0640018f000000200740019000000080057001bf000001000000613d0000008008000039000000000901034f000000009a09043c0000000008a80436000000000058004b000000fc0000c13d000000000006004b0000010d0000613d000000000771034f0000000306600210000000000805043300000000086801cf000000000868022f000000000707043b0000010006600089000000000767022f00000000066701cf000000000686019f0000000000650435000000000003001f0000000100200190000001d70000613d00000000050004110000001f01400039000000600110018f00000080011001bf000000400010043f000000200030008c000000560000413d000000800100043d000000000001004b0000000002000039000000010200c039000000000021004b000000560000c13d000000000001004b000002c00000c13d0000015401000041000000000010043f000000040050043f0000016901000041000000240010043f0000015501000041000004ec000104300000008001000039000000010220018f000000000021043500000040011002100000016c011001c7000004eb0001042e000600000007001d0000013c0010009c0000013c01008041000000c00110021000000150011001c704ea04e50000040f00000060031002700000013c0b3001970000002000b0008c000000200400003900000000040b40190000001f0640018f000000200740019000000080057001bf000001410000613d0000008008000039000000000901034f000000009a09043c0000000008a80436000000000058004b0000013d0000c13d000000000006004b0000014e0000613d000000000771034f0000000306600210000000000805043300000000086801cf000000000868022f000000000707043b0000010006600089000000000767022f00000000066701cf000000000686019f000000000065043500000000000b001f0000000100200190000002230000613d0000000103000039000000000600041100000006070000290000001f01400039000000600210018f00000080012001bf000000400010043f0000002000b0008c000000560000413d000000800500043d000000000005004b0000000004000039000000010400c039000000000045004b000000560000c13d000000000005004b000002730000c13d0000015401000041000000000010043f000000040060043f0000016d01000041000000240010043f0000015501000041000004ec000104300000013c0010009c0000013c01008041000000c0011002100000016b011001c704ea04e50000040f00000060031002700000013c03300197000000200030008c000000200400003900000000040340190000001f0640018f000000200740019000000080057001bf0000017d0000613d0000008008000039000000000901034f000000009a09043c0000000008a80436000000000058004b000001790000c13d000000000006004b0000018a0000613d000000000771034f0000000306600210000000000805043300000000086801cf000000000868022f000000000707043b0000010006600089000000000767022f00000000066701cf000000000686019f0000000000650435000000000003001f00000001002001900000023d0000613d0000001f01400039000000600110018f00000080011001bf000000400010043f000000200030008c000000560000413d000000800300043d000000000003004b0000000002000039000000010200c039000000000023004b000000560000c13d000001270000013d000600000005001d0000013c0010009c0000013c01008041000000c00110021000000150011001c704ea04e50000040f000000800a00003900000060031002700000013c03300197000000200030008c000000200400003900000000040340190000001f0640018f000000200740019000000080057001bf000001af0000613d000000000801034f000000008908043c000000000a9a043600000000005a004b000001ab0000c13d000000000006004b000001bc0000613d000000000771034f0000000306600210000000000805043300000000086801cf000000000868022f000000000707043b0000010006600089000000000767022f00000000066701cf000000000686019f0000000000650435000000000003001f0000000100200190000002490000613d0000000605000029000000010600003900000000070004110000001f01400039000000600110018f00000080011001bf000000400010043f000000200030008c000000560000413d000000800100043d000000000001004b0000000002000039000000010200c039000000000021004b000000560000c13d000000000001004b000002860000c13d0000015401000041000000000010043f000000040070043f0000014f01000041000000240010043f0000015501000041000004ec000104300000001f0530018f0000013e06300198000000400200043d0000000004620019000002600000613d000000000701034f0000000008020019000000007907043c0000000008980436000000000048004b000001de0000c13d000002600000013d000500000006001d000400000005001d0000013c0010009c0000013c01008041000000c00110021000000158011001c7000600000002001d04ea04e50000040f00000060031002700000013c03300197000000200030008c000000200400003900000000040340190000001f0640018f000000200740019000000080057001bf000001fa0000613d0000008008000039000000000901034f000000009a09043c0000000008a80436000000000058004b000001f60000c13d000000000006004b000002070000613d000000000771034f0000000306600210000000000805043300000000086801cf000000000868022f000000000707043b0000010006600089000000000767022f00000000066701cf000000000686019f0000000000650435000000000003001f00000001002001900000000602000029000002550000613d000000040500002900000005060000290000001f01400039000000600110018f00000080071001bf000000400070043f000000200030008c000000560000413d000000800300043d0000013f0030009c000000560000213d00000084081001bf000000000003004b0000028f0000c13d0000015903000041000000000037043500000020030000390000000000380435000000c40210003900000168030000410000000000320435000000a4011000390000001a02000039000002d90000013d0000001f05b0018f0000013e06b00198000000400200043d00000000046200190000022e0000613d000000000701034f0000000008020019000000007907043c0000000008980436000000000048004b0000022a0000c13d000000000005004b0000023b0000613d000000000161034f0000000305500210000000000604043300000000065601cf000000000656022f000000000101043b0000010005500089000000000151022f00000000015101cf000000000161019f00000000001404350000006001b002100000026e0000013d0000001f0530018f0000013e06300198000000400200043d0000000004620019000002600000613d000000000701034f0000000008020019000000007907043c0000000008980436000000000048004b000002440000c13d000002600000013d0000001f0530018f0000013e06300198000000400200043d0000000004620019000002600000613d000000000701034f0000000008020019000000007907043c0000000008980436000000000048004b000002500000c13d000002600000013d0000001f0530018f0000013e06300198000000400200043d0000000004620019000002600000613d000000000701034f0000000008020019000000007907043c0000000008980436000000000048004b0000025c0000c13d000000000005004b0000026d0000613d000000000161034f0000000305500210000000000604043300000000065601cf000000000656022f000000000101043b0000010005500089000000000151022f00000000015101cf000000000161019f000000000014043500000060013002100000013c0020009c0000013c020080410000004002200210000000000112019f000004ec00010430000000000503041a000000ff0450018f000000000007004b000002ae0000c13d000000000004004b000002c20000613d0000017202500197000000000023041b0000000000610435000000400110021000000000020004140000013c0020009c0000013c02008041000000c002200210000000000112019f0000016e011001c70000800d020000390000017004000041000002bd0000013d00000008015002100000014101100197000000000206041a0000015102200197000000000112019f000000000016041b000000000005004b000000780000613d000002c00000013d0000000004000411000000000043004b000002d00000c13d000001560300004100000000003704350000015c0300004100000000003804350000000003000414000000040020008c000002dd0000c13d0000000008170019000000400080043f0000000002070433000300000002001d0000013f0020009c000000560000213d000500000006001d0000015e020000410000000000280435000600000008001d00000004028001bf000400000005001d00000000005204350000000002000414000000040040008c0000031e0000c13d00000006040000290000000002410019000200000002001d000000400020043f0000034e0000013d000000000004004b000002c20000c13d000001720250019700000001022001bf000000000023041b0000000000610435000000400110021000000000020004140000013c0020009c0000013c02008041000000c002200210000000000112019f0000016e011001c70000800d020000390000016f0400004104ea04e00000040f0000000100200190000000560000613d0000000001000019000004eb0001042e0000015903000041000000000031043500000084032001bf00000020040000390000000000430435000000c40320003900000171040000410000000000430435000000a4022000390000001403000039000000000032043500000040011002100000015b011001c7000004ec000104300000015903000041000000000037043500000020030000390000000000380435000000c4021000390000015a030000410000000000320435000000a4011000390000001802000039000000000021043500000040017002100000015b011001c7000004ec00010430000500000006001d000400000005001d0000013c0030009c0000013c03008041000000c0013002100000004003700210000000000131019f0000015d011001c7000600000007001d04ea04e50000040f00000060031002700000013c03300197000000200030008c000000200400003900000000040340190000001f0640018f0000002007400190000000060b0000290000000605700029000002f70000613d000000000801034f00000000090b0019000000008a08043c0000000009a90436000000000059004b000002f30000c13d000000000006004b000003040000613d000000000771034f0000000306600210000000000805043300000000086801cf000000000868022f000000000707043b0000010006600089000000000767022f00000000066701cf000000000686019f0000000000650435000000000003001f0000000100200190000003120000613d0000001f01400039000000600110018f00000000070b00190000000008b10019000000400080043f000000200030008c000000040500002900000005060000290000000004000411000000560000413d0000029b0000013d0000001f0530018f0000013e06300198000000400200043d0000000004620019000002600000613d000000000701034f0000000008020019000000007907043c0000000008980436000000000048004b000003190000c13d000002600000013d0000013c0020009c0000013c02008041000000c00120021000000006020000290000004002200210000000000112019f0000015d011001c7000000000200041104ea04e50000040f00000060031002700000013c03300197000000200030008c000000200400003900000000040340190000001f0640018f00000020074001900000000605700029000003360000613d000000000801034f0000000609000029000000008a08043c0000000009a90436000000000059004b000003320000c13d000000000006004b000003430000613d000000000771034f0000000306600210000000000805043300000000086801cf000000000868022f000000000707043b0000010006600089000000000767022f00000000066701cf000000000686019f0000000000650435000000000003001f0000000100200190000003680000613d0000001f01400039000000600110018f00000006040000290000000002410019000200000002001d000000400020043f000000200030008c000000560000413d0000000002040433000000000002004b0000000003000039000000010300c039000000000032004b000000560000c13d000000000002004b000003740000c13d00000005010000290006013f0010019c000002c00000613d00000160010000410000000202000029000000000012043500000004012000390000000602000029000000000021043500000000010004140000000302000029000000040020008c000003bb0000c13d0000000003000031000000200030008c00000020040000390000000004034019000003e60000013d0000001f0530018f0000013e06300198000000400200043d0000000004620019000002600000613d000000000701034f0000000008020019000000007907043c0000000008980436000000000048004b0000036f0000c13d000002600000013d0000015f020000410000000203000029000000000023043500000004023000390000000403000029000000000032043500000000020004140000000003000411000000040030008c0000038a0000c13d0000000202100029000600000002001d000000400020043f00000002020000290000000002020433000100000002001d0000013f0020009c000000560000213d000000010000006b000004380000c13d000200060000002d000003560000013d0000013c0020009c0000013c02008041000000c0012002100000000202000029000200000002001d0000004002200210000000000112019f0000015d011001c7000000000200041104ea04e50000040f00000060031002700000013c03300197000000200030008c000000200400003900000000040340190000001f0640018f00000020074001900000000205700029000003a30000613d000000000801034f0000000209000029000000008a08043c0000000009a90436000000000059004b0000039f0000c13d000000000006004b000003b00000613d000000000771034f0000000306600210000000000805043300000000086801cf000000000868022f000000000707043b0000010006600089000000000767022f00000000066701cf000000000686019f0000000000650435000000000003001f0000000100200190000003f10000613d0000001f01400039000000600110018f0000000202100029000600000002001d000000400020043f000000200030008c000000560000413d000003810000013d0000000202000029000200000002001d0000013c0020009c0000013c0200804100000040022002100000013c0010009c0000013c01008041000000c001100210000000000121019f0000015d011001c7000000030200002904ea04e50000040f00000060031002700000013c03300197000000200030008c000000200400003900000000040340190000001f0640018f00000020074001900000000205700029000003d60000613d000000000801034f0000000209000029000000008a08043c0000000009a90436000000000059004b000003d20000c13d000000000006004b000003e30000613d000000000771034f0000000306600210000000000805043300000000086801cf000000000868022f000000000707043b0000010006600089000000000767022f00000000066701cf000000000686019f0000000000650435000000000003001f0000000100200190000004470000613d0000001f01400039000000600110018f0000000201100029000001650010009c000003fd0000a13d0000016701000041000000000010043f0000004101000039000000040010043f0000015d01000041000004ec000104300000001f0530018f0000013e06300198000000400200043d0000000004620019000002600000613d000000000701034f0000000008020019000000007907043c0000000008980436000000000048004b000003f80000c13d000002600000013d000000400010043f000000200030008c000000560000413d00000002010000290000000001010433000000000001004b000002c00000c13d000001610100004100000000001004430000000301000029000000040010044300000000010004140000013c0010009c0000013c01008041000000c00110021000000162011001c7000080020200003904ea04e50000040f0000000100200190000004b80000613d000000000101043b000000000001004b0000000402000029000000560000613d000000400300043d0000002401300039000000000021043500000166010000410000000000130435000500000003001d00000004013000390000000602000029000000000021043500000000010004140000000302000029000000040020008c000004310000613d00000005020000290000013c0020009c0000013c0200804100000040022002100000013c0010009c0000013c01008041000000c001100210000000000121019f00000155011001c7000000030200002904ea04e00000040f00000060031002700000013c0030019d0000000100200190000004c50000613d0000000501000029000001650010009c000003eb0000213d0000000501000029000000400010043f0000000001000019000004eb0001042e00000160020000410000000603000029000000000023043500000004023000390000000103000029000000000032043500000000020004140000000303000029000000040030008c000004530000c13d0000000601100029000200000001001d000000400010043f0000000402000029000004840000013d0000001f0530018f0000013e06300198000000400200043d0000000004620019000002600000613d000000000701034f0000000008020019000000007907043c0000000008980436000000000048004b0000044e0000c13d000002600000013d0000013c0020009c0000013c02008041000000c0012002100000000602000029000600000002001d0000004002200210000000000112019f0000015d011001c7000000030200002904ea04e50000040f00000060031002700000013c03300197000000200030008c000000200400003900000000040340190000001f0640018f000000200740019000000006057000290000046c0000613d000000000801034f0000000609000029000000008a08043c0000000009a90436000000000059004b000004680000c13d000000000006004b000004790000613d000000000771034f0000000306600210000000000805043300000000086801cf000000000868022f000000000707043b0000010006600089000000000767022f00000000066701cf000000000686019f0000000000650435000000000003001f0000000100200190000004b90000613d0000001f01400039000000600110018f0000000601100029000200000001001d000000400010043f000000200030008c0000000402000029000000560000413d00000006010000290000000001010433000000000021004b000003560000c13d000001610100004100000000001004430000000301000029000000040010044300000000010004140000013c0010009c0000013c01008041000000c00110021000000162011001c7000080020200003904ea04e50000040f0000000100200190000004b80000613d000000000101043b000000000001004b000000560000613d000000400200043d00000163010000410000000000120435000200000002001d00000004012000390000000102000029000000000021043500000000010004140000000302000029000000040020008c000004b20000613d00000002020000290000013c0020009c0000013c0200804100000040022002100000013c0010009c0000013c01008041000000c001100210000000000121019f0000015d011001c7000000030200002904ea04e00000040f00000060031002700000013c0030019d0000000100200190000004d20000613d0000000201000029000001640010009c000003eb0000813d0000000201000029000000400010043f000003560000013d000000000001042f0000001f0530018f0000013e06300198000000400200043d0000000004620019000002600000613d000000000701034f0000000008020019000000007907043c0000000008980436000000000048004b000004c00000c13d000002600000013d0000013c033001970000001f0530018f0000013e06300198000000400200043d0000000004620019000002600000613d000000000701034f0000000008020019000000007907043c0000000008980436000000000048004b000004cd0000c13d000002600000013d0000013c033001970000001f0530018f0000013e06300198000000400200043d0000000004620019000002600000613d000000000701034f0000000008020019000000007907043c0000000008980436000000000048004b000004da0000c13d000002600000013d000000000001042f000004e3002104210000000102000039000000000001042d0000000002000019000000000001042d000004e8002104230000000102000039000000000001042d0000000002000019000000000001042d000004ea00000432000004eb0001042e000004ec0001043000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffff00000000000000000000000000000000000000000000000000000001ffffffe000000000000000000000000000000000000000000000000000000000ffffffe0000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffff00cdbb7acffe582512e911743a6b3ee147b4abd6c8d10817f3f2f48972e6c109540000000200000000000000000000000000000040000001000000000000000000000000000000000000000000000000000000000000000000000000008129fc1b00000000000000000000000000000000000000000000000000000000dd898b2e00000000000000000000000000000000000000000000000000000000dd898b2f00000000000000000000000000000000000000000000000000000000ed022ebd000000000000000000000000000000000000000000000000000000008129fc1c000000000000000000000000000000000000000000000000000000008ce516da0000000000000000000000000000000000000000000000000000000016c38b3c000000000000000000000000000000000000000000000000000000005c975abb000000000000000000000000000000000000000000000000000000005d1ca6310000000000000000000000000000000000000020000000800000000000000000c36dd7ea00000000000000000000000000000000000000000000000000000000241ecf16d79d0f8dbfb92cbc07fe17840425976cf0667f022fe9877caa831b080000000000000000000000000000000000000044000000800000000000000000ffffffffffffffffffffff0000000000000000000000000000000000000000ffa4b914810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000161a64a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004400000000000000000000000053e41c1e00000000000000000000000000000000000000000000000000000000b31775265933e5e6f3b2d519a9dcdfa71b65581e94932ab3a3e5108d0bd44c34000000000000000000000000000000000000002400000080000000000000000008c379a000000000000000000000000000000000000000000000000000000000496e636f727265637420746f6b656e20636f6e74726163740000000000000000000000000000000000000000000000000000006400000000000000000000000021ca133936d4563655fffbb8a80562871d737bffbe741fdcca6f8efef7a2463700000000000000000000000000000000000000240000000000000000000000004f558e79000000000000000000000000000000000000000000000000000000006352211e00000000000000000000000000000000000000000000000000000000783957ae000000000000000000000000000000000000000000000000000000001806aa1896bbf26568e884a7374b41e002500962caba6a15023a8d90e8508b830200000200000000000000000000000000000024000000000000000000000000676d3d4f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000ffffffffffffffff73db153e000000000000000000000000000000000000000000000000000000004e487b7100000000000000000000000000000000000000000000000000000000476967614e616d654e4654206e6f742072656769737465726564000000000000fc425f2263d0df187444b70e47283d622c70181c5baebb1306a01edba1ce184c5c975abb000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000800000000000000000000000000000000000000000000000000000002000000000000000000000000065d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a020000000000000000000000000000000000002000000000000000000000000062e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2585db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa5061757361626c653a206e6f7420706175736564000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000000e1063eabfc54a0b8ebfed394e9fae659fa03d1cbe63a66f13742ad6bf5f2dd4
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
00000000000000000000000074eb92b33f2400eb14f6d6725b14f76078d5e731
-----Decoded View---------------
Arg [0] : gameRegistryAddress (address): 0x74eb92b33f2400EB14F6D6725B14F76078d5E731
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 00000000000000000000000074eb92b33f2400eb14f6d6725b14f76078d5e731
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 31 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
[ Download: CSV Export ]
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.