Contract 0x3C2e532a334149D6a2E43523f2427e2fA187c5f0 1
My Name Tag:
Not Available
TokenTracker:
[ Download CSV Export ]
OVERVIEW
Welcome to the world of Pirate Nation!Join a new type of blockchain game on the high seas. Build your ship, recruit your crew, and battle your way across the isles to become the top pirate! What say ye, matey?
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0x71BD13EF8f3D63F6924f48b6806D7000A355B353 The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
GoldToken
Compiler Version
v0.8.13+commit.abaa5c0e
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity >=0.6.0; /** * @title The ERC-2771 Recipient Base Abstract Class - Declarations * * @notice A contract must implement this interface in order to support relayed transaction. * * @notice It is recommended that your contract inherits from the ERC2771Recipient contract. */ abstract contract IERC2771Recipient { /** * :warning: **Warning** :warning: The Forwarder can have a full control over your Recipient. Only trust verified Forwarder. * @param forwarder The address of the Forwarder contract that is being used. * @return isTrustedForwarder `true` if the Forwarder is trusted to forward relayed transactions by this Recipient. */ function isTrustedForwarder(address forwarder) public virtual view returns(bool); /** * @notice Use this method the contract anywhere instead of msg.sender to support relayed transactions. * @return sender The real sender of this call. * For a call that came through the Forwarder the real sender is extracted from the last 20 bytes of the `msg.data`. * Otherwise simply returns `msg.sender`. */ function _msgSender() internal virtual view returns (address); /** * @notice Use this method in the contract instead of `msg.data` when difference matters (hashing, signature, etc.) * @return data The real `msg.data` of this call. * For a call that came through the Forwarder, the real sender address was appended as the last 20 bytes * of the `msg.data` - so this method will strip those 20 bytes off. * Otherwise (if the call was made directly and not through the forwarder) simply returns `msg.data`. */ function _msgData() internal virtual view returns (bytes calldata); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { _checkOwner(); _; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { require(owner() == _msgSender(), "Ownable: caller is not the owner"); } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.0; import "./IERC20.sol"; import "./extensions/IERC20Metadata.sol"; import "../../utils/Context.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ function transferFrom( address from, address to, uint256 amount ) public virtual override returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, allowance(owner, spender) + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { address owner = _msgSender(); uint256 currentAllowance = allowance(owner, spender); require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `from` to `to`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. */ function _transfer( address from, address to, uint256 amount ) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(from, to, amount); uint256 fromBalance = _balances[from]; require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[from] = fromBalance - amount; // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by // decrementing then incrementing. _balances[to] += amount; } emit Transfer(from, to, amount); _afterTokenTransfer(from, to, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; unchecked { // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above. _balances[account] += amount; } emit Transfer(address(0), account, amount); _afterTokenTransfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; // Overflow not possible: amount <= accountBalance <= totalSupply. _totalSupply -= amount; } emit Transfer(account, address(0), amount); _afterTokenTransfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Updates `owner` s allowance for `spender` based on spent `amount`. * * Does not update the allowance amount in case of infinite allowance. * Revert if not enough allowance is available. * * Might emit an {Approval} event. */ function _spendAllowance( address owner, address spender, uint256 amount ) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { require(currentAllowance >= amount, "ERC20: insufficient allowance"); unchecked { _approve(owner, spender, currentAllowance - amount); } } } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); }
// 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/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 pragma solidity ^0.8.13; import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import {IERC20BeforeTokenTransferHandler} from "./IERC20BeforeTokenTransferHandler.sol"; /** * ERC20 BeforeTokenTransferHandler allows you to add a before token transfer handler * which can be used to add additional logic to the before token transfer hook. */ abstract contract ERC20BeforeTokenTransferHandler is Ownable, ERC20 { /// @notice Reference to the handler contract for transfer hooks address public beforeTokenTransferHandler; /** * Sets the after token transfer handler * * @param handlerAddress Address to the transfer hook handler contract */ function setBeforeTokenTransferHandler( address handlerAddress ) external onlyOwner { beforeTokenTransferHandler = handlerAddress; } /** * @notice Handles any after-transfer actions * @inheritdoc ERC20 */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual override { if (beforeTokenTransferHandler != address(0)) { IERC20BeforeTokenTransferHandler handlerRef = IERC20BeforeTokenTransferHandler( beforeTokenTransferHandler ); handlerRef.beforeTokenTransfer( address(this), _msgSender(), from, to, amount ); } super._beforeTokenTransfer(from, to, amount); } }
// SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.9; interface IERC20BeforeTokenTransferHandler { /** * Handles before token transfer events from a ERC721 contract */ function beforeTokenTransfer( address tokenContract, address operator, address from, address to, uint256 amount ) external; }
// SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.9; // Used for calculating decimal-point percentages (10000 = 100%) uint256 constant PERCENTAGE_RANGE = 10000; // Pauser Role - Can pause the game bytes32 constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); // Minter Role - Can mint items, NFTs, and ERC20 currency bytes32 constant MINTER_ROLE = keccak256("MINTER_ROLE"); // Manager Role - Can manage the shop, loot tables, and other game data bytes32 constant MANAGER_ROLE = keccak256("MANAGER_ROLE"); // Game Logic Contract - Contract that executes game logic and accesses other systems bytes32 constant GAME_LOGIC_CONTRACT_ROLE = keccak256( "GAME_LOGIC_CONTRACT_ROLE" ); // Game Currency Contract - Allowlisted currency ERC20 contract bytes32 constant GAME_CURRENCY_CONTRACT_ROLE = keccak256( "GAME_CURRENCY_CONTRACT_ROLE" ); // Game NFT Contract - Allowlisted game NFT ERC721 contract bytes32 constant GAME_NFT_CONTRACT_ROLE = keccak256("GAME_NFT_CONTRACT_ROLE"); // Game Items Contract - Allowlist game items ERC1155 contract bytes32 constant GAME_ITEMS_CONTRACT_ROLE = keccak256( "GAME_ITEMS_CONTRACT_ROLE" ); // Depositor role - used by Polygon bridge to mint on child chain bytes32 constant DEPOSITOR_ROLE = keccak256("DEPOSITOR_ROLE"); // Randomizer role - Used by the randomizer contract to callback bytes32 constant RANDOMIZER_ROLE = keccak256("RANDOMIZER_ROLE"); // Trusted forwarder role - Used by meta transactions to verify trusted forwader(s) bytes32 constant TRUSTED_FORWARDER_ROLE = keccak256("TRUSTED_FORWARDER_ROLE"); // ===== // All of the possible traits in the system // ===== /// @dev Trait that points to another token/template id uint256 constant TEMPLATE_ID_TRAIT_ID = uint256(keccak256("template_id")); // Generation of a token uint256 constant GENERATION_TRAIT_ID = uint256(keccak256("generation")); // XP for a token uint256 constant XP_TRAIT_ID = uint256(keccak256("xp")); // Current level of a token uint256 constant LEVEL_TRAIT_ID = uint256(keccak256("level")); // Whether or not a token is a pirate uint256 constant IS_PIRATE_TRAIT_ID = uint256(keccak256("is_pirate")); // Whether or not a token is a ship uint256 constant IS_SHIP_TRAIT_ID = uint256(keccak256("is_ship")); // Whether or not an item is equippable on ships uint256 constant EQUIPMENT_TYPE_TRAIT_ID = uint256(keccak256("equipment_type")); // Item slots uint256 constant ITEM_SLOTS_TRAIT_ID = uint256(keccak256("item_slots")); // Rank of the ship uint256 constant SHIP_RANK_TRAIT_ID = uint256(keccak256("ship_rank")); // Current Health trait uint256 constant CURRENT_HEALTH_TRAIT_ID = uint256(keccak256("current_health")); // Health trait uint256 constant HEALTH_TRAIT_ID = uint256(keccak256("health")); // Damage trait uint256 constant DAMAGE_TRAIT_ID = uint256(keccak256("damage")); // Speed trait uint256 constant SPEED_TRAIT_ID = uint256(keccak256("speed")); // Accuracy trait uint256 constant ACCURACY_TRAIT_ID = uint256(keccak256("accuracy")); // Evasion trait uint256 constant EVASION_TRAIT_ID = uint256(keccak256("evasion")); // Image hash of token's image, used for verifiable / fair drops uint256 constant IMAGE_HASH_TRAIT_ID = uint256(keccak256("image_hash")); // Name of a token uint256 constant NAME_TRAIT_ID = uint256(keccak256("name_trait")); // Description of a token uint256 constant DESCRIPTION_TRAIT_ID = uint256(keccak256("description_trait")); // General rarity for a token (corresponds to IGameRarity) uint256 constant RARITY_TRAIT_ID = uint256(keccak256("rarity")); // The character's affinity for a specific element uint256 constant ELEMENTAL_AFFINITY_TRAIT_ID = uint256( keccak256("affinity_id") ); // Boss start time trait uint256 constant BOSS_START_TIME_TRAIT_ID = uint256( keccak256("boss_start_time") ); // Boss end time trait uint256 constant BOSS_END_TIME_TRAIT_ID = uint256(keccak256("boss_end_time")); // Boss type trait uint256 constant BOSS_TYPE_TRAIT_ID = uint256(keccak256("boss_type")); // The character's dice rolls uint256 constant DICE_ROLL_1_TRAIT_ID = uint256(keccak256("dice_roll_1")); uint256 constant DICE_ROLL_2_TRAIT_ID = uint256(keccak256("dice_roll_2")); // The character's star sign (astrology) uint256 constant STAR_SIGN_TRAIT_ID = uint256(keccak256("star_sign")); // Image for the token uint256 constant IMAGE_TRAIT_ID = uint256(keccak256("image_trait")); // How much energy the token provides if used uint256 constant ENERGY_PROVIDED_TRAIT_ID = uint256( keccak256("energy_provided") ); // Whether a given token is soulbound, meaning it is unable to be transferred uint256 constant SOULBOUND_TRAIT_ID = uint256(keccak256("soulbound")); // ------ // Avatar Profile Picture related traits // If an avatar is a 1 of 1, this is their only trait uint256 constant PROFILE_IS_LEGENDARY_TRAIT_ID = uint256( keccak256("profile_is_legendary") ); // Avatar's archetype -- possible values: Human (including Druid, Mage, Berserker, Crusty), Robot, Animal, Zombie, Vampire, Ghost uint256 constant PROFILE_CHARACTER_TYPE = uint256( keccak256("profile_character_type") ); // Avatar's profile picture's background image uint256 constant PROFILE_BACKGROUND_TRAIT_ID = uint256( keccak256("profile_background") ); // Avatar's eye style uint256 constant PROFILE_EYES_TRAIT_ID = uint256(keccak256("profile_eyes")); // Avatar's facial hair type uint256 constant PROFILE_FACIAL_HAIR_TRAIT_ID = uint256( keccak256("profile_facial_hair") ); // Avatar's hair style uint256 constant PROFILE_HAIR_TRAIT_ID = uint256(keccak256("profile_hair")); // Avatar's skin color uint256 constant PROFILE_SKIN_TRAIT_ID = uint256(keccak256("profile_skin")); // Avatar's coat color uint256 constant PROFILE_COAT_TRAIT_ID = uint256(keccak256("profile_coat")); // Avatar's earring(s) type uint256 constant PROFILE_EARRING_TRAIT_ID = uint256( keccak256("profile_facial_hair") ); // Avatar's eye covering uint256 constant PROFILE_EYE_COVERING_TRAIT_ID = uint256( keccak256("profile_eye_covering") ); // Avatar's headwear uint256 constant PROFILE_HEADWEAR_TRAIT_ID = uint256( keccak256("profile_headwear") ); // Avatar's (Mages only) gem color uint256 constant PROFILE_MAGE_GEM_TRAIT_ID = uint256( keccak256("profile_mage_gem") );
// SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.9; import "@openzeppelin/contracts/access/Ownable.sol"; import "@opengsn/contracts/src/interfaces/IERC2771Recipient.sol"; import {IGameRegistry} from "./interfaces/IGameRegistry.sol"; import {ISystem} from "./interfaces/ISystem.sol"; import {TRUSTED_FORWARDER_ROLE} from "./Constants.sol"; import {ITraitsProvider, ID as TRAITS_PROVIDER_ID} from "./interfaces/ITraitsProvider.sol"; import {ILockingSystem, ID as LOCKING_SYSTEM_ID} from "./locking/ILockingSystem.sol"; import {IRandomizer, IRandomizerCallback, ID as RANDOMIZER_ID} from "./randomizer/IRandomizer.sol"; import {ILootSystem, ID as LOOT_SYSTEM_ID} from "./loot/ILootSystem.sol"; /** @title Contract that lets a child contract access the GameRegistry contract */ abstract contract GameRegistryConsumer is ISystem, Ownable, IERC2771Recipient, IRandomizerCallback { /// @notice Whether or not the contract is paused bool private _paused; /// @notice Id for the system/component uint256 private _id; /// @notice Read access contract IGameRegistry private _gameRegistry; /** EVENTS **/ /// @dev Emitted when the pause is triggered by `account`. event Paused(address account); /// @dev Emitted when the pause is lifted by `account`. event Unpaused(address account); /** ERRORS **/ /// @notice Not authorized to perform action error MissingRole(address account, bytes32 expectedRole); /** MODIFIERS **/ // Modifier to verify a user has the appropriate role to call a given function modifier onlyRole(bytes32 role) { _checkRole(role, _msgSender()); _; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { _requireNotPaused(); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { _requirePaused(); _; } /** ERRORS **/ /// @notice gameRegistryAddress does not implement IGameRegistry error InvalidGameRegistry(); /** SETUP **/ /** Sets the GameRegistry contract address for this contract */ constructor(address gameRegistryAddress, uint256 id) { _gameRegistry = IGameRegistry(gameRegistryAddress); _id = id; if (gameRegistryAddress == address(0)) { revert InvalidGameRegistry(); } _paused = true; } /** EXTERNAL **/ /** @return ID for this system */ function getId() public view override returns (uint256) { return _id; } /** * Pause/Unpause the contract * * @param shouldPause Whether or pause or unpause */ function setPaused(bool shouldPause) external onlyOwner { if (shouldPause) { _pause(); } else { _unpause(); } } /** * @dev Returns true if the contract OR the GameRegistry is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused || _gameRegistry.paused(); } /** * Sets the GameRegistry contract address for this contract * * @param gameRegistryAddress Address for the GameRegistry contract */ function setGameRegistry(address gameRegistryAddress) external onlyOwner { _gameRegistry = IGameRegistry(gameRegistryAddress); if (gameRegistryAddress == address(0)) { revert InvalidGameRegistry(); } } /** @return GameRegistry contract for this contract */ function getGameRegistry() external view returns (IGameRegistry) { return _gameRegistry; } /** * @dev Returns `true` if `account` has been granted `role`. */ function _hasAccessRole(bytes32 role, address account) internal view returns (bool) { return _gameRegistry.hasAccessRole(role, account); } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) virtual internal view { if (!_gameRegistry.hasAccessRole(role, account)) { revert MissingRole(account, role); } } /** Returns the traits provider for this contract */ function _traitsProvider() internal view returns (ITraitsProvider) { return ITraitsProvider(_getSystem(TRAITS_PROVIDER_ID)); } /** @return Interface to the LockingSystem */ function _lockingSystem() internal view returns (ILockingSystem) { return ILockingSystem(_gameRegistry.getSystem(LOCKING_SYSTEM_ID)); } /** @return Interface to the LootSystem */ function _lootSystem() internal view returns (ILootSystem) { return ILootSystem(_gameRegistry.getSystem(LOOT_SYSTEM_ID)); } /** @return Interface to the Randomizer */ function _randomizer() internal view returns (IRandomizer) { return IRandomizer(_gameRegistry.getSystem(RANDOMIZER_ID)); } /** @return Address for a given system */ function _getSystem(uint256 systemId) internal view returns (address) { return _gameRegistry.getSystem(systemId); } /** * Requests randomness from the game's Randomizer contract * * @param numWords Number of words to request from the VRF * * @return Id of the randomness request */ function _requestRandomWords(uint32 numWords) internal returns (uint256) { return _randomizer().requestRandomWords( IRandomizerCallback(this), numWords ); } /** * Callback for when a random number request has returned with random words * * @param requestId Id of the request * @param randomWords Random words */ function fulfillRandomWordsCallback( uint256 requestId, uint256[] memory randomWords ) external virtual override { // Do nothing by default } /** * Returns the Player address for the Operator account * @param operatorAccount address of the Operator account to retrieve the player for */ function _getPlayerAccount(address operatorAccount) internal view returns (address playerAccount) { return _gameRegistry.getPlayerAccount(operatorAccount); } /// @inheritdoc IERC2771Recipient function isTrustedForwarder(address forwarder) public view virtual override returns (bool) { return address(_gameRegistry) != address(0) && _hasAccessRole(TRUSTED_FORWARDER_ROLE, forwarder); } /** INTERNAL **/ /// @inheritdoc IERC2771Recipient function _msgSender() internal view virtual override(Context, IERC2771Recipient) returns (address ret) { if (msg.data.length >= 20 && isTrustedForwarder(msg.sender)) { assembly { ret := shr(96, calldataload(sub(calldatasize(), 20))) } } else { ret = msg.sender; } } /// @inheritdoc IERC2771Recipient function _msgData() internal view virtual override(Context, IERC2771Recipient) returns (bytes calldata ret) { if (msg.data.length >= 20 && isTrustedForwarder(msg.sender)) { return msg.data[0:msg.data.length - 20]; } else { return msg.data; } } /** PAUSABLE **/ /** * @dev Throws if the contract is paused. */ function _requireNotPaused() internal view virtual { require(!paused(), "Pausable: paused"); } /** * @dev Throws if the contract is not paused. */ function _requirePaused() internal view virtual { require(paused(), "Pausable: not paused"); } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual { require(_paused == false, "Pausable: not paused"); _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual { require(_paused == true, "Pausable: not paused"); _paused = false; emit Unpaused(_msgSender()); } }
// SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.9; import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; // @title Interface the game's ACL / Management Layer interface IGameRegistry is IERC165 { /** * @dev Returns `true` if `account` has been granted `role`. */ function hasAccessRole(bytes32 role, address account) external view returns (bool); /** @return Whether or not the registry is paused */ function paused() external view returns (bool); /** * Registers a system by id * * @param systemId Id of the system * @param systemAddress Address of the system contract */ function registerSystem(uint256 systemId, address systemAddress) external; /** @return System based on an id */ function getSystem(uint256 systemId) external view returns (address); /** @return Authorized Player account for an address * @param operatorAddress Address of the Operator account */ function getPlayerAccount(address operatorAddress) external view returns (address); }
// SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.9; import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; /** * Defines a system the game engine */ interface ISystem { /** @return The ID for the system. Ex: a uint256 casted keccak256 hash */ function getId() external view returns (uint256); }
// SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.9; import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; uint256 constant ID = uint256(keccak256("game.piratenation.traitsprovider")); // Enum describing how the trait can be modified enum TraitBehavior { NOT_INITIALIZED, // Trait has not been initialized UNRESTRICTED, // Trait can be changed unrestricted IMMUTABLE, // Trait can only be set once and then never changed INCREMENT_ONLY, // Trait can only be incremented DECREMENT_ONLY // Trait can only be decremented } // Type of data to allow in the trait enum TraitDataType { NOT_INITIALIZED, // Trait has not been initialized INT, // int256 data type UINT, // uint256 data type BOOL, // bool data type STRING, // string data type INT_ARRAY, // int256 array data type UINT_ARRAY // uint256 array data type } // Holds metadata for a given trait type struct TraitMetadata { // Name of the trait, used in tokenURIs string name; // How the trait can be modified TraitBehavior behavior; // Trait type TraitDataType dataType; // Whether or not the trait is a top-level property and should not be in the attribute array bool isTopLevelProperty; // Whether or not the trait should be hidden from end-users bool hidden; } // Used to pass traits around for URI generation struct TokenURITrait { string name; bytes value; TraitDataType dataType; bool isTopLevelProperty; bool hidden; } /** @title Provides a set of traits to a set of ERC721/ERC1155 contracts */ interface ITraitsProvider is IERC165 { /** * Sets the value for the string trait of a token, also checks to make sure trait can be modified * * @param tokenContract Address of the token's contract * @param tokenId NFT tokenId or ERC1155 token type id * @param traitId Id of the trait to modify * @param value New value for the given trait */ function setTraitString( address tokenContract, uint256 tokenId, uint256 traitId, string calldata value ) external; /** * Sets several string traits for a given token * * @param tokenContract Address of the token's contract * @param tokenIds Ids of the token to set traits for * @param traitIds Ids of traits to set * @param values Values of traits to set */ function batchSetTraitString( address tokenContract, uint256[] calldata tokenIds, uint256[] calldata traitIds, string[] calldata values ) external; /** * Sets the value for the uint256 trait of a token, also checks to make sure trait can be modified * * @param tokenContract Address of the token's contract * @param tokenId NFT tokenId or ERC1155 token type id * @param traitId Id of the trait to modify * @param value New value for the given trait */ function setTraitUint256( address tokenContract, uint256 tokenId, uint256 traitId, uint256 value ) external; /** * Sets several uint256 traits for a given token * * @param tokenContract Address of the token's contract * @param tokenIds Ids of the token to set traits for * @param traitIds Ids of traits to set * @param values Values of traits to set */ function batchSetTraitUint256( address tokenContract, uint256[] calldata tokenIds, uint256[] calldata traitIds, uint256[] calldata values ) external; /** * Sets the value for the int256 trait of a token, also checks to make sure trait can be modified * * @param tokenContract Address of the token's contract * @param tokenId NFT tokenId or ERC1155 token type id * @param traitId Id of the trait to modify * @param value New value for the given trait */ function setTraitInt256( address tokenContract, uint256 tokenId, uint256 traitId, int256 value ) external; /** * Sets several int256 traits for a given token * * @param tokenContract Address of the token's contract * @param tokenIds Ids of the token to set traits for * @param traitIds Ids of traits to set * @param values Values of traits to set */ function batchSetTraitInt256( address tokenContract, uint256[] calldata tokenIds, uint256[] calldata traitIds, int256[] calldata values ) external; /** * Sets the value for the int256[] trait of a token, also checks to make sure trait can be modified * * @param tokenContract Address of the token's contract * @param tokenId NFT tokenId or ERC1155 token type id * @param traitId Id of the trait to modify * @param value New value for the given trait */ function setTraitInt256Array( address tokenContract, uint256 tokenId, uint256 traitId, int256[] calldata value ) external; /** * Sets the value for the uint256[] trait of a token, also checks to make sure trait can be modified * * @param tokenContract Address of the token's contract * @param tokenId NFT tokenId or ERC1155 token type id * @param traitId Id of the trait to modify * @param value New value for the given trait */ function setTraitUint256Array( address tokenContract, uint256 tokenId, uint256 traitId, uint256[] calldata value ) external; /** * Sets the value for the bool trait of a token, also checks to make sure trait can be modified * * @param tokenContract Address of the token's contract * @param tokenId NFT tokenId or ERC1155 token type id * @param traitId Id of the trait to modify * @param value New value for the given trait */ function setTraitBool( address tokenContract, uint256 tokenId, uint256 traitId, bool value ) external; /** * Sets several bool traits for a given token * * @param tokenContract Address of the token's contract * @param tokenIds Ids of the token to set traits for * @param traitIds Ids of traits to set * @param values Values of traits to set */ function batchSetTraitBool( address tokenContract, uint256[] calldata tokenIds, uint256[] calldata traitIds, bool[] calldata values ) external; /** * Increments the trait for a token by the given amount * * @param tokenContract Address of the token's contract * @param tokenId NFT tokenId or ERC1155 token type id * @param traitId Id of the trait to modify * @param amount Amount to increment trait by */ function incrementTrait( address tokenContract, uint256 tokenId, uint256 traitId, uint256 amount ) external; /** * Decrements the trait for a token by the given amount * * @param tokenContract Address of the token's contract * @param tokenId NFT tokenId or ERC1155 token type id * @param traitId Id of the trait to modify * @param amount Amount to decrement trait by */ function decrementTrait( address tokenContract, uint256 tokenId, uint256 traitId, uint256 amount ) external; /** * Returns the trait data for a given token * * @param tokenContract Address of the token's contract * @param tokenId NFT tokenId or ERC1155 token type id * * @return A struct containing all traits for the token */ function getTraitIds( address tokenContract, uint256 tokenId ) external view returns (uint256[] memory); /** * Retrieves a raw abi-encoded byte data for the given trait * * @param tokenContract Token contract (ERC721 or ERC1155) * @param tokenId Id of the NFT or token type * @param traitId Id of the trait to retrieve * * @return The value of the trait if it exists, reverts if the trait has not been set or is of a different type. */ function getTraitBytes( address tokenContract, uint256 tokenId, uint256 traitId ) external view returns (bytes memory); /** * Retrieves a int256 trait for the given token * * @param tokenContract Token contract (ERC721 or ERC1155) * @param tokenId Id of the NFT or token type * @param traitId Id of the trait to retrieve * * @return The value of the trait if it exists, reverts if the trait has not been set or is of a different type. */ function getTraitInt256( address tokenContract, uint256 tokenId, uint256 traitId ) external view returns (int256); /** * Retrieves a int256 array trait for the given token * * @param tokenContract Token contract (ERC721 or ERC1155) * @param tokenId Id of the NFT or token type * @param traitId Id of the trait to retrieve * * @return The value of the trait if it exists, reverts if the trait has not been set or is of a different type. */ function getTraitInt256Array( address tokenContract, uint256 tokenId, uint256 traitId ) external view returns (int256[] memory); /** * Retrieves a uint256 trait for the given token * * @param tokenContract Token contract (ERC721 or ERC1155) * @param tokenId Id of the NFT or token type * @param traitId Id of the trait to retrieve * * @return The value of the trait if it exists, reverts if the trait has not been set or is of a different type. */ function getTraitUint256( address tokenContract, uint256 tokenId, uint256 traitId ) external view returns (uint256); /** * Retrieves a uint256 array trait for the given token * * @param tokenContract Token contract (ERC721 or ERC1155) * @param tokenId Id of the NFT or token type * @param traitId Id of the trait to retrieve * * @return The value of the trait if it exists, reverts if the trait has not been set or is of a different type. */ function getTraitUint256Array( address tokenContract, uint256 tokenId, uint256 traitId ) external view returns (uint256[] memory); /** * Retrieves a bool trait for the given token * * @param tokenContract Token contract (ERC721 or ERC1155) * @param tokenId Id of the NFT or token type * @param traitId Id of the trait to retrieve * * @return The value of the trait if it exists, reverts if the trait has not been set or is of a different type. */ function getTraitBool( address tokenContract, uint256 tokenId, uint256 traitId ) external view returns (bool); /** * Retrieves a string trait for the given token * * @param tokenContract Token contract (ERC721 or ERC1155) * @param tokenId Id of the NFT or token type * @param traitId Id of the trait to retrieve * * @return The value of the trait if it exists, reverts if the trait has not been set or is of a different type. */ function getTraitString( address tokenContract, uint256 tokenId, uint256 traitId ) external view returns (string memory); /** * Returns whether or not the given token has a trait * * @param tokenContract Address of the token's contract * @param tokenId NFT tokenId or ERC1155 token type id * @param traitId Id of the trait to retrieve * * @return Whether or not the token has the trait */ function hasTrait( address tokenContract, uint256 tokenId, uint256 traitId ) external view returns (bool); /** * @param traitId Id of the trait to get metadata for * @return Metadata for the given trait */ function getTraitMetadata( uint256 traitId ) external view returns (TraitMetadata memory); /** * Generate a tokenURI based on a set of global properties and traits * * @param tokenContract Address of the token contract * @param tokenId Id of the token to generate traits for * * @return base64-encoded fully-formed tokenURI */ function generateTokenURI( address tokenContract, uint256 tokenId, TokenURITrait[] memory extraTraits ) external view returns (string memory); }
// SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.9; import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; uint256 constant ID = uint256(keccak256("game.piratenation.lockingsystem")); /// @title Interface for the LockingSystem that allows tokens to be locked by the game to prevent transfer interface ILockingSystem is IERC165 { /** * Whether or not an NFT is locked * * @param tokenContract Token contract address * @param tokenId Id of the token */ function isNFTLocked(address tokenContract, uint256 tokenId) external view returns (bool); /** * Amount of token locked in the system by a given owner * * @param account Token owner * @param tokenContract Token contract address * @param tokenId Id of the token * * @return Number of tokens locked */ function itemAmountLocked( address account, address tokenContract, uint256 tokenId ) external view returns (uint256); /** * Amount of tokens available for unlock * * @param account Token owner * @param tokenContract Token contract address * @param tokenId Id of the token * * @return Number of tokens locked */ function itemAmountUnlocked( address account, address tokenContract, uint256 tokenId ) external view returns (uint256); /** * Whether or not the given items can be transferred * * @param account Token owner * @param tokenContract Token contract address * @param ids Ids of the tokens * @param amounts Amounts of the tokens * * @return Whether or not the given items can be transferred */ function canTransferItems( address account, address tokenContract, uint256[] memory ids, uint256[] memory amounts ) external view returns (bool); /** * Lets the game add a reservation to a given NFT, this prevents the NFT from being unlocked * * @param tokenContract Token contract address * @param tokenId Token id to reserve * @param exclusive Whether or not the reservation is exclusive. Exclusive reservations prevent other reservations from using the tokens by removing them from the pool. * @param data Data determined by the reserver, can be used to identify the source of the reservation for display in UI */ function addNFTReservation( address tokenContract, uint256 tokenId, bool exclusive, uint32 data ) external returns (uint32); /** * Lets the game remove a reservation from a given token * * @param tokenContract Token contract * @param tokenId Id of the token * @param reservationId Id of the reservation to remove */ function removeNFTReservation( address tokenContract, uint256 tokenId, uint32 reservationId ) external; /** * Lets the game add a reservation to a given token, this prevents the token from being unlocked * * @param account Owner of the token to reserver * @param tokenContract Token contract address * @param tokenId Token id to reserve * @param amount Number of tokens to reserve (1 for NFTs, >=1 for ERC1155) * @param exclusive Whether or not the reservation is exclusive. Exclusive reservations prevent other reservations from using the tokens by removing them from the pool. * @param data Data determined by the reserver, can be used to identify the source of the reservation for display in UI */ function addItemReservation( address account, address tokenContract, uint256 tokenId, uint256 amount, bool exclusive, uint32 data ) external returns (uint32); /** * Lets the game remove a reservation from a given token * * @param account Owner to remove reservation from * @param tokenContract Token contract * @param tokenId Id of the token * @param reservationId Id of the reservation to remove */ function removeItemReservation( address account, address tokenContract, uint256 tokenId, uint32 reservationId ) external; }
// SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.9; import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; uint256 constant ID = uint256(keccak256("game.piratenation.lootsystem")); /// @title Interface for the LootSystem that gives player loot (tokens, XP, etc) for playing the game interface ILootSystem is IERC165 { // Type of loot enum LootType { UNDEFINED, ERC20, ERC721, ERC1155, LOOT_TABLE, CALLBACK } // Individual loot to grant struct Loot { // Type of fulfillment (ERC721, ERC1155, ERC20, LOOT_TABLE) LootType lootType; // Contract to grant tokens from address tokenContract; // Id of the token to grant (ERC1155/LOOT TABLE/CALLBACK types only) uint256 lootId; // Amount of token to grant (XP, ERC20, ERC1155) uint256 amount; } /** * Grants the given user loot(s), calls VRF to ensure it's truly random * * @param to Address to grant loot to * @param loots Loots to grant */ function grantLoot(address to, Loot[] calldata loots) external; /** * Grants the given user loot(s), calls VRF to ensure it's truly random * * @param to Address to grant loot to * @param loots Loots to grant * @param randomWord Optional random word to skip VRF callback if we already have words generated / are in a VRF callback */ function grantLootWithRandomWord( address to, Loot[] calldata loots, uint256 randomWord ) external; /** * Grants the given user loot(s) in batches. Presumes no randomness or loot tables * * @param to Address to grant loot to * @param loots Loots to grant * @param amount Amount of each loot to grant */ function batchGrantLootWithoutRandomness( address to, Loot[] calldata loots, uint8 amount ) external; /** * Validate that loots are properly formed. Reverts if the loots are not valid * * @param loots Loots to validate * @return needsVRF Whether or not the loots specified require VRF to generate */ function validateLoots( Loot[] calldata loots ) external view returns (bool needsVRF); }
// SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.9; import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; import {IRandomizerCallback} from "./IRandomizerCallback.sol"; uint256 constant ID = uint256(keccak256("game.piratenation.randomizer")); interface IRandomizer is IERC165 { /** * Starts a VRF random number request * * @param callbackAddress Address to callback with the random numbers * @param numWords Number of words to request from VRF * * @return requestId for the random number, will be passed to the callback contract */ function requestRandomWords( IRandomizerCallback callbackAddress, uint32 numWords ) external returns (uint256); }
// SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.9; import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; interface IRandomizerCallback { /** * Callback for when the Chainlink request returns * * @param requestId Id of the random word request * @param randomWords Random words that were generated by the VRF */ function fulfillRandomWordsCallback( uint256 requestId, uint256[] memory randomWords ) external; }
// SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.9; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import {MINTER_ROLE} from "../../Constants.sol"; import {IGoldToken, ID} from "./IGoldToken.sol"; import {GameRegistryConsumer} from "../../GameRegistryConsumer.sol"; import {ERC20BeforeTokenTransferHandler} from "@proofofplay/erc721-extensions/src/ERC20BeforeTokenTransferHandler.sol"; /** @title In-game Currency: Gold */ contract GoldToken is IGoldToken, GameRegistryConsumer, ERC20BeforeTokenTransferHandler { /** ERRORS **/ /// @notice Invalid params error InvalidParams(); constructor( address gameRegistryAddress ) ERC20("Pirate Gold", "PGLD") GameRegistryConsumer(gameRegistryAddress, ID) { // Do nothing } /** * Mint token to recipient * * @param to The recipient of the token * @param amount The amount of token to mint */ function mint( address to, uint256 amount ) external override whenNotPaused onlyRole(MINTER_ROLE) { _mint(to, amount); } /** * @dev No restriction for paused * Batch mint token to recipients * * @param toAddresses The recipients of the token * @param amounts The amounts of token to mint */ function batchMint( address[] calldata toAddresses, uint256[] calldata amounts ) external whenNotPaused onlyRole(MINTER_ROLE) { if (toAddresses.length != amounts.length) { revert InvalidParams(); } for (uint256 i = 0; i < toAddresses.length; i++) { _mint(toAddresses[i], amounts[i]); } } /** * Burn token from holder * * @param from The holder of the token * @param amount The amount of token to burn */ function burn( address from, uint256 amount ) external override whenNotPaused onlyRole(MINTER_ROLE) { _burn(from, amount); } /** * @inheritdoc ERC20 * @dev Note: minters can also move currency around to allow in-game actions. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override(ERC20, IERC20) returns (bool) { // Minters can move currency around to enable gameplay if (_hasAccessRole(MINTER_ROLE, _msgSender())) { // Note this avoids events _transfer(sender, recipient, amount); return true; } // Normal ERC20 security flow (need approval, etc.) return super.transferFrom(sender, recipient, amount); } /** * Message sender override to get Context to work with meta transactions * */ function _msgSender() internal view override(Context, GameRegistryConsumer) returns (address) { return GameRegistryConsumer._msgSender(); } /** * Message data override to get Context to work with meta transactions * */ function _msgData() internal view override(Context, GameRegistryConsumer) returns (bytes memory) { return GameRegistryConsumer._msgData(); } }
// SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.9; import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; import {IGameCurrency} from "../IGameCurrency.sol"; uint256 constant ID = uint256(keccak256("game.piratenation.goldtoken")); interface IGoldToken is IGameCurrency {}
// SPDX-License-Identifier: MIT LICENSE pragma solidity ^0.8.9; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; /** * @title Interface for a in-game currency, based off of ERC20 */ interface IGameCurrency is IERC20 { function mint(address to, uint256 amount) external; function burn(address from, uint256 amount) external; }
{ "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "metadata": { "useLiteralContent": true }, "libraries": {} }
[{"inputs":[{"internalType":"address","name":"gameRegistryAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidGameRegistry","type":"error"},{"inputs":[],"name":"InvalidParams","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"expectedRole","type":"bytes32"}],"name":"MissingRole","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"toAddresses","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"name":"batchMint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"beforeTokenTransferHandler","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"requestId","type":"uint256"},{"internalType":"uint256[]","name":"randomWords","type":"uint256[]"}],"name":"fulfillRandomWordsCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getGameRegistry","outputs":[{"internalType":"contract IGameRegistry","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"forwarder","type":"address"}],"name":"isTrustedForwarder","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"handlerAddress","type":"address"}],"name":"setBeforeTokenTransferHandler","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"gameRegistryAddress","type":"address"}],"name":"setGameRegistry","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"shouldPause","type":"bool"}],"name":"setPaused","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Deployed Bytecode
0x608060405234801561001057600080fd5b506004361061018e5760003560e01c806368573107116100de578063a457c2d711610097578063dd898b2f11610071578063dd898b2f1461034c578063eb0c3a151461035f578063ed022ebd14610372578063f2fde38b1461038357600080fd5b8063a457c2d714610313578063a9059cbb14610326578063dd62ed3e1461033957600080fd5b806368573107146102a357806370a08231146102b6578063715018a6146102df5780638da5cb5b146102e757806395d89b41146102f85780639dc29fac1461030057600080fd5b8063313ce5671161014b578063572b6c0511610125578063572b6c05146102555780635c975abb146102685780635d1ca631146102705780636838c0621461027857600080fd5b8063313ce56714610220578063395093511461022f57806340c10f191461024257600080fd5b806306c1cb911461019357806306fdde03146101a7578063095ea7b3146101c557806316c38b3c146101e857806318160ddd146101fb57806323b872dd1461020d575b600080fd5b6101a56101a1366004611287565b5050565b005b6101af610396565b6040516101bc9190611351565b60405180910390f35b6101d86101d33660046113c2565b610428565b60405190151581526020016101bc565b6101a56101f63660046113fa565b61044a565b6005545b6040519081526020016101bc565b6101d861021b366004611417565b61046b565b604051601281526020016101bc565b6101d861023d3660046113c2565b6104b9565b6101a56102503660046113c2565b6104e5565b6101d8610263366004611453565b61051c565b6101d8610564565b6001546101ff565b60085461028b906001600160a01b031681565b6040516001600160a01b0390911681526020016101bc565b6101a56102b13660046114ba565b6105f4565b6101ff6102c4366004611453565b6001600160a01b031660009081526003602052604090205490565b6101a56106a4565b6000546001600160a01b031661028b565b6101af6106b8565b6101a561030e3660046113c2565b6106c7565b6101d86103213660046113c2565b6106f4565b6101d86103343660046113c2565b61078a565b6101ff610347366004611526565b6107a2565b6101a561035a366004611453565b6107cd565b6101a561036d366004611453565b610810565b6002546001600160a01b031661028b565b6101a5610391366004611453565b61083a565b6060600680546103a590611559565b80601f01602080910402602001604051908101604052809291908181526020018280546103d190611559565b801561041e5780601f106103f35761010080835404028352916020019161041e565b820191906000526020600020905b81548152906001019060200180831161040157829003601f168201915b5050505050905090565b6000806104336108de565b90506104408185856108e8565b5060019392505050565b610452610a0c565b801561046357610460610a85565b50565b610460610b2f565b600061048c60008051602061160e8339815191526104876108de565b610bba565b156104a45761049c848484610c30565b5060016104b2565b6104af848484610de8565b90505b9392505050565b6000806104c46108de565b90506104408185856104d685896107a2565b6104e091906115a9565b6108e8565b6104ed610e0b565b60008051602061160e83398151915261050d816105086108de565b610e53565b6105178383610ef6565b505050565b6002546000906001600160a01b03161580159061055e575061055e7fd3df22cd6a774f62b0ae21ffd602cc92e7f3390518eee8b33307fc70380da7d283610bba565b92915050565b60008054600160a01b900460ff16806105ef5750600260009054906101000a90046001600160a01b03166001600160a01b0316635c975abb6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156105cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105ef91906115c1565b905090565b6105fc610e0b565b60008051602061160e833981519152610617816105086108de565b83821461063757604051635435b28960e11b815260040160405180910390fd5b60005b8481101561069c5761068a868683818110610657576106576115de565b905060200201602081019061066c9190611453565b85858481811061067e5761067e6115de565b90506020020135610ef6565b80610694816115f4565b91505061063a565b505050505050565b6106ac610a0c565b6106b66000610fc3565b565b6060600780546103a590611559565b6106cf610e0b565b60008051602061160e8339815191526106ea816105086108de565b6105178383611013565b6000806106ff6108de565b9050600061070d82866107a2565b9050838110156107725760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084015b60405180910390fd5b61077f82868684036108e8565b506001949350505050565b6000806107956108de565b9050610440818585610c30565b6001600160a01b03918216600090815260046020908152604080832093909416825291909152205490565b6107d5610a0c565b600280546001600160a01b0319166001600160a01b0383169081179091556104605760405163a4b9148160e01b815260040160405180910390fd5b610818610a0c565b600880546001600160a01b0319166001600160a01b0392909216919091179055565b610842610a0c565b6001600160a01b0381166108a75760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610769565b61046081610fc3565b6000601436108015906108c757506108c73361051c565b156108d9575060131936013560601c90565b503390565b60006105ef6108b0565b6001600160a01b03831661094a5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610769565b6001600160a01b0382166109ab5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610769565b6001600160a01b0383811660008181526004602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b610a146108de565b6001600160a01b0316610a2f6000546001600160a01b031690565b6001600160a01b0316146106b65760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610769565b600054600160a01b900460ff1615610ad65760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610769565b6000805460ff60a01b1916600160a01b1790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258610b126108de565b6040516001600160a01b03909116815260200160405180910390a1565b600054600160a01b900460ff161515600114610b845760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610769565b6000805460ff60a01b191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa610b126108de565b6002546040516361b6ebf560e11b8152600481018490526001600160a01b038381166024830152600092169063c36dd7ea90604401602060405180830381865afa158015610c0c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104b291906115c1565b6001600160a01b038316610c945760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610769565b6001600160a01b038216610cf65760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610769565b610d01838383611153565b6001600160a01b03831660009081526003602052604090205481811015610d795760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610769565b6001600160a01b0380851660008181526003602052604080822086860390559286168082529083902080548601905591517fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90610dd99086815260200190565b60405180910390a35b50505050565b600080610df36108de565b9050610e008582856111fd565b61077f858585610c30565b610e13610564565b156106b65760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610769565b6002546040516361b6ebf560e11b8152600481018490526001600160a01b0383811660248301529091169063c36dd7ea90604401602060405180830381865afa158015610ea4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ec891906115c1565b6101a15760405162b0d32560e11b81526001600160a01b038216600482015260248101839052604401610769565b6001600160a01b038216610f4c5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610769565b610f5860008383611153565b8060056000828254610f6a91906115a9565b90915550506001600160a01b0382166000818152600360209081526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6001600160a01b0382166110735760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610769565b61107f82600083611153565b6001600160a01b038216600090815260036020526040902054818110156110f35760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610769565b6001600160a01b03831660008181526003602090815260408083208686039055600580548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b6008546001600160a01b031615610517576008546001600160a01b03168063cff4dd9f3061117f6108de565b6040516001600160e01b031960e085901b1681526001600160a01b0392831660048201529082166024820152818816604482015290861660648201526084810185905260a401600060405180830381600087803b1580156111df57600080fd5b505af11580156111f3573d6000803e3d6000fd5b5050505050505050565b600061120984846107a2565b90506000198114610de257818110156112645760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610769565b610de284848484036108e8565b634e487b7160e01b600052604160045260246000fd5b6000806040838503121561129a57600080fd5b8235915060208084013567ffffffffffffffff808211156112ba57600080fd5b818601915086601f8301126112ce57600080fd5b8135818111156112e0576112e0611271565b8060051b604051601f19603f8301168101818110858211171561130557611305611271565b60405291825284820192508381018501918983111561132357600080fd5b938501935b8285101561134157843584529385019392850192611328565b8096505050505050509250929050565b600060208083528351808285015260005b8181101561137e57858101830151858201604001528201611362565b81811115611390576000604083870101525b50601f01601f1916929092016040019392505050565b80356001600160a01b03811681146113bd57600080fd5b919050565b600080604083850312156113d557600080fd5b6113de836113a6565b946020939093013593505050565b801515811461046057600080fd5b60006020828403121561140c57600080fd5b81356104b2816113ec565b60008060006060848603121561142c57600080fd5b611435846113a6565b9250611443602085016113a6565b9150604084013590509250925092565b60006020828403121561146557600080fd5b6104b2826113a6565b60008083601f84011261148057600080fd5b50813567ffffffffffffffff81111561149857600080fd5b6020830191508360208260051b85010111156114b357600080fd5b9250929050565b600080600080604085870312156114d057600080fd5b843567ffffffffffffffff808211156114e857600080fd5b6114f48883890161146e565b9096509450602087013591508082111561150d57600080fd5b5061151a8782880161146e565b95989497509550505050565b6000806040838503121561153957600080fd5b611542836113a6565b9150611550602084016113a6565b90509250929050565b600181811c9082168061156d57607f821691505b60208210810361158d57634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b600082198211156115bc576115bc611593565b500190565b6000602082840312156115d357600080fd5b81516104b2816113ec565b634e487b7160e01b600052603260045260246000fd5b60006001820161160657611606611593565b506001019056fe9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6a26469706673582212209972425aba7a4509da1cec6617b47083dd14fce21e13a949d6563d84dbdcf05164736f6c634300080d0033
Age | Block | Fee Address | BC Fee Address | Voting Power | Jailed | Incoming |
---|
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.