pragma solidity ^0.8.18;





abstract contract OperatorFilterer {
    /// @dev The default OpenSea operator blocklist subscription.
    address internal constant _DEFAULT_SUBSCRIPTION =
        0x3cc6CddA760b79bAfa08dF41ECFA224f810dCeB6;

    /// @dev The OpenSea operator filter registry.
    address internal constant _OPERATOR_FILTER_REGISTRY =
        0x000000000000AAeB6D7670E522A718067333cd4E;

    /// @dev Registers the current contract to OpenSea's operator filter,
    /// and subscribe to the default OpenSea operator blocklist.
    /// Note: Will not revert nor update existing settings for repeated registration.
    function _registerForOperatorFiltering() internal virtual {
        _registerForOperatorFiltering(_DEFAULT_SUBSCRIPTION, true);
    }

    /// @dev Registers the current contract to OpenSea's operator filter.
    /// Note: Will not revert nor update existing settings for repeated registration.
    function _registerForOperatorFiltering(
        address subscriptionOrRegistrantToCopy,
        bool subscribe
    ) internal virtual {
        /// @solidity memory-safe-assembly
        assembly {
            let functionSelector := 0x7d3e3dbe // `registerAndSubscribe(address,address)`.

            // Clean the upper 96 bits of `subscriptionOrRegistrantToCopy` in case they are dirty.
            subscriptionOrRegistrantToCopy := shr(
                96,
                shl(96, subscriptionOrRegistrantToCopy)
            )
            // prettier-ignore
            for {} iszero(subscribe) {} {
                if iszero(subscriptionOrRegistrantToCopy) {
                    functionSelector := 0x4420e486 // `register(address)`.
                    break
                }
                functionSelector := 0xa0af2903 // `registerAndCopyEntries(address,address)`.
                break
            }
            // Store the function selector.
            mstore(0x00, shl(224, functionSelector))
            // Store the `address(this)`.
            mstore(0x04, address())
            // Store the `subscriptionOrRegistrantToCopy`.
            mstore(0x24, subscriptionOrRegistrantToCopy)
            // Register into the registry.
            pop(
                call(
                    gas(),
                    _OPERATOR_FILTER_REGISTRY,
                    0,
                    0x00,
                    0x44,
                    0x00,
                    0x00
                )
            )
            // Restore the part of the free memory pointer that was overwritten,
            // which is guaranteed to be zero, because of Solidity's memory size limits.
            mstore(0x24, 0)
        }
    }

    /// @dev Modifier to guard a function and revert if `from` is a blocked operator.
    /// Can be turned on / off via `enabled`.
    /// For gas efficiency, you can use tight variable packing to efficiently read / write
    /// the boolean value for `enabled`.
    modifier onlyAllowedOperator(address from, bool enabled) virtual {
        /// @solidity memory-safe-assembly
        assembly {
            // This code prioritizes runtime gas costs on a chain with the registry.
            // As such, we will not use `extcodesize`, but rather abuse the behavior
            // of `staticcall` returning 1 when called on an empty / missing contract,
            // to avoid reverting when a chain does not have the registry.

            if enabled {
                // Check if `from` is not equal to `msg.sender`,
                // discarding the upper 96 bits of `from` in case they are dirty.
                if iszero(eq(shr(96, shl(96, from)), caller())) {
                    // Store the function selector of `isOperatorAllowed(address,address)`,
                    // shifted left by 6 bytes, which is enough for 8tb of memory.
                    // We waste 6-3 = 3 bytes to save on 6 runtime gas (PUSH1 0x224 SHL).
                    mstore(0x00, 0xc6171134001122334455)
                    // Store the `address(this)`.
                    mstore(0x1a, address())
                    // Store the `msg.sender`.
                    mstore(0x3a, caller())

                    // `isOperatorAllowed` always returns true if it does not revert.
                    if iszero(
                        staticcall(
                            gas(),
                            _OPERATOR_FILTER_REGISTRY,
                            0x16,
                            0x44,
                            0x00,
                            0x00
                        )
                    ) {
                        // Bubble up the revert if the staticcall reverts.
                        returndatacopy(0x00, 0x00, returndatasize())
                        revert(0x00, returndatasize())
                    }

                    // We'll skip checking if `from` is inside the blacklist.
                    // Even though that can block transferring out of wrapper contracts,
                    // we don't want tokens to be stuck.

                    // Restore the part of the free memory pointer that was overwritten,
                    // which is guaranteed to be zero, if less than 8tb of memory is used.
                    mstore(0x3a, 0)
                }
            }
        }
        _;
    }

    /// @dev Modifier to guard a function from approving a blocked operator.
    /// Can be turned on / off via `enabled`.
    /// For efficiency, you can use tight variable packing to efficiently read / write
    /// the boolean value for `enabled`.
    modifier onlyAllowedOperatorApproval(address operator, bool enabled)
        virtual {
        /// @solidity memory-safe-assembly
        assembly {
            // For more information on the optimization techniques used,
            // see the comments in `onlyAllowedOperator`.

            if enabled {
                // Store the function selector of `isOperatorAllowed(address,address)`,
                mstore(0x00, 0xc6171134001122334455)
                // Store the `address(this)`.
                mstore(0x1a, address())
                // Store the `operator`, discarding the upper 96 bits in case they are dirty.
                mstore(0x3a, shr(96, shl(96, operator)))

                // `isOperatorAllowed` always returns true if it does not revert.
                if iszero(
                    staticcall(
                        gas(),
                        _OPERATOR_FILTER_REGISTRY,
                        0x16,
                        0x44,
                        0x00,
                        0x00
                    )
                ) {
                    // Bubble up the revert if the staticcall reverts.
                    returndatacopy(0x00, 0x00, returndatasize())
                    revert(0x00, returndatasize())
                }

                // Restore the part of the free memory pointer that was overwritten.
                mstore(0x3a, 0)
            }
        }
        _;
    }
}

