Contract Name:
ColumnInitializer
Contract Source Code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IDataStore, ID as DataStoreId} from "./IDataStore.sol";
import {GameRegistryConsumer} from "../core/GameRegistryConsumer.sol";
import {DEPLOYER_ROLE} from "../constants/RoleConstants.sol";
import {
NAME_CID,
DESCRIPTION_CID,
LEVEL_CID,
IS_NOOB_CID,
NOOB_TOKEN_CID,
GIGA_NAME_TOKENDID_CID,
IS_GIGA_NAME_CID,
GAME_ITEM_ID_CID,
UINT256_CID,
ETH_MINT_PRICE_CID,
NEXT_DOCID_CID,
ID_CID,
BASE_NAME_CID,
BASE_URI_CID,
LAST_TRANSFER_TIME_CID,
OWNER_CID,
INITIALIZED_CID,
MAX_SUPPLY_CID,
ADDRESS_CID,
IS_SOULBOUND_CID,
TIME_BETWEEN_CID,
TIMESTAMP_CID,
IMG_URL_CID,
PLAYER_CID,
MINT_COUNT_CID,
CONTRACT_URI_CID,
IS_RECYCLABLE_CID,
BURN_COUNT_CID,
BALANCE_CID,
EXPORT_AMOUNT_CID,
IMPORT_AMOUNT_CID,
EXPORT_LICENSE_CID
} from "../constants/ColumnConstants.sol";
uint256 constant ID = uint256(keccak256("game.gigaverse.columninit"));
contract ColumnInitializer is GameRegistryConsumer {
constructor(address gameRegistryAddress) GameRegistryConsumer(gameRegistryAddress, ID) { }
function initialize() override external onlyRole(DEPLOYER_ROLE) {
IDataStore dataStore = IDataStore(_gameRegistry.getSystem(DataStoreId));
dataStore.setColumnType(NAME_CID, IDataStore.ColumnType.STRING);
dataStore.setColumnType(DESCRIPTION_CID, IDataStore.ColumnType.STRING);
dataStore.setColumnType(LEVEL_CID, IDataStore.ColumnType.UINT256);
dataStore.setColumnType(IS_NOOB_CID, IDataStore.ColumnType.BOOL);
dataStore.setColumnType(NOOB_TOKEN_CID, IDataStore.ColumnType.UINT256);
dataStore.setColumnType(GIGA_NAME_TOKENDID_CID, IDataStore.ColumnType.UINT256);
dataStore.setColumnType(IS_GIGA_NAME_CID, IDataStore.ColumnType.BOOL);
dataStore.setColumnType(GAME_ITEM_ID_CID, IDataStore.ColumnType.UINT256);
dataStore.setColumnType(UINT256_CID, IDataStore.ColumnType.UINT256);
dataStore.setColumnType(ETH_MINT_PRICE_CID, IDataStore.ColumnType.UINT256);
dataStore.setColumnType(NEXT_DOCID_CID, IDataStore.ColumnType.UINT256);
dataStore.setColumnType(ID_CID, IDataStore.ColumnType.UINT256);
dataStore.setColumnType(BASE_NAME_CID, IDataStore.ColumnType.STRING);
dataStore.setColumnType(BASE_URI_CID, IDataStore.ColumnType.STRING);
dataStore.setColumnType(LAST_TRANSFER_TIME_CID, IDataStore.ColumnType.UINT256);
dataStore.setColumnType(OWNER_CID, IDataStore.ColumnType.ADDRESS);
dataStore.setColumnType(INITIALIZED_CID, IDataStore.ColumnType.BOOL);
dataStore.setColumnType(MAX_SUPPLY_CID, IDataStore.ColumnType.UINT256);
dataStore.setColumnType(ADDRESS_CID, IDataStore.ColumnType.ADDRESS);
dataStore.setColumnType(IS_SOULBOUND_CID, IDataStore.ColumnType.BOOL);
dataStore.setColumnType(TIME_BETWEEN_CID, IDataStore.ColumnType.UINT256);
dataStore.setColumnType(TIMESTAMP_CID, IDataStore.ColumnType.UINT256);
dataStore.setColumnType(IMG_URL_CID, IDataStore.ColumnType.STRING);
dataStore.setColumnType(PLAYER_CID, IDataStore.ColumnType.ADDRESS);
dataStore.setColumnType(MINT_COUNT_CID, IDataStore.ColumnType.UINT256);
dataStore.setColumnType(CONTRACT_URI_CID, IDataStore.ColumnType.STRING);
dataStore.setColumnType(IS_RECYCLABLE_CID, IDataStore.ColumnType.BOOL);
dataStore.setColumnType(BURN_COUNT_CID, IDataStore.ColumnType.UINT256);
dataStore.setColumnType(BALANCE_CID, IDataStore.ColumnType.UINT256);
dataStore.setColumnType(EXPORT_AMOUNT_CID, IDataStore.ColumnType.UINT256);
dataStore.setColumnType(IMPORT_AMOUNT_CID, IDataStore.ColumnType.UINT256);
dataStore.setColumnType(EXPORT_LICENSE_CID, IDataStore.ColumnType.UINT256);
}
}
// 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 LICENSE
pragma solidity ^0.8.13;
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/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 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;
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"));
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @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 EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* 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;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
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
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// 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;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
// 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
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* 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[ERC 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);
}