// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
import { Verification } from "./Verification.sol";
/// @title AI Arena Mint Pass
/// @author ArenaX Labs Inc.
/// @notice This contract creates mint passes for those who have qualified, which are claimable
/// for AI Arena fighters at a later date
contract AAMintPass is ERC721, ERC721Burnable {
// The founder address is the address that deploys the smart contract
address public founderAddress;
// The fighterFarm address will have the ability at a future date to burn the mintpass in order
// to mint an AI Arena fighter (at the NFT owner's discretion)
address public fighterFarmContractAddress;
// The delegated address is responsible for signing messages to confirm someone is able to
// claim mint passes
address public delegatedAddress;
// Mapping to check if an address has admin rights
mapping(address => bool) public isAdmin;
// Mapping that returns the tokenURI for a given id
mapping(uint256 => string) private tokenURIs;
// Mapping that returns how many passes an address has claimed already
mapping(address => mapping(uint8 => uint8)) public passesClaimed;
// Boolean that dictates whether or not users are able to mint (paused means they cannot)
bool public mintingPaused = true;
// Number of tokens outstanding (which have not been burned)
uint256 public numTokensOutstanding = 0;
// Number of tokens which have been burned
uint256 public numTokensBurned = 0;
/// @dev Initializes the smart contract with the founder and delegated addresses
/// Also sets the founder as an admin by default
constructor(address _founderAddress, address _delegatedAddress)
ERC721("AI Arena Mint Pass", "AAMP")
{
delegatedAddress = _delegatedAddress;
founderAddress = _founderAddress;
isAdmin[founderAddress] = true;
}
/// @dev This function gives the founder the ability to transfer ownership to another address
/// At the time of setting a new founder address, the old founder is removed as an admin
/// @param _newFounderAddress The new address which will have control over the smart contract
function transferOwnership(address _newFounderAddress) external {
require(msg.sender == founderAddress);
isAdmin[founderAddress] = false;
founderAddress = _newFounderAddress;
isAdmin[_newFounderAddress] = true;
}
/// @notice Adds a new admin
/// @param _newAdmin The address of the new admin
/// @dev This function can only be called by the contract founder to add a new admin.
function addAdmin(address _newAdmin) external {
require(msg.sender == founderAddress);
isAdmin[_newAdmin] = true;
}
/// @dev Remove existing admins from the mapping (Founder-Only)
/// @param adminAddress An address to remove from the mapping
function removeAdmin(address adminAddress) external {
require(msg.sender == founderAddress);
isAdmin[adminAddress] = false;
}
/// @dev Set the fighter farm address (Founder-Only)
/// @param _fighterFarmAddress The new address to set
function setFighterFarmAddress(address _fighterFarmAddress) external {
require(msg.sender == founderAddress);
fighterFarmContractAddress = _fighterFarmAddress;
}
/// @dev Set the delegated address (Founder-Only)
/// @param _delegatedAddress The new address to set
function setDelegatedAddress(address _delegatedAddress) external {
require(msg.sender == founderAddress);
delegatedAddress = _delegatedAddress;
}
/// @dev Change the 'paused' state of minting (Admin-Only)
/// @param _state The new paused state to set
function setPaused(bool _state) external {
require(isAdmin[msg.sender]);
mintingPaused = _state;
}
/// @notice This allows you to claim a mintpass which you have qualified for
/// @dev Users must provide the number of mintpasses they want to claim, along with the
/// tokenURIs and a signature from our delegated server address. We then verify that the
/// server did indeed sign a message approving them to claim the amount of mint passes.
/// We use passesClaimed as a part of the message and increment it to ensure they cannot use
/// the same signature multiple times.
/// @param numToMint The number of mintpasses to claim. The first element in the array is the
/// number of AI Champion mintpasses and the second element is the number of Dendroid
/// mintpasses.
/// @param signature The signature from the delegated server address
/// @param _tokenURIs Token URIs for each of the mintpasses a user claims
function claimMintPass(
uint8[2] calldata numToMint,
bytes calldata signature,
string[] calldata _tokenURIs
)
external
{
require(!mintingPaused);
bytes32 msgHash = bytes32(keccak256(abi.encode(
msg.sender,
numToMint[0],
numToMint[1],
passesClaimed[msg.sender][0],
passesClaimed[msg.sender][1],
_tokenURIs
)));
require(Verification.verify(delegatedAddress, msgHash, signature));
uint16 totalToMint = uint16(numToMint[0] + numToMint[1]);
require(_tokenURIs.length == totalToMint);
passesClaimed[msg.sender][0] += numToMint[0];
passesClaimed[msg.sender][1] += numToMint[1];
for (uint16 i = 0; i < totalToMint; i++) {
createMintPass(msg.sender, _tokenURIs[i]);
}
}
/// @dev Burns the NFT and alters some counters
/// @param _tokenId The id for the NFT
function burn(uint256 _tokenId) public override {
require(msg.sender == fighterFarmContractAddress || msg.sender == ownerOf(_tokenId));
numTokensBurned++;
numTokensOutstanding--;
super.burn(_tokenId);
}
/// @dev Informs the user of the total number of NFTs outstanding (non-burned)
function totalSupply() public view returns (uint256) {
return numTokensOutstanding;
}
/// @notice The contract URI
function contractURI() public pure returns (string memory) {
return "ipfs://bafybeifdvzwsjpxrkbyhqpz3y57j7nwm3eyyc3feqppqggslea3g5kk3jq";
}
/// @dev Returns the tokenURI for a given token id
/// @param _tokenId The id for the NFT
function tokenURI(uint256 _tokenId) public view override(ERC721) returns (string memory) {
require(_exists(_tokenId), "ERC721Metadata: URI query for nonexistent token");
return tokenURIs[_tokenId];
}
/// @dev Mints the NFT for the mintpass and sets the tokenURI, while incrementing counter
/// @param _receiver The address receiving the mintpass
/// @param _tokenURI The tokenURI to attach to the mintpass
function createMintPass(address _receiver, string calldata _tokenURI) private {
numTokensOutstanding++;
uint256 tokenId = numTokensOutstanding + numTokensBurned;
tokenURIs[tokenId] = _tokenURI;
_safeMint(_receiver, tokenId);
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
import { FighterOps } from "./FighterOps.sol";
/// @title AI Arena Helper
/// @author ArenaX Labs Inc.
/// @notice This contract generates and manages an AI Arena fighters physical attributes.
contract AiArenaHelper {
/*//////////////////////////////////////////////////////////////
STATE VARIABLES
//////////////////////////////////////////////////////////////*/
/// @notice List of attributes
string[] public attributes = ["head", "eyes", "mouth", "body", "hands", "feet"];
/// The address that has owner privileges (initially the contract deployer).
address _ownerAddress;
/*//////////////////////////////////////////////////////////////
MAPPINGS
//////////////////////////////////////////////////////////////*/
/// @notice Mapping tracking fighter generation to attribute probabilities
mapping(uint256 => mapping(string => uint8[])) public attributeProbabilities;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
/// @dev Constructor to initialize the contract with the attribute probabilities for gen 0.
/// @param probabilities An array of attribute probabilities for the generation.
constructor(uint8[][] memory probabilities) {
_ownerAddress = msg.sender;
addAttributeProbabilities(0, probabilities);
}
/*//////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice Transfers ownership from one address to another.
/// @dev Only the owner address is authorized to call this function.
/// @param newOwnerAddress The address of the new owner
function transferOwnership(address newOwnerAddress) external {
require(msg.sender == _ownerAddress);
_ownerAddress = newOwnerAddress;
}
/// @notice Create physical attributes for a fighter based on DNA.
/// @param dna The DNA of the fighter.
/// @param iconsType Type of icons fighter (0 means it's not an icon).
/// @param generation Generation of the fighter
/// @param dendroidBool Whether the fighter is a dendroid or not
/// @param rerolledBool Whether the fighter has rerolled or not
/// @return Fighter physical attributes.
function createPhysicalAttributes(
uint256 dna,
uint8 generation,
uint8 iconsType,
bool dendroidBool,
bool rerolledBool
)
external
view
returns (FighterOps.FighterPhysicalAttributes memory)
{
require(attributeProbabilities[generation]["head"].length > 0);
if (dendroidBool) {
return FighterOps.FighterPhysicalAttributes(99, 99, 99, 99, 99, 99);
} else {
uint256[] memory finalAttributeProbabilityIndexes = new uint[](attributes.length);
uint256 attributesLength = attributes.length;
for (uint8 i = 0; i < attributesLength; i++) {
if (
i == 0 && iconsType == 2 || // Custom icons head (beta helmet)
i == 1 && iconsType > 0 || // Custom icons eyes (red diamond)
i == 4 && iconsType == 3 // Custom icons hands (bowling ball)
) {
finalAttributeProbabilityIndexes[i] = 50;
} else if (!rerolledBool && iconsType > 0) {
finalAttributeProbabilityIndexes[i] = 0;
} else {
uint256 rarityRank = dna % 100;
dna /= 100;
uint256 attributeIndex = dnaToIndex(generation, rarityRank, attributes[i]);
finalAttributeProbabilityIndexes[i] = attributeIndex;
}
}
return FighterOps.FighterPhysicalAttributes(
finalAttributeProbabilityIndexes[0],
finalAttributeProbabilityIndexes[1],
finalAttributeProbabilityIndexes[2],
finalAttributeProbabilityIndexes[3],
finalAttributeProbabilityIndexes[4],
finalAttributeProbabilityIndexes[5]
);
}
}
/*//////////////////////////////////////////////////////////////
PUBLIC FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice Add attribute probabilities for a given generation.
/// @dev Only the owner can call this function.
/// @param generation The generation number.
/// @param probabilities An array of attribute probabilities for the generation.
function addAttributeProbabilities(uint256 generation, uint8[][] memory probabilities) public {
require(msg.sender == _ownerAddress);
require(probabilities.length == attributes.length);
uint256 attributesLength = attributes.length;
for (uint8 i = 0; i < attributesLength; i++) {
attributeProbabilities[generation][attributes[i]] = probabilities[i];
}
}
/// @dev Get the attribute probabilities for a given generation and attribute.
/// @param generation The generation number.
/// @param attribute The attribute name.
/// @return Attribute probabilities.
function getAttributeProbabilities(uint256 generation, string memory attribute)
public
view
returns (uint8[] memory)
{
require(attributeProbabilities[generation][attribute].length > 0);
return attributeProbabilities[generation][attribute];
}
/// @dev Convert DNA and rarity rank into an attribute probability index.
/// @param attribute The attribute name.
/// @param rarityRank The rarity rank.
/// @return attributeProbabilityIndex attribute probability index.
function dnaToIndex(uint256 generation, uint256 rarityRank, string memory attribute)
public
view
returns (uint256 attributeProbabilityIndex)
{
uint8[] memory attrProbabilities = getAttributeProbabilities(generation, attribute);
uint256 cumProb = 0;
uint256 attrProbabilitiesLength = attrProbabilities.length;
for (uint8 i = 0; i < attrProbabilitiesLength; i++) {
cumProb += attrProbabilities[i];
if (cumProb > rarityRank) {
attributeProbabilityIndex = i + 1;
break;
}
}
return attributeProbabilityIndex;
}
}
// 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 (last updated v4.7.3) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.0;
import "../Strings.sol";
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
} else if (error == RecoverError.InvalidSignatureV) {
revert("ECDSA: invalid signature 'v' value");
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature` or error string. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
/// @solidity memory-safe-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address, RecoverError) {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*
* _Available since v4.2._
*/
function recover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
if (v != 27 && v != 28) {
return (address(0), RecoverError.InvalidSignatureV);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
}
/**
* @dev Returns an Ethereum Signed Message, created from `s`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
}
/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*
* See {recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.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.zeppelin.solutions/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;
}
_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;
_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;
}
_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 (last updated v4.7.0) (token/ERC721/ERC721.sol)
pragma solidity ^0.8.0;
import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/ERC165.sol";
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to owner address
mapping(uint256 => address) private _owners;
// Mapping owner address to token count
mapping(address => uint256) private _balances;
// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: address zero is not a valid owner");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ERC721: invalid token ID");
return owner;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
_requireMinted(tokenId);
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overridden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not token owner nor approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
_requireMinted(tokenId);
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner nor approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory data
) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner nor approved");
_safeTransfer(from, to, tokenId, data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(
address from,
address to,
uint256 tokenId,
bytes memory data
) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == spender);
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(
address to,
uint256 tokenId,
bytes memory data
) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
_afterTokenTransfer(address(0), to, tokenId);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
// Clear approvals
_approve(address(0), tokenId);
_balances[owner] -= 1;
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
_afterTokenTransfer(owner, address(0), tokenId);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
// Clear approvals from the previous owner
_approve(address(0), tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
_afterTokenTransfer(from, to, tokenId);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits an {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Emits an {ApprovalForAll} event.
*/
function _setApprovalForAll(
address owner,
address operator,
bool approved
) internal virtual {
require(owner != operator, "ERC721: approve to caller");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Reverts if the `tokenId` has not been minted yet.
*/
function _requireMinted(uint256 tokenId) internal view virtual {
require(_exists(tokenId), "ERC721: invalid token ID");
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory data
) private returns (bool) {
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
return retval == IERC721Receiver.onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
/// @solidity memory-safe-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` 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 tokenId
) 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.
* - `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 tokenId
) internal virtual {}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/extensions/ERC721Burnable.sol)
pragma solidity ^0.8.0;
import "../ERC721.sol";
import "../../../utils/Context.sol";
/**
* @title ERC721 Burnable Token
* @dev ERC721 Token that can be burned (destroyed).
*/
abstract contract ERC721Burnable is Context, ERC721 {
/**
* @dev Burns `tokenId`. See {ERC721-_burn}.
*
* Requirements:
*
* - The caller must own `tokenId` or be an approved operator.
*/
function burn(uint256 tokenId) public virtual {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner nor approved");
_burn(tokenId);
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/ERC721Enumerable.sol)
pragma solidity ^0.8.0;
import "../ERC721.sol";
import "./IERC721Enumerable.sol";
/**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
return _allTokens[index];
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
import { FighterOps } from "./FighterOps.sol";
import { Verification } from "./Verification.sol";
import { AAMintPass } from "./AAMintPass.sol";
import { AiArenaHelper } from "./AiArenaHelper.sol";
import { Neuron } from "./Neuron.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
/// @title AI Arena Fighter NFT
/// @author ArenaX Labs Inc.
/// @notice This contract manages the creation, ownership, and redemption of AI Arena Fighter NFTs,
/// including the ability to mint new NFTs from a merging pool or through the redemption of mint passes.
contract FighterFarm is ERC721, ERC721Enumerable {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
/// @notice Event emitted when a fighter is locked and thus cannot be traded.
event Locked(uint256 tokenId);
/// @notice Event emitted when a fighter is unlocked and can be traded.
event Unlocked(uint256 tokenId);
/*//////////////////////////////////////////////////////////////
STATE VARIABLES
//////////////////////////////////////////////////////////////*/
/// @notice The maximum amount of rerolls for each fighter.
uint8[2] public maxRerollsAllowed = [3, 3];
/// @notice The cost ($NRN) to reroll a fighter.
uint256 public rerollCost = 1000 * 10**18;
/// @notice Stores the current generation for each fighter type.
uint8[2] public generation = [0, 0];
/// @notice The number of icon fighters minted [type 1, type 2, type 3].
uint8[3] public numIcons = [0, 0, 0];
/// @notice The address of treasury.
address public treasuryAddress;
/// The address responsible for setting token URIs and signing fighter claim messages.
address public delegatedAddress;
/// The address of the Merging Pool contract.
address public mergingPoolAddress;
/// The address of the Mintpass contract
address public mintpassAddress;
/// The address of the Neuron contract
address public neuronAddress;
/// The address of the Helper contract for fighter attributes
address public aiArenaHelperAddress;
/// The address that has owner privileges (initially the contract deployer).
address public ownerAddress;
/// Placeholder tokenURI
string _placeholderURI = "ipfs://QmetA726ZTd4npfMwvjuTkJzPHaGsRo4tRydTHkosXMcJK";
/// The contract URI that third-parties use
string _contractURI = "ipfs://QmVCch4uAPPk6FfWWz6qKgaKzqfGE6qE7yC5s1Mm8qNWkk";
/// @dev Instance of the AI Arena Helper contract.
AiArenaHelper _aiArenaHelperInstance;
/// @dev Instance of the AI Arena Mintpass contract (ERC721).
AAMintPass _mintpassInstance;
/// @dev Instance of the Neuron contract (ERC20).
Neuron _neuronInstance;
/// @notice List of all fighter structs, accessible by using tokenId as index.
FighterOps.Fighter[] public fighters;
/*//////////////////////////////////////////////////////////////
MAPPINGS
//////////////////////////////////////////////////////////////*/
/// @notice Mapping to keep track of whether a tokenId has staked or not.
mapping(uint256 => bool) public fighterStaked;
/// @notice Mapping to keep track of how many times an NFT has been re-rolled.
mapping(uint256 => uint8) public numRerolls;
/// @notice Mapping to indicate which addresses are able to stake fighters.
mapping(address => bool) public hasStakerRole;
/// @notice Mapping of number elements by generation.
mapping(uint8 => uint8) public numElements;
/// @notice Maps address to fighter type to return the number of NFTs claimed.
mapping(address => mapping(uint8 => uint8)) public nftsClaimed;
/// @notice Mapping to keep track of tokenIds and their URI.
mapping(uint256 => string) private _tokenURIs;
/// @notice Mapping of address to admin status.
mapping(address => bool) public isAdmin;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
/// @notice Sets the owner address, the delegated address.
/// @param ownerAddress_ Address of contract deployer.
/// @param delegatedAddress_ Address of delegated signer for messages.
/// @param treasuryAddress_ Community treasury address.
constructor(address ownerAddress_, address delegatedAddress_, address treasuryAddress_)
ERC721("AI Arena Fighter", "FTR")
{
ownerAddress = ownerAddress_;
delegatedAddress = delegatedAddress_;
treasuryAddress = treasuryAddress_;
isAdmin[ownerAddress] = true;
numElements[0] = 3;
}
/*//////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice Transfers ownership from one address to another.
/// @dev Only the owner address is authorized to call this function.
/// @param newOwnerAddress The address of the new owner
function transferOwnership(address newOwnerAddress) external {
require(msg.sender == ownerAddress);
ownerAddress = newOwnerAddress;
}
/// @notice Adjusts admin access for a user.
/// @dev Only the owner address is authorized to call this function.
/// @param adminAddress The address of the admin.
/// @param access Whether the address has admin access or not.
function adjustAdminAccess(address adminAddress, bool access) external {
require(msg.sender == ownerAddress);
require(isAdmin[adminAddress] != access, "Nothing to change");
isAdmin[adminAddress] = access;
}
/// @notice Adjusts the allowed staking addresses.
/// @dev Only the owner address is authorized to call this function.
/// @param stakerAddress The address to adjust for staking.
/// @param access Whether or not an address has staking access
function adjustStakingAccess(address stakerAddress, bool access) public {
require(msg.sender == ownerAddress);
require(hasStakerRole[stakerAddress] != access, "Nothing to change");
hasStakerRole[stakerAddress] = access;
}
/// @notice Instantiates the ai arena helper contract.
/// @dev Only the owner address is authorized to call this function.
/// @param aiArenaHelperAddress_ Address of new helper contract.
function instantiateAIArenaHelperContract(address aiArenaHelperAddress_) external {
require(msg.sender == ownerAddress);
_aiArenaHelperInstance = AiArenaHelper(aiArenaHelperAddress_);
aiArenaHelperAddress = aiArenaHelperAddress_;
}
/// @notice Instantiates the mint pass contract.
/// @dev Only the owner address is authorized to call this function.
/// @param mintpassAddress_ The address of the new AAMintPass contract instance.
function instantiateMintpassContract(address mintpassAddress_) external {
require(msg.sender == ownerAddress);
_mintpassInstance = AAMintPass(mintpassAddress_);
mintpassAddress = mintpassAddress_;
}
/// @notice Instantiates the neuron contract.
/// @dev Only the owner address is authorized to call this function.
/// @param neuronAddress_ The address of the new Neuron contract instance.
function instantiateNeuronContract(address neuronAddress_) external {
require(msg.sender == ownerAddress);
_neuronInstance = Neuron(neuronAddress_);
neuronAddress = neuronAddress_;
}
/// @notice Sets the merging pool contract address.
/// @dev Only the owner address is authorized to call this function.
/// @param mergingPoolAddress_ Address of the new Merging Pool contract.
function setMergingPoolAddress(address mergingPoolAddress_) external {
require(msg.sender == ownerAddress);
mergingPoolAddress = mergingPoolAddress_;
}
/// @notice Sets the treasury address.
/// @dev Only the owner address is authorized to call this function.
/// @param treasuryAddress_ Address of the new treasury.
function setTreasuryAddress(address treasuryAddress_) external {
require(msg.sender == ownerAddress);
treasuryAddress = treasuryAddress_;
}
/// @notice Sets the delegated address.
/// @dev Only the owner address is authorized to call this function.
/// @param delegatedAddress_ Address of the new delegate.
function setDelegatedAddress(address delegatedAddress_) external {
require(msg.sender == ownerAddress);
delegatedAddress = delegatedAddress_;
}
/// @notice Increase the generation of the specified fighter type.
/// @dev Only an admin address is authorized to call this function.
/// @param fighterType Type of fighter either 0 or 1 (champion or dendroid).
/// @return Generation count of the fighter type.
function incrementGeneration(uint8 fighterType) external returns (uint8) {
require(isAdmin[msg.sender]);
require(fighterType == 0 || fighterType == 1);
generation[fighterType] += 1;
maxRerollsAllowed[fighterType] += 1;
return generation[fighterType];
}
/// @notice Updates the number of elements for a given generation.
/// @dev Only an admin address is authorized to call this function.
/// @param newNumElements number of elements for the generation.
/// @param generation_ generation to be updated.
function setNumElements(uint8 newNumElements, uint8 generation_) external {
require(isAdmin[msg.sender]);
require(newNumElements >= 1);
numElements[generation_] = newNumElements;
}
/// @notice Sets the delegated address.
/// @dev Only an admin address is authorized to call this function.
/// @param newRerollCost The new re-roll cost.
function setRerollCost(uint256 newRerollCost) external {
require(isAdmin[msg.sender]);
require(rerollCost != newRerollCost, "Nothing to change");
rerollCost = newRerollCost;
}
/// @notice Sets the contract URI.
/// @dev Only an admin address is authorized to call this function.
/// @param newContractURI The new contract URI.
function setContractURI(string calldata newContractURI) external {
require(isAdmin[msg.sender]);
_contractURI = newContractURI;
}
/// @notice Sets the tokenURI for the given tokenId.
/// @dev Only the delegated address is authorized to call this function.
/// @param tokenId The ID of the token to set the URI for.
/// @param newTokenURI The new URI to set for the given token.
function setTokenURI(uint256 tokenId, string calldata newTokenURI) external {
require(msg.sender == delegatedAddress);
require(_exists(tokenId));
_tokenURIs[tokenId] = newTokenURI;
}
/// @notice Enables users to claim a pre-determined number of fighters.
/// @dev The function verifies if the message signature is from the delegated address.
/// @param numToMint Array specifying the number of fighters to be claimed for each fighter type.
/// @param signature Signature of the claim message.
function claimFighters(uint8[2] calldata numToMint, bytes calldata signature) external {
bytes32 msgHash = bytes32(keccak256(abi.encode(
msg.sender,
numToMint[0],
numToMint[1],
nftsClaimed[msg.sender][0],
nftsClaimed[msg.sender][1]
)));
require(Verification.verify(delegatedAddress, msgHash, signature));
uint16 totalToMint = uint16(numToMint[0] + numToMint[1]);
nftsClaimed[msg.sender][0] += numToMint[0];
nftsClaimed[msg.sender][1] += numToMint[1];
for (uint16 i = 0; i < totalToMint; i++) {
_createNewFighter(
msg.sender,
uint256(keccak256(abi.encode(
msg.sender,
nftsClaimed[msg.sender][0] + i,
nftsClaimed[msg.sender][1] + i,
block.timestamp
))),
i < numToMint[0] ? 0 : 1,
0,
[uint256(100), uint256(100)]
);
}
}
/// @notice Burns multiple mint passes in exchange for fighter NFTs.
/// @dev This function requires the length of all input arrays to be equal.
/// @dev Each input array must correspond to the same index, i.e., the first element in each
/// array belongs to the same mint pass, and so on.
/// @param mintpassIdsToBurn Array of mint pass IDs to be burned for each fighter to be minted.
/// @param fighterTypes Array of fighter types corresponding to the fighters being minted.
/// @param iconsTypes Array of icon types corresponding to the fighters being minted.
/// @param mintPassDnas Array of DNA strings of the mint passes to be minted as fighters.
/// @param signature Signature of the redeem message.
function redeemMintPass(
uint256[] calldata mintpassIdsToBurn,
uint8[] calldata fighterTypes,
uint8[] calldata iconsTypes,
string[] calldata mintPassDnas,
bytes calldata signature
)
external
{
require(
mintpassIdsToBurn.length == mintPassDnas.length &&
mintPassDnas.length == fighterTypes.length &&
fighterTypes.length == iconsTypes.length
);
bytes32 msgHash = bytes32(keccak256(abi.encode(
mintpassIdsToBurn,
fighterTypes,
iconsTypes,
mintPassDnas
)));
require(Verification.verify(delegatedAddress, msgHash, signature));
for (uint16 i = 0; i < mintpassIdsToBurn.length; i++) {
require(msg.sender == _mintpassInstance.ownerOf(mintpassIdsToBurn[i]));
_mintpassInstance.burn(mintpassIdsToBurn[i]);
_createNewFighter(
msg.sender,
uint256(keccak256(abi.encode(mintPassDnas[i], block.timestamp))),
fighterTypes[i],
iconsTypes[i],
[uint256(100), uint256(100)]
);
}
}
/// @notice Update the staking status of the fighter associated with the given token ID.
/// @dev Only addresses which have the staker role are authorized to call this function.
/// @param tokenId The ID of the fighter to update the staking status for.
/// @param stakingStatus The new staking status to set for the fighter.
function updateFighterStaking(uint256 tokenId, bool stakingStatus) external {
require(hasStakerRole[msg.sender]);
require(_exists(tokenId));
fighterStaked[tokenId] = stakingStatus;
if (stakingStatus) {
emit Locked(tokenId);
} else {
emit Unlocked(tokenId);
}
}
/// @notice Checks whether the token ID exists.
/// @param tokenId The ID of the fighter to check for existence.
function doesTokenExist(uint256 tokenId) external view returns (bool) {
return _exists(tokenId);
}
/*//////////////////////////////////////////////////////////////
PUBLIC FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice Mints a new fighter from the merging pool.
/// @dev Only the merging pool contract address is authorized to call this function.
/// @param to The address that the new fighter will be assigned to.
/// @param customAttributes Array with [element, weight] of the newly created fighter.
function mintFromMergingPool(address to, uint256[2] calldata customAttributes) public {
require(msg.sender == mergingPoolAddress);
_createNewFighter(
to,
uint256(keccak256(abi.encode(to, fighters.length, block.timestamp))),
0,
0,
customAttributes
);
}
/// @notice Transfer NFT ownership from one address to another.
/// @dev Add a custom check for an ability to transfer the fighter.
/// @param from Address of the current owner.
/// @param to Address of the new owner.
/// @param tokenId ID of the fighter being transferred.
function transferFrom(
address from,
address to,
uint256 tokenId
)
public
override(ERC721, IERC721)
{
require(_ableToTransfer(tokenId));
_transfer(from, to, tokenId);
}
/// @notice Safely transfers an NFT from one address to another.
/// @dev Add a custom check for an ability to transfer the fighter.
/// @param from Address of the current owner.
/// @param to Address of the new owner.
/// @param tokenId ID of the fighter being transferred.
/// @param data Additional data.
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory data
)
public
virtual
override(ERC721, IERC721)
{
require(_ableToTransfer(tokenId));
_safeTransfer(from, to, tokenId, data);
}
/// @notice Rolls a new fighter with random traits.
/// @param tokenId ID of the fighter being re-rolled.
function reRoll(uint256 tokenId) public {
uint8 fighterType = fighters[tokenId].specialAttributes.dendroidBool ? 1 : 0;
require(msg.sender == ownerOf(tokenId));
require(numRerolls[tokenId] < maxRerollsAllowed[fighterType]);
require(_neuronInstance.balanceOf(msg.sender) >= rerollCost, "Not enough NRN for reroll");
bool success = _neuronInstance.transferFrom(msg.sender, treasuryAddress, rerollCost);
if (success) {
numRerolls[tokenId] += 1;
uint256 dna = uint256(keccak256(abi.encode(tokenId, numRerolls[tokenId], block.timestamp)));
(uint256 element, uint256 weight, uint256 newDna) = _createFighterBase(dna, fighterType);
fighters[tokenId].element = element;
fighters[tokenId].weight = weight;
fighters[tokenId].physicalAttributes = _aiArenaHelperInstance.createPhysicalAttributes(
newDna,
generation[fighterType],
fighters[tokenId].specialAttributes.iconsType,
fighters[tokenId].specialAttributes.dendroidBool,
true
);
fighters[tokenId].specialAttributes.rerolledBool = true;
_tokenURIs[tokenId] = _placeholderURI;
}
}
/// @notice Returns the URI where the contract metadata is stored.
/// @return URI where the contract metadata is stored.
function contractURI() public view returns (string memory) {
return _contractURI;
}
/// @notice Returns the URI where the token metadata is stored.
/// @param tokenId The ID of the fighter.
/// @return URI where the token metadata is stored.
function tokenURI(uint256 tokenId) public view override(ERC721) returns (string memory) {
return _tokenURIs[tokenId];
}
/// @notice Returns whether a given interface is supported by this contract.
/// @dev Calls ERC721.supportsInterface.
/// @param _interfaceId The interface ID.
/// @return Bool whether the interface is supported by this contract.
function supportsInterface(bytes4 _interfaceId)
public
view
override(ERC721, ERC721Enumerable)
returns (bool)
{
return super.supportsInterface(_interfaceId);
}
/// @notice Returns all information related to the specified fighter token ID.
/// @param tokenId The unique identifier for the fighter token.
function getAllFighterInfo(
uint256 tokenId
)
public
view
returns (
address,
uint256[6] memory,
uint256,
uint256,
uint16,
uint8[2] memory,
bool[2] memory
)
{
return FighterOps.viewFighterInfo(fighters[tokenId], ownerOf(tokenId));
}
/*//////////////////////////////////////////////////////////////
INTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice Hook that is called before a token transfer.
/// @param from The address transferring the token.
/// @param to The address receiving the token.
/// @param tokenId The ID of the NFT being transferred.
function _beforeTokenTransfer(address from, address to, uint256 tokenId)
internal
override(ERC721, ERC721Enumerable)
{
super._beforeTokenTransfer(from, to, tokenId);
}
/*//////////////////////////////////////////////////////////////
PRIVATE FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice Creates the base attributes for the fighter.
/// @param dna The dna of the fighter.
/// @param fighterType The type of the fighter.
/// @return Attributes of the new fighter: element, weight, and dna.
function _createFighterBase(
uint256 dna,
uint8 fighterType
)
private
view
returns (uint256, uint256, uint256)
{
uint256 element = dna % numElements[generation[fighterType]];
uint256 weight = dna % 31 + 65;
uint256 newDna = fighterType == 0 ? dna : uint256(fighterType);
return (element, weight, newDna);
}
/// @notice Creates a new fighter and mints an NFT to the specified address.
/// @param to The address to mint the new NFT to.
/// @param dna The DNA of the new fighter.
/// @param fighterType The type of fighter to create.
/// @param iconsType Type of icons fighter (0 means it's not an icon).
/// @param customAttributes Array with [element, weight] of the newly created fighter.
function _createNewFighter(
address to,
uint256 dna,
uint8 fighterType,
uint8 iconsType,
uint256[2] memory customAttributes
)
private
{
uint256 element;
uint256 weight;
uint256 newDna;
if (customAttributes[0] == 100) {
(element, weight, newDna) = _createFighterBase(dna, fighterType);
} else {
element = customAttributes[0];
weight = customAttributes[1];
newDna = dna;
}
uint256 newId = fighters.length;
bool dendroidBool = fighterType == 1;
FighterOps.FighterPhysicalAttributes memory attrs = _aiArenaHelperInstance.createPhysicalAttributes(
newDna,
generation[fighterType],
iconsType,
dendroidBool,
false
);
uint8 iconsId = 100;
if (iconsType == 1) {
iconsId = numIcons[0] + 2;
} else if (iconsType == 2) {
iconsId = 0;
} else if (iconsType == 3) {
iconsId = 1;
}
fighters.push(
FighterOps.Fighter(
weight,
element,
attrs,
newId,
generation[fighterType],
FighterOps.SpecialFighterAttributes(iconsId, iconsType, dendroidBool, false)
)
);
if (iconsType > 0) {
numIcons[iconsType - 1] += 1;
}
_safeMint(to, newId);
_tokenURIs[newId] = _placeholderURI;
FighterOps.fighterCreatedEmitter(newId, weight, element, generation[fighterType]);
}
/// @notice Check if the transfer of a specific token is allowed.
/// @dev Cannot receive another fighter if the user already has the maximum amount.
/// @dev Additionally, users cannot trade fighters that are currently staked.
/// @param tokenId The token ID of the fighter being transferred.
/// @return Bool whether the transfer is allowed or not.
function _ableToTransfer(uint256 tokenId) private view returns(bool) {
return (
_isApprovedOrOwner(msg.sender, tokenId) &&
!fighterStaked[tokenId]
);
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
/// @title FighterOps library for managing fighters in the AI Arena game.
/// @author ArenaX Labs Inc.
/// @notice This library is used for creating and managing Fighter NFTs in the AI Arena game.
library FighterOps {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
/// @notice Emitted when a new Fighter NFT is created.
event FighterCreated(
uint256 id,
uint256 weight,
uint256 element,
uint8 generation
);
/*//////////////////////////////////////////////////////////////
STRUCTS
//////////////////////////////////////////////////////////////*/
/// @notice Struct that defines a Fighter's physical attributes.
struct FighterPhysicalAttributes {
uint256 head;
uint256 eyes;
uint256 mouth;
uint256 body;
uint256 hands;
uint256 feet;
}
/// @notice Struct that defines a Fighter's special attributes.
struct SpecialFighterAttributes {
uint8 iconsId;
uint8 iconsType;
bool dendroidBool;
bool rerolledBool;
}
/// @notice Struct that defines a Fighter NFT.
struct Fighter {
uint256 weight;
uint256 element;
FighterPhysicalAttributes physicalAttributes;
uint256 id;
uint8 generation;
SpecialFighterAttributes specialAttributes;
}
/*//////////////////////////////////////////////////////////////
PUBLIC FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice Emits a FighterCreated event.
function fighterCreatedEmitter(
uint256 id,
uint256 weight,
uint256 element,
uint8 generation
)
public
{
emit FighterCreated(id, weight, element, generation);
}
/// @notice Extracting the fighter attributes from the struct
/// @param self Fighter struct
/// @return Array of Fighter Attributes
function getFighterAttributes(Fighter storage self) public view returns (uint256[6] memory) {
return [
self.physicalAttributes.head,
self.physicalAttributes.eyes,
self.physicalAttributes.mouth,
self.physicalAttributes.body,
self.physicalAttributes.hands,
self.physicalAttributes.feet
];
}
/// @notice Extracting the icons data from the special attributes struct
/// @param self Fighter struct
/// @return Array of Icons Data
function getIconsData(Fighter storage self) public view returns (uint8[2] memory) {
return [self.specialAttributes.iconsId, self.specialAttributes.iconsType];
}
/// @notice Extracting the special bools from the special attributes struct
/// @param self Fighter struct
/// @return Array of Special Bools
function getSpecialBools(Fighter storage self) public view returns (bool[2] memory) {
return [self.specialAttributes.dendroidBool, self.specialAttributes.rerolledBool];
}
/// @notice Gets all of the relevant fighter information
function viewFighterInfo(
Fighter storage self,
address owner
)
public
view
returns (
address,
uint256[6] memory,
uint256,
uint256,
uint16,
uint8[2] memory,
bool[2] memory
)
{
return (
owner,
getFighterAttributes(self),
self.weight,
self.element,
self.generation,
getIconsData(self),
getSpecialBools(self)
);
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.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 (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.7.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: 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 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.5.0) (token/ERC721/extensions/IERC721Enumerable.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
/// @title Neuron
/// @author ArenaX Labs Inc.
/// @notice ERC20 token contract representing Neuron (NRN) tokens.
contract Neuron is ERC20 {
/*//////////////////////////////////////////////////////////////
STATE VARIABLES
//////////////////////////////////////////////////////////////*/
/// @notice Maximum supply of Neuron tokens.
uint256 public constant MAX_SUPPLY = 10**18 * 10**9;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
/// @notice Mints the initial supply to the ditribution address.
/// @param initialDistributionAddress The initial address that will receive all the tokens and
/// then proceed to distribute them
constructor(address initialDistributionAddress) ERC20("Neuron", "NRN") {
_mint(initialDistributionAddress, MAX_SUPPLY);
}
/*//////////////////////////////////////////////////////////////
PUBLIC FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice Burns the specified amount of tokens from the caller's address.
/// @param amount The amount of tokens to be burned.
function burn(uint256 amount) public virtual {
_burn(msg.sender, amount);
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
library Verification {
using ECDSA for bytes32;
function verify(
address signer,
bytes32 messageHash,
bytes memory signature
)
public
pure
returns (bool)
{
// Since the message is already a hash, directly prepare it for signature verification
bytes32 ethSignedMessageHash = messageHash.toEthSignedMessageHash();
// Recover the signer's address from the signature
address recoveredSigner = ethSignedMessageHash.recover(signature);
// Check if the recovered address is the same as the expected signer
return recoveredSigner == signer;
}
}
{
"compilationTarget": {
"src/FighterFarm.sol": "FighterFarm"
},
"evmVersion": "paris",
"libraries": {
"src/FighterOps.sol:FighterOps": "0xd32b1d0ba24ba527257fab75afecd8a906db973c",
"src/Verification.sol:Verification": "0xf5cb875678b2067188e19ef97ced5807edbce3cf"
},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": [
":@openzeppelin/=lib/openzeppelin-contracts/",
":ds-test/=lib/forge-std/lib/ds-test/src/",
":forge-std/=lib/forge-std/src/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/"
]
}
[{"inputs":[{"internalType":"address","name":"ownerAddress_","type":"address"},{"internalType":"address","name":"delegatedAddress_","type":"address"},{"internalType":"address","name":"treasuryAddress_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Locked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Unlocked","type":"event"},{"inputs":[{"internalType":"address","name":"adminAddress","type":"address"},{"internalType":"bool","name":"access","type":"bool"}],"name":"adjustAdminAccess","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"stakerAddress","type":"address"},{"internalType":"bool","name":"access","type":"bool"}],"name":"adjustStakingAccess","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"aiArenaHelperAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint8[2]","name":"numToMint","type":"uint8[2]"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"claimFighters","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"contractURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"delegatedAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"doesTokenExist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"fighterStaked","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"fighters","outputs":[{"internalType":"uint256","name":"weight","type":"uint256"},{"internalType":"uint256","name":"element","type":"uint256"},{"components":[{"internalType":"uint256","name":"head","type":"uint256"},{"internalType":"uint256","name":"eyes","type":"uint256"},{"internalType":"uint256","name":"mouth","type":"uint256"},{"internalType":"uint256","name":"body","type":"uint256"},{"internalType":"uint256","name":"hands","type":"uint256"},{"internalType":"uint256","name":"feet","type":"uint256"}],"internalType":"struct FighterOps.FighterPhysicalAttributes","name":"physicalAttributes","type":"tuple"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint8","name":"generation","type":"uint8"},{"components":[{"internalType":"uint8","name":"iconsId","type":"uint8"},{"internalType":"uint8","name":"iconsType","type":"uint8"},{"internalType":"bool","name":"dendroidBool","type":"bool"},{"internalType":"bool","name":"rerolledBool","type":"bool"}],"internalType":"struct FighterOps.SpecialFighterAttributes","name":"specialAttributes","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"generation","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getAllFighterInfo","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256[6]","name":"","type":"uint256[6]"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint16","name":"","type":"uint16"},{"internalType":"uint8[2]","name":"","type":"uint8[2]"},{"internalType":"bool[2]","name":"","type":"bool[2]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"hasStakerRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint8","name":"fighterType","type":"uint8"}],"name":"incrementGeneration","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"aiArenaHelperAddress_","type":"address"}],"name":"instantiateAIArenaHelperContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"mintpassAddress_","type":"address"}],"name":"instantiateMintpassContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"neuronAddress_","type":"address"}],"name":"instantiateNeuronContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isAdmin","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"maxRerollsAllowed","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mergingPoolAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256[2]","name":"customAttributes","type":"uint256[2]"}],"name":"mintFromMergingPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"mintpassAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"neuronAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint8","name":"","type":"uint8"}],"name":"nftsClaimed","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint8","name":"","type":"uint8"}],"name":"numElements","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"numIcons","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"numRerolls","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ownerAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"reRoll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"mintpassIdsToBurn","type":"uint256[]"},{"internalType":"uint8[]","name":"fighterTypes","type":"uint8[]"},{"internalType":"uint8[]","name":"iconsTypes","type":"uint8[]"},{"internalType":"string[]","name":"mintPassDnas","type":"string[]"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"redeemMintPass","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rerollCost","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"newContractURI","type":"string"}],"name":"setContractURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"delegatedAddress_","type":"address"}],"name":"setDelegatedAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"mergingPoolAddress_","type":"address"}],"name":"setMergingPoolAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"newNumElements","type":"uint8"},{"internalType":"uint8","name":"generation_","type":"uint8"}],"name":"setNumElements","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newRerollCost","type":"uint256"}],"name":"setRerollCost","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"string","name":"newTokenURI","type":"string"}],"name":"setTokenURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"treasuryAddress_","type":"address"}],"name":"setTreasuryAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","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":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwnerAddress","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"treasuryAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bool","name":"stakingStatus","type":"bool"}],"name":"updateFighterStaking","outputs":[],"stateMutability":"nonpayable","type":"function"}]