abstract contract ERC721 {
    function ownerOf(uint256 tokenId) public view virtual returns (address);
}

abstract contract MyToken {
    function publicMint(
        address to,
        uint256 tokenId,
        string memory uri
    ) external virtual;
}

contract Boy_Soldier_Pre_Fusion is ERC1155, Ownable, ERC2981, OperatorFilterer {
    bool public operatorFilteringEnabled;
    string public name = unicode"Boy Soldier Pre-Fusion";
    string public symbol = unicode"Boy Soldier Pre-Fusion";

    bool public craft = false;
    bool public enableMint = false;
    uint256 public totalSupply;
    uint256 public price = 0.017 ether;
    uint256 public id = 1;
    uint256 public counter = 1;
    string private craftURI;
    string public _baseURI;

    address public craftingContractAddress;

    mapping(address => bool) public minter;
    mapping(address => bool) public isUk;
    mapping(uint256 => uint256) public supplyAgainstId;

    event newCraft(uint256[4] tokenIds, uint256[4] amounts, address owner);

    constructor(
        address initialOwner,
        address royalityReciever,
        uint96 royality
    ) Ownable(initialOwner) {
        _registerForOperatorFiltering();
        operatorFilteringEnabled = true;
        _setDefaultRoyalty(royalityReciever, royality);
    }

    modifier onlyMinter() {
        require(minter[msg.sender] == true, "You're not a minter");
        _;
    }

    function mint(
        address account,
        uint256 _id,
        uint256 amount,
        bool _isUk
    ) public payable onlyMinter {
        require(enableMint == true, "minting is not enabled yet");
        require(_id == id, "id is not correct");
        uint256 totalCost = amount * price;
        require(msg.value >= totalCost, "you do not have enough funds to complete the transaction");
        if (id == 1) {
            supplyAgainstId[id] += amount;
            totalSupply = supplyAgainstId[id];
        } else {
            supplyAgainstId[id] += amount;
            require(supplyAgainstId[id] <= totalSupply, "supply completed");
        }
        bytes memory data = "0x";
        isUk[account] = _isUk;
        _mint(account, id, amount, data);
        if (msg.value > totalCost) {
            payable(msg.sender).transfer(msg.value - totalCost);
        }
    }

    function changeId(uint256 _id) external onlyOwner {
        id = _id;
    }

    // Forge function
    function craftToken(
        uint256[4] calldata tokenIds,
        uint256[4] calldata amounts
    ) public {
        require(craft == true, "Crafting is not enabled");
        require(
            craftingContractAddress !=
                0x0000000000000000000000000000000000000000,
            "No forging address set for this token"
        );

        for (uint256 i = 0; i < tokenIds.length; ++i) {
            require(amounts[i] == 1, "values are not same");
            require(
                balanceOf[msg.sender][tokenIds[i]] >= amounts[i],
                "Doesn't own the token"
            ); // Check if the user own one of the ERC-1155

            _burn(msg.sender, tokenIds[i], amounts[i]); // Burn one the ERC-1155 token
        }

        string memory uri1 = string.concat(
            craftURI,
            Strings.toString(counter),
            ".json"
        );

        MyToken forgingContract = MyToken(craftingContractAddress);
        forgingContract.publicMint(msg.sender, counter, uri1); // Mint the ERC-721 token
        counter++;
        emit newCraft(tokenIds, amounts, msg.sender);
    }

    function reserve(
        address to,
        uint256 _id,
        uint256 amount
    ) external onlyOwner {
        bytes memory data = "0x";
        supplyAgainstId[id] += amount;
        totalSupply = supplyAgainstId[id];
        _mint(to, _id, amount, data);
    }

    function setBaseURI(string memory _bbaseURI) public onlyOwner {
        _baseURI = _bbaseURI;
    }

    function setCraftStatus(bool status) external onlyOwner {
        craft = status;
    }

    function enableMinting(bool mintStatus) external onlyOwner {
        enableMint = mintStatus;
    }

    function updateTokenSupply(uint256 _newSupply) external onlyOwner {
        totalSupply = _newSupply;
    }

    function setPrice(uint256 _newPrice) external onlyOwner {
        price = _newPrice;
    }

    function setCraftURI(string memory _newUri) external onlyOwner {
        craftURI = _newUri;
    }

    function assignMinterRoles(address[] memory _minters) external onlyOwner {
        for (uint256 i = 0; i < _minters.length; i++) {
            address _minter = _minters[i];
            require(!minter[_minter], "Address is already a minter");
            minter[_minter] = true;
        }
    }

    function revokeMinterRoles(address[] memory _minters) external onlyOwner {
        for (uint256 i = 0; i < _minters.length; i++) {
            address _minter = _minters[i];
            require(minter[_minter], "Address is not a minter");
            minter[_minter] = false;
        }
    }

    // --------
    // Getter
    // --------
    function uri(uint256 _id) public view override returns (string memory) {
        // use vanilla URLs instead of ERC-1155 {id} urls
        return string.concat(_baseURI, Strings.toString(_id), ".json");
    }

    function supportsInterface(bytes4 interfaceId)
        public
        view
        override(ERC1155, ERC2981)
        returns (bool)
    {
        return super.supportsInterface(interfaceId);
    }

    /**
     * @notice Set the state of the OpenSea operator filter
     * @param value Flag indicating if the operator filter should be applied to transfers and approvals
     */
    function setOperatorFilteringEnabled(bool value) external onlyOwner {
        operatorFilteringEnabled = value;
    }

    function setCraftingAddress(address newAddress) public onlyOwner {
        craftingContractAddress = newAddress;
    }

    // In case someone send money to the contract by mistake
    function withdrawFunds() public onlyOwner {
        payable(msg.sender).transfer(address(this).balance);
    }
}
[{"inputs":[{"internalType":"address","name":"initialOwner","type":"address"},{"internalType":"address","name":"royalityReciever","type":"address"},{"internalType":"uint96","name":"royality","type":"uint96"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"numerator","type":"uint256"},{"internalType":"uint256","name":"denominator","type":"uint256"}],"name":"ERC2981InvalidDefaultRoyalty","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"ERC2981InvalidDefaultRoyaltyReceiver","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"numerator","type":"uint256"},{"internalType":"uint256","name":"denominator","type":"uint256"}],"name":"ERC2981InvalidTokenRoyalty","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"ERC2981InvalidTokenRoyaltyReceiver","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":true,"internalType":"address","name":"owner","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":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","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":"amounts","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":"amount","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":"uint256[4]","name":"tokenIds","type":"uint256[4]"},{"indexed":false,"internalType":"uint256[4]","name":"amounts","type":"uint256[4]"},{"indexed":false,"internalType":"address","name":"owner","type":"address"}],"name":"newCraft","type":"event"},{"inputs":[],"name":"_baseURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"_minters","type":"address[]"}],"name":"assignMinterRoles","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"owners","type":"address[]"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"}],"name":"balanceOfBatch","outputs":[{"internalType":"uint256[]","name":"balances","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_id","type":"uint256"}],"name":"changeId","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"counter","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"craft","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[4]","name":"tokenIds","type":"uint256[4]"},{"internalType":"uint256[4]","name":"amounts","type":"uint256[4]"}],"name":"craftToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"craftingContractAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"enableMint","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"mintStatus","type":"bool"}],"name":"enableMinting","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"id","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isUk","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"_id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bool","name":"_isUk","type":"bool"}],"name":"mint","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"minter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"operatorFilteringEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"price","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"_id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"reserve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_minters","type":"address[]"}],"name":"revokeMinterRoles","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":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_bbaseURI","type":"string"}],"name":"setBaseURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"status","type":"bool"}],"name":"setCraftStatus","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_newUri","type":"string"}],"name":"setCraftURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newAddress","type":"address"}],"name":"setCraftingAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"value","type":"bool"}],"name":"setOperatorFilteringEnabled","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newPrice","type":"uint256"}],"name":"setPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"supplyAgainstId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","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":[],"name":"totalSupply","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":"_newSupply","type":"uint256"}],"name":"updateTokenSupply","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_id","type":"uint256"}],"name":"uri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"withdrawFunds","outputs":[],"stateMutability":"nonpayable","type":"function"}]