编译器
0.8.24+commit.e11b9ed9
文件 1 的 13:Context.sol
pragma solidity ^0.8.20;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
文件 2 的 13:ERC1155Holder.sol
pragma solidity ^0.8.20;
import {IERC165, ERC165} from "../../../utils/introspection/ERC165.sol";
import {IERC1155Receiver} from "../IERC1155Receiver.sol";
abstract contract ERC1155Holder is ERC165, IERC1155Receiver {
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);
}
function onERC1155Received(
address,
address,
uint256,
uint256,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address,
address,
uint256[] memory,
uint256[] memory,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155BatchReceived.selector;
}
}
文件 3 的 13:ERC165.sol
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
abstract contract ERC165 is IERC165 {
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
文件 4 的 13:ERC721Holder.sol
pragma solidity ^0.8.20;
import {IERC721Receiver} from "../IERC721Receiver.sol";
abstract contract ERC721Holder is IERC721Receiver {
function onERC721Received(address, address, uint256, bytes memory) public virtual returns (bytes4) {
return this.onERC721Received.selector;
}
}
文件 5 的 13:GenesisClaim.sol
pragma solidity 0.8.24;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IERC1155} from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import {ERC721Holder} from "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
import {ERC1155Holder} from "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
import {IGenesisERC721} from "./IGenesisERC721.sol";
import {GenesisNftTypes} from "../lib/GenesisNftTypes.sol";
contract GenesisClaim is Ownable, ERC721Holder, ERC1155Holder {
struct UserData {
uint64 silverNftAmount;
uint64 goldNftAmount;
uint64 blackGoldNftAmount;
uint[] nftIds;
}
address[] public userAddresses;
mapping(address => UserData) public userData;
address public genesisERC1155Address;
address public genesisERC721Address;
string public silverNftUri;
string public goldNftUri;
string public blackGoldNftUri;
constructor(address genesisERC1155Address_, address genesisERC721Address_, string memory silverNftUri_, string memory goldNftUri_, string memory blackGoldNftUri_) Ownable(_msgSender()) {
genesisERC1155Address = genesisERC1155Address_;
genesisERC721Address = genesisERC721Address_;
silverNftUri = silverNftUri_;
goldNftUri = goldNftUri_;
blackGoldNftUri = blackGoldNftUri_;
}
function getUserAddresses()
public view returns (address[] memory) {
return userAddresses;
}
function getUserNftIds(address userAddress)
public view returns (uint[] memory) {
return userData[userAddress].nftIds;
}
function claim()
public {
IERC1155 genesisERC1155 = IERC1155(genesisERC1155Address);
IGenesisERC721 genesisERC721 = IGenesisERC721(genesisERC721Address);
uint64 silverNftAmount = uint64(genesisERC1155.balanceOf(_msgSender(), GenesisNftTypes.SILVER));
uint64 goldNftAmount = uint64(genesisERC1155.balanceOf(_msgSender(), GenesisNftTypes.GOLD));
uint64 blackGoldNftAmount = uint64(genesisERC1155.balanceOf(_msgSender(), GenesisNftTypes.BLACK_GOLD));
if (silverNftAmount == 0 && goldNftAmount == 0 && blackGoldNftAmount == 0) {
revert("You do not have any Genesis NFT");
}
userAddresses.push(_msgSender());
UserData storage data = userData[_msgSender()];
uint[] storage userNftIds = data.nftIds;
if (silverNftAmount > 0) {
genesisERC1155.safeTransferFrom(_msgSender(), address(this), 1, silverNftAmount, "0x0");
data.silverNftAmount += silverNftAmount;
for (uint i; i < silverNftAmount; i++) {
userNftIds.push(genesisERC721.safeMint(address(this), silverNftUri, GenesisNftTypes.SILVER));
}
}
if (goldNftAmount > 0) {
genesisERC1155.safeTransferFrom(_msgSender(), address(this), 2, goldNftAmount, "0x0");
data.goldNftAmount += goldNftAmount;
for (uint i; i < goldNftAmount; i++) {
userNftIds.push(genesisERC721.safeMint(address(this), goldNftUri, GenesisNftTypes.GOLD));
}
}
if (blackGoldNftAmount > 0) {
genesisERC1155.safeTransferFrom(_msgSender(), address(this), 3, blackGoldNftAmount, "0x0");
data.blackGoldNftAmount += blackGoldNftAmount;
for (uint i; i < blackGoldNftAmount; i++) {
userNftIds.push(genesisERC721.safeMint(address(this), blackGoldNftUri, GenesisNftTypes.BLACK_GOLD));
}
}
emit Claim(_msgSender());
}
function lock(uint[] calldata nftIds)
public {
IGenesisERC721 genesisERC721 = IGenesisERC721(genesisERC721Address);
userAddresses.push(_msgSender());
uint[] storage userNftIds = userData[_msgSender()].nftIds;
for (uint i; i < nftIds.length; i++) {
genesisERC721.transferFrom(_msgSender(), address(this), nftIds[i]);
userNftIds.push(nftIds[i]);
}
emit Lock(_msgSender());
}
function unlock(uint[] calldata nftIds)
public {
IGenesisERC721 genesisERC721 = IGenesisERC721(genesisERC721Address);
uint[] storage userNftIds = userData[_msgSender()].nftIds;
for (uint i; i < nftIds.length; i++) {
if (!_removeFromArray(userNftIds, nftIds[i])) {
revert NftNotFound(nftIds[i]);
}
genesisERC721.transferFrom(address(this), _msgSender(), nftIds[i]);
}
emit Unlock(_msgSender());
}
function unlockAll()
public {
IGenesisERC721 genesisERC721 = IGenesisERC721(genesisERC721Address);
UserData storage data = userData[_msgSender()];
uint[] storage userNftIds = data.nftIds;
for (uint i; i < userNftIds.length; i++) {
genesisERC721.transferFrom(address(this), _msgSender(), userNftIds[i]);
}
delete data.nftIds;
emit UnlockAll(_msgSender());
}
function _removeFromArray(uint[] storage arr, uint val)
internal returns (bool) {
uint arrLength = arr.length;
for (uint i = 0; i < arrLength; i++) {
if (arr[i] == val) {
arr[i] = arr[arrLength - 1];
arr.pop();
return true;
}
}
return false;
}
error NftNotFound(uint nftId);
event Claim(address userAddress);
event Lock(address userAddress);
event Unlock(address userAddress);
event UnlockAll(address userAddress);
}
文件 6 的 13:GenesisNftTypes.sol
pragma solidity 0.8.24;
library GenesisNftTypes {
uint16 public constant UNKNOWN = 0;
uint16 public constant SILVER = 1;
uint16 public constant GOLD = 2;
uint16 public constant BLACK_GOLD = 3;
}
文件 7 的 13:IERC1155.sol
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
interface IERC1155 is IERC165 {
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
event TransferBatch(
address indexed operator,
address indexed from,
address indexed to,
uint256[] ids,
uint256[] values
);
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
event URI(string value, uint256 indexed id);
function balanceOf(address account, uint256 id) external view returns (uint256);
function balanceOfBatch(
address[] calldata accounts,
uint256[] calldata ids
) external view returns (uint256[] memory);
function setApprovalForAll(address operator, bool approved) external;
function isApprovedForAll(address account, address operator) external view returns (bool);
function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes calldata data) external;
function safeBatchTransferFrom(
address from,
address to,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external;
}
文件 8 的 13:IERC1155Receiver.sol
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
interface IERC1155Receiver is IERC165 {
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}
文件 9 的 13:IERC165.sol
pragma solidity ^0.8.20;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 10 的 13:IERC721.sol
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
interface IERC721 is IERC165 {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
function balanceOf(address owner) external view returns (uint256 balance);
function ownerOf(uint256 tokenId) external view returns (address owner);
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
function safeTransferFrom(address from, address to, uint256 tokenId) external;
function transferFrom(address from, address to, uint256 tokenId) external;
function approve(address to, uint256 tokenId) external;
function setApprovalForAll(address operator, bool approved) external;
function getApproved(uint256 tokenId) external view returns (address operator);
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
文件 11 的 13:IERC721Receiver.sol
pragma solidity ^0.8.20;
interface IERC721Receiver {
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
文件 12 的 13:IGenesisERC721.sol
pragma solidity 0.8.24;
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
interface IGenesisERC721 is IERC721 {
function safeMint(address to, string calldata uri, uint tokenType) external returns (uint);
}
文件 13 的 13:Ownable.sol
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
error OwnableUnauthorizedAccount(address account);
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
{
"compilationTarget": {
"contracts/GenesisClaim.sol": "GenesisClaim"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 1000000
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"genesisERC1155Address_","type":"address"},{"internalType":"address","name":"genesisERC721Address_","type":"address"},{"internalType":"string","name":"silverNftUri_","type":"string"},{"internalType":"string","name":"goldNftUri_","type":"string"},{"internalType":"string","name":"blackGoldNftUri_","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"nftId","type":"uint256"}],"name":"NftNotFound","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"userAddress","type":"address"}],"name":"Claim","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"userAddress","type":"address"}],"name":"Lock","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"userAddress","type":"address"}],"name":"Unlock","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"userAddress","type":"address"}],"name":"UnlockAll","type":"event"},{"inputs":[],"name":"blackGoldNftUri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"genesisERC1155Address","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"genesisERC721Address","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getUserAddresses","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"userAddress","type":"address"}],"name":"getUserNftIds","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"goldNftUri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"nftIds","type":"uint256[]"}],"name":"lock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155BatchReceived","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"silverNftUri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"nftIds","type":"uint256[]"}],"name":"unlock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unlockAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"userAddresses","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userData","outputs":[{"internalType":"uint64","name":"silverNftAmount","type":"uint64"},{"internalType":"uint64","name":"goldNftAmount","type":"uint64"},{"internalType":"uint64","name":"blackGoldNftAmount","type":"uint64"}],"stateMutability":"view","type":"function"}]