// SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.16; // ========== External imports ========== import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; import "@openzeppelin/contracts/interfaces/IERC2981.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "@openzeppelin/contracts/security/Pausable.sol"; import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; // ========== Internal imports ========== import "./lib/CurrencyTransferLib.sol"; // ========== Features ========== import "./extension/RoyaltySplitter.sol"; import "./extension/PrimarySale.sol"; import "./extension/Drop1155.sol"; import "./extension/WalletClaimCounter1155.sol"; import "./extension/Oneshot.sol"; import "./extension/ThirdPartyMint1155.sol"; contract KanjiDropERC1155 is WalletClaimCounter1155, RoyaltySplitter, PrimarySale, Ownable, Drop1155, ThirdPartyMint1155, ReentrancyGuard, Pausable, Oneshot, ERC1155 { using Strings for uint256; /*/////////////////////////////////////////////////////////////// Errors //////////////////////////////////////////////////////////////*/ error ExceedMaxTotalSupplyError(); error ExceedClaimLimitForWalletError( uint256 quantity, uint256 walletClaimCountClaimer, address claimer, uint256 maxWalletClaimCount ); error PausedError(); error IncorrectMsgValue(uint256 expected); /*/////////////////////////////////////////////////////////////// Mappings //////////////////////////////////////////////////////////////*/ /// @dev Mapping from token ID => total circulating supply of tokens with that ID. mapping(uint256 => uint256) public totalSupply; /// @dev Mapping from token ID => maximum possible total circulating supply of tokens with that ID. mapping(uint256 => uint256) public maxTotalSupply; /// @dev Base URI which may be encrypted mapping(uint256 => string) internal uriOfEdition; /*/////////////////////////////////////////////////////////////// Events //////////////////////////////////////////////////////////////*/ event MaxTotalSupplyUpdated(uint256 tokenId, uint256 maxTotalSupply); /*/////////////////////////////////////////////////////////////// State variables //////////////////////////////////////////////////////////////*/ // Token name string public name; // Token symbol string public symbol; /// @dev Max bps in the thirdweb system. uint256 private constant MAX_BPS = 10_000; /*/////////////////////////////////////////////////////////////// Constructor + initializer logic //////////////////////////////////////////////////////////////*/ /// @notice Creates a new `KanjiDropERC1155` contract. /// @param _name The name of the NFT. /// @param _symbol The symbol of the NFT. /// @param _metadata Contract-level metadata /// @param _saleRecipients Recipients of the sale /// @param _royaltyBps The ERC2981 royalty cut /// @param _royaltyRecipients The ERC2981 royalty recipients constructor( string memory _name, string memory _symbol, Metadata memory _metadata, PrimarySaleRecipient[] memory _saleRecipients, uint16 _royaltyBps, RoyaltyRecipient[] memory _royaltyRecipients, IAccessControl _thirdParty ) PrimarySale(_saleRecipients) RoyaltySplitter(_royaltyRecipients, _metadata, _royaltyBps) ERC1155("") ReentrancyGuard() Ownable() Pausable() ThirdPartyMint1155(_thirdParty) {} /*/////////////////////////////////////////////////////////////// ERC 165 / 1155 / 2981 logic //////////////////////////////////////////////////////////////*/ /// @dev Returns the URI for a given editionId. function uri(uint256 _editionId) public view override returns (string memory) { return string(abi.encodePacked(uriOfEdition[_editionId], _editionId.toString(), ".json")); } /// @dev See ERC 165 function supportsInterface(bytes4 interfaceId) public view virtual override(ERC1155, IERC165) returns (bool) { return super.supportsInterface(interfaceId) || type(IERC2981).interfaceId == interfaceId; } /*/////////////////////////////////////////////////////////////// Owner logic //////////////////////////////////////////////////////////////*/ function setBaseURI(uint256 _editionId, string calldata _baseURI, uint256 _maxSupply) public onlyOwner { uriOfEdition[_editionId] = _baseURI; maxTotalSupply[_editionId] = _maxSupply; } /// @notice owner mint a reserve of tokens to specific address /// @param _receiver receiver of mint /// @param _editionId edition id of mint /// @param _quantity quantity gonna be mint function mintOwner(address _receiver, uint256 _editionId, uint256 _quantity) public onlyOwner { if (maxTotalSupply[_editionId] != 0 && totalSupply[_editionId] + _quantity > maxTotalSupply[_editionId]) { revert ExceedMaxTotalSupplyError(); } _mint(_receiver, _editionId, _quantity, ""); } struct BatchMintData { uint256 editionId; uint256 amount; } /// @notice owner mint a one token for every address in the list /// Be aware of the order, as the tokenID depends on it /// @param recipients receiver of mint function batchMintOwner(address[] memory recipients, BatchMintData[] memory editionsWithAmounts) external onlyOwner { for (uint256 i = 0; i < recipients.length; i++) { for (uint256 j = 0; j < editionsWithAmounts.length; j++) { mintOwner(recipients[i], editionsWithAmounts[j].editionId, editionsWithAmounts[j].amount); } } } /*/////////////////////////////////////////////////////////////// Setter functions //////////////////////////////////////////////////////////////*/ /// @dev Lets a contract admin set the global maximum supply for collection's NFTs. function setMaxTotalSupply(uint256 _editionId, uint256 _maxTotalSupply) external onlyOwner { maxTotalSupply[_editionId] = _maxTotalSupply; emit MaxTotalSupplyUpdated(_editionId, _maxTotalSupply); } /*/////////////////////////////////////////////////////////////// Internal functions //////////////////////////////////////////////////////////////*/ /// @dev Runs before every `claim` function call. function _beforeClaim(uint256 _editionId, address _claimer, uint256 _quantity, bytes32[] calldata) internal view override { if (maxTotalSupply[_editionId] != 0 && totalSupply[_editionId] + _quantity > maxTotalSupply[_editionId]) { revert ExceedMaxTotalSupplyError(); } if ( maxWalletClaimCount[_editionId] != 0 && walletClaimCount[_editionId][_claimer] + _quantity > maxWalletClaimCount[_editionId] ) { revert ExceedClaimLimitForWalletError({ quantity: _quantity, walletClaimCountClaimer: walletClaimCount[_editionId][_claimer], claimer: _claimer, maxWalletClaimCount: maxWalletClaimCount[_editionId] }); } } /// @dev Collects and distributes the primary sale value of NFTs being claimed. function collectPriceOnClaim(uint256, uint256 _quantityToClaim, uint256 _pricePerToken) internal override { if (_pricePerToken == 0) { return; } uint256 totalPrice = _quantityToClaim * _pricePerToken; if (msg.value != totalPrice) { revert IncorrectMsgValue({expected: totalPrice}); } address[] memory recipients = primarySaleRecipients(); for (uint256 i = 0; i < recipients.length; i++) { uint256 payout = ((totalPrice) * primarySaleRecipientBps(recipients[i])) / MAX_BPS; CurrencyTransferLib.transferCurrency(CurrencyTransferLib.NATIVE_TOKEN, _msgSender(), recipients[i], payout); } } /// @dev Transfers the NFTs being claimed. function transferTokensOnClaim(address _to, uint256 _editionId, uint256 _quantityBeingClaimed) internal override { walletClaimCount[_editionId][_msgSender()] += _quantityBeingClaimed; _mint(_to, _editionId, _quantityBeingClaimed, ""); } function _afterMintFromThirdParty(address _receiver, uint256 _editionId, uint256 _quantity) internal override { _mint(_receiver, _editionId, _quantity, ""); } function _beforeChangeThirdPartySetup(IAccessControl _thirdPartySetup) internal override onlyOwner {} /*/////////////////////////////////////////////////////////////// Miscellaneous //////////////////////////////////////////////////////////////*/ /** * @dev See {ERC1155-_beforeTokenTransfer}. */ function _beforeTokenTransfer( address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) internal virtual override { if (paused()) { revert PausedError(); } super._beforeTokenTransfer(operator, from, to, ids, amounts, data); if (from == address(0)) { for (uint256 i = 0; i < ids.length; ++i) { totalSupply[ids[i]] += amounts[i]; } } // this will never be the case as the burn is disabled // if (to == address(0)) { // for (uint256 i = 0; i < ids.length; ++i) { // totalSupply[ids[i]] -= amounts[i]; // } // } } /// @notice Temporarily lock the contract function pause() external onlyOwner { if (paused()) _unpause(); else _pause(); } function setClaimConditions(uint256 _editionId, ClaimCondition[] calldata _conditions, bool _resetClaimEligibility) public override onlyOwner { super.setClaimConditions(_editionId, _conditions, _resetClaimEligibility); } function claim(address _receiver, uint256 _editionId, uint256 _quantity, bytes32[] calldata _proof) public payable override nonReentrant { super.claim(_receiver, _editionId, _quantity, _proof); } }