¡El código fuente de este contrato está verificado!
Metadatos del Contrato
Compilador
0.8.24+commit.e11b9ed9
Idioma
Solidity
Código Fuente del Contrato
Archivo 1 de 17: Address.sol
Código Fuente del Contrato
Archivo 2 de 17: Context.sol
Código Fuente del Contrato
Archivo 3 de 17: Counters.sol
Código Fuente del Contrato
Archivo 4 de 17: ERC165.sol
Código Fuente del Contrato
Archivo 5 de 17: ERC721.sol
Código Fuente del Contrato
Archivo 6 de 17: ERC721Enumerable.sol
Código Fuente del Contrato
Archivo 7 de 17: IERC165.sol
Código Fuente del Contrato
Archivo 8 de 17: IERC20.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)pragmasolidity ^0.8.20;/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/interfaceIERC20{
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/eventTransfer(addressindexedfrom, addressindexed 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.
*/eventApproval(addressindexed owner, addressindexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransfer(address to, uint256 value) externalreturns (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.
*/functionallowance(address owner, address spender) externalviewreturns (uint256);
/**
* @dev Sets a `value` amount of tokens 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.
*/functionapprove(address spender, uint256 value) externalreturns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransferFrom(addressfrom, address to, uint256 value) externalreturns (bool);
}
Código Fuente del Contrato
Archivo 9 de 17: IERC721.sol
Código Fuente del Contrato
Archivo 10 de 17: IERC721Enumerable.sol
Código Fuente del Contrato
Archivo 11 de 17: IERC721Metadata.sol
Código Fuente del Contrato
Archivo 12 de 17: IERC721Receiver.sol
Código Fuente del Contrato
Archivo 13 de 17: MerkleProof.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/MerkleProof.sol)pragmasolidity ^0.8.20;/**
* @dev These functions deal with verification of Merkle Tree proofs.
*
* The tree and the proofs can be generated using our
* https://github.com/OpenZeppelin/merkle-tree[JavaScript library].
* You will find a quickstart guide in the readme.
*
* WARNING: You should avoid using leaf values that are 64 bytes long prior to
* hashing, or use a hash function other than keccak256 for hashing leaves.
* This is because the concatenation of a sorted pair of internal nodes in
* the Merkle tree could be reinterpreted as a leaf value.
* OpenZeppelin's JavaScript library generates Merkle trees that are safe
* against this attack out of the box.
*/libraryMerkleProof{
/**
*@dev The multiproof provided is not valid.
*/errorMerkleProofInvalidMultiproof();
/**
* @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
* defined by `root`. For this, a `proof` must be provided, containing
* sibling hashes on the branch from the leaf to the root of the tree. Each
* pair of leaves and each pair of pre-images are assumed to be sorted.
*/functionverify(bytes32[] memory proof, bytes32 root, bytes32 leaf) internalpurereturns (bool) {
return processProof(proof, leaf) == root;
}
/**
* @dev Calldata version of {verify}
*/functionverifyCalldata(bytes32[] calldata proof, bytes32 root, bytes32 leaf) internalpurereturns (bool) {
return processProofCalldata(proof, leaf) == root;
}
/**
* @dev Returns the rebuilt hash obtained by traversing a Merkle tree up
* from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
* hash matches the root of the tree. When processing the proof, the pairs
* of leafs & pre-images are assumed to be sorted.
*/functionprocessProof(bytes32[] memory proof, bytes32 leaf) internalpurereturns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i =0; i < proof.length; i++) {
computedHash = _hashPair(computedHash, proof[i]);
}
return computedHash;
}
/**
* @dev Calldata version of {processProof}
*/functionprocessProofCalldata(bytes32[] calldata proof, bytes32 leaf) internalpurereturns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i =0; i < proof.length; i++) {
computedHash = _hashPair(computedHash, proof[i]);
}
return computedHash;
}
/**
* @dev Returns true if the `leaves` can be simultaneously proven to be a part of a Merkle tree defined by
* `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.
*
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
*/functionmultiProofVerify(bytes32[] memory proof,
bool[] memory proofFlags,
bytes32 root,
bytes32[] memory leaves
) internalpurereturns (bool) {
return processMultiProof(proof, proofFlags, leaves) == root;
}
/**
* @dev Calldata version of {multiProofVerify}
*
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
*/functionmultiProofVerifyCalldata(bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32 root,
bytes32[] memory leaves
) internalpurereturns (bool) {
return processMultiProofCalldata(proof, proofFlags, leaves) == root;
}
/**
* @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction
* proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another
* leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false
* respectively.
*
* CAUTION: Not all Merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
* is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
* tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
*/functionprocessMultiProof(bytes32[] memory proof,
bool[] memory proofFlags,
bytes32[] memory leaves
) internalpurereturns (bytes32 merkleRoot) {
// This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by// consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the// `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of// the Merkle tree.uint256 leavesLen = leaves.length;
uint256 proofLen = proof.length;
uint256 totalHashes = proofFlags.length;
// Check proof validity.if (leavesLen + proofLen != totalHashes +1) {
revert MerkleProofInvalidMultiproof();
}
// The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using// `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".bytes32[] memory hashes =newbytes32[](totalHashes);
uint256 leafPos =0;
uint256 hashPos =0;
uint256 proofPos =0;
// At each step, we compute the next hash using two values:// - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we// get the next hash.// - depending on the flag, either another value from the "main queue" (merging branches) or an element from the// `proof` array.for (uint256 i =0; i < totalHashes; i++) {
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
bytes32 b = proofFlags[i]
? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
: proof[proofPos++];
hashes[i] = _hashPair(a, b);
}
if (totalHashes >0) {
if (proofPos != proofLen) {
revert MerkleProofInvalidMultiproof();
}
unchecked {
return hashes[totalHashes -1];
}
} elseif (leavesLen >0) {
return leaves[0];
} else {
return proof[0];
}
}
/**
* @dev Calldata version of {processMultiProof}.
*
* CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
*/functionprocessMultiProofCalldata(bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32[] memory leaves
) internalpurereturns (bytes32 merkleRoot) {
// This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by// consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the// `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of// the Merkle tree.uint256 leavesLen = leaves.length;
uint256 proofLen = proof.length;
uint256 totalHashes = proofFlags.length;
// Check proof validity.if (leavesLen + proofLen != totalHashes +1) {
revert MerkleProofInvalidMultiproof();
}
// The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using// `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".bytes32[] memory hashes =newbytes32[](totalHashes);
uint256 leafPos =0;
uint256 hashPos =0;
uint256 proofPos =0;
// At each step, we compute the next hash using two values:// - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we// get the next hash.// - depending on the flag, either another value from the "main queue" (merging branches) or an element from the// `proof` array.for (uint256 i =0; i < totalHashes; i++) {
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
bytes32 b = proofFlags[i]
? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
: proof[proofPos++];
hashes[i] = _hashPair(a, b);
}
if (totalHashes >0) {
if (proofPos != proofLen) {
revert MerkleProofInvalidMultiproof();
}
unchecked {
return hashes[totalHashes -1];
}
} elseif (leavesLen >0) {
return leaves[0];
} else {
return proof[0];
}
}
/**
* @dev Sorts the pair (a, b) and hashes the result.
*/function_hashPair(bytes32 a, bytes32 b) privatepurereturns (bytes32) {
return a < b ? _efficientHash(a, b) : _efficientHash(b, a);
}
/**
* @dev Implementation of keccak256(abi.encode(a, b)) that doesn't allocate or expand memory.
*/function_efficientHash(bytes32 a, bytes32 b) privatepurereturns (bytes32 value) {
/// @solidity memory-safe-assemblyassembly {
mstore(0x00, a)
mstore(0x20, b)
value :=keccak256(0x00, 0x40)
}
}
}
Código Fuente del Contrato
Archivo 14 de 17: Ownable.sol
Código Fuente del Contrato
Archivo 15 de 17: ReentrancyGuard.sol
Código Fuente del Contrato
Archivo 16 de 17: Strings.sol
Código Fuente del Contrato
Archivo 17 de 17: erctamagotchi.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;import"https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.5.0/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import"https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.5.0/contracts/security/ReentrancyGuard.sol";
import"https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.5.0/contracts/utils/Counters.sol";
import"https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.5.0/contracts/access/Ownable.sol";
import"@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import"@openzeppelin/contracts/token/ERC20/IERC20.sol"; // Use IERC20 interfacecontractTamagotchiERCisERC721Enumerable, ReentrancyGuard, Ownable{
usingCountersforCounters.Counter;
Counters.Counter private _tokenIdCounter;
mapping(uint256=>uint256) public tokenMintTimestamps;
mapping(uint256=>uint256) public claimCounts;
mapping(uint256=>string) private _evolvedURIs;
mapping(uint256=>bool) public hasEvolved;
stringprivate _baseTokenURI;
stringprivate _baseEvolvedTokenURI;
stringprivate _contractURI;
uint256public evolvedCount;
bytes32public merkleRoot;
uint256public HOLDING_PERIOD =6hours;
uint256publicconstant REWARD_AMOUNT =10* (10**18);
uint256publicconstant EVOLVED_REWARD_AMOUNT =30* (10**18);
uint256publicconstant INITIAL_CLAIM_AMOUNT =100* (10**18);
IERC20 public rewardToken;
mapping(uint256=>bool) public hasClaimedInitialAmount;
uint256public evolveInterval =800;
boolpublic gameStarted =false;
uint256publicconstant MINT_PRICE =0.012ether;
uint256publicconstant WL_MINT_PRICE =0.006ether;
uint256publicconstant MAX_MINT_PER_WALLET =200;
uint256publicconstant MAX_MINT_AT_ONCE =100;
uint256publicconstant MAX_WL_MINT_PER_WALLET =20;
uint256publicconstant MAX_WL_MINT_AT_ONCE =20;
uint256constantpublic MAX_TIME_DURATION =1hours;
mapping(address=>uint256) public mintedPerWallet;
boolpublic mintingOpen =false;
boolpublic WLopen =false;
constructor() ERC721("BASED PETS", "GOTCHI") Ownable() {}
functionisValidTimestamp(uint256 _timestamp) internalviewreturns (bool) {
uint256 currentBlockTime =block.timestamp;
uint256 currentBlockStart = currentBlockTime - (currentBlockTime % MAX_TIME_DURATION);
uint256 currentBlockEnd = currentBlockStart + MAX_TIME_DURATION;
return (_timestamp >= currentBlockStart && _timestamp < currentBlockEnd);
}
functionsetRewardToken(address _rewardTokenAddress) publiconlyOwner{
require(address(rewardToken) ==address(0), "RewardToken contract address already set");
rewardToken = IERC20(_rewardTokenAddress);
}
functionsetURIs(stringmemory baseTokenURI_, stringmemory baseEvolvedTokenURI_) publiconlyOwner{
_baseTokenURI = baseTokenURI_;
_baseEvolvedTokenURI = baseEvolvedTokenURI_;
}
functionsetContractURI(stringmemory contractURI_) publiconlyOwner{
_contractURI = contractURI_;
}
functionstartGame() publiconlyOwner{
gameStarted =true;
}
functionopenMint() publiconlyOwner{
if (mintingOpen ==true) {
mintingOpen =false;
} else {
mintingOpen =true;
}
}
functionopenWL() publiconlyOwner{
if (WLopen ==true) {
WLopen =false;
} else {
WLopen =true;
}
}
functionnumberOfEvolvedPets(address user) publicviewreturns (uint256 count) {
uint256 ownerTokenCount = balanceOf(user);
count =0;
for (uint256 i =0; i < ownerTokenCount; i++) {
uint256 tokenId = tokenOfOwnerByIndex(user, i);
if (hasEvolved[tokenId]) {
count +=1;
}
}
}
functionmintNFT(uint256 quantity) publicpayable{
require(mintingOpen, "Minting is closed");
require(quantity >0&& quantity <= MAX_MINT_AT_ONCE, "Cannot mint specified number at once");
require(mintedPerWallet[msg.sender] + quantity <= MAX_MINT_PER_WALLET, "Exceeds maximum per wallet");
require(msg.value>= MINT_PRICE * quantity, "Ether sent is not correct");
for (uint256 i =0; i < quantity; i++) {
_tokenIdCounter.increment();
uint256 tokenId = _tokenIdCounter.current();
_mint(msg.sender, tokenId);
tokenMintTimestamps[tokenId] =block.timestamp;
claimCounts[tokenId] =0;
}
mintedPerWallet[msg.sender] += quantity;
}
functionwhitelistMint(uint256 quantity, bytes32[] calldata merkleProof) publicpayable{
require(WLopen, "Whitelist is closed");
require(mintingOpen, "Minting is closed");
require(quantity >0&& quantity <= MAX_WL_MINT_AT_ONCE, "Cannot mint specified number at once");
require(mintedPerWallet[msg.sender] + quantity <= MAX_WL_MINT_PER_WALLET, "Exceeds maximum whitelist mint per wallet");
require(msg.value>= WL_MINT_PRICE * quantity, "Ether sent is not correct");
bytes32 leaf =keccak256(abi.encodePacked(msg.sender));
require(MerkleProof.verify(merkleProof, merkleRoot, leaf), "Invalid Merkle Proof");
for (uint256 i =0; i < quantity; i++) {
_tokenIdCounter.increment();
uint256 tokenId = _tokenIdCounter.current();
_mint(msg.sender, tokenId);
tokenMintTimestamps[tokenId] =block.timestamp;
claimCounts[tokenId] =0;
}
mintedPerWallet[msg.sender] += quantity;
}
functionclaimAllRewards() publicnonReentrant{
require(gameStarted, "Game has not started yet");
uint256 ownerTokenCount = balanceOf(msg.sender);
require(ownerTokenCount >0, "No NFTs owned.");
uint256 totalReward =0;
for (uint256 i =0; i < ownerTokenCount; i++) {
uint256 tokenId = tokenOfOwnerByIndex(msg.sender, i);
if (!hasClaimedInitialAmount[tokenId] ||block.timestamp>= tokenMintTimestamps[tokenId] + HOLDING_PERIOD) {
tokenMintTimestamps[tokenId] =block.timestamp;
uint256 rewardAmount;
if (!hasClaimedInitialAmount[tokenId]) {
rewardAmount = INITIAL_CLAIM_AMOUNT;
hasClaimedInitialAmount[tokenId] =true;
} else {
rewardAmount = hasEvolved[tokenId] ? EVOLVED_REWARD_AMOUNT : REWARD_AMOUNT;
}
totalReward += rewardAmount;
claimCounts[tokenId] +=1;
if (claimCounts[tokenId] >=5) {
evolve(tokenId);
}
}
}
require(totalReward >0, "No rewards available to claim.");
bool sent = rewardToken.transfer(msg.sender, totalReward);
require(sent, "Reward token transfer failed.");
}
functiontokenURI(uint256 tokenId) publicviewoverridereturns (stringmemory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
if (hasEvolved[tokenId]) {
returnstring(abi.encodePacked(_baseEvolvedTokenURI, Strings.toString(tokenId)));
} else {
returnstring(abi.encodePacked(_baseTokenURI, Strings.toString(tokenId)));
}
}
functioncontractURI() publicviewreturns (stringmemory) {
return _contractURI;
}
functionsetEvolveInterval(uint256 interval) publiconlyOwner{
evolveInterval = interval;
}
functionevolve(uint256 tokenId) public{
require(ownerOf(tokenId) ==msg.sender, "Caller is not the owner");
require(claimCounts[tokenId] >=5, "Not enough claims to evolve");
require(isValidTimestamp(block.timestamp), "Invalid timestamp");
require(!hasEvolved[tokenId], "Token has already evolved");
hasEvolved[tokenId] =true;
evolvedCount++;
if (evolvedCount % evolveInterval ==0) {
HOLDING_PERIOD +=6hours;
}
}
functionwithdraw(uint256 amount) publiconlyOwner{
require(amount <=address(this).balance, "Insufficient balance");
(bool sent, ) = owner().call{value: amount}("");
require(sent, "Failed to send Ether");
}
functionsetMerkleRoot(bytes32 _merkleRoot) publiconlyOwner{
merkleRoot = _merkleRoot;
}
}