增加202306活动相关合约

This commit is contained in:
zhl 2023-06-14 11:40:27 +08:00
parent bae404762d
commit 4e9e7bb42a
5 changed files with 43970 additions and 13 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,74 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.10;
import "../core/HasSignature.sol";
import "../utils/TimeChecker.sol";
interface IClaimBox {
function mint(address to) external returns (uint256);
}
contract ClaimBoxFactory is HasSignature, TimeChecker {
address public executor;
mapping(address => bool) public tokenSupported;
event BoxClaimed(
address indexed nftAddress,
address indexed to,
uint256 indexed nonce,
uint256 tokenId
);
constructor() HasSignature("ClaimBoxFactory", "1") {}
function addTokenSupport(address nftToken) external onlyOwner {
tokenSupported[nftToken] = true;
}
function removeTokenSupport(address nftToken) external onlyOwner {
tokenSupported[nftToken] = false;
}
/**
* @dev update executor
*/
function updateExecutor(address account) external onlyOwner {
require(account != address(0), "ClaimBoxFactory: address can not be zero");
executor = account;
}
function claim(
address nftAddress,
uint256 startTime,
uint256 saltNonce,
bytes calldata signature
) external signatureValid(signature) timeValid(startTime) {
require(tokenSupported[nftAddress], "ClaimBoxFactory: unsupported NFT");
address to = _msgSender();
bytes32 criteriaMessageHash = getMessageHash(
to,
nftAddress,
startTime,
saltNonce
);
checkSigner(executor, criteriaMessageHash, signature);
uint256 tokenId = IClaimBox(nftAddress).mint(to);
_useSignature(signature);
emit BoxClaimed(nftAddress, to, saltNonce, tokenId);
}
function getMessageHash(
address _to,
address _address,
uint256 _startTime,
uint256 _saltNonce
) public pure returns (bytes32) {
bytes memory encoded = abi.encodePacked(
_to,
_address,
_startTime,
_saltNonce
);
return keccak256(encoded);
}
}

View File

@ -2,12 +2,14 @@
pragma solidity 0.8.10;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
contract Soulbound is ERC721Enumerable, Ownable {
contract SoulboundNFT is AccessControl, ERC721Enumerable {
using Counters for Counters.Counter;
string private _baseTokenURI = "https://market.cebg.games/api/nft/info/";
bytes32 public constant BURN_ROLE = keccak256("BURN_ROLE");
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
uint256 public immutable supplyLimit;
Counters.Counter private _tokenIdCounter;
@ -18,6 +20,27 @@ contract Soulbound is ERC721Enumerable, Ownable {
uint256 _supplyLimt
) ERC721(_name, _symbol) {
supplyLimit = _supplyLimt;
_setRoleAdmin(BURN_ROLE, DEFAULT_ADMIN_ROLE);
_setRoleAdmin(MINTER_ROLE, DEFAULT_ADMIN_ROLE);
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
_setupRole(MINTER_ROLE, msg.sender);
_setupRole(BURN_ROLE, msg.sender);
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(
bytes4 interfaceId
)
public
view
virtual
override(AccessControl, ERC721Enumerable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
function _beforeTokenTransfer(
@ -25,21 +48,67 @@ contract Soulbound is ERC721Enumerable, Ownable {
address to,
uint256 tokenId
) internal override(ERC721Enumerable) {
require(from == address(0), "Token not transferable");
require(from == address(0) || to == address(0), "Token not transferable");
super._beforeTokenTransfer(from, to, tokenId);
}
function mint() public {
if (supplyLimit > 0) {
require((totalSupply() + 1) <= supplyLimit, "Exceed the total supply");
}
address to = msg.sender;
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
}
function _baseURI() internal view virtual override returns (string memory) {
return _baseTokenURI;
}
/**
* @dev Set token URI
*/
function updateBaseURI(
string calldata baseTokenURI
) external onlyRole(DEFAULT_ADMIN_ROLE) {
_baseTokenURI = baseTokenURI;
}
function mint(address to) external onlyRole(MINTER_ROLE) returns (uint256) {
require(to != address(0), "Cannot mint to zero address");
if (supplyLimit > 0) {
require((totalSupply() + 1) <= supplyLimit, "Exceed the total supply");
}
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
return tokenId;
}
function burn(uint256 tokenId) external onlyRole(BURN_ROLE) {
require(
_isApprovedOrOwner(_msgSender(), tokenId),
"Caller is not owner nor approved"
);
_burn(tokenId);
}
/**
* @dev Grant mint role to address
*/
function setMintRole(address to) external {
grantRole(MINTER_ROLE, to);
}
/**
* @dev Remove mint role to address
*/
function removeMintRole(address to) external {
revokeRole(MINTER_ROLE, to);
}
/**
* @dev Grant burn role to address
*/
function setBurnRole(address to) external {
grantRole(BURN_ROLE, to);
}
/**
* @dev Remove burn role to address
*/
function removeBurnRole(address to) external {
revokeRole(BURN_ROLE, to);
}
}