编译器
0.8.14+commit.80d49f37
文件 1 的 17:Address.sol
pragma solidity ^0.8.1;
library Address {
function isContract(address account) internal view returns (bool) {
return account.code.length > 0;
}
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");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
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");
}
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);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
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);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
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);
}
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
文件 2 的 17:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 3 的 17:ERC1155.sol
pragma solidity ^0.8.0;
import "./IERC1155.sol";
import "./IERC1155Receiver.sol";
import "./extensions/IERC1155MetadataURI.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/introspection/ERC165.sol";
contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
using Address for address;
mapping(uint256 => mapping(address => uint256)) private _balances;
mapping(address => mapping(address => bool)) private _operatorApprovals;
string private _uri;
constructor(string memory uri_) {
_setURI(uri_);
}
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC1155).interfaceId ||
interfaceId == type(IERC1155MetadataURI).interfaceId ||
super.supportsInterface(interfaceId);
}
function uri(uint256) public view virtual override returns (string memory) {
return _uri;
}
function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
require(account != address(0), "ERC1155: balance query for the zero address");
return _balances[id][account];
}
function balanceOfBatch(address[] memory accounts, uint256[] memory ids)
public
view
virtual
override
returns (uint256[] memory)
{
require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch");
uint256[] memory batchBalances = new uint256[](accounts.length);
for (uint256 i = 0; i < accounts.length; ++i) {
batchBalances[i] = balanceOf(accounts[i], ids[i]);
}
return batchBalances;
}
function setApprovalForAll(address operator, bool approved) public virtual override {
_setApprovalForAll(_msgSender(), operator, approved);
}
function isApprovedForAll(address account, address operator) public view virtual override returns (bool) {
return _operatorApprovals[account][operator];
}
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: caller is not owner nor approved"
);
_safeTransferFrom(from, to, id, amount, data);
}
function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: transfer caller is not owner nor approved"
);
_safeBatchTransferFrom(from, to, ids, amounts, data);
}
function _safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: transfer to the zero address");
address operator = _msgSender();
uint256[] memory ids = _asSingletonArray(id);
uint256[] memory amounts = _asSingletonArray(amount);
_beforeTokenTransfer(operator, from, to, ids, amounts, data);
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
unchecked {
_balances[id][from] = fromBalance - amount;
}
_balances[id][to] += amount;
emit TransferSingle(operator, from, to, id, amount);
_afterTokenTransfer(operator, from, to, ids, amounts, data);
_doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data);
}
function _safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
require(to != address(0), "ERC1155: transfer to the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, from, to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; ++i) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
unchecked {
_balances[id][from] = fromBalance - amount;
}
_balances[id][to] += amount;
}
emit TransferBatch(operator, from, to, ids, amounts);
_afterTokenTransfer(operator, from, to, ids, amounts, data);
_doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data);
}
function _setURI(string memory newuri) internal virtual {
_uri = newuri;
}
function _mint(
address to,
uint256 id,
uint256 amount,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: mint to the zero address");
address operator = _msgSender();
uint256[] memory ids = _asSingletonArray(id);
uint256[] memory amounts = _asSingletonArray(amount);
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
_balances[id][to] += amount;
emit TransferSingle(operator, address(0), to, id, amount);
_afterTokenTransfer(operator, address(0), to, ids, amounts, data);
_doSafeTransferAcceptanceCheck(operator, address(0), to, id, amount, data);
}
function _mintBatch(
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: mint to the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; i++) {
_balances[ids[i]][to] += amounts[i];
}
emit TransferBatch(operator, address(0), to, ids, amounts);
_afterTokenTransfer(operator, address(0), to, ids, amounts, data);
_doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);
}
function _burn(
address from,
uint256 id,
uint256 amount
) internal virtual {
require(from != address(0), "ERC1155: burn from the zero address");
address operator = _msgSender();
uint256[] memory ids = _asSingletonArray(id);
uint256[] memory amounts = _asSingletonArray(amount);
_beforeTokenTransfer(operator, from, address(0), ids, amounts, "");
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
unchecked {
_balances[id][from] = fromBalance - amount;
}
emit TransferSingle(operator, from, address(0), id, amount);
_afterTokenTransfer(operator, from, address(0), ids, amounts, "");
}
function _burnBatch(
address from,
uint256[] memory ids,
uint256[] memory amounts
) internal virtual {
require(from != address(0), "ERC1155: burn from the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, from, address(0), ids, amounts, "");
for (uint256 i = 0; i < ids.length; i++) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
unchecked {
_balances[id][from] = fromBalance - amount;
}
}
emit TransferBatch(operator, from, address(0), ids, amounts);
_afterTokenTransfer(operator, from, address(0), ids, amounts, "");
}
function _setApprovalForAll(
address owner,
address operator,
bool approved
) internal virtual {
require(owner != operator, "ERC1155: setting approval status for self");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {}
function _afterTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {}
function _doSafeTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) private {
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
if (response != IERC1155Receiver.onERC1155Received.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non ERC1155Receiver implementer");
}
}
}
function _doSafeBatchTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) private {
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (
bytes4 response
) {
if (response != IERC1155Receiver.onERC1155BatchReceived.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non ERC1155Receiver implementer");
}
}
}
function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) {
uint256[] memory array = new uint256[](1);
array[0] = element;
return array;
}
}
文件 4 的 17:ERC165.sol
pragma solidity ^0.8.0;
import "./IERC165.sol";
abstract contract ERC165 is IERC165 {
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
文件 5 的 17:ERC2981.sol
pragma solidity ^0.8.0;
import "../../interfaces/IERC2981.sol";
import "../../utils/introspection/ERC165.sol";
abstract contract ERC2981 is IERC2981, ERC165 {
struct RoyaltyInfo {
address receiver;
uint96 royaltyFraction;
}
RoyaltyInfo private _defaultRoyaltyInfo;
mapping(uint256 => RoyaltyInfo) private _tokenRoyaltyInfo;
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {
return interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId);
}
function royaltyInfo(uint256 _tokenId, uint256 _salePrice) public view virtual override returns (address, uint256) {
RoyaltyInfo memory royalty = _tokenRoyaltyInfo[_tokenId];
if (royalty.receiver == address(0)) {
royalty = _defaultRoyaltyInfo;
}
uint256 royaltyAmount = (_salePrice * royalty.royaltyFraction) / _feeDenominator();
return (royalty.receiver, royaltyAmount);
}
function _feeDenominator() internal pure virtual returns (uint96) {
return 10000;
}
function _setDefaultRoyalty(address receiver, uint96 feeNumerator) internal virtual {
require(feeNumerator <= _feeDenominator(), "ERC2981: royalty fee will exceed salePrice");
require(receiver != address(0), "ERC2981: invalid receiver");
_defaultRoyaltyInfo = RoyaltyInfo(receiver, feeNumerator);
}
function _deleteDefaultRoyalty() internal virtual {
delete _defaultRoyaltyInfo;
}
function _setTokenRoyalty(
uint256 tokenId,
address receiver,
uint96 feeNumerator
) internal virtual {
require(feeNumerator <= _feeDenominator(), "ERC2981: royalty fee will exceed salePrice");
require(receiver != address(0), "ERC2981: Invalid parameters");
_tokenRoyaltyInfo[tokenId] = RoyaltyInfo(receiver, feeNumerator);
}
function _resetTokenRoyalty(uint256 tokenId) internal virtual {
delete _tokenRoyaltyInfo[tokenId];
}
}
文件 6 的 17:IERC1155.sol
pragma solidity ^0.8.0;
import "../../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 amount,
bytes calldata data
) external;
function safeBatchTransferFrom(
address from,
address to,
uint256[] calldata ids,
uint256[] calldata amounts,
bytes calldata data
) external;
}
文件 7 的 17:IERC1155MetadataURI.sol
pragma solidity ^0.8.0;
import "../IERC1155.sol";
interface IERC1155MetadataURI is IERC1155 {
function uri(uint256 id) external view returns (string memory);
}
文件 8 的 17:IERC1155Receiver.sol
pragma solidity ^0.8.0;
import "../../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 的 17:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 10 的 17:IERC20.sol
pragma solidity ^0.8.0;
import "../token/ERC20/IERC20.sol";
文件 11 的 17:IERC2981.sol
pragma solidity ^0.8.0;
import "../utils/introspection/IERC165.sol";
interface IERC2981 is IERC165 {
function royaltyInfo(uint256 tokenId, uint256 salePrice)
external
view
returns (address receiver, uint256 royaltyAmount);
}
文件 12 的 17:IERC721.sol
pragma solidity ^0.8.0;
import "../token/ERC721/IERC721.sol";
文件 13 的 17:MerkleProof.sol
pragma solidity ^0.8.0;
library MerkleProof {
function verify(
bytes32[] memory proof,
bytes32 root,
bytes32 leaf
) internal pure returns (bool) {
return processProof(proof, leaf) == root;
}
function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
bytes32 proofElement = proof[i];
if (computedHash <= proofElement) {
computedHash = _efficientHash(computedHash, proofElement);
} else {
computedHash = _efficientHash(proofElement, computedHash);
}
}
return computedHash;
}
function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
assembly {
mstore(0x00, a)
mstore(0x20, b)
value := keccak256(0x00, 0x40)
}
}
}
文件 14 的 17:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 15 的 17:Pausable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Pausable is Context {
event Paused(address account);
event Unpaused(address account);
bool private _paused;
constructor() {
_paused = false;
}
function paused() public view virtual returns (bool) {
return _paused;
}
modifier whenNotPaused() {
require(!paused(), "Pausable: paused");
_;
}
modifier whenPaused() {
require(paused(), "Pausable: not paused");
_;
}
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
文件 16 的 17:SpaceFightRelease.sol
pragma solidity ^0.8.14;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/interfaces/IERC20.sol";
import "@openzeppelin/contracts/interfaces/IERC721.sol";
import "@openzeppelin/contracts/token/common/ERC2981.sol";
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
interface SplitMain {
function createSplit(
address[] calldata accounts,
uint32[] calldata percentAllocations,
uint32 distributorFee,
address controller
) external returns (address);
function predictImmutableSplitAddress(
address[] calldata accounts,
uint32[] calldata percentAllocations,
uint32 distributorFee
) external view returns (address);
}
contract SpaceFightRelease is ERC1155, ERC2981, Ownable, Pausable {
using Strings for uint256;
event RoyaltyConfigured(uint256 tokenId, address royaltyPayoutAddress, uint256 basisPoints);
event CreatedSplit(address splitAddress, address[] receivers, uint32[] percentages);
uint256 constant public RELEASE_DENOMINATOR = 10_000;
SplitMain immutable public splitterFactory;
string constant public name = "Space Fight Release";
string constant public symbol = "SFR";
struct Release {
uint96 mintPrice;
uint64 maxSupply;
uint64 teamReserve;
uint8 walletMintLimit;
uint8 txMintLimit;
uint16 tracksAmount;
string metadataUri;
}
mapping(uint256 => Release) public releases;
mapping(uint256 => uint256) public mintedSupply;
mapping(uint256 => mapping(address => uint256)) public minted;
uint256 public releaseIdForSale;
bytes32 public currentMerkleRoot;
address public mintPayoutAddress;
address public coreTeamPayoutAddress;
address[] public createdSplits;
uint96 public defaultRoyaltyBasisPoints;
uint256 public releaseCounter;
constructor(
address _mintPayoutAddress,
address _teamPayoutAddress,
address _splitterFactoryAddress
) ERC1155("") {
mintPayoutAddress = _mintPayoutAddress;
coreTeamPayoutAddress = _teamPayoutAddress;
splitterFactory = SplitMain(_splitterFactoryAddress);
setDefaultRoyalty(coreTeamPayoutAddress, 1000);
_pause();
}
function addRelease(
uint96 mintPrice,
uint64 maxSupply,
uint64 teamReserve,
uint8 walletMintLimit,
uint8 txMintLimit,
uint16 tracksAmount,
address[] calldata artistAddresses,
string calldata metadataUri
)
external
onlyOwner
{
uint256 releaseId = ++releaseCounter;
require(maxSupply > 0, "Supply must be > 0");
require(maxSupply >= teamReserve, "Max supply must be >= team reserve");
require(teamReserve > 0, "Must mint 1 by default");
require(tracksAmount < RELEASE_DENOMINATOR, "Tracks amount over limit");
require(artistAddresses.length == tracksAmount, "Specify one artist address per track");
releases[releaseId] = Release(
mintPrice,
maxSupply,
teamReserve - 1,
walletMintLimit,
txMintLimit,
tracksAmount,
metadataUri
);
mintInternal(msg.sender, releaseId, tracksAmount, 1);
for (uint256 i = 0; i < tracksAmount;) {
uint256 tokenId = toTokenId(releaseId, i + 1);
emit URI(uri(tokenId), tokenId);
setTokenRoyaltyForArtist(tokenId, artistAddresses[i], defaultRoyaltyBasisPoints);
unchecked{++i;}
}
}
function setMintPrice(uint256 releaseId, uint96 mintPrice) external onlyOwner whenReleaseExists(releaseId) {
releases[releaseId].mintPrice = mintPrice;
}
function reduceMaxSupply(uint256 releaseId, uint64 maxSupply) external onlyOwner whenReleaseExists(releaseId) {
uint256 currentSupply = totalReleaseSupply(releaseId);
require(maxSupply >= currentSupply + releases[releaseId].teamReserve, "New supply below existing/reserved supply");
require(maxSupply <= releases[releaseId].maxSupply, "Can only reduce supply");
releases[releaseId].maxSupply = maxSupply;
}
function setWalletMintLimit(uint256 releaseId, uint8 limit) external onlyOwner whenReleaseExists(releaseId) {
releases[releaseId].walletMintLimit = limit;
}
function setTxMintLimit(uint256 releaseId, uint8 limit) external onlyOwner whenReleaseExists(releaseId) {
releases[releaseId].txMintLimit = limit;
}
function setMetadataUri(uint256 releaseId, string calldata metadataUri) external onlyOwner whenReleaseExists(releaseId) {
releases[releaseId].metadataUri = metadataUri;
uint16 tracksAmount = releases[releaseId].tracksAmount;
for (uint256 i = 0; i < tracksAmount;) {
uint256 tokenId = toTokenId(releaseId, ++i);
emit URI(uri(tokenId), tokenId);
}
}
function mintTeamReserve(uint256 releaseId, address to, uint64 amount) external onlyOwner whenReleaseExists(releaseId) {
require(releases[releaseId].teamReserve >= amount, "Over team reserve");
releases[releaseId].teamReserve -= amount;
uint16 tracksAmount = releases[releaseId].tracksAmount;
mintInternal(to, releaseId, tracksAmount, amount);
}
function uri(uint256 tokenId) public view override returns (string memory) {
(uint256 releaseId, uint256 trackId) = toReleaseAndTrackIds(tokenId);
require(mintedSupply[releaseId] > 0, "Invalid release");
require(trackId <= releases[releaseId].tracksAmount, "Invalid track");
string storage metadataUri = releases[releaseId].metadataUri;
if (bytes(metadataUri).length > 0) {
return string(abi.encodePacked(metadataUri, trackId.toString()));
} else {
return "";
}
}
function saleState() external view returns (uint256 state) {
if (paused() || releaseIdForSale == 0) {
return 0;
} else if (currentMerkleRoot != 0) {
return 1;
} else {
return 2;
}
}
function startPublicSale(uint256 releaseId) external onlyOwner whenPaused whenReleaseExists(releaseId) {
releaseIdForSale = releaseId;
currentMerkleRoot = 0;
_unpause();
}
function startReservedSale(uint256 releaseId, bytes32 merkleRoot) external onlyOwner whenPaused whenReleaseExists(releaseId) {
releaseIdForSale = releaseId;
currentMerkleRoot = merkleRoot;
_unpause();
}
function pauseSale() external onlyOwner whenNotPaused {
_pause();
}
function endSale() external onlyOwner {
_endSale();
}
function _endSale() internal whenNotPaused {
releaseIdForSale = 0;
currentMerkleRoot = 0;
_pause();
}
function mintSale(uint256 amount, bytes32[] calldata proof) external payable whenNotPaused whenReleaseExists(releaseIdForSale) {
if (currentMerkleRoot != 0) {
require(
MerkleProof.verify(proof, currentMerkleRoot, keccak256(abi.encodePacked(msg.sender))),
"Invalid merkle proof"
);
}
require(amount > 0, "Must mint at least one");
Release storage release = releases[releaseIdForSale];
if (release.txMintLimit > 0) {
require(amount <= release.txMintLimit, "Over tx mint limit");
}
require(msg.value == amount * release.mintPrice, "Wrong ETH amount");
if (release.walletMintLimit > 0) {
require(minted[releaseIdForSale][msg.sender] + amount <= release.walletMintLimit, "Over wallet mint limit");
}
uint256 newTotalSupply = totalReleaseSupply(releaseIdForSale) + amount;
uint256 maxMintableSupply = release.maxSupply - release.teamReserve;
require(newTotalSupply <= maxMintableSupply, "Over mintable supply");
mintInternal(msg.sender, releaseIdForSale, release.tracksAmount, amount);
if (newTotalSupply == maxMintableSupply) {
_endSale();
}
}
function mintSpecial(
uint256 releaseId,
address[] calldata to,
uint256[] calldata amounts
) external onlyOwner {
require(to.length == amounts.length, "Recipients and amounts must match");
uint256 amount = to.length;
uint256 tokenId = toTokenId(releaseId, 0);
for (uint256 i = 0; i < amount;) {
_mint(to[i], tokenId, amounts[i], "");
unchecked {++i;}
}
}
function mintInternal(address to, uint256 releaseId, uint256 tracksAmount, uint256 amount) internal {
minted[releaseId][to] = minted[releaseId][to] + amount;
mintedSupply[releaseId] = mintedSupply[releaseId] + amount;
uint256[] memory ids = new uint256[](tracksAmount);
uint256[] memory amounts = new uint256[](tracksAmount);
for (uint256 i = 0; i < tracksAmount;) {
ids[i] = toTokenId(releaseId, i + 1);
amounts[i] = amount;
unchecked {++i;}
}
_mintBatch(to, ids, amounts, "");
}
function setMerkleRoot(bytes32 merkleRoot) external onlyOwner {
currentMerkleRoot = merkleRoot;
}
receive() external payable {}
function setMintPayoutAddress(address payoutAddress) external onlyOwner {
mintPayoutAddress = payoutAddress;
}
function setTeamPayoutAddress(address payoutAddress) external onlyOwner {
coreTeamPayoutAddress = payoutAddress;
}
function withdraw() external onlyOwner {
Address.sendValue(payable(mintPayoutAddress), address(this).balance);
}
function setDefaultRoyalty(address receiver, uint96 basisPoints) public onlyOwner {
defaultRoyaltyBasisPoints = basisPoints;
_setDefaultRoyalty(receiver, basisPoints);
}
function setTokenRoyaltyForArtist(
uint256 tokenId,
address artistAddress,
uint96 basisPoints
) public onlyOwner {
if (artistAddress == address(0)) {
_resetTokenRoyalty(tokenId);
return;
}
address[] memory recipients = new address[](2);
if (artistAddress > coreTeamPayoutAddress) {
recipients[0] = coreTeamPayoutAddress;
recipients[1] = artistAddress;
} else {
recipients[0] = artistAddress;
recipients[1] = coreTeamPayoutAddress;
}
uint32[] memory percentages = new uint32[](2);
percentages[0] = uint32(50_0000);
percentages[1] = uint32(50_0000);
address predictedRoyaltyPayoutAddress = splitterFactory.predictImmutableSplitAddress(recipients, percentages, 0);
if (Address.isContract(predictedRoyaltyPayoutAddress)) {
setTokenRoyalty(tokenId, predictedRoyaltyPayoutAddress, basisPoints);
} else {
address royaltyPayoutAddress = splitterFactory.createSplit(recipients, percentages, 0, address(0));
emit CreatedSplit(royaltyPayoutAddress, recipients, percentages);
createdSplits.push(royaltyPayoutAddress);
setTokenRoyalty(tokenId, royaltyPayoutAddress, basisPoints);
}
}
function setTokenRoyalty(uint256 tokenId, address receiver, uint96 basisPoints) public onlyOwner {
uint96 royaltyAmount = basisPoints == 0 ? defaultRoyaltyBasisPoints : basisPoints;
_setTokenRoyalty(tokenId, receiver, royaltyAmount);
emit RoyaltyConfigured(tokenId, receiver, royaltyAmount);
}
function withdrawERC20(IERC20 token, address toAddress, uint256 amount) external onlyOwner {
token.transfer(toAddress, amount);
}
function withdrawERC721(IERC721 token, address toAddress, uint256 tokenId) external onlyOwner {
token.transferFrom(address(this), toAddress, tokenId);
}
function withdrawERC1155(IERC1155 token, address toAddress, uint256 tokenId) external onlyOwner {
token.safeTransferFrom(address(this), toAddress, tokenId, token.balanceOf(address(this), tokenId), "");
}
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC1155, ERC2981)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
function totalReleaseSupply(uint256 releaseId) public view whenReleaseExists(releaseId) returns (uint256) {
return mintedSupply[releaseId];
}
function toReleaseAndTrackIds(uint256 tokenId) public pure returns (uint256 releaseId, uint256 trackId) {
return (tokenId / RELEASE_DENOMINATOR, tokenId % RELEASE_DENOMINATOR);
}
function toTokenId(uint256 releaseId, uint256 trackId) public pure returns (uint256 tokenId) {
require(trackId < RELEASE_DENOMINATOR, "Track ID out of bounds");
return releaseId * RELEASE_DENOMINATOR + trackId;
}
modifier whenReleaseExists(uint256 releaseId) {
require(mintedSupply[releaseId] > 0, "Invalid release");
_;
}
}
文件 17 的 17:Strings.sol
pragma solidity ^0.8.0;
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
function toString(uint256 value) internal pure returns (string memory) {
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);
}
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);
}
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);
}
}
{
"compilationTarget": {
"contracts/SpaceFightRelease.sol": "SpaceFightRelease"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_mintPayoutAddress","type":"address"},{"internalType":"address","name":"_teamPayoutAddress","type":"address"},{"internalType":"address","name":"_splitterFactoryAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","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":"address","name":"splitAddress","type":"address"},{"indexed":false,"internalType":"address[]","name":"receivers","type":"address[]"},{"indexed":false,"internalType":"uint32[]","name":"percentages","type":"uint32[]"}],"name":"CreatedSplit","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":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"address","name":"royaltyPayoutAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"basisPoints","type":"uint256"}],"name":"RoyaltyConfigured","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"values","type":"uint256[]"}],"name":"TransferBatch","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"TransferSingle","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"value","type":"string"},{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"URI","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[],"name":"RELEASE_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint96","name":"mintPrice","type":"uint96"},{"internalType":"uint64","name":"maxSupply","type":"uint64"},{"internalType":"uint64","name":"teamReserve","type":"uint64"},{"internalType":"uint8","name":"walletMintLimit","type":"uint8"},{"internalType":"uint8","name":"txMintLimit","type":"uint8"},{"internalType":"uint16","name":"tracksAmount","type":"uint16"},{"internalType":"address[]","name":"artistAddresses","type":"address[]"},{"internalType":"string","name":"metadataUri","type":"string"}],"name":"addRelease","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"accounts","type":"address[]"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"}],"name":"balanceOfBatch","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"coreTeamPayoutAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"createdSplits","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentMerkleRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultRoyaltyBasisPoints","outputs":[{"internalType":"uint96","name":"","type":"uint96"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"endSale","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mintPayoutAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes32[]","name":"proof","type":"bytes32[]"}],"name":"mintSale","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"releaseId","type":"uint256"},{"internalType":"address[]","name":"to","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"name":"mintSpecial","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"releaseId","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint64","name":"amount","type":"uint64"}],"name":"mintTeamReserve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"}],"name":"minted","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"mintedSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pauseSale","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"releaseId","type":"uint256"},{"internalType":"uint64","name":"maxSupply","type":"uint64"}],"name":"reduceMaxSupply","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"releaseCounter","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"releaseIdForSale","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"releases","outputs":[{"internalType":"uint96","name":"mintPrice","type":"uint96"},{"internalType":"uint64","name":"maxSupply","type":"uint64"},{"internalType":"uint64","name":"teamReserve","type":"uint64"},{"internalType":"uint8","name":"walletMintLimit","type":"uint8"},{"internalType":"uint8","name":"txMintLimit","type":"uint8"},{"internalType":"uint16","name":"tracksAmount","type":"uint16"},{"internalType":"string","name":"metadataUri","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint256","name":"_salePrice","type":"uint256"}],"name":"royaltyInfo","outputs":[{"internalType":"address","name":"","type":"address"},{"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":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeBatchTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"saleState","outputs":[{"internalType":"uint256","name":"state","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint96","name":"basisPoints","type":"uint96"}],"name":"setDefaultRoyalty","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"merkleRoot","type":"bytes32"}],"name":"setMerkleRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"releaseId","type":"uint256"},{"internalType":"string","name":"metadataUri","type":"string"}],"name":"setMetadataUri","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"payoutAddress","type":"address"}],"name":"setMintPayoutAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"releaseId","type":"uint256"},{"internalType":"uint96","name":"mintPrice","type":"uint96"}],"name":"setMintPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"payoutAddress","type":"address"}],"name":"setTeamPayoutAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint96","name":"basisPoints","type":"uint96"}],"name":"setTokenRoyalty","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"artistAddress","type":"address"},{"internalType":"uint96","name":"basisPoints","type":"uint96"}],"name":"setTokenRoyaltyForArtist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"releaseId","type":"uint256"},{"internalType":"uint8","name":"limit","type":"uint8"}],"name":"setTxMintLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"releaseId","type":"uint256"},{"internalType":"uint8","name":"limit","type":"uint8"}],"name":"setWalletMintLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"splitterFactory","outputs":[{"internalType":"contract SplitMain","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"releaseId","type":"uint256"}],"name":"startPublicSale","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"releaseId","type":"uint256"},{"internalType":"bytes32","name":"merkleRoot","type":"bytes32"}],"name":"startReservedSale","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":"tokenId","type":"uint256"}],"name":"toReleaseAndTrackIds","outputs":[{"internalType":"uint256","name":"releaseId","type":"uint256"},{"internalType":"uint256","name":"trackId","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"releaseId","type":"uint256"},{"internalType":"uint256","name":"trackId","type":"uint256"}],"name":"toTokenId","outputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"releaseId","type":"uint256"}],"name":"totalReleaseSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"uri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC1155","name":"token","type":"address"},{"internalType":"address","name":"toAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"withdrawERC1155","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"address","name":"toAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC721","name":"token","type":"address"},{"internalType":"address","name":"toAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"withdrawERC721","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]