Verified contractExact
ForgottenRunesBeastSpawner
Address0x1f0744c221cc98697d4de5596da3be5e835dcb34
- Balance
0 ETH
- Transactions
303
- Compiler
solc 0.8.6
- Same code
Only this contract
Details
- Compiler
- solc 0.8.6+commit.11564f7e
- Language
- solidity
- Optimization
- Yes, 200 runs
- License
- Not stated
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 14,552,456
- Creation transaction
- 0xfdd6217fd8…c75f94ac32
8 files
- contracts/beasts/ForgottenRunesBeastSpawner.solmain15.52 KB
- @openzeppelin/contracts/access/Ownable.sol2.21 KB
- @openzeppelin/contracts/security/ReentrancyGuard.sol2.59 KB
- @openzeppelin/contracts/token/ERC721/IERC721.sol4.68 KB
- @openzeppelin/contracts/utils/Context.sol790 B
- @openzeppelin/contracts/utils/introspection/IERC165.sol786 B
- contracts/beasts/interfaces/IBeastsToken.sol341 B
- contracts/beasts/interfaces/ISpawnToken.sol532 B
contracts/beasts/ForgottenRunesBeastSpawner.sol
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@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@@@@.. ..@@**........ @@@@@@**....**@@....@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.. ..((##,,,,,, @@////,,,,##(( ..@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@****..........******@@@@@@****...... ..@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@****........**************..........**@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@******..**..**************......**@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@##**,,..**,, ,,****,,##@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@..** **@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@..** **@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@..** .. **@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ,*,, ,,,** @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ** ************ **@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ..**** **********@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ....****** ******....**@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ......**@@((((((@@**......**@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@......**@@@@@@@@@@@@@@**......**@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ .. ....**@@@@@@@@@@@@@@**.... .. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//
// Forgotten Runes Beast Spawn
// https://forgottenrunes.com
// Twitter: @forgottenrunes
pragma solidity ^0.8.0;
import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/security/ReentrancyGuard.sol';
import '@openzeppelin/contracts/token/ERC721/IERC721.sol';
import {IBeastsToken} from './interfaces/IBeastsToken.sol';
import {ISpawnToken} from './interfaces/ISpawnToken.sol';
contract ForgottenRunesBeastSpawner is Ownable, ReentrancyGuard {
/// @notice The Beasts ERC721 token contract
IBeastsToken public beastsToken;
/// @notice The Spawn ERC721 token contract
ISpawnToken public spawnToken;
/// @notice The address of the Wizards contract
address public wizardsAddress;
/// @notice The address of the Souls contract
address public soulsAddress;
/// @notice The Great Seed of Unpredictable Randomness
string public seed = 'Forgotten Runes';
/// @notice The fixed number of Spawn per Beast
uint256 public spawnPerBeast = 42;
/// @notice The number of Forgotten Runes Wizards and Souls
uint256 public NUM_WIZARDS = 10000;
/// @notice The number of beasts that can spawn
uint256 public spawnableSupply = 8;
/// @notice Start block overall
uint256 public startBlock = 0;
/// @notice Allow setting a block per beast for special situations
mapping(uint256 => uint256) public beastIdToSpawnStartBlock;
/// @notice Spawn supply per beast
mapping(uint256 => uint256) public beastIdToSpawnMinted;
/// @notice Wizard ID to beast spawned
mapping(uint256 => mapping(uint256 => bool)) public wizardIdToBeastSpawned;
/// @notice Set of owners that won't allow spawning e.g. the auction contracts
mapping(address => bool) public denyspawnOwners;
/**
* @dev Convenient way to initialize the contract
* @param _beastsToken address of the minter contract
*/
function initialize(
IBeastsToken _beastsToken,
ISpawnToken _spawnToken,
address _denyspawnAddress,
address _wizardsAddress,
address _soulsAddress
) public onlyOwner {
setBeastsToken(_beastsToken);
setSpawnToken(_spawnToken);
setDenyspawnOwner(_denyspawnAddress, true);
setWizardsAddress(_wizardsAddress);
setSoulsAddress(_soulsAddress);
}
/**
* @dev Spawn the token for beastId given the minter index
* @param beastId uint256 the number of the beast
* @param minterIdx uint256 the index of the spawn you wish to mint
*/
function spawn(uint256 beastId, uint256 minterIdx) public nonReentrant {
require(block.number > startBlock, 'Paused');
require(
block.number > beastIdToSpawnStartBlock[beastId],
'Beast paused'
);
require(IBeastsToken(beastsToken).exists(beastId), 'Invalid beast');
require(beastId < spawnableSupply, 'Beast cant be spawned');
require(
!denyspawnOwners[IBeastsToken(beastsToken).ownerOf(beastId)],
'Wont spawn'
);
require(beastIdToSpawnMinted[beastId] < spawnPerBeast, 'No spawn left');
require(minterIdx < spawnPerBeast, 'Invalid index');
uint256 wizardId = seedToWizard(beastId, minterIdx);
require(ownerOfWizardOrSoul(wizardId) == msg.sender, 'Not the owner');
require(!wizardIdToBeastSpawned[wizardId][beastId], 'Already spawned');
wizardIdToBeastSpawned[wizardId][beastId] = true;
ISpawnToken(spawnToken).mint(
msg.sender,
beastId,
beastIdToSpawnMinted[beastId]
);
beastIdToSpawnMinted[beastId] += 1;
}
/**
* @dev Given the beast, day, index, and seed returns the wizardId for the given index
* @param beastId uint256 the number of the beast
* @param idx uint256 the index of the spawn
* @return wizardId uint256 the id of a wizard or soul that can mint
*/
function seedToWizard(uint256 beastId, uint256 idx)
public
view
returns (uint256)
{
require(idx < spawnPerBeast, 'Invalid index');
uint256 day = block.timestamp / 1 days;
return
uint256(keccak256(abi.encodePacked(day, beastId, idx, seed))) %
NUM_WIZARDS; // Some modulo bias here, but close enough
}
/**
* @dev Convenience function to return all wizard IDs that can claim spawn for a given beast right now
* @param beastId uint256 the number of the beast
* @param startIdx uint256 the start index number e.g. 0
* @param endIdx uint256 the end index number e.g. 41
* @return wizards uint256[] an array of wizard IDs that can claim
*/
function seedToWizards(
uint256 beastId,
uint256 startIdx,
uint256 endIdx
) public view returns (uint256[] memory) {
require(endIdx < spawnPerBeast, 'endIdx too high');
uint256[] memory wizards = new uint256[](endIdx - startIdx + 1);
for (uint256 i = startIdx; i < endIdx + 1; i++) {
wizards[i] = seedToWizard(beastId, i);
}
return wizards;
}
/**
* @dev Convenience function to return all owner addresses that can claim spawn for a given beast right now
* @param beastId uint256 the number of the beast
* @param startIdx uint256 the start index number e.g. 0
* @param endIdx uint256 the end index number e.g. 41
* @return owners address[] an array of addresses of the owners (or address(0))
*/
function seedToOwners(
uint256 beastId,
uint256 startIdx,
uint256 endIdx
) public view returns (address[] memory) {
require(endIdx < spawnPerBeast, 'endIdx too high');
address[] memory owners = new address[](endIdx - startIdx + 1);
for (uint256 i = startIdx; i < endIdx + 1; i++) {
owners[i] = ownerOfWizardOrSoul(seedToWizard(beastId, i));
}
return owners;
}
/**
* @dev Convenience function to return the owner of wizId regardless of if it's a Wizard or a Soul. (Wizards and Souls) share the same ID space
* @param wizId uint256 the number of the wizard (or soul)
* @return owner address the owner or address(0)
*/
function ownerOfWizardOrSoul(uint256 wizId) public view returns (address) {
try IERC721(wizardsAddress).ownerOf(wizId) returns (
address wizardOwner
) {
if (wizardOwner != address(0)) {
return wizardOwner;
}
} catch {
// try a soul
}
try IERC721(soulsAddress).ownerOf(wizId) returns (address soulOwner) {
if (soulOwner != address(0)) {
return soulOwner;
}
} catch {
// not soul either
}
return address(0);
}
/**
* Only the owner can do these things
*/
/**
* @dev Sets a new beast token address
* @param newBeastsToken address the new beasts token address
*/
function setBeastsToken(IBeastsToken newBeastsToken) public onlyOwner {
beastsToken = newBeastsToken;
}
/**
* @dev Sets a new spawn token address
* @param newSpawnToken address the new spawn token adress
*/
function setSpawnToken(ISpawnToken newSpawnToken) public onlyOwner {
spawnToken = newSpawnToken;
}
/**
* @dev Sets a new wizards token address
* @param newWizardsAddress address the new wizards token address
*/
function setWizardsAddress(address newWizardsAddress) public onlyOwner {
wizardsAddress = newWizardsAddress;
}
/**
* @dev Sets a new souls token address
* @param newSoulsAddress address the new souls token address
*/
function setSoulsAddress(address newSoulsAddress) public onlyOwner {
soulsAddress = newSoulsAddress;
}
/**
* @dev Sets a new seed
* @param newSeed string new seed
*/
function setSeed(string memory newSeed) public onlyOwner {
seed = newSeed;
}
/**
* @dev Sets a new start block
* @param newStartBlock uint256 new start block
*/
function setStartBlock(uint256 newStartBlock) public onlyOwner {
startBlock = newStartBlock;
}
/**
* @dev Sets an address that when a Beast is owned by it, spawning doesn't work. This is for e.g. preventing spawn during an auction
* @param denyspawnOwner address the address to set
* @param denied bool whether denied or not
*/
function setDenyspawnOwner(address denyspawnOwner, bool denied)
public
onlyOwner
{
denyspawnOwners[denyspawnOwner] = denied;
}
/**
* @dev Sets a new start block
* @param beastId uint256 the beast id
* @param newSpawnStartBlock uint256 the block number at which `beastId` may spawn
*/
function setBeastIdToSpawnStartBlock(
uint256 beastId,
uint256 newSpawnStartBlock
) public onlyOwner {
beastIdToSpawnStartBlock[beastId] = newSpawnStartBlock;
}
/**
* @dev Sets a new spawnable supply count
* @param newSpawnableSupply uint256 new seed
*/
function setSpawnableSupply(uint256 newSpawnableSupply) public onlyOwner {
spawnableSupply = newSpawnableSupply;
}
/**
* @dev Sets the number of Wizards
* @param newNumWizards uint256 new start block
*/
function __setNumWizards(uint256 newNumWizards) public onlyOwner {
NUM_WIZARDS = newNumWizards;
}
}
@openzeppelin/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
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() {
_setOwner(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
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 {
_setOwner(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");
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
@openzeppelin/contracts/security/ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
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 make it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
@openzeppelin/contracts/token/ERC721/IERC721.sol
// SPDX-License-Identifier: MIT
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`, 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 be 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: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* 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 Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @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 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);
/**
* @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;
}
@openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
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;
}
}
@openzeppelin/contracts/utils/introspection/IERC165.sol
// SPDX-License-Identifier: MIT
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);
}
contracts/beasts/interfaces/IBeastsToken.sol
// SPDX-License-Identifier: GPL-3.0
/// @title Interface for BeastsToken
pragma solidity ^0.8.6;
import {IERC721} from '@openzeppelin/contracts/token/ERC721/IERC721.sol';
interface IBeastsToken is IERC721 {
function mint(address recipient) external returns (uint256);
function exists(uint256 tokenId) external returns (bool);
}
contracts/beasts/interfaces/ISpawnToken.sol
// SPDX-License-Identifier: GPL-3.0
/// @title Interface for BeastsToken
pragma solidity ^0.8.6;
import {IERC721} from '@openzeppelin/contracts/token/ERC721/IERC721.sol';
interface ISpawnToken is IERC721 {
/// @notice Spawned event is emitted whenever a token is spawned
event Spawned(
uint256 spawnTokenId,
uint256 beastTokenId,
uint256 spawnIndex
);
function mint(
address recipient,
uint256 beastTokenId,
uint256 spawnIndex
) external returns (uint256);
}
Compiler settingsShow
{
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
}
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.