Contract Name:
DungeonEntry
Contract Source Code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "./interfaces/IDungeonEntry.sol";
import "./interfaces/IDungeonGame.sol";
import "./interfaces/INFTStats.sol";
import "./interfaces/IPrizePool.sol";
import "./interfaces/ICollectionRegistry.sol";
/// @title DungeonEntry
/// @notice Manages dungeon entry and active run state for NFTs
contract DungeonEntry is IDungeonEntry, Ownable, ReentrancyGuard {
// Core contract references
ICollectionRegistry public immutable collectionRegistry;
INFTStats public immutable nftStats;
IPrizePool public prizePool;
IDungeonGame public dungeonGame;
bool private initialized;
// Entry fee in wei
uint256 private entryFee;
// Maximum time allowed for a dungeon run (24 hours)
uint256 private constant MAX_RUN_DURATION = 24 hours;
// Mapping to track NFTs in the dungeon
mapping(address => mapping(uint256 => bool)) private inDungeon;
// Events
event EntryFeeUpdated(uint256 newFee);
event RunExpired(address indexed collection, uint256 indexed tokenId);
event DungeonEntryInitialized(address indexed prizePool, address indexed dungeonGame);
constructor(
address _collectionRegistry,
address _nftStats,
uint256 _initialEntryFee
) Ownable() {
require(_collectionRegistry != address(0), "Invalid registry address");
require(_nftStats != address(0), "Invalid stats address");
collectionRegistry = ICollectionRegistry(_collectionRegistry);
nftStats = INFTStats(_nftStats);
entryFee = _initialEntryFee;
}
/// @notice Initialize the DungeonEntry with required contract addresses
/// @param _prizePool Address of the PrizePool contract
/// @param _dungeonGame Address of the DungeonGame contract
function initialize(
address _prizePool,
address _dungeonGame
) external onlyOwner {
require(!initialized, "Already initialized");
require(_prizePool != address(0), "Invalid prize pool address");
require(_dungeonGame != address(0), "Invalid dungeon game address");
prizePool = IPrizePool(_prizePool);
dungeonGame = IDungeonGame(_dungeonGame);
initialized = true;
emit DungeonEntryInitialized(_prizePool, _dungeonGame);
}
/// @notice Start a new dungeon run for an NFT
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
function startDungeonRun(
address collection,
uint256 tokenId
) external payable nonReentrant {
require(initialized, "Not initialized");
// Check entry fee
require(msg.value >= entryFee, "Insufficient entry fee");
// Verify collection is whitelisted
require(collectionRegistry.isWhitelisted(collection), "Collection not whitelisted");
// Verify NFT ownership
require(IERC721(collection).ownerOf(tokenId) == msg.sender, "Not NFT owner");
// Check if NFT is already in dungeon
require(!inDungeon[collection][tokenId], "Already in dungeon");
// Initialize stats if needed
if (!nftStats.isInitialized(collection, tokenId)) {
nftStats.initializeStats(collection, tokenId);
}
// Add character to dungeon queue
uint256 roomNumber = dungeonGame.addCharacterToDungeon(collection, tokenId);
require(roomNumber > 0, "No room available");
// Mark NFT as in dungeon
inDungeon[collection][tokenId] = true;
// Forward entry fee to prize pool
prizePool.depositEntryFee{value: entryFee}(collection, tokenId);
// Refund excess payment if any
uint256 excess = msg.value - entryFee;
if (excess > 0) {
(bool success, ) = msg.sender.call{value: excess}("");
require(success, "Refund failed");
}
emit DungeonRunStarted(collection, tokenId, msg.sender, entryFee);
}
/// @notice End an active dungeon run
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
/// @param success Whether the run was successful
function endDungeonRun(
address collection,
uint256 tokenId,
bool success
) external {
require(initialized, "Not initialized");
// Only DungeonGame contract can end runs
require(msg.sender == address(dungeonGame), "Not authorized");
require(inDungeon[collection][tokenId], "Not in dungeon");
// Mark NFT as no longer in dungeon
inDungeon[collection][tokenId] = false;
emit DungeonRunEnded(collection, tokenId, success);
}
/// @notice Update the entry fee
/// @param newFee New entry fee in wei
function updateEntryFee(uint256 newFee) external onlyOwner {
entryFee = newFee;
emit EntryFeeUpdated(newFee);
}
/// @notice Get the current dungeon run state for an NFT
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
/// @return DungeonRun struct containing current run state
function getCurrentRun(
address collection,
uint256 tokenId
) external view returns (DungeonRun memory) {
if (!inDungeon[collection][tokenId]) {
return DungeonRun(0, 0, 0, 0, 0, false);
}
uint256 roomNumber = dungeonGame.getCharacterRoom(collection, tokenId);
if (roomNumber == 0) {
return DungeonRun(0, 0, 0, 0, 0, false);
}
IDungeonGame.RoomState memory state = dungeonGame.getRoomState(roomNumber);
return DungeonRun({
currentHp: state.currentHp,
currentAttack: state.currentAttack,
currentSpeed: state.currentSpeed,
currentRoom: roomNumber,
startTime: state.entryIndex,
isActive: true
});
}
/// @notice Check if an NFT has an active dungeon run
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
/// @return bool True if NFT has an active run
function hasActiveRun(
address collection,
uint256 tokenId
) public view returns (bool) {
if (!inDungeon[collection][tokenId]) return false;
uint256 roomNumber = dungeonGame.getCharacterRoom(collection, tokenId);
if (roomNumber == 0) return false;
IDungeonGame.RoomState memory state = dungeonGame.getRoomState(roomNumber);
if (block.timestamp > state.entryIndex + MAX_RUN_DURATION) {
return false;
}
return true;
}
/// @notice Get the current entry fee for dungeon runs
/// @return uint256 Current entry fee in wei
function getEntryFee() external view returns (uint256) {
return entryFee;
}
/// @notice Get time remaining for an active run
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
/// @return uint256 Time remaining in seconds, 0 if no active run
function getTimeRemaining(
address collection,
uint256 tokenId
) external view returns (uint256) {
if (!inDungeon[collection][tokenId]) return 0;
uint256 roomNumber = dungeonGame.getCharacterRoom(collection, tokenId);
if (roomNumber == 0) return 0;
IDungeonGame.RoomState memory state = dungeonGame.getRoomState(roomNumber);
uint256 endTime = state.entryIndex + MAX_RUN_DURATION;
if (block.timestamp >= endTime) return 0;
return endTime - block.timestamp;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
/// @title IDungeonEntry
/// @notice Interface for managing dungeon entry and run initialization
interface IDungeonEntry {
/// @notice Structure for active dungeon run state
struct DungeonRun {
uint256 currentHp;
uint256 currentAttack;
uint256 currentSpeed;
uint256 currentRoom;
uint256 startTime;
bool isActive;
}
/// @notice Event emitted when a dungeon run is started
event DungeonRunStarted(
address indexed collection,
uint256 indexed tokenId,
address indexed player,
uint256 entryFee
);
/// @notice Event emitted when a dungeon run is ended
event DungeonRunEnded(
address indexed collection,
uint256 indexed tokenId,
bool success
);
/// @notice Start a new dungeon run for an NFT
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
function startDungeonRun(address collection, uint256 tokenId) external payable;
/// @notice End an active dungeon run (called by DungeonGame)
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
/// @param success Whether the run was successful
function endDungeonRun(address collection, uint256 tokenId, bool success) external;
/// @notice Get the current dungeon run state for an NFT
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
/// @return DungeonRun struct containing current run state
function getCurrentRun(address collection, uint256 tokenId) external view returns (DungeonRun memory);
/// @notice Check if an NFT has an active dungeon run
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
/// @return bool True if NFT has an active run
function hasActiveRun(address collection, uint256 tokenId) external view returns (bool);
/// @notice Get the current entry fee for dungeon runs
/// @return uint256 Current entry fee in wei
function getEntryFee() external view returns (uint256);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
/// @title IDungeonGame
/// @notice Interface for core dungeon game mechanics and progression
interface IDungeonGame {
/// @notice Structure for dungeon room state
struct RoomState {
address collection;
uint256 tokenId;
uint256 entryIndex; // Used for ordering characters
uint256 currentHp;
uint256 currentAttack;
uint256 currentSpeed;
bool isOccupied;
}
/// @notice Structure for encounter results
struct EncounterResult {
int256 hpChange;
int256 attackChange;
int256 speedChange;
uint256 xpGained;
bool survived;
string encounterDescription;
uint256 roomNumber;
}
/// @notice Event emitted when an encounter is completed
event EncounterCompleted(
address indexed collection,
uint256 indexed tokenId,
uint256 roomNumber,
uint256 xpGained,
bool survived,
string encounterDescription
);
/// @notice Event emitted when a dungeon run is completed
event DungeonCompleted(
address indexed collection,
uint256 indexed tokenId,
bool success,
uint256 roomsCleared,
uint256 totalXpGained,
uint256 reward
);
/// @notice Progress all characters in the dungeon by one room
/// @return EncounterResult[] Array of encounter results for each character that moved
function progressAllCharacters() external returns (EncounterResult[] memory);
/// @notice Add a new character to the dungeon queue
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
/// @return roomNumber The room number the character was placed in
function addCharacterToDungeon(address collection, uint256 tokenId) external returns (uint256 roomNumber);
/// @notice Claim rewards for a successful dungeon run
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
function claimRewards(address collection, uint256 tokenId) external;
/// @notice Get the state of a specific room
/// @param roomNumber Room number to query
/// @return RoomState Current state of the room
function getRoomState(uint256 roomNumber) external view returns (RoomState memory);
/// @notice Get all active room states
/// @return RoomState[] Array of all room states
function getAllRoomStates() external view returns (RoomState[] memory);
/// @notice Get the room number where a character is located
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
/// @return uint256 Room number, 0 if not in dungeon
function getCharacterRoom(address collection, uint256 tokenId) external view returns (uint256);
/// @notice Get the total number of rooms in the dungeon
/// @return uint256 Number of rooms (16)
function getTotalRooms() external pure returns (uint256);
/// @notice Check if a character has completed the dungeon
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
/// @return bool True if character has completed all rooms
function isDungeonCompleted(address collection, uint256 tokenId) external view returns (bool);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
/// @title INFTStats
/// @notice Interface for managing individual NFT stats and progression
interface INFTStats {
/// @notice Structure for NFT permanent stats
struct NFTStatsData {
uint256 hp;
uint256 attack;
uint256 speed;
uint256 level;
uint256 currentXP;
uint256 xpToNextLevel;
uint256 dungeonRuns;
uint256 successfulRuns;
uint256 roomsCleared;
bool initialized;
}
/// @notice Event emitted when an NFT's stats are initialized
event StatsInitialized(address indexed collection, uint256 indexed tokenId, uint256 hp, uint256 attack, uint256 speed);
/// @notice Event emitted when an NFT's stats are boosted
event StatsBoosted(address indexed collection, uint256 indexed tokenId, uint256 newHp, uint256 newAttack, uint256 newSpeed);
/// @notice Event emitted when XP is gained
event XPGained(address indexed collection, uint256 indexed tokenId, uint256 xpGained, uint256 newTotalXP);
/// @notice Event emitted when a level up occurs
event LevelUp(address indexed collection, uint256 indexed tokenId, uint256 newLevel, uint256 newHp, uint256 newAttack, uint256 newSpeed);
/// @notice Event emitted when a run is recorded
event RunRecorded(address indexed collection, uint256 indexed tokenId, bool success, uint256 roomsCleared, uint256 xpGained);
/// @notice Initialize stats for an NFT based on its collection's base stats
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
function initializeStats(address collection, uint256 tokenId) external;
/// @notice Award XP for dungeon progress
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
/// @param xpAmount Amount of XP to award
/// @param roomsCleared Number of rooms cleared in this run
function awardXP(
address collection,
uint256 tokenId,
uint256 xpAmount,
uint256 roomsCleared
) external;
/// @notice Calculate XP required for next level
/// @param currentLevel Current level of the NFT
/// @return uint256 XP required for next level
function getXPForNextLevel(uint256 currentLevel) external pure returns (uint256);
/// @notice Get the stat increases for a level up
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
/// @return hpIncrease Amount HP increases
/// @return attackIncrease Amount Attack increases
/// @return speedIncrease Amount Speed increases
function getLevelUpStats(
address collection,
uint256 tokenId
) external view returns (
uint256 hpIncrease,
uint256 attackIncrease,
uint256 speedIncrease
);
/// @notice Record a dungeon run attempt
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
/// @param success Whether the run was successful
function recordRun(address collection, uint256 tokenId, bool success) external;
/// @notice Get current stats for an NFT
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
/// @return NFTStatsData struct containing current stats
function getStats(address collection, uint256 tokenId) external view returns (NFTStatsData memory);
/// @notice Check if an NFT has been initialized
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
/// @return bool True if NFT has been initialized
function isInitialized(address collection, uint256 tokenId) external view returns (bool);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
/// @title IPrizePool
/// @notice Interface for managing dungeon rewards and prize distribution
interface IPrizePool {
/// @notice Event emitted when entry fee is deposited
event EntryFeeDeposited(address indexed collection, uint256 indexed tokenId, uint256 amount);
/// @notice Event emitted when reward is claimed
event RewardClaimed(address indexed collection, uint256 indexed tokenId, address indexed recipient, uint256 amount);
/// @notice Event emitted when prize pool parameters are updated
event PrizePoolParametersUpdated(uint256 entryFee, uint256 winnerShare);
/// @notice Deposit entry fee for a dungeon run
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
function depositEntryFee(address collection, uint256 tokenId) external payable;
/// @notice Register a winner for prize claiming
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
/// @param amount Amount to be claimed
function registerWinner(address collection, uint256 tokenId, uint256 amount) external;
/// @notice Claim prize for a winning NFT
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
function claimPrize(address collection, uint256 tokenId) external;
/// @notice Get claimable prize amount for a winning NFT
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
/// @return uint256 Claimable amount
function getClaimablePrize(address collection, uint256 tokenId) external view returns (uint256);
/// @notice Get current prize pool balance
/// @return uint256 Current balance
function getCurrentPrizePool() external view returns (uint256);
/// @notice Check if an NFT has an unclaimed prize
/// @param collection Address of the NFT collection
/// @param tokenId Token ID of the NFT
/// @return bool True if NFT has unclaimed prize
function hasUnclaimedPrize(address collection, uint256 tokenId) external view returns (bool);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
/// @title ICollectionRegistry
/// @notice Interface for managing whitelisted NFT collections and their base stats
interface ICollectionRegistry {
/// @notice Stats structure for NFT collections
struct CollectionStats {
uint256 baseHp;
uint256 baseAttack;
uint256 baseSpeed;
bool isWhitelisted;
}
/// @notice Event emitted when a collection is whitelisted
event CollectionWhitelisted(address indexed collection, uint256 baseHp, uint256 baseAttack, uint256 baseSpeed);
/// @notice Event emitted when a collection's stats are updated
event CollectionStatsUpdated(address indexed collection, uint256 baseHp, uint256 baseAttack, uint256 baseSpeed);
/// @notice Event emitted when a collection is removed from whitelist
event CollectionRemoved(address indexed collection);
/// @notice Whitelist a new NFT collection with base stats
/// @param collection Address of the NFT collection
/// @param baseHp Initial HP for NFTs from this collection
/// @param baseAttack Initial Attack for NFTs from this collection
/// @param baseSpeed Initial Speed for NFTs from this collection
function whitelistCollection(
address collection,
uint256 baseHp,
uint256 baseAttack,
uint256 baseSpeed
) external;
/// @notice Update base stats for a whitelisted collection
/// @param collection Address of the NFT collection
/// @param baseHp New base HP
/// @param baseAttack New base Attack
/// @param baseSpeed New base Speed
function updateCollectionStats(
address collection,
uint256 baseHp,
uint256 baseAttack,
uint256 baseSpeed
) external;
/// @notice Remove a collection from the whitelist
/// @param collection Address of the NFT collection to remove
function removeCollection(address collection) external;
/// @notice Check if a collection is whitelisted
/// @param collection Address of the NFT collection to check
/// @return bool True if collection is whitelisted
function isWhitelisted(address collection) external view returns (bool);
/// @notice Get base stats for a collection
/// @param collection Address of the NFT collection
/// @return CollectionStats struct containing base stats
function getCollectionStats(address collection) external view returns (CollectionStats memory);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/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);
}