BaseBase
0xBA...7a89
Elephants: Onchain Summer Attributes

Elephants: Onchain Summer Attributes

ATTRIBUTE_SUMMER

Colección
Precio de Piso
0,00001 ETH
$2,345.34
Tamaño
57.602 Piezas
57.613 Ediciones
Propietarios
3147
5 % Propietarios Únicos
¡El código fuente de este contrato está verificado!
Metadatos del Contrato
Compilador
0.8.23+commit.f704f362
Idioma
Solidity
Código Fuente del Contrato
Archivo 1 de 26: AttributeSummer.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import "@openzeppelin/contracts/utils/Strings.sol";
import "@patchwork/interfaces/IPatchworkMintable.sol";
import "@patchwork/PatchworkFragmentSingle.sol";
import "@patchwork/PatchworkUtils.sol";
import "./IAttribute.sol";
import "./IStickerPack.sol";

/**
                                                                   
,------.,--.              ,--.                       ,--.          
|  .---'|  | ,---.  ,---. |  ,---.  ,--,--.,--,--, ,-'  '-. ,---.  
|  `--, |  || .-. :| .-. ||  .-.  |' ,-.  ||      \'-.  .-'(  .-'  
|  `---.|  |\   --.| '-' '|  | |  |\ '-'  ||  ||  |  |  |  .-'  `) 
`------'`--' `----'|  |-' `--' `--' `--`--'`--''--'  `--'  `----'  
                   `--'
Attribute Onchain Summer Kit by Runic Labs, Inc

*/

/**
@notice An Elephant Onchain Summer Attribute
@author Runic Labs, Inc
*/



contract AttributeSummer is IAttribute, IStickerPack, PatchworkFragmentSingle, IPatchworkMintable {

    struct AttributesByType {
        uint16[] attributeIds;
        mapping(uint16 => uint256) index;
    }

    /**
    @notice The length of the input arrays do not match
    */
    error InputLengthMismatch();

    /// next tokenId to mint
    uint256 private _nextTokenId;

    AttributesByType[] private _attributesByType;

    /// Attribute definitions
    mapping(uint16 => Definition) private _attributeDefs;

    /// Sticker info by type ID
    mapping(uint32=>StickerInfo) internal _stickerInfo;

    /// Count of stickers in the pack
    uint256 internal _stickerCount;

    //Everyone who has minted an onchain summer attribute
    mapping(address => bool) private _minters;

    string private _uriRoot;

    constructor(address manager_, address owner_) Patchwork721("elephants", "Elephants: Onchain Summer Attributes", "ATTRIBUTE_SUMMER", manager_, owner_) {
        _attributesByType.push(); // BACKGROUND
        _attributesByType.push(); // BASE
        _attributesByType.push(); // EYES
        _attributesByType.push(); // MOUTH
        _attributesByType.push(); // CLOTHING
        _attributesByType.push(); // HAT
        _attributesByType.push(); // ACCESSORY
        _uriRoot = "https://elephants.fun/";
    }

    /**
    @dev ERC-165
    */
    function supportsInterface(bytes4 interfaceID) public view virtual override returns (bool) {
        return interfaceID == type(IAttribute).interfaceId ||
            interfaceID == type(IPatchworkMintable).interfaceId ||
            interfaceID == type(IStickerPack).interfaceId ||
            super.supportsInterface(interfaceID); 
    }

        /**
    @notice Set a batch of stickers
    @param typeIds the type IDs of the stickers
    @param infos the sticker infos
    */
    function setStickerBatch(uint32[] memory typeIds, StickerInfo[] memory infos) public onlyOwner {
        if (typeIds.length != infos.length) {
            revert InputLengthMismatch();
        }
        for (uint256 i = 0; i < infos.length; i++) {
            setSticker(typeIds[i], infos[i]);
        }
    }
    
    /**
    @notice Set a sticker
    @param typeId the type ID of the sticker
    @param info the sticker info
    */
    function setSticker(uint32 typeId, StickerInfo memory info) public onlyOwner {
        if (bytes(info.imageURI).length == 0 && bytes(_stickerInfo[typeId].imageURI).length != 0) {
            _stickerCount--;
        }
        if (bytes(info.imageURI).length != 0 && bytes(_stickerInfo[typeId].imageURI).length == 0) {
            _stickerCount++;
        }
        _stickerInfo[typeId] = info;
        emit SetSticker(typeId, info.name, info.imageURI, info.plunkPrice);
    }

        /**
    @notice count of stickers in the pack
    @return count the count of stickers
    */
    function stickerCount() public view returns (uint256 count) {
        return _stickerCount;
    }

    /**
    @notice gets the total supply
    @return uint256 the supply
    */
    function totalSupply() public view returns (uint256) {
        return _nextTokenId;
    }

    /**
     * @dev Sets the base URI root. Only callable by the contract owner.
     * @param uriRoot_ The new URI root to be set.
     */
    function setUriRoot(string calldata uriRoot_) external onlyOwner {
        _uriRoot = uriRoot_;
    }

    /**
    @notice Mints one of the onchain summer attributes
    @param to the new owner of the attribute
    @param data mint data (empty)
    @return tokenId the newly minted tokenId
    */
    function mint(address to, bytes calldata data) public payable returns (uint256 tokenId) {
        if (msg.sender != _manager) {
            return IPatchworkProtocol(_manager).mint{value: msg.value}(to, address(this), data);
        }
        uint16 randomAttributeId = _getRandomAttributeId();
        _minters[to] = true; 
        return _mintAttribute(to, randomAttributeId);
    }

    /**
    @notice Mints one onchain summer attribute
    @param to the new owner of the attribute
    @param data mint data (empty)
    @param quantity the number of attributes to mint
    @return tokenIds the newly minted tokenIds
    */
    function mintBatch(address to, bytes calldata data, uint256 quantity) public payable returns (uint256[] memory tokenIds) {
        if (msg.sender != _manager) {
            return IPatchworkProtocol(_manager).mintBatch{value: msg.value}(to, address(this), data, quantity);
        }
        tokenIds = new uint256[](quantity);
        for (uint256 i = 0; i < quantity; i++) {
            uint16 randomAttributeId = _getRandomAttributeId();
            tokenIds[i] = _mintAttribute(to, randomAttributeId);
        }
        _minters[to] = true; 
        return tokenIds;
    }

    /**
    @dev mints an attribute
    @param to the new owner
    @param attributeId the attributeId to mint
    @return uint256 the new tokenId
    */
    function _mintAttribute(address to, uint16 attributeId) private returns (uint256) {
        uint256 tokenId = _nextTokenId;
        _nextTokenId++;
        _safeMint(to, tokenId);
        Definition memory def = _attributeDefs[attributeId];
        Metadata memory metadata = Metadata(
            def.attributeType,
            def.attributeId,
            def.tier,
            def.name
        );
        _storeMetadata(tokenId, metadata);
        return tokenId;
    }

    /**
    @dev generates a random attributeId
    @return uint16 the random attributeId
    */
    function _getRandomAttributeId() private view returns (uint16) {
        uint typeIndex = uint(keccak256(abi.encodePacked(block.prevrandao, _nextTokenId))) % _attributesByType.length;
        uint16[] storage ids = _attributesByType[typeIndex].attributeIds;
        require(ids.length > 0, "no attributes registered for this type");
        return ids[uint16(uint(keccak256(abi.encodePacked(block.prevrandao, _nextTokenId))) % ids.length)];
    }

    /**
    @dev baseURI for json (used by OpenZeppelin tokenURI())
    */
    function _baseURI() internal view override returns (string memory) {
        return string.concat(_uriRoot, "metadata/onchainsummer_attribute/");
    }

    /**
    @notice a schema URI for an attribute
    @return string The schema URI
    */
    function schemaURI() external view returns (string memory) {
        return string.concat(_uriRoot, "schemas/onchainsummer_attribute.json");
    }

    /**
    @notice an image URI for an attribute
    @param tokenId the tokenId of the attribute
    @return string The image URI
    */
    function imageURI(uint256 tokenId) external view returns (string memory) {
        return string.concat(_uriRoot, "assets/onchainsummer_attribute/", Strings.toString(tokenId));
    }

    /**
    @notice registers attributes
    @param attributeDefs the attribute definitions
    */
    function registerAttributes(Definition[] memory attributeDefs) public onlyOwner {
        for (uint256 i = 0; i < attributeDefs.length; i++) {
            _registerAttribute(attributeDefs[i]);
        }
    }

    /**
    @notice Locks supply for an attributeId (forever)
    @param attributeId the attributeId to supplylock
    */
    function supplyLock(uint16 attributeId) public onlyOwner {
        Definition memory def = _attributeDefs[attributeId];
        require(def.attributeId != 0, "attribute does not exist");
        uint8 attributeType = uint8(def.attributeType);
        _removeFromType(attributeType, attributeId);
        emit SupplyLock(attributeId);
    }

    /**
    @notice the patchwork metadata schema
    @return MetadataSchema the schema
    */
    function schema() external pure override returns (MetadataSchema memory) {
        MetadataSchemaEntry[] memory entries = new MetadataSchemaEntry[](4);
        entries[0] = MetadataSchemaEntry(0, 0, FieldType.UINT8, 1, FieldVisibility.PUBLIC, 0, 0, "attributeType");
        entries[1] = MetadataSchemaEntry(1, 1, FieldType.UINT16, 1, FieldVisibility.PUBLIC, 0, 8, "attributeId");
        entries[2] = MetadataSchemaEntry(2, 2, FieldType.UINT8, 1, FieldVisibility.PUBLIC, 0, 24, "tier");
        entries[3] = MetadataSchemaEntry(3, 3, FieldType.CHAR16, 1, FieldVisibility.PUBLIC, 0, 32, "name");
        return MetadataSchema(1, entries);
    }

    /**
    @notice Stores metadata for a tokenId
    @param tokenId the tokenId to store metadata for
    @param data the metadata
    */
    function storeMetadata(uint256 tokenId, Metadata memory data) public {
        require(_checkTokenWriteAuth(tokenId), "not authorized");
        _storeMetadata(tokenId, data);
    }

    /**
    @dev packs and stores metadata
    @param tokenId the tokenId
    @param data the metadata struct
    */
    function _storeMetadata(uint256 tokenId, Metadata memory data) private {
        _metadataStorage[tokenId] = packMetadata(data);
    }

    /**
    @notice Loads metadata for a tokenId
    @param tokenId the tokenId to load metadata for
    @return data the metadata
    */
    function loadMetadata(uint256 tokenId) public view returns (Metadata memory data) {
        return unpackMetadata(_metadataStorage[tokenId]);
    }

    /**
    @notice Packs metadata for storage
    @param data the metadata struct
    @return slots the metadata slots
    */
    function packMetadata(Metadata memory data) public pure returns (uint256[] memory slots) {
        slots = new uint256[](1);
        slots[0] = uint256(data.attributeType) | uint256(data.attributeId) << 8 | uint256(data.tier) << 24
            | PatchworkUtils.strToUint256(data.name) >> 128 << 32;
        return slots;
    }

    /**
    @notice Unpacks packed metadata from storage format
    @param slots the metadata slots
    @return data the metadata struct
    */
    function unpackMetadata(uint256[] memory slots) public pure returns (Metadata memory data) {
        data.attributeType = Type(uint8(slots[0] >> 0));
        data.attributeId = uint16(slots[0] >> 8);
        data.tier = uint8(slots[0] >> 24);
        data.name = PatchworkUtils.toString16(uint128(slots[0] >> 32));
        return data;
    }

    /**
    @notice Loads an attributeType for a tokenId 
    @param tokenId the tokenId to use
    @return Type the attributeType
    */
    function loadAttributeType(uint256 tokenId) public view returns (Type) {
        uint256 value = uint256(_metadataStorage[tokenId][0]);
        return Type(uint8(value));
    }

    /**
    @notice Loads an attributeId for a tokenId 
    @param tokenId the tokenId to use
    @return uint16 the attributeId
    */
    function loadAttributeId(uint256 tokenId) public view returns (uint16) {
        uint256 value = uint256(_metadataStorage[tokenId][0]) >> 8;
        return uint16(value);
    }

    /**
    @notice Loads a tier for a tokenId 
    @param tokenId the tokenId to use
    @return uint8 the tier
    */
    function loadTier(uint256 tokenId) public view returns (uint8) {
        uint256 value = uint256(_metadataStorage[tokenId][0]) >> 24;
        return uint8(value);
    }
    
    /**
    @notice Loads an attribute name for a tokenId 
    @param tokenId the tokenId to use
    @return string the name
    */
    function loadName(uint256 tokenId) public view returns (string memory) {
        uint256 value = uint256(_metadataStorage[tokenId][0]) >> 32;
        return PatchworkUtils.toString16(uint128(value));
    }

    /**
    @dev registers an attribute
    @param attribute the attribute definition to register
    */
    function _registerAttribute(Definition memory attribute) internal {
        uint16 attrId = attribute.attributeId;
        require(attrId != 0, "attribute ID 0 is reserved");
        require(_attributeDefs[attrId].attributeId == 0, "attribute ID already registered");
        require(attribute.tier == 0, 'invalid tier');

         // Handling the AttributesByType struct
        AttributesByType storage attrsByType = _attributesByType[uint(attribute.attributeType)];
        attrsByType.attributeIds.push(attribute.attributeId);
        // Actual index is length - 1, but storing as length to avoid default value in 0 index
        attrsByType.index[attribute.attributeId] = attrsByType.attributeIds.length;
        _attributeDefs[attrId] = attribute;
        emit Register(attrId, attribute.tier, attribute.name, attribute.isPromo);
    }

        /**
    @dev removes an attributeId from a type
    @param attributeType the tier to remove from
    @param attributeId the attributeId to remove
    */
    function _removeFromType(uint8 attributeType, uint16 attributeId) internal {
        uint16[] storage ids = _attributesByType[attributeType].attributeIds;
        mapping(uint16 => uint256) storage indexMap = _attributesByType[attributeType].index;
        if (indexMap[attributeId] == 0) {
            revert("attribute not found or already locked");
        }
        if (ids.length == 0) {
            revert("no attributes in tier");
        }
        // Adjust the index value, subtracting 1 because array indices are 0-based
        uint256 index = indexMap[attributeId] - 1;
        if (index >= ids.length) {
            revert("index out of bounds");
        }
        // If the attribute is not the last element, swap it with the last
        if (index != ids.length - 1) {
            uint16 lastAttributeId = ids[ids.length - 1];
            ids[index] = lastAttributeId;
            indexMap[lastAttributeId] = index + 1;
        }
        // finally remove the old last element from the list and the old attributeId from the index
        ids.pop();
        delete indexMap[attributeId];
    }

    /**
    @notice get a sticker by type ID
    @param typeId the type ID of the sticker
    @return info the sticker info
    */
    function sticker(uint32 typeId) public view returns (StickerInfo memory info) {
        return _stickerInfo[typeId];
    }

    /**
    @notice allow a user to use the sticker pack
    @param by the user to allow
    @return use true if the user is allowed to use the sticker pack
    */
    function allowUse(address by) public view returns (bool use) {
        return _minters[by];
    }

}
Código Fuente del Contrato
Archivo 2 de 26: Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
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;
    }
}
Código Fuente del Contrato
Archivo 3 de 26: ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)

pragma solidity ^0.8.20;

import {IERC165} from "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}
Código Fuente del Contrato
Archivo 4 de 26: ERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/ERC721.sol)

pragma solidity ^0.8.20;

import {IERC721} from "./IERC721.sol";
import {IERC721Receiver} from "./IERC721Receiver.sol";
import {IERC721Metadata} from "./extensions/IERC721Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {Strings} from "../../utils/Strings.sol";
import {IERC165, ERC165} from "../../utils/introspection/ERC165.sol";
import {IERC721Errors} from "../../interfaces/draft-IERC6093.sol";

/**
 * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
 * the Metadata extension, but not including the Enumerable extension, which is available separately as
 * {ERC721Enumerable}.
 */
abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Errors {
    using Strings for uint256;

    // Token name
    string private _name;

    // Token symbol
    string private _symbol;

    mapping(uint256 tokenId => address) private _owners;

    mapping(address owner => uint256) private _balances;

    mapping(uint256 tokenId => address) private _tokenApprovals;

    mapping(address owner => mapping(address operator => bool)) private _operatorApprovals;

    /**
     * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
        return
            interfaceId == type(IERC721).interfaceId ||
            interfaceId == type(IERC721Metadata).interfaceId ||
            super.supportsInterface(interfaceId);
    }

    /**
     * @dev See {IERC721-balanceOf}.
     */
    function balanceOf(address owner) public view virtual returns (uint256) {
        if (owner == address(0)) {
            revert ERC721InvalidOwner(address(0));
        }
        return _balances[owner];
    }

    /**
     * @dev See {IERC721-ownerOf}.
     */
    function ownerOf(uint256 tokenId) public view virtual returns (address) {
        return _requireOwned(tokenId);
    }

    /**
     * @dev See {IERC721Metadata-name}.
     */
    function name() public view virtual returns (string memory) {
        return _name;
    }

    /**
     * @dev See {IERC721Metadata-symbol}.
     */
    function symbol() public view virtual returns (string memory) {
        return _symbol;
    }

    /**
     * @dev See {IERC721Metadata-tokenURI}.
     */
    function tokenURI(uint256 tokenId) public view virtual returns (string memory) {
        _requireOwned(tokenId);

        string memory baseURI = _baseURI();
        return bytes(baseURI).length > 0 ? string.concat(baseURI, tokenId.toString()) : "";
    }

    /**
     * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
     * token will be the concatenation of the `baseURI` and the `tokenId`. Empty
     * by default, can be overridden in child contracts.
     */
    function _baseURI() internal view virtual returns (string memory) {
        return "";
    }

    /**
     * @dev See {IERC721-approve}.
     */
    function approve(address to, uint256 tokenId) public virtual {
        _approve(to, tokenId, _msgSender());
    }

    /**
     * @dev See {IERC721-getApproved}.
     */
    function getApproved(uint256 tokenId) public view virtual returns (address) {
        _requireOwned(tokenId);

        return _getApproved(tokenId);
    }

    /**
     * @dev See {IERC721-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual {
        _setApprovalForAll(_msgSender(), operator, approved);
    }

    /**
     * @dev See {IERC721-isApprovedForAll}.
     */
    function isApprovedForAll(address owner, address operator) public view virtual returns (bool) {
        return _operatorApprovals[owner][operator];
    }

    /**
     * @dev See {IERC721-transferFrom}.
     */
    function transferFrom(address from, address to, uint256 tokenId) public virtual {
        if (to == address(0)) {
            revert ERC721InvalidReceiver(address(0));
        }
        // Setting an "auth" arguments enables the `_isAuthorized` check which verifies that the token exists
        // (from != 0). Therefore, it is not needed to verify that the return value is not 0 here.
        address previousOwner = _update(to, tokenId, _msgSender());
        if (previousOwner != from) {
            revert ERC721IncorrectOwner(from, tokenId, previousOwner);
        }
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) public {
        safeTransferFrom(from, to, tokenId, "");
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual {
        transferFrom(from, to, tokenId);
        _checkOnERC721Received(from, to, tokenId, data);
    }

    /**
     * @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist
     *
     * IMPORTANT: Any overrides to this function that add ownership of tokens not tracked by the
     * core ERC721 logic MUST be matched with the use of {_increaseBalance} to keep balances
     * consistent with ownership. The invariant to preserve is that for any address `a` the value returned by
     * `balanceOf(a)` must be equal to the number of tokens such that `_ownerOf(tokenId)` is `a`.
     */
    function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
        return _owners[tokenId];
    }

    /**
     * @dev Returns the approved address for `tokenId`. Returns 0 if `tokenId` is not minted.
     */
    function _getApproved(uint256 tokenId) internal view virtual returns (address) {
        return _tokenApprovals[tokenId];
    }

    /**
     * @dev Returns whether `spender` is allowed to manage `owner`'s tokens, or `tokenId` in
     * particular (ignoring whether it is owned by `owner`).
     *
     * WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this
     * assumption.
     */
    function _isAuthorized(address owner, address spender, uint256 tokenId) internal view virtual returns (bool) {
        return
            spender != address(0) &&
            (owner == spender || isApprovedForAll(owner, spender) || _getApproved(tokenId) == spender);
    }

    /**
     * @dev Checks if `spender` can operate on `tokenId`, assuming the provided `owner` is the actual owner.
     * Reverts if `spender` does not have approval from the provided `owner` for the given token or for all its assets
     * the `spender` for the specific `tokenId`.
     *
     * WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this
     * assumption.
     */
    function _checkAuthorized(address owner, address spender, uint256 tokenId) internal view virtual {
        if (!_isAuthorized(owner, spender, tokenId)) {
            if (owner == address(0)) {
                revert ERC721NonexistentToken(tokenId);
            } else {
                revert ERC721InsufficientApproval(spender, tokenId);
            }
        }
    }

    /**
     * @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override.
     *
     * NOTE: the value is limited to type(uint128).max. This protect against _balance overflow. It is unrealistic that
     * a uint256 would ever overflow from increments when these increments are bounded to uint128 values.
     *
     * WARNING: Increasing an account's balance using this function tends to be paired with an override of the
     * {_ownerOf} function to resolve the ownership of the corresponding tokens so that balances and ownership
     * remain consistent with one another.
     */
    function _increaseBalance(address account, uint128 value) internal virtual {
        unchecked {
            _balances[account] += value;
        }
    }

    /**
     * @dev Transfers `tokenId` from its current owner to `to`, or alternatively mints (or burns) if the current owner
     * (or `to`) is the zero address. Returns the owner of the `tokenId` before the update.
     *
     * The `auth` argument is optional. If the value passed is non 0, then this function will check that
     * `auth` is either the owner of the token, or approved to operate on the token (by the owner).
     *
     * Emits a {Transfer} event.
     *
     * NOTE: If overriding this function in a way that tracks balances, see also {_increaseBalance}.
     */
    function _update(address to, uint256 tokenId, address auth) internal virtual returns (address) {
        address from = _ownerOf(tokenId);

        // Perform (optional) operator check
        if (auth != address(0)) {
            _checkAuthorized(from, auth, tokenId);
        }

        // Execute the update
        if (from != address(0)) {
            // Clear approval. No need to re-authorize or emit the Approval event
            _approve(address(0), tokenId, address(0), false);

            unchecked {
                _balances[from] -= 1;
            }
        }

        if (to != address(0)) {
            unchecked {
                _balances[to] += 1;
            }
        }

        _owners[tokenId] = to;

        emit Transfer(from, to, tokenId);

        return from;
    }

    /**
     * @dev Mints `tokenId` and transfers it to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - `to` cannot be the zero address.
     *
     * Emits a {Transfer} event.
     */
    function _mint(address to, uint256 tokenId) internal {
        if (to == address(0)) {
            revert ERC721InvalidReceiver(address(0));
        }
        address previousOwner = _update(to, tokenId, address(0));
        if (previousOwner != address(0)) {
            revert ERC721InvalidSender(address(0));
        }
    }

    /**
     * @dev Mints `tokenId`, transfers it to `to` and checks for `to` acceptance.
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeMint(address to, uint256 tokenId) internal {
        _safeMint(to, tokenId, "");
    }

    /**
     * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
     * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
     */
    function _safeMint(address to, uint256 tokenId, bytes memory data) internal virtual {
        _mint(to, tokenId);
        _checkOnERC721Received(address(0), to, tokenId, data);
    }

    /**
     * @dev Destroys `tokenId`.
     * The approval is cleared when the token is burned.
     * This is an internal function that does not check if the sender is authorized to operate on the token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     *
     * Emits a {Transfer} event.
     */
    function _burn(uint256 tokenId) internal {
        address previousOwner = _update(address(0), tokenId, address(0));
        if (previousOwner == address(0)) {
            revert ERC721NonexistentToken(tokenId);
        }
    }

    /**
     * @dev Transfers `tokenId` from `from` to `to`.
     *  As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     *
     * Emits a {Transfer} event.
     */
    function _transfer(address from, address to, uint256 tokenId) internal {
        if (to == address(0)) {
            revert ERC721InvalidReceiver(address(0));
        }
        address previousOwner = _update(to, tokenId, address(0));
        if (previousOwner == address(0)) {
            revert ERC721NonexistentToken(tokenId);
        } else if (previousOwner != from) {
            revert ERC721IncorrectOwner(from, tokenId, previousOwner);
        }
    }

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking that contract recipients
     * are aware of the ERC721 standard to prevent tokens from being forever locked.
     *
     * `data` is additional data, it has no specified format and it is sent in call to `to`.
     *
     * This internal function is like {safeTransferFrom} in the sense that it invokes
     * {IERC721Receiver-onERC721Received} on the receiver, and can be used to e.g.
     * implement alternative mechanisms to perform token transfer, such as signature-based.
     *
     * Requirements:
     *
     * - `tokenId` token must exist and be owned by `from`.
     * - `to` cannot be the zero address.
     * - `from` cannot be the zero address.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeTransfer(address from, address to, uint256 tokenId) internal {
        _safeTransfer(from, to, tokenId, "");
    }

    /**
     * @dev Same as {xref-ERC721-_safeTransfer-address-address-uint256-}[`_safeTransfer`], with an additional `data` parameter which is
     * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
     */
    function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual {
        _transfer(from, to, tokenId);
        _checkOnERC721Received(from, to, tokenId, data);
    }

    /**
     * @dev Approve `to` to operate on `tokenId`
     *
     * The `auth` argument is optional. If the value passed is non 0, then this function will check that `auth` is
     * either the owner of the token, or approved to operate on all tokens held by this owner.
     *
     * Emits an {Approval} event.
     *
     * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
     */
    function _approve(address to, uint256 tokenId, address auth) internal {
        _approve(to, tokenId, auth, true);
    }

    /**
     * @dev Variant of `_approve` with an optional flag to enable or disable the {Approval} event. The event is not
     * emitted in the context of transfers.
     */
    function _approve(address to, uint256 tokenId, address auth, bool emitEvent) internal virtual {
        // Avoid reading the owner unless necessary
        if (emitEvent || auth != address(0)) {
            address owner = _requireOwned(tokenId);

            // We do not use _isAuthorized because single-token approvals should not be able to call approve
            if (auth != address(0) && owner != auth && !isApprovedForAll(owner, auth)) {
                revert ERC721InvalidApprover(auth);
            }

            if (emitEvent) {
                emit Approval(owner, to, tokenId);
            }
        }

        _tokenApprovals[tokenId] = to;
    }

    /**
     * @dev Approve `operator` to operate on all of `owner` tokens
     *
     * Requirements:
     * - operator can't be the address zero.
     *
     * Emits an {ApprovalForAll} event.
     */
    function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
        if (operator == address(0)) {
            revert ERC721InvalidOperator(operator);
        }
        _operatorApprovals[owner][operator] = approved;
        emit ApprovalForAll(owner, operator, approved);
    }

    /**
     * @dev Reverts if the `tokenId` doesn't have a current owner (it hasn't been minted, or it has been burned).
     * Returns the owner.
     *
     * Overrides to ownership logic should be done to {_ownerOf}.
     */
    function _requireOwned(uint256 tokenId) internal view returns (address) {
        address owner = _ownerOf(tokenId);
        if (owner == address(0)) {
            revert ERC721NonexistentToken(tokenId);
        }
        return owner;
    }

    /**
     * @dev Private function to invoke {IERC721Receiver-onERC721Received} on a target address. This will revert if the
     * recipient doesn't accept the token transfer. The call is not executed if the target address is not a contract.
     *
     * @param from address representing the previous owner of the given token ID
     * @param to target address that will receive the tokens
     * @param tokenId uint256 ID of the token to be transferred
     * @param data bytes optional data to send along with the call
     */
    function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory data) private {
        if (to.code.length > 0) {
            try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
                if (retval != IERC721Receiver.onERC721Received.selector) {
                    revert ERC721InvalidReceiver(to);
                }
            } catch (bytes memory reason) {
                if (reason.length == 0) {
                    revert ERC721InvalidReceiver(to);
                } else {
                    /// @solidity memory-safe-assembly
                    assembly {
                        revert(add(32, reason), mload(reason))
                    }
                }
            }
        }
    }
}
Código Fuente del Contrato
Archivo 5 de 26: IAttribute.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

/**
@notice Interface for Attribute
@author Runic Labs, Inc
*/
interface IAttribute {
    /**
    @notice Register event
    @param attributeId the attributeId registered
    @param tier the tier
    @param name the attribute name
    @param isPromoReserved if this attribute is reserved for promo
    */
    event Register(uint16 indexed attributeId, uint8 tier, string name, bool isPromoReserved);

    /**
    @notice Supply lock event
    @param attributeId the attributeId that was supply locked
    */
    event SupplyLock(uint16 indexed attributeId);

    /// Types used for attributeType field
    enum Type {
        BACKGROUND,
        BASE,
        EYES,
        MOUTH,
        CLOTHING,
        HAT,
        ACCESSORY
    }

    /// Tiers used for tier field
    enum Tier {
        COMMON,
        RARE,
        LEGENDARY,
        MYTHIC,
        EXCLUSIVE
    }

    /// An attribute definition
    struct Definition {
        Type attributeType;
        uint16 attributeId;
        uint8 tier;
        bool isPromo;
        string name;
    }

    /// Onchain attribute metadata
    struct Metadata {
        Type attributeType;
        uint16 attributeId;
        uint8 tier;
        string name;
    }

    /// A mint tier configuration
    struct MintTier {
        uint8 frequency;
        uint16[] attributeIds;
        mapping(uint16 => uint256) index;
    }

    /**
    @notice Stores metadata for a tokenId
    @param tokenId the tokenId to store metadata for
    @param data the metadata
    */
    function storeMetadata(uint256 tokenId, Metadata memory data) external;

    /**
    @notice Loads metadata for a tokenId
    @param tokenId the tokenId to load metadata for
    @return data the metadata
    */
    function loadMetadata(uint256 tokenId) external view returns (Metadata memory data);

    /**
    @notice Packs metadata for storage
    @param data the metadata struct
    @return slots the metadata slots
    */
    function packMetadata(Metadata memory data) external pure returns (uint256[] memory slots);

    /**
    @notice Unpacks packed metadata from storage format
    @param slots the metadata slots
    @return data the metadata struct
    */
    function unpackMetadata(uint256[] memory slots) external pure returns (Metadata memory data);

    /**
    @notice Loads an attributeType for a tokenId 
    @param tokenId the tokenId to use
    @return Type the attributeType
    */
    function loadAttributeType(uint256 tokenId) external view returns (Type);

    /**
    @notice Loads an attributeId for a tokenId 
    @param tokenId the tokenId to use
    @return uint16 the attributeId
    */
    function loadAttributeId(uint256 tokenId) external view returns (uint16);

    /**
    @notice Loads a tier for a tokenId 
    @param tokenId the tokenId to use
    @return uint8 the tier
    */
    function loadTier(uint256 tokenId) external view returns (uint8);
    
    /**
    @notice Loads an attribute name for a tokenId 
    @param tokenId the tokenId to use
    @return string the name
    */
    function loadName(uint256 tokenId) external view returns (string memory);
}
Código Fuente del Contrato
Archivo 6 de 26: IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
Código Fuente del Contrato
Archivo 7 de 26: IERC4906.sol
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.23;

import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";

/// @title EIP-721 Metadata Update Extension
interface IERC4906 is IERC165, IERC721 {
    /// @dev This event emits when the metadata of a token is changed.
    /// So that the third-party platforms such as NFT market could
    /// timely update the images and related attributes of the NFT.
    event MetadataUpdate(uint256 indexed _tokenId);

    /// @dev This event emits when the metadata of a range of tokens is changed.
    /// So that the third-party platforms such as NFT market could
    /// timely update the images and related attributes of the NFTs.    
    event BatchMetadataUpdate(uint256 indexed _fromTokenId, uint256 indexed _toTokenId);
}
Código Fuente del Contrato
Archivo 8 de 26: IERC5192.sol
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.23;

interface IERC5192 {
  /// @notice Emitted when the locking status is changed to locked.
  /// @dev If a token is minted and the status is locked, this event should be emitted.
  /// @param tokenId The identifier for a token.
  event Locked(uint256 indexed tokenId);

  /// @notice Emitted when the locking status is changed to unlocked.
  /// @dev If a token is minted and the status is unlocked, this event should be emitted.
  /// @param tokenId The identifier for a token.
  event Unlocked(uint256 indexed tokenId);

  /// @notice Returns the locking status of an Soulbound Token
  /// @dev SBTs assigned to zero address are considered invalid, and queries
  /// about them do throw.
  /// @param tokenId The identifier for an SBT.
  function locked(uint256 tokenId) external view returns (bool);
}
Código Fuente del Contrato
Archivo 9 de 26: IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.20;

import {IERC165} from "../../utils/introspection/IERC165.sol";

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
     *   a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or
     *   {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
     *   a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
     * understand this adds an external call which potentially creates a reentrancy vulnerability.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the address zero.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);
}
Código Fuente del Contrato
Archivo 10 de 26: IERC721Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Metadata.sol)

pragma solidity ^0.8.20;

import {IERC721} from "../IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Metadata is IERC721 {
    /**
     * @dev Returns the token collection name.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the token collection symbol.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
     */
    function tokenURI(uint256 tokenId) external view returns (string memory);
}
Código Fuente del Contrato
Archivo 11 de 26: IERC721Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721Receiver.sol)

pragma solidity ^0.8.20;

/**
 * @title ERC721 token receiver interface
 * @dev Interface for any contract that wants to support safeTransfers
 * from ERC721 asset contracts.
 */
interface IERC721Receiver {
    /**
     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
     * by `operator` from `from`, this function is called.
     *
     * It must return its Solidity selector to confirm the token transfer.
     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be
     * reverted.
     *
     * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}
Código Fuente del Contrato
Archivo 12 de 26: IPatchwork721.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "./IERC5192.sol";
import "./IPatchworkScoped.sol";

/** 
@title Patchwork Protocol Interface Metadata
@author Runic Labs, Inc
@notice Metadata for IPatchwork721 and related contract interfaces
*/
interface IPatchworkMetadata {
    /**
    @notice Enumeration of possible field data types.
    @dev This defines the various basic data types for the fields.
     */
    enum FieldType {
        BOOLEAN,  ///< A Boolean type (true or false).
        INT8,     ///< An 8-bit signed integer.
        INT16,    ///< A 16-bit signed integer.
        INT32,    ///< A 32-bit signed integer.
        INT64,    ///< A 64-bit signed integer.
        INT128,   ///< A 128-bit signed integer.
        INT256,   ///< A 256-bit signed integer.
        UINT8,    ///< An 8-bit unsigned integer.
        UINT16,   ///< A 16-bit unsigned integer.
        UINT32,   ///< A 32-bit unsigned integer.
        UINT64,   ///< A 64-bit unsigned integer.
        UINT128,  ///< A 128-bit unsigned integer.
        UINT256,  ///< A 256-bit unsigned integer.
        CHAR8,    ///< An 8-character string (64 bits).
        CHAR16,   ///< A 16-character string (128 bits).
        CHAR32,   ///< A 32-character string (256 bits).
        CHAR64,   ///< A 64-character string (512 bits).
        LITEREF,  ///< A 64-bit Literef reference to a patchwork fragment.
        ADDRESS,  ///< A 160-bit address.
        STRING    ///< A dynamically-sized string.
    }

    /**
    @notice Struct defining the metadata schema.
    @dev This defines the overall structure of the metadata and contains entries describing each data field.
    */
    struct MetadataSchema {
        uint256 version;                    ///< Version of the metadata schema.
        MetadataSchemaEntry[] entries;      ///< Array of entries in the schema.
    }

    /**
    @notice Struct defining individual entries within the metadata schema.
    @dev Represents each data field in the schema, detailing its properties and type.
    */
    struct MetadataSchemaEntry {
        uint256 id;                        ///< Index or unique identifier of the entry.
        uint256 permissionId;              ///< Permission identifier associated with the entry.
        FieldType fieldType;               ///< Type of field data (from the FieldType enum).
        uint256 fieldCount;                ///< Number of elements of this field (0 = Dynamic Array, 1 = Single, >1 = Static Array)
        FieldVisibility visibility;        ///< Visibility level of the field.
        uint256 slot;                      ///< Starting storage slot, may span multiple slots based on width.
        uint256 offset;                    ///< Offset in bits within the storage slot.
        string key;                        ///< Key or name associated with the field.
    }

    /**
    @notice Enumeration of field visibility options.
    @dev Specifies whether a field is publicly accessible or private.
    */
    enum FieldVisibility {
        PUBLIC,  ///< Field is publicly accessible.
        PRIVATE  ///< Field is private
    }
}

/**
@title Patchwork Protocol 721 Interface
@author Runic Labs, Inc
@notice Interface for contracts supporting Patchwork metadata standard
*/
interface IPatchwork721 is IPatchworkScoped, IPatchworkMetadata, IERC5192, IERC721 {
    /**
    @notice Emitted when the freeze status is changed to frozen.
    @param tokenId The identifier for a token.
    */
    event Frozen(uint256 indexed tokenId);

    /**
    @notice Emitted when the locking status is changed to not frozen.
    @param tokenId The identifier for a token.
    */
    event Thawed(uint256 indexed tokenId);

    /**
    @notice Emitted when the permissions are changed
    @param to The address the permissions are assigned to
    @param permissions The permissions
    */
    event PermissionChange(address indexed to, uint256 permissions);

    /**
    @notice Emitted when the schema has changed
    @param addr the address of the Patchwork721
    */
    event SchemaChange(address indexed addr);

    /**
    @notice Returns the URI of the schema
    @return string the URI of the schema
    */
    function schemaURI() external view returns (string memory);

    /**
    @notice Returns the metadata schema
    @return MetadataSchema the metadata schema
    */
    function schema() external view returns (MetadataSchema memory);

    /**
    @notice Returns the URI of the image associated with the given token ID
    @param tokenId ID of the token
    @return string the image URI
    */
    function imageURI(uint256 tokenId) external view returns (string memory);

    /**
    @notice Sets permissions for a given address
    @param to Address to set permissions for
    @param permissions Permissions value
    */
    function setPermissions(address to, uint256 permissions) external;

    /**
    @notice Stores packed metadata for a given token ID and slot
    @param tokenId ID of the token
    @param slot Slot to store metadata
    @param data Metadata to store
    */
    function storePackedMetadataSlot(uint256 tokenId, uint256 slot, uint256 data) external;

    /**
    @notice Stores packed metadata for a given token ID
    @param tokenId ID of the token
    @param data Metadata to store
    */
    function storePackedMetadata(uint256 tokenId, uint256[] memory data) external;

    /**
    @notice Loads packed metadata for a given token ID and slot
    @param tokenId ID of the token
    @param slot Slot to load metadata from
    @return uint256 the raw slot data as a uint256
    */
    function loadPackedMetadataSlot(uint256 tokenId, uint256 slot) external view returns (uint256);

    /**
    @notice Loads packed metadata for a given token ID
    @param tokenId ID of the token
    @return uint256[] the raw slot data as a uint256 array
    */
    function loadPackedMetadata(uint256 tokenId) external view returns (uint256[] memory);

    /**
    @notice Returns the freeze nonce for a given token ID
    @param tokenId ID of the token
    @return nonce the nonce
    */
    function getFreezeNonce(uint256 tokenId) external view returns (uint256 nonce);

    /**
    @notice Sets the freeze status of a token
    @param tokenId ID of the token
    @param frozen Freeze status to set
    */
    function setFrozen(uint256 tokenId, bool frozen) external;

    /**
    @notice Gets the freeze status of a token (ERC-5192)
    @param tokenId ID of the token
    @return bool true if frozen, false if not
     */
    function frozen(uint256 tokenId) external view returns (bool);

    /**
    @notice Sets the lock status of a token
    @param tokenId ID of the token
    @param locked Lock status to set
    */
    function setLocked(uint256 tokenId, bool locked) external;
}
Código Fuente del Contrato
Archivo 13 de 26: IPatchworkAssignable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import "./IPatchworkScoped.sol";

/**
@title Patchwork Protocol Assignable NFT Interface
@author Runic Labs, Inc
@notice Interface for contracts supporting Patchwork assignment
*/
interface IPatchworkAssignable is IPatchworkScoped {
    
    /// Represents an assignment of a token from an external NFT contract to a token in this contract.
    struct Assignment {
        address tokenAddr;  /// The address of the external NFT contract.
        uint256 tokenId;    /// The ID of the token in the external NFT contract.
    }

    /**
    @notice Assigns a token to another
    @param ourTokenId ID of our token
    @param to Address to assign to
    @param tokenId ID of the token to assign
    */
    function assign(uint256 ourTokenId, address to, uint256 tokenId) external;

    /**
    @notice Checks permissions for assignment
    @param ourTokenId the tokenID to assign
    @param target the address of the target
    @param targetTokenId the tokenID of the target
    @param targetOwner the ownerOf of the target
    @param by the account invoking the assignment to Patchwork Protocol
    @param scopeName the scope name of the contract to assign to
    */
    function allowAssignment(uint256 ourTokenId, address target, uint256 targetTokenId, address targetOwner, address by, string memory scopeName) external view returns (bool);
}
Código Fuente del Contrato
Archivo 14 de 26: IPatchworkMintable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import "./IPatchworkScoped.sol";

/**
@title Patchwork Mintable Interface
@author Runic Labs, Inc
*/
interface IPatchworkMintable is IPatchworkScoped {

    /**
    @notice Mint a new token
    @dev Mints a single token to a specified address.
    @param to The address to which the token will be minted.
    @param data Additional data to be passed to the minting process.
    @return tokenId The ID of the minted token.
    */
    function mint(address to, bytes calldata data) external payable returns (uint256 tokenId);
    
    /**
    @notice Mint a batch of new tokens
    @dev Mints multiple tokens to a specified address.
    @param to The address to which the tokens will be minted.
    @param data Additional data to be passed to the minting process.
    @param quantity The number of tokens to mint.
    @return tokenIds An array of the IDs of the minted tokens.
    */
    function mintBatch(address to, bytes calldata data, uint256 quantity) external payable returns (uint256[] memory tokenIds);
}
Código Fuente del Contrato
Archivo 15 de 26: IPatchworkProtocol.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

/**
@title Patchwork Protocol Interface
@author Runic Labs, Inc
@notice Interface for Patchwork Protocol
*/
interface IPatchworkProtocol {
    /**
    @notice The address is not authorized to perform this action
    @param addr The address attempting to perform the action
    */
    error NotAuthorized(address addr);

    /**
    @notice The scope with the provided name already exists
    @param scopeName Name of the scope
    */
    error ScopeExists(string scopeName);

    /**
    @notice The scope with the provided name does not exist
    @param scopeName Name of the scope
    */
    error ScopeDoesNotExist(string scopeName);

    /**
    @notice Transfer of the scope to the provided address is not allowed
    @param to Address not allowed for scope transfer
    */
    error ScopeTransferNotAllowed(address to);

    /**
    @notice The token with the provided ID at the given address is frozen
    @param addr Address of the token owner
    @param tokenId ID of the frozen token
    */
    error Frozen(address addr, uint256 tokenId);

    /**
    @notice The token with the provided ID at the given address is locked
    @param addr Address of the token owner
    @param tokenId ID of the locked token
    */
    error Locked(address addr, uint256 tokenId);

    /**
    @notice The address is not whitelisted for the given scope
    @param scopeName Name of the scope
    @param addr Address that isn't whitelisted
    */
    error NotWhitelisted(string scopeName, address addr);

    /**
    @notice The address at the given address has already been patched
    @param addr The address that was patched
    @param patchAddress Address of the patch applied
    */
    error AccountAlreadyPatched(address addr, address patchAddress);

    /**
    @notice The token at the given address has already been patched
    @param addr Address of the original 721
    @param tokenId ID of the patched token
    @param patchAddress Address of the patch applied
    */
    error AlreadyPatched(address addr, uint256 tokenId, address patchAddress);

    /**
    @notice The ERC1155 path has already been patched
    @param addr Address of the 1155
    @param tokenId ID of the patched token
    @param account The account patched
    @param patchAddress Address of the patch applied
    */
    error ERC1155AlreadyPatched(address addr, uint256 tokenId, address account, address patchAddress);

    /**
    @notice The provided input lengths are not compatible or valid
    @dev for any multi array inputs, they must be the same length
    */
    error BadInputLengths();

    /**
    @notice The fragment at the given address is unregistered
    @param addr Address of the unregistered fragment
    */
    error FragmentUnregistered(address addr);

    /**
    @notice The fragment at the given address has been redacted
    @param addr Address of the redacted fragment
    */
    error FragmentRedacted(address addr);

    /**
    @notice The fragment with the provided ID at the given address is already assigned
    @param addr Address of the fragment
    @param tokenId ID of the assigned fragment
    */
    error FragmentAlreadyAssigned(address addr, uint256 tokenId);

    /**
    @notice The reference was not found for the given fragment and target
    @param target Address of the target token
    @param fragment Address of the fragment
    @param tokenId ID of the fragment
    */
    error RefNotFound(address target, address fragment, uint256 tokenId);

    /**
    @notice The fragment with the provided ID at the given address is not assigned
    @param addr Address of the fragment
    @param tokenId ID of the fragment
    */
    error FragmentNotAssigned(address addr, uint256 tokenId);

    /**
    @notice The fragment with the provided ID at the given address is not assigned to the target
    @param addr Address of the fragment
    @param tokenId ID of the fragment
    @param targetAddress Address of the target
    @param targetTokenId ID of the target
    */
    error FragmentNotAssignedToTarget(address addr, uint256 tokenId, address targetAddress, uint256 targetTokenId);

    /**
    @notice The fragment at the given address is already registered
    @param addr Address of the registered fragment
    */
    error FragmentAlreadyRegistered(address addr);

    /**
    @notice Ran out of available IDs for allocation
    @dev Max 255 IDs per target
    */
    error OutOfIDs();

    /**
    @notice The provided token ID is unsupported
    @dev TokenIds may only be 56 bits long
    @param tokenId The unsupported token ID
    */
    error UnsupportedTokenId(uint256 tokenId);

    /**
    @notice Cannot lock the soulbound patch at the given address
    @param addr Address of the soulbound patch
    */
    error CannotLockSoulboundPatch(address addr);

    /**
    @notice The token with the provided ID at the given address is not frozen
    @param addr Address of the token owner
    @param tokenId ID of the token
    */
    error NotFrozen(address addr, uint256 tokenId);

    /**
    @notice The nonce for the token with the provided ID at the given address is incorrect
    @dev It may be incorrect or a newer nonce may be present
    @param addr Address of the token owner
    @param tokenId ID of the token
    @param nonce The incorrect nonce
    */
    error IncorrectNonce(address addr, uint256 tokenId, uint256 nonce);

    /**
    @notice Self assignment of the token with the provided ID at the given address is not allowed
    @param addr Address of the token owner
    @param tokenId ID of the token
    */
    error SelfAssignmentNotAllowed(address addr, uint256 tokenId);

    /**
    @notice Transfer of the token with the provided ID at the given address is not allowed
    @param addr Address of the token owner
    @param tokenId ID of the token
    */
    error TransferNotAllowed(address addr, uint256 tokenId);

    /**
    @notice Transfer of the token with the provided ID at the given address is blocked by an assignment
    @param addr Address of the token owner
    @param tokenId ID of the token
    */
    error TransferBlockedByAssignment(address addr, uint256 tokenId);

    /**
    @notice A rule is blocking the mint to this owner address
    @param addr Address of the token owner
    */
    error MintNotAllowed(address addr);

    /**
    @notice The token at the given address is not IPatchworkAssignable
    @param addr Address of the non-assignable token
    */
    error NotPatchworkAssignable(address addr);

    /**
    @notice A data integrity error has been detected
    @dev Addr+TokenId is expected where addr2+tokenId2 is present
    @param addr Address of the first token
    @param tokenId ID of the first token
    @param addr2 Address of the second token
    @param tokenId2 ID of the second token
    */
    error DataIntegrityError(address addr, uint256 tokenId, address addr2, uint256 tokenId2);

    /**
    @notice The available balance does not satisfy the amount
    */
    error InsufficientFunds();

    /**
    @notice The supplied fee is not the corret amount
    */
    error IncorrectFeeAmount();

    /**
    @notice Minting is not active for this address 
    */
    error MintNotActive();

    /**
    @notice The value could not be sent 
    */
    error FailedToSend();   
    
    /**
    @notice The contract is not supported
    */
    error UnsupportedContract();
    
    /**
    @notice The operation is not supported
    */
    error UnsupportedOperation();

    /**
    @notice No proposed fee is set 
    */
    error NoProposedFeeSet();

    /**
    @notice Timelock has not elapsed
    */
    error TimelockNotElapsed();

    /**
    @notice Invalid fee value 
    */
    error InvalidFeeValue();

    /**
    @notice No delegate proposed 
    */
    error NoDelegateProposed();
    
    /** 
    @notice Fee Configuration
    */
    struct FeeConfig {
        uint256 mintBp;   /// mint basis points (10000 = 100%)
        uint256 patchBp;  /// patch basis points (10000 = 100%)
        uint256 assignBp; /// assign basis points (10000 = 100%)
    }

    /** 
    @notice Fee Configuration Override
    */
    struct FeeConfigOverride {
        uint256 mintBp;   /// mint basis points (10000 = 100%)
        uint256 patchBp;  /// patch basis points (10000 = 100%)
        uint256 assignBp; /// assign basis points (10000 = 100%)
        bool active; /// true for present
    }

    /**
    @notice Proposal to change a fee configuration for either protocol or scope override
    */
    struct ProposedFeeConfig {
        FeeConfig config;
        uint256 timestamp;
        bool active; /// Used to enable/disable overrides - ignored for protocol
    }

    /**
    @notice Mint configuration
    */
    struct MintConfig {
        uint256 flatFee; /// fee per 1 quantity mint in wei
        bool active;     /// If the mint is active
    }

    /**
    @notice Proposed assigner delegate
    */
    struct ProposedAssignerDelegate {
        uint256 timestamp;
        address addr;
    }

    /**
    @notice Represents a defined scope within the system
    @dev Contains details about the scope ownership, permissions, and mappings for references and assignments
    */
    struct Scope {
        /**
        @notice Owner of this scope
        @dev Address of the account or contract that owns this scope
        */
        address owner;

        /**
        @notice Owner-elect
        @dev Used in two-step transfer process. If this is set, only this owner can accept the transfer
        */
        address ownerElect;

        /**
        @notice Indicates whether a user is allowed to patch within this scope
        @dev True if a user can patch, false otherwise. If false, only operators and the scope owner can perform patching.
        */
        bool allowUserPatch;

        /**
        @notice Indicates whether a user is allowed to assign within this scope
        @dev True if a user can assign, false otherwise. If false, only operators and the scope owner can perform assignments.
        */
        bool allowUserAssign;

        /**
        @notice Indicates if a whitelist is required for operations within this scope
        @dev True if whitelist is required, false otherwise
        */
        bool requireWhitelist;

        /**
        @notice Mapped list of operator addresses for this scope
        @dev Address of the operator mapped to a boolean indicating if they are an operator
        */
        mapping(address => bool) operators;

        /**
        @notice Mapped whitelist of addresses that belong to this scope
        @dev Address mapped to a boolean indicating if it's whitelisted
        */
        mapping(address => bool) whitelist;

        /**
        @notice Mapped list of mint configurations for this scope
        @dev Address of the IPatchworkMintable mapped to the configuration
        */
        mapping(address => MintConfig) mintConfigurations;

        /**
        @notice Mapped list of patch fees for this scope
        @dev Address of a 721, 1155 or account patch mapped to the fee in wei 
        */
        mapping(address => uint256) patchFees;

        /**
        @notice Mapped list of assign fees for this scope
        @dev Address of an IPatchworkAssignable mapped to the fee in wei 
        */        
        mapping(address => uint256) assignFees;

        /**
        @notice Balance in wei for this scope
        @dev accrued in mint, patch and assign fees, may only be withdrawn by scope bankers
        */
        uint256 balance;

        /**
        @notice Mapped list of addresses that are designated bankers for this scope 
        @dev Address mapped to a boolean indicating if they are a banker
        */
        mapping(address => bool) bankers;
    }

    /**
    @notice Emitted when a fragment is assigned
    @param owner The owner of the target and fragment
    @param fragmentAddress The address of the fragment's contract
    @param fragmentTokenId The tokenId of the fragment
    @param targetAddress The address of the target's contract
    @param targetTokenId The tokenId of the target
    @param scopeFee The fee collected to the scope
    @param protocolFee The fee collected to the protocol
    */
    event Assign(address indexed owner, address fragmentAddress, uint256 fragmentTokenId, address indexed targetAddress, uint256 indexed targetTokenId, uint256 scopeFee, uint256 protocolFee);

    /**
    @notice Emitted when a fragment is unassigned
    @param owner The owner of the fragment
    @param fragmentAddress The address of the fragment's contract
    @param fragmentTokenId The tokenId of the fragment
    @param targetAddress The address of the target's contract
    @param targetTokenId The tokenId of the target
    */
    event Unassign(address indexed owner, address fragmentAddress, uint256 fragmentTokenId, address indexed targetAddress, uint256 indexed targetTokenId);

    /**
    @notice Emitted when a patch is minted
    @param owner The owner of the patch
    @param originalAddress The address of the original 721's contract
    @param originalTokenId The tokenId of the original 721
    @param patchAddress The address of the patch's contract
    @param patchTokenId The tokenId of the patch
    @param scopeFee The fee collected to the scope
    @param protocolFee The fee collected to the protocol
    */
    event Patch(address indexed owner, address originalAddress, uint256 originalTokenId, address indexed patchAddress, uint256 indexed patchTokenId, uint256 scopeFee, uint256 protocolFee);

    /**
    @notice Emitted when a patch is minted
    @param owner The owner of the patch
    @param originalAddress The address of the original 1155's contract
    @param originalTokenId The tokenId of the original 1155
    @param originalAccount The address of the original 1155's account
    @param patchAddress The address of the patch's contract
    @param patchTokenId The tokenId of the patch
    @param scopeFee The fee collected to the scope
    @param protocolFee The fee collected to the protocol
    */
    event ERC1155Patch(address indexed owner, address originalAddress, uint256 originalTokenId, address originalAccount, address indexed patchAddress, uint256 indexed patchTokenId, uint256 scopeFee, uint256 protocolFee);


    /**
    @notice Emitted when an account patch is minted
    @param owner The owner of the patch
    @param originalAddress The address of the original account
    @param patchAddress The address of the patch's contract
    @param patchTokenId The tokenId of the patch
    @param scopeFee The fee collected to the scope
    @param protocolFee The fee collected to the protocol
    */
    event AccountPatch(address indexed owner, address originalAddress, address indexed patchAddress, uint256 indexed patchTokenId, uint256 scopeFee, uint256 protocolFee);

    /**
    @notice Emitted when a new scope is claimed
    @param scopeName The name of the claimed scope
    @param owner The owner of the scope
    */
    event ScopeClaim(string scopeName, address indexed owner);

    /**
    @notice Emitted when a scope has elected a new owner to transfer to
    @param scopeName The name of the transferred scope
    @param from The owner of the scope
    @param to The owner-elect of the scope
    */
    event ScopeTransferElect(string scopeName, address indexed from, address indexed to);

    /**
    @notice Emitted when a scope transfer is canceled
    @param scopeName The name of the transferred scope
    @param from The owner of the scope
    @param to The owner-elect of the scope
    */
    event ScopeTransferCancel(string scopeName, address indexed from, address indexed to);

    /**
    @notice Emitted when a scope is transferred
    @param scopeName The name of the transferred scope
    @param from The address transferring the scope
    @param to The recipient of the scope
    */
    event ScopeTransfer(string scopeName, address indexed from, address indexed to);

    /**
    @notice Emitted when a scope has an operator added
    @param scopeName The name of the scope
    @param actor The address responsible for the action
    @param operator The new operator's address
    */
    event ScopeAddOperator(string scopeName, address indexed actor, address indexed operator);

    /**
    @notice Emitted when a scope has an operator removed
    @param scopeName The name of the scope
    @param actor The address responsible for the action
    @param operator The operator's address being removed
    */
    event ScopeRemoveOperator(string scopeName, address indexed actor, address indexed operator);

    /**
    @notice Emitted when a scope's rules are changed
    @param scopeName The name of the scope
    @param actor The address responsible for the action
    @param allowUserPatch Indicates whether user patches are allowed
    @param allowUserAssign Indicates whether user assignments are allowed
    @param requireWhitelist Indicates whether a whitelist is required
    */
    event ScopeRuleChange(string scopeName, address indexed actor, bool allowUserPatch, bool allowUserAssign, bool requireWhitelist);

    /**
    @notice Emitted when a scope has an address added to the whitelist
    @param scopeName The name of the scope
    @param actor The address responsible for the action
    @param addr The address being added to the whitelist
    */
    event ScopeWhitelistAdd(string scopeName, address indexed actor, address indexed addr);

    /**
    @notice Emitted when a scope has an address removed from the whitelist
    @param scopeName The name of the scope
    @param actor The address responsible for the action
    @param addr The address being removed from the whitelist
    */
    event ScopeWhitelistRemove(string scopeName, address indexed actor, address indexed addr);

    /**
    @notice Emitted when a mint is configured
    @param scopeName The name of the scope
    @param mintable The address of the IPatchworkMintable
    @param config The mint configuration
    */
    event MintConfigure(string scopeName, address indexed actor, address indexed mintable, MintConfig config);

    /**
    @notice Emitted when a banker is added to a scope
    @param scopeName The name of the scope
    @param actor The address responsible for the action
    @param banker The banker that was added
    */
    event ScopeBankerAdd(string scopeName, address indexed actor, address indexed banker);

    /**
    @notice Emitted when a banker is removed from a scope
    @param scopeName The name of the scope
    @param actor The address responsible for the action
    @param banker The banker that was removed
    */
    event ScopeBankerRemove(string scopeName, address indexed actor, address indexed banker);
    
    /**
    @notice Emitted when a withdrawl is made from a scope
    @param scopeName The name of the scope
    @param actor The address responsible for the action
    @param amount The amount withdrawn
    */    
    event ScopeWithdraw(string scopeName, address indexed actor, uint256 amount);

    /**
    @notice Emitted when a banker is added to the protocol
    @param actor The address responsible for the action
    @param banker The banker that was added
    */
    event ProtocolBankerAdd(address indexed actor, address indexed banker);

    /**
    @notice Emitted when a banker is removed from the protocol
    @param actor The address responsible for the action
    @param banker The banker that was removed
    */
    event ProtocolBankerRemove(address indexed actor, address indexed banker);

    /**
    @notice Emitted when a withdrawl is made from the protocol
    @param actor The address responsible for the action
    @param amount The amount withdrawn
    */
    event ProtocolWithdraw(address indexed actor, uint256 amount);

    /**
    @notice Emitted on mint
    @param actor The address responsible for the action
    @param scopeName The scope of the IPatchworkMintable
    @param to The receipient of the mint
    @param mintable The IPatchworkMintable minted
    @param data The data used to mint
    @param scopeFee The fee collected to the scope
    @param protocolFee The fee collected to the protocol
    */
    event Mint(address indexed actor, string scopeName, address indexed to, address indexed mintable, bytes data, uint256 scopeFee, uint256 protocolFee);

    /**
    @notice Emitted on batch mint
    @param actor The address responsible for the action
    @param scopeName The scope of the IPatchworkMintable
    @param to The receipient of the mint
    @param mintable The IPatchworkMintable minted
    @param data The data used to mint
    @param quantity The quantity minted
    @param scopeFee The fee collected to the scope
    @param protocolFee The fee collected to the protocol
    */
    event MintBatch(address indexed actor, string scopeName, address indexed to, address indexed mintable, bytes data, uint256 quantity, uint256 scopeFee, uint256 protocolFee);

    /**
    @notice Emitted on protocol fee config proposed
    @param config The fee configuration
    */
    event ProtocolFeeConfigPropose(FeeConfig config);

    /**
    @notice Emitted on protocol fee config committed
    @param config The fee configuration
    */
    event ProtocolFeeConfigCommit(FeeConfig config);

    /**
    @notice Emitted on scope fee config override proposed
    @param scopeName The scope
    @param config The fee configuration
    */
    event ScopeFeeOverridePropose(string scopeName, FeeConfigOverride config);

    /**
    @notice Emitted on scope fee config override committed
    @param scopeName The scope
    @param config The fee configuration
    */
    event ScopeFeeOverrideCommit(string scopeName, FeeConfigOverride config);

    /**
    @notice Emitted on patch fee change
    @param scopeName The scope of the patch
    @param addr The address of the patch
    @param fee The new fee
    */
    event PatchFeeChange(string scopeName, address indexed addr, uint256 fee);

    /**
    @notice Emitted on assign fee change 
    @param scopeName The scope of the assignable
    @param addr The address of the assignable
    @param fee The new fee
    */
    event AssignFeeChange(string scopeName, address indexed addr, uint256 fee);

    /**
    @notice Emitted on assigner delegate propose
    @param addr The address of the delegate
    */
    event AssignerDelegatePropose(address indexed addr);

    /**
    @notice Emitted on assigner delegate commit
    @param addr The address of the delegate
    */
    event AssignerDelegateCommit(address indexed addr);

    /**
    @notice Claim a scope
    @param scopeName the name of the scope
    */
    function claimScope(string calldata scopeName) external;

    /**
    @notice Transfer ownership of a scope
    @dev must be accepted by transferee - see {acceptScopeTransfer}
    @param scopeName Name of the scope
    @param newOwner Address of the new owner
    */
    function transferScopeOwnership(string calldata scopeName, address newOwner) external;

    /**
    @notice Cancel a pending scope transfer
    @param scopeName Name of the scope
    */
    function cancelScopeTransfer(string calldata scopeName) external;

    /**
    @notice Accept a scope transfer
    @param scopeName Name of the scope
    */
    function acceptScopeTransfer(string calldata scopeName) external;

    /**
    @notice Get owner-elect of a scope
    @param scopeName Name of the scope
    @return ownerElect Address of the scope's owner-elect
    */
    function getScopeOwnerElect(string calldata scopeName) external view returns (address ownerElect);

    /**
    @notice Get owner of a scope
    @param scopeName Name of the scope
    @return owner Address of the scope owner
    */
    function getScopeOwner(string calldata scopeName) external view returns (address owner);

    /**
    @notice Add an operator to a scope
    @param scopeName Name of the scope
    @param op Address of the operator
    */
    function addOperator(string calldata scopeName, address op) external;

    /**
    @notice Remove an operator from a scope
    @param scopeName Name of the scope
    @param op Address of the operator
    */
    function removeOperator(string calldata scopeName, address op) external;

    /**
    @notice Set rules for a scope
    @param scopeName Name of the scope
    @param allowUserPatch Boolean indicating whether user patches are allowed
    @param allowUserAssign Boolean indicating whether user assignments are allowed
    @param requireWhitelist Boolean indicating whether whitelist is required
    */
    function setScopeRules(string calldata scopeName, bool allowUserPatch, bool allowUserAssign, bool requireWhitelist) external;

    /**
    @notice Add an address to a scope's whitelist
    @param scopeName Name of the scope
    @param addr Address to be whitelisted
    */
    function addWhitelist(string calldata scopeName, address addr) external;

    /**
    @notice Remove an address from a scope's whitelist
    @param scopeName Name of the scope
    @param addr Address to be removed from the whitelist
    */
    function removeWhitelist(string calldata scopeName, address addr) external;

    /**
    @notice Set the mint configuration for a given address
    @param addr The address for which to set the mint configuration, must be IPatchworkMintable
    @param config The mint configuration to be set
    */
    function setMintConfiguration(address addr, MintConfig memory config) external;

    /**
    @notice Get the mint configuration for a given address
    @param addr The address for which to get the mint configuration
    @return config The mint configuration of the given address
    */
    function getMintConfiguration(address addr) external view returns (MintConfig memory config);

    /**
    @notice Set the patch fee for a given address
    @dev must be banker of scope claimed by addr to call
    @param addr The address for which to set the patch fee
    @param baseFee The patch fee to be set in wei
    */
    function setPatchFee(address addr, uint256 baseFee) external;

    /**
    @notice Get the patch fee for a given address
    @param addr The address for which to get the patch fee
    @return baseFee The patch fee of the given address in wei
    */
    function getPatchFee(address addr) external view returns (uint256 baseFee);

    /**
    @notice Set the assign fee for a given fragment address
    @dev must be banker of scope claimed by fragmentAddress to call
    @param fragmentAddress The address of the fragment for which to set the fee
    @param baseFee The assign fee to be set in wei
    */
    function setAssignFee(address fragmentAddress, uint256 baseFee) external;

    /**
    @notice Get the assign fee for a given fragment address
    @param fragmentAddress The address of the fragment for which to get the fee
    @return baseFee The assign fee of the given fragment address in wei
    */
    function getAssignFee(address fragmentAddress) external view returns (uint256 baseFee);

    /**
    @notice Add a banker to a given scope
    @dev must be owner of scope to call
    @param scopeName The name of the scope
    @param addr The address to be added as a banker
    */
    function addBanker(string memory scopeName, address addr) external;

    /**
    @notice Remove a banker from a given scope
    @dev must be owner of scope to call
    @param scopeName The name of the scope
    @param addr The address to be removed as a banker
    */
    function removeBanker(string memory scopeName, address addr) external;

    /**
    @notice Withdraw an amount from the balance of a given scope
    @dev must be owner of scope or banker of scope to call
    @dev transfers to the msg.sender
    @param scopeName The name of the scope
    @param amount The amount to be withdrawn in wei
    */
    function withdraw(string memory scopeName, uint256 amount) external;

    /**
    @notice Get the balance of a given scope
    @param scopeName The name of the scope
    @return balance The balance of the given scope in wei
    */
    function balanceOf(string memory scopeName) external view returns (uint256 balance);

    /**
    @notice Mint a new token
    @param to The address to which the token will be minted
    @param mintable The address of the IPatchworkMintable contract
    @param data Additional data to be passed to the minting
    @return tokenId The ID of the minted token
    */
    function mint(address to, address mintable, bytes calldata data) external payable returns (uint256 tokenId);

    /**
    @notice Mint a batch of new tokens
    @param to The address to which the tokens will be minted
    @param mintable The address of the IPatchworkMintable contract
    @param data Additional data to be passed to the minting
    @param quantity The number of tokens to mint
    @return tokenIds An array of the IDs of the minted tokens
    */
    function mintBatch(address to, address mintable, bytes calldata data, uint256 quantity) external payable returns (uint256[] memory tokenIds);

    /**
    @notice Proposes a protocol fee configuration
    @dev must be protocol owner or banker to call
    @dev configuration does not apply until commitProtocolFeeConfig is called
    @param config The protocol fee configuration to be set
    */
    function proposeProtocolFeeConfig(FeeConfig memory config) external;

    /**
    @notice Commits the current proposed protocol fee configuration
    @dev must be protocol owner or banker to call
    @dev may only be called after timelock has passed
    */
    function commitProtocolFeeConfig() external;

    /**
    @notice Get the current protocol fee configuration
    @return config The current protocol fee configuration
    */
    function getProtocolFeeConfig() external view returns (FeeConfig memory config);

    /**
    @notice Proposes a protocol fee override for a scope
    @dev must be protocol owner or banker to call
    @param config The protocol fee override configuration to be set
    */
    function proposeScopeFeeOverride(string memory scopeName, FeeConfigOverride memory config) external;

    /**
    @notice Commits the current proposed protocol fee override configuration for a scope
    @dev must be protocol owner or banker to call
    @dev may only be called after timelock has passed
    */
    function commitScopeFeeOverride(string memory scopeName) external;

    /**
    @notice Get the protocol fee override for a scope
    @return config The current protocol fee override
    */
    function getScopeFeeOverride(string memory scopeName) external view returns (FeeConfigOverride memory config);

    /**
    @notice Add a banker to the protocol
    @dev must be protocol owner to call
    @param addr The address to be added as a protocol banker
    */
    function addProtocolBanker(address addr) external;

    /**
    @notice Remove a banker from the protocol
    @dev must be protocol owner to call
    @param addr The address to be removed as a protocol banker
    */
    function removeProtocolBanker(address addr) external;

    /**
    @notice Withdraw a specified amount from the protocol balance
    @dev must be protocol owner or banker to call
    @dev transfers to the msg.sender
    @param balance The amount to be withdrawn in wei
    */
    function withdrawFromProtocol(uint256 balance) external;

    /**
    @notice Get the current balance of the protocol
    @return balance The balance of the protocol in wei
    */
    function balanceOfProtocol() external view returns (uint256 balance);

    /**
    @notice Create a new patch
    @param owner The owner of the patch
    @param originalAddress Address of the original 721
    @param originalTokenId Token ID of the original 721
    @param patchAddress Address of the IPatchworkPatch to mint
    @return tokenId Token ID of the newly created patch
    */
    function patch(address owner, address originalAddress, uint originalTokenId, address patchAddress) external payable returns (uint256 tokenId);

    /**
    @notice Callback for when a patch is burned
    @dev can only be called from the patchAddress
    @param originalAddress Address of the original 721
    @param originalTokenId Token ID of the original 721
    @param patchAddress Address of the IPatchworkPatch to mint
    */
    function patchBurned(address originalAddress, uint originalTokenId, address patchAddress) external;

    /**
    @notice Create a new 1155 patch
    @param originalAddress Address of the original 1155
    @param originalTokenId Token ID of the original 1155
    @param originalAccount Address of the account to patch
    @param patchAddress Address of the IPatchworkPatch to mint
    @return tokenId Token ID of the newly created patch
    */
    function patch1155(address to, address originalAddress, uint originalTokenId, address originalAccount, address patchAddress) external payable returns (uint256 tokenId);
    
    /**
    @notice Callback for when an 1155 patch is burned
    @dev can only be called from the patchAddress
    @param originalAddress Address of the original 1155
    @param originalTokenId Token ID of the original 1155
    @param originalAccount Address of the account to patch
    @param patchAddress Address of the IPatchworkPatch to mint
    */
    function patchBurned1155(address originalAddress, uint originalTokenId, address originalAccount, address patchAddress) external;

    /**
    @notice Create a new account patch
    @param owner The owner of the patch
    @param originalAddress Address of the original account
    @param patchAddress Address of the IPatchworkPatch to mint
    @return tokenId Token ID of the newly created patch
    */
    function patchAccount(address owner, address originalAddress, address patchAddress) external payable returns (uint256 tokenId);

    /**
    @notice Callback for when an account patch is burned
    @dev can only be called from the patchAddress
    @param originalAddress Address of the original 1155
    @param patchAddress Address of the IPatchworkPatch to mint
    */
    function patchBurnedAccount(address originalAddress, address patchAddress) external;

    /**
    @notice Assigns a relation to have an IPatchworkLiteRef form a LiteRef to a IPatchworkAssignable
    @param fragment The IPatchworkAssignable address to assign
    @param fragmentTokenId The IPatchworkAssignable Token ID to assign
    @param target The IPatchworkLiteRef address to hold the reference to the fragment
    @param targetTokenId The IPatchworkLiteRef Token ID to hold the reference to the fragment
    */
    function assign(address fragment, uint256 fragmentTokenId, address target, uint256 targetTokenId) external payable;

    /**
    @notice Assigns a relation to have an IPatchworkLiteRef form a LiteRef to a IPatchworkAssignable
    @param fragment The IPatchworkAssignable address to assign
    @param fragmentTokenId The IPatchworkAssignable Token ID to assign
    @param target The IPatchworkLiteRef address to hold the reference to the fragment
    @param targetTokenId The IPatchworkLiteRef Token ID to hold the reference to the fragment
    @param targetMetadataId The metadata ID on the target to store the reference in
    */
    function assign(address fragment, uint256 fragmentTokenId, address target, uint256 targetTokenId, uint256 targetMetadataId) external payable;

    /**
    @notice Assign multiple fragments to a target in batch
    @param fragments The array of addresses of the fragment IPatchworkAssignables
    @param tokenIds The array of token IDs of the fragment IPatchworkAssignables
    @param target The address of the target IPatchworkLiteRef 
    @param targetTokenId The token ID of the target IPatchworkLiteRef 
    */
    function assignBatch(address[] calldata fragments, uint256[] calldata tokenIds, address target, uint256 targetTokenId) external payable;

    /**
    @notice Assign multiple fragments to a target in batch
    @param fragments The array of addresses of the fragment IPatchworkAssignables
    @param tokenIds The array of token IDs of the fragment IPatchworkAssignables
    @param target The address of the target IPatchworkLiteRef 
    @param targetTokenId The token ID of the target IPatchworkLiteRef 
    @param targetMetadataId The metadata ID on the target to store the references in
    */
    function assignBatch(address[] calldata fragments, uint256[] calldata tokenIds, address target, uint256 targetTokenId, uint256 targetMetadataId) external payable;

    /**
    @notice Unassign a fragment from a target
    @param fragment The IPatchworkSingleAssignable address of the fragment
    @param fragmentTokenId The IPatchworkSingleAssignable token ID of the fragment
    @dev reverts if fragment is not an IPatchworkSingleAssignable
    */
    function unassignSingle(address fragment, uint256 fragmentTokenId) external;
    
    /**
    @notice Unassign a fragment from a target
    @param fragment The IPatchworkSingleAssignable address of the fragment
    @param fragmentTokenId The IPatchworkSingleAssignable token ID of the fragment
    @param targetMetadataId The metadata ID on the target to unassign from
    @dev reverts if fragment is not an IPatchworkSingleAssignable
    */
    function unassignSingle(address fragment, uint256 fragmentTokenId, uint256 targetMetadataId) external;

    /**
    @notice Unassigns a multi relation
    @param fragment The IPatchworMultiAssignable address to unassign
    @param fragmentTokenId The IPatchworkMultiAssignable Token ID to unassign
    @param target The IPatchworkLiteRef address which holds a reference to the fragment
    @param targetTokenId The IPatchworkLiteRef Token ID which holds a reference to the fragment
    @dev reverts if fragment is not an IPatchworkMultiAssignable
    */
    function unassignMulti(address fragment, uint256 fragmentTokenId, address target, uint256 targetTokenId) external;

    /**
    @notice Unassigns a multi relation
    @param fragment The IPatchworMultiAssignable address to unassign
    @param fragmentTokenId The IPatchworkMultiAssignable Token ID to unassign
    @param target The IPatchworkLiteRef address which holds a reference to the fragment
    @param targetTokenId The IPatchworkLiteRef Token ID which holds a reference to the fragment
    @param targetMetadataId The metadata ID on the target to unassign from
    @dev reverts if fragment is not an IPatchworkMultiAssignable
    */
    function unassignMulti(address fragment, uint256 fragmentTokenId, address target, uint256 targetTokenId, uint256 targetMetadataId) external;

    /**
    @notice Unassigns a relation (single or multi)
    @param fragment The IPatchworkAssignable address to unassign
    @param fragmentTokenId The IPatchworkAssignable Token ID to unassign
    @param target The IPatchworkLiteRef address which holds a reference to the fragment
    @param targetTokenId The IPatchworkLiteRef Token ID which holds a reference to the fragment
    */
    function unassign(address fragment, uint256 fragmentTokenId, address target, uint256 targetTokenId) external;

    /**
    @notice Unassigns a relation (single or multi)
    @param fragment The IPatchworkAssignable address to unassign
    @param fragmentTokenId The IPatchworkAssignable Token ID to unassign
    @param target The IPatchworkLiteRef address which holds a reference to the fragment
    @param targetTokenId The IPatchworkLiteRef Token ID which holds a reference to the fragment
    @param targetMetadataId The metadata ID on the target to unassign from
    */
    function unassign(address fragment, uint256 fragmentTokenId, address target, uint256 targetTokenId, uint256 targetMetadataId) external;

    /**
    @notice Apply transfer rules and actions of a specific token from one address to another
    @param from The address of the sender
    @param to The address of the receiver
    @param tokenId The ID of the token to be transferred
    */
    function applyTransfer(address from, address to, uint256 tokenId) external;

    /**
    @notice Update the ownership tree of a specific Patchwork 721
    @param addr The address of the Patchwork 721
    @param tokenId The ID of the token whose ownership tree needs to be updated
    */
    function updateOwnershipTree(address addr, uint256 tokenId) external;

    /**
    @notice Propose an assigner delegate module
    @param addr The address of the new delegate module
    */
    function proposeAssignerDelegate(address addr) external;

    /**
    @notice Commit the proposed assigner delegate module
    @dev must be past timelock
    */
    function commitAssignerDelegate() external;
}
Código Fuente del Contrato
Archivo 16 de 26: IPatchworkScoped.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

/**
@title Patchwork Protocol Scoped Interface
@author Runic Labs, Inc
@notice Interface for contracts supporting scopes
*/
interface IPatchworkScoped {
    /**
    @notice Get the scope this NFT claims to belong to
    @return string the name of the scope
    */
    function getScopeName() external view returns (string memory);
}
Código Fuente del Contrato
Archivo 17 de 26: IPatchworkSingleAssignable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import "./IPatchworkAssignable.sol";

/**
@title Patchwork Protocol Assignable Interface
@author Runic Labs, Inc
@notice Interface for contracts supporting Patchwork assignment
*/
interface IPatchworkSingleAssignable is IPatchworkAssignable {
    /**
    @notice The token is assigned and cannot be set to locked
    @param tokenId The identifier for a token
    */
    error AssignedFragmentCannotSetLocked(uint256 tokenId);

    /**
    @notice Unassigns a token
    @param ourTokenId ID of our token
    */
    function unassign(uint256 ourTokenId) external;

    /**
    @notice Returns the address and token ID that our token is assigned to
    @param ourTokenId ID of our token
    @return address the address this is assigned to
    @return uint256 the tokenId this is assigned to
    */
    function getAssignedTo(uint256 ourTokenId) external view returns (address, uint256);

    /**
    @notice Returns the underlying stored owner of a token ignoring current assignment
    @param ourTokenId ID of our token
    @return address address of the owner
    */
    function unassignedOwnerOf(uint256 ourTokenId) external view returns (address);

    /**
    @notice Sends events for a token when the assigned-to token has been transferred
    @param from Sender address
    @param to Recipient address
    @param tokenId ID of the token
    */
    function onAssignedTransfer(address from, address to, uint256 tokenId) external;

    /**
    @notice Updates the real underlying ownership of a token in storage (if different from current)
    @param tokenId ID of the token
    */
    function updateOwnership(uint256 tokenId) external;
}
Código Fuente del Contrato
Archivo 18 de 26: IStickerPack.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

/**
                         
          /)    ,     /) 
    __   // ___  __  (/_ 
    /_)_(/_(_)_(_/ (_/(__
 .-/                     
(_/                      

 */
 
/**
@notice A Ploink-compatible Sticker Pack
@author Runic Labs, Inc
*/
interface IStickerPack {

    /**
    @notice A sticker was set
    @param typeId the type ID of the sticker
    @param name the name of the sticker
    @param imageURI the image URI of the sticker
    @param plunkPrice the price of the sticker in Plunk
    */
    event SetSticker(uint32 indexed typeId, string name, string imageURI, uint256 plunkPrice);

    /// Sticker info
    struct StickerInfo {
        string name;
        string imageURI;
        uint256 plunkPrice;
    }

    /**
    @notice count of stickers in the pack
    @return count the count of stickers
    */
    function stickerCount() external view returns (uint256 count);

    /**
    @notice get a sticker by type ID
    @param typeId the type ID of the sticker
    @return info the sticker info
    */
    function sticker(uint32 typeId) external view returns (StickerInfo memory info);

    /**
    @notice allow a user to use the sticker pack
    @param by the user to allow
    @return use true if the user is allowed to use the sticker pack
    */
    function allowUse(address by) external view returns (bool use);
}
Código Fuente del Contrato
Archivo 19 de 26: Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)

pragma solidity ^0.8.20;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @dev Muldiv operation overflow.
     */
    error MathOverflowedMulDiv();

    enum Rounding {
        Floor, // Toward negative infinity
        Ceil, // Toward positive infinity
        Trunc, // Toward zero
        Expand // Away from zero
    }

    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds towards infinity instead
     * of rounding towards zero.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        if (b == 0) {
            // Guarantee the same behavior as in a regular Solidity division.
            return a / b;
        }

        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
     * denominator == 0.
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
     * Uniswap Labs also under MIT license.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0 = x * y; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            if (denominator <= prod1) {
                revert MathOverflowedMulDiv();
            }

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator.
            // Always >= 1. See https://cs.stackexchange.com/q/138556/92363.

            uint256 twos = denominator & (0 - denominator);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
            // works in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
     * towards zero.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
        }
    }

    /**
     * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
     */
    function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
        return uint8(rounding) % 2 == 1;
    }
}
Código Fuente del Contrato
Archivo 20 de 26: Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
Código Fuente del Contrato
Archivo 21 de 26: Patchwork721.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/IPatchwork721.sol";
import "./interfaces/IERC4906.sol";
import "./interfaces/IPatchworkProtocol.sol";

/**
@title Patchwork721 Abstract Contract
@dev This abstract contract defines the core functionalities for the Patchwork721.
     It inherits from the standard ERC721, as well as the IPatchwork721 and IERC4906 interfaces.
*/
abstract contract Patchwork721 is ERC721, IPatchwork721, IERC4906, Ownable {

    /// @dev The scope name of this 721.
    string internal _scopeName;

    /// @dev Our manager (PatchworkProtocol).
    address internal immutable _manager;

    /// @dev A mapping to keep track of permissions for each address.
    mapping(address => uint256) internal _permissionsAllow;

    /// @dev A mapping for storing metadata associated with each token ID.
    mapping(uint256 => uint256[]) internal _metadataStorage;

    /// @dev A mapping for storing freeze nonces of each token ID.
    mapping(uint256 => uint256) internal _freezeNonces;

    /// @dev A mapping indicating whether a specific token ID is frozen.
    mapping(uint256 => bool) internal _freezes;

    /// @dev A mapping indicating whether a specific token ID is locked.
    mapping(uint256 => bool) internal _locks;

    /**
    @notice Creates a new instance of the Patchwork721 contract with the provided parameters.
    @dev msg.sender will be initial owner
    @param scopeName_ The scope name.
    @param name_ The ERC-721 name.
    @param symbol_ The ERC-721 symbol.
    @param manager_ The address that will be set as the manager (PatchworkProtocol).
    @param owner_ The address that will be set as the owner
    */
    constructor(
        string memory scopeName_,
        string memory name_,
        string memory symbol_,
        address manager_,
        address owner_
    ) ERC721(name_, symbol_) Ownable(owner_) {
        _scopeName = scopeName_;
        _manager = manager_;
    } 

    /**
    @dev See {IPatchwork721-getScopeName}
    */
    function getScopeName() public view virtual returns (string memory) {
        return _scopeName;
    }

    /**
    @dev See {IPatchwork721-storePackedMetadataSlot}
    */
    function storePackedMetadataSlot(uint256 tokenId, uint256 slot, uint256 data) public virtual mustHaveTokenWriteAuth(tokenId) {
        _metadataStorage[tokenId][slot] = data;
    }

    /**
    @dev See {IPatchwork721-storePackedMetadata}
    */
    function storePackedMetadata(uint256 tokenId, uint256[] memory data) public virtual mustHaveTokenWriteAuth(tokenId) {
         _metadataStorage[tokenId] = data;
    }

    /**
    @dev See {IPatchwork721-loadPackedMetadataSlot}
    */
    function loadPackedMetadataSlot(uint256 tokenId, uint256 slot) public virtual view returns (uint256) {
        return _metadataStorage[tokenId][slot];
    }

    /**
    @dev See {IPatchwork721-loadPackedMetadata}
    */
    function loadPackedMetadata(uint256 tokenId) public virtual view returns (uint256[] memory) {
        return _metadataStorage[tokenId];
    }

    // Does msg.sender have permission to write to our top level storage?
    function _checkWriteAuth() internal virtual view returns (bool allow) {
        return (msg.sender == owner());
    }

    // Does msg.sender have permission to write to this token's data?
    function _checkTokenWriteAuth(uint256 /*tokenId*/) internal virtual view returns (bool allow) {
        return (msg.sender == owner() || msg.sender == _manager);
    }

    /**
    @dev See {IPatchwork721-setPermissions}
    */
    function setPermissions(address to, uint256 permissions) public virtual mustHaveWriteAuth {
        _permissionsAllow[to] = permissions;
        emit PermissionChange(to, permissions);
    }

    /**
    @dev See {IERC165-supportsInterface}
    */
    function supportsInterface(bytes4 interfaceID) public view virtual override(ERC721, IERC165) returns (bool) {
        return interfaceID == type(IPatchwork721).interfaceId ||
            interfaceID == type(IERC5192).interfaceId ||
            interfaceID == type(IERC4906).interfaceId ||    
            interfaceID == type(IPatchworkScoped).interfaceId ||
            ERC721.supportsInterface(interfaceID);
    }

    /**
    @dev See {IERC721-transferFrom}.
    */
    function transferFrom(address from, address to, uint256 tokenId) public virtual override(ERC721, IERC721) {
        IPatchworkProtocol(_manager).applyTransfer(from, to, tokenId);
        super.transferFrom(from, to, tokenId);
    }

    /**
    @dev See {IERC721-safeTransferFrom}.
    */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual override(ERC721, IERC721) {
        IPatchworkProtocol(_manager).applyTransfer(from, to, tokenId);
        super.safeTransferFrom(from, to, tokenId, data);
    }

    /**
    @notice transfers a token with a known freeze nonce
    @dev reverts if the token is not frozen or if the current freeze nonce does not match the provided nonce
    @dev See {IERC721-transferFrom}.
    */
    function transferFromWithFreezeNonce(address from, address to, uint256 tokenId, uint256 nonce) public mustBeFrozenWithNonce(tokenId, nonce) {
        transferFrom(from, to, tokenId);
    }

    /**
    @notice transfers a token with a known freeze nonce
    @dev reverts if the token is not frozen or if the current freeze nonce does not match the provided nonce
    @dev See {IERC721-safeTransferFrom}.
    */
    function safeTransferFromWithFreezeNonce(address from, address to, uint256 tokenId, uint256 nonce) public mustBeFrozenWithNonce(tokenId, nonce) {
        safeTransferFrom(from, to, tokenId);
    }

    /**
    @notice transfers a token with a known freeze nonce
    @dev reverts if the token is not frozen or if the current freeze nonce does not match the provided nonce
    @dev See {IERC721-safeTransferFrom}.
    */
    function safeTransferFromWithFreezeNonce(address from, address to, uint256 tokenId, bytes memory data, uint256 nonce) public mustBeFrozenWithNonce(tokenId, nonce) {
        safeTransferFrom(from, to, tokenId, data);
    }

    /**
    @dev See {IPatchwork721-getFreezeNonce}
    */
    function getFreezeNonce(uint256 tokenId) public view virtual returns (uint256 nonce) {
        return _freezeNonces[tokenId];
    }

    /**
    @dev See {IPatchwork721-setFrozen}
    */
    function setFrozen(uint256 tokenId, bool frozen_) public virtual mustBeTokenOwner(tokenId) {
        bool _frozen = _freezes[tokenId];
        if (_frozen != frozen_) {
            if (frozen_) {
                _freezes[tokenId] = true;
                emit Frozen(tokenId);
            } else {
                _freezeNonces[tokenId]++;
                _freezes[tokenId] = false;
                emit Thawed(tokenId);
            }
        }
    }

    /**
    @dev See {IPatchwork721-frozen}
    */
    function frozen(uint256 tokenId) public view virtual returns (bool) {
        return _freezes[tokenId];
    }

    /**
    @dev See {IPatchwork721-locked}
    */
    function locked(uint256 tokenId) public view virtual returns (bool) {
        return _locks[tokenId];
    }

    /**
    @dev See {IPatchwork721-setLocked}
    */
    function setLocked(uint256 tokenId, bool locked_) public virtual mustBeTokenOwner(tokenId) {
        bool _locked = _locks[tokenId];
        if (_locked != locked_) {
            _locks[tokenId] = locked_;
            if (locked_) {
                emit Locked(tokenId);
            } else {
                emit Unlocked(tokenId);
            }
        }
    }

    modifier mustHaveWriteAuth {
        if (!_checkWriteAuth()) {
            revert IPatchworkProtocol.NotAuthorized(msg.sender);
        }
        _;
    }

    modifier mustHaveTokenWriteAuth(uint256 tokenId) {
        if (!_checkTokenWriteAuth(tokenId)) {
            revert IPatchworkProtocol.NotAuthorized(msg.sender);
        }
        _;
    }
        
    modifier mustBeTokenOwner(uint256 tokenId) {
        if (msg.sender != ownerOf(tokenId)) {
            revert IPatchworkProtocol.NotAuthorized(msg.sender);
        }
        _;
    }

    modifier mustBeFrozenWithNonce(uint256 tokenId, uint256 nonce) {
        if (!frozen(tokenId)) {
            revert IPatchworkProtocol.NotFrozen(address(this), tokenId);
        }
        if (getFreezeNonce(tokenId) != nonce) {
            revert IPatchworkProtocol.IncorrectNonce(address(this), tokenId, nonce);
        }
        _;
    }

    modifier mustBeManager() {
        if (msg.sender != _manager) {
            revert IPatchworkProtocol.NotAuthorized(msg.sender);
        }
        _;
    }
}
Código Fuente del Contrato
Archivo 22 de 26: PatchworkFragmentSingle.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import "./Patchwork721.sol";
import "./interfaces/IPatchworkSingleAssignable.sol";

/**
@title PatchworkFragmentSingle
@dev base implementation of a Single-relation Fragment is IPatchworkSingleAssignable
*/
abstract contract PatchworkFragmentSingle is Patchwork721, IPatchworkSingleAssignable {

    /// A mapping from token IDs in this contract to their assignments.
    mapping(uint256 => Assignment) internal _assignments;

    /**
    @dev See {IERC165-supportsInterface}
    */
    function supportsInterface(bytes4 interfaceID) public view virtual override returns (bool) {
        return interfaceID == type(IPatchworkAssignable).interfaceId ||
        interfaceID == type(IPatchworkSingleAssignable).interfaceId ||
        super.supportsInterface(interfaceID); 
    }

    /**
    @dev See {IPatchworkAssignableNFT-assign}
    */
    function assign(uint256 ourTokenId, address to, uint256 tokenId) public virtual mustHaveTokenWriteAuth(tokenId) {
        // One time use policy
        Assignment storage a = _assignments[ourTokenId];
        if (a.tokenAddr != address(0)) {
            revert IPatchworkProtocol.FragmentAlreadyAssigned(address(this), ourTokenId);
        }
        a.tokenAddr = to;
        a.tokenId = tokenId;
        emit Locked(ourTokenId);
    }

    /**
    @dev See {IPatchworkAssignableNFT-unassign}
    */
    function unassign(uint256 tokenId) public virtual mustHaveTokenWriteAuth(tokenId) {
        if (_assignments[tokenId].tokenAddr == address(0)) {
            revert IPatchworkProtocol.FragmentNotAssigned(address(this), tokenId);
        }
        updateOwnership(tokenId);
        delete _assignments[tokenId];
        emit Unlocked(tokenId);
    }

    /**
    @dev See {IPatchworAssignable-allowAssignment}
    */
    function allowAssignment(uint256 ourTokenId, address /*target*/, uint256 /*targetTokenId*/, address targetOwner, address /*by*/, string memory /*scopeName*/) virtual public view returns (bool) {
        // By default only allow single assignments to be to the same owner as the target
        // Warning - Changing this without changing the other ownership logic in this contract to reflect this will make ownership inconsistent
        return targetOwner == ownerOf(ourTokenId);
    }

    /**
    @dev See {IPatchworkAssignableNFT-updateOwnership}
    */
    function updateOwnership(uint256 tokenId) public virtual {
        Assignment storage assignment = _assignments[tokenId];
        if (assignment.tokenAddr != address(0)) {
            address owner_ = ownerOf(tokenId);
            address curOwner = super.ownerOf(tokenId);
            if (owner_ != curOwner) {
                // Parent ownership has changed, update our ownership to reflect this
                ERC721._transfer(curOwner, owner_, tokenId);
            }
        }
    }

    /**
    @dev owned by the assignment's owner
    @dev See {IERC721-ownerOf}
    */
    function ownerOf(uint256 tokenId) public view virtual override(ERC721, IERC721) returns (address) {
        // If assigned, it's owned by the assignment, otherwise normal owner
        Assignment storage assignment = _assignments[tokenId];
        if (assignment.tokenAddr != address(0)) {
            return IERC721(assignment.tokenAddr).ownerOf(assignment.tokenId);
        }
        return super.ownerOf(tokenId);
    }

    /**
    @dev See {IPatchworkAssignableNFT-unassignedOwnerOf}
    */
    function unassignedOwnerOf(uint256 tokenId) public virtual view returns (address) {
        return super.ownerOf(tokenId);
    }

    /**
    @dev See {IPatchworkAssignableNFT-getAssignedTo}
    */
    function getAssignedTo(uint256 ourTokenId) public virtual view returns (address, uint256) {
         Assignment storage a = _assignments[ourTokenId];
         return (a.tokenAddr, a.tokenId); 
    }

    /**
    @dev See {IPatchworkAssignableNFT-onAssignedTransfer}
    */
    function onAssignedTransfer(address from, address to, uint256 tokenId) public virtual {
        require(msg.sender == _manager);
        emit Transfer(from, to, tokenId);
    }

    /**
    @dev See {IPatchwork721-locked}
    */
    function locked(uint256 tokenId) public view virtual override returns (bool) {
        // Locked when assigned (implicit) or if explicitly locked
        return _assignments[tokenId].tokenAddr != address(0) || super.locked(tokenId);
    }

    /**
    @dev See {IPatchwork721-setLocked}
    */
    function setLocked(uint256 tokenId, bool locked_) public virtual override {
        if (msg.sender != ownerOf(tokenId)) {
            revert IPatchworkProtocol.NotAuthorized(msg.sender);
        }
        if (_assignments[tokenId].tokenAddr != address(0)) {
            revert AssignedFragmentCannotSetLocked(tokenId);
        }
        super.setLocked(tokenId, locked_);
    }
}
Código Fuente del Contrato
Archivo 23 de 26: PatchworkUtils.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

/**
@title Patchwork Contract Utilities
 */
library PatchworkUtils {
    /**
    @notice Converts uint64 raw data to an 8 character string
    @param raw the raw data
    @return out the string
    */
    function toString8(uint64 raw) internal pure returns (string memory out) {
        bytes memory byteArray = abi.encodePacked(bytes8(raw));
        // optimized shortcut out for full string value and no checks required later
        if (byteArray[7] != 0) {
            return string(byteArray);
        }
        return trimUp(byteArray);
    }

    /**
    @notice Converts uint128 raw data to a 16 character string
    @param raw the raw data
    @return out the string
    */
    function toString16(uint128 raw) internal pure returns (string memory out) {
        bytes memory byteArray = abi.encodePacked(bytes16(raw));
        // optimized shortcut out for full string value and no checks required later
        if (byteArray[15] != 0) {
            return string(byteArray);
        }
        return trimUp(byteArray);
    }

    /**
    @notice Converts uint256 raw data to a 32 character string
    @param raw the raw data
    @return out the string
    */
    function toString32(uint256 raw) internal pure returns (string memory out) {
        bytes memory byteArray = abi.encodePacked(bytes32(raw));
        // optimized shortcut out for full string value and no checks required later
        if (byteArray[31] != 0) {
            return string(byteArray);
        }
        return trimUp(byteArray);
    }

    /**
    @notice Trims a raw string to its null-terminated length
    @param byteArray the raw string
    @return out the trimmed string
    */
    function trimUp(bytes memory byteArray) internal pure returns (string memory out) {
        // uses about 40 more gas per call to be DRY, consider inlining to save gas if contract isn't too big
        uint nullPos = 0;
        while (true) {
            if (byteArray[nullPos] == 0) {
                break;
            }
            nullPos++;
        }
        bytes memory trimmedByteArray = new bytes(nullPos);
        for (uint256 i = 0; i < nullPos; i++) {
            trimmedByteArray[i] = byteArray[i];
        }
        out = string(trimmedByteArray);
    }

    /**
    @notice Converts a uint16 into a 2-byte array
    @param input the uint16
    @return bytes the array
    */
    function convertUint16ToBytes(uint16 input) internal pure returns (bytes memory) {
        // Extract the higher and lower bytes
        bytes1 high = bytes1(uint8(input >> 8));
        bytes1 low = bytes1(uint8(input & 0xFF));

        // Return the two bytes as a dynamic bytes array
        return abi.encodePacked(high, low);
    }

    /**
    @notice Converts a string to a uint256
    @param str the string to convert
    @return val the uint256 value
    */
    function strToUint256(string memory str) internal pure returns (uint256 val) {
        uint256 strLength;
        bytes memory str_ = bytes(str);
        // dynamic string or bytes memory layout has 1+ words: (length, valueBytes...)
        assembly {
            strLength := mload(str_)
        }
        if (strLength == 0) {
            val = 0;
        } else {
            bytes32 strBytes32;
            assembly {
                strBytes32 := mload(add(str_, 32))
            }
            val = uint256(strBytes32);
        }
    }
}
Código Fuente del Contrato
Archivo 24 de 26: SignedMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.20;

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Returns the largest of two signed numbers.
     */
    function max(int256 a, int256 b) internal pure returns (int256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two signed numbers.
     */
    function min(int256 a, int256 b) internal pure returns (int256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two signed numbers without overflow.
     * The result is rounded towards zero.
     */
    function average(int256 a, int256 b) internal pure returns (int256) {
        // Formula from the book "Hacker's Delight"
        int256 x = (a & b) + ((a ^ b) >> 1);
        return x + (int256(uint256(x) >> 255) & (a ^ b));
    }

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // must be unchecked in order to support `n = type(int256).min`
            return uint256(n >= 0 ? n : -n);
        }
    }
}
Código Fuente del Contrato
Archivo 25 de 26: Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)

pragma solidity ^0.8.20;

import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant HEX_DIGITS = "0123456789abcdef";
    uint8 private constant ADDRESS_LENGTH = 20;

    /**
     * @dev The `value` string doesn't fit in the specified `length`.
     */
    error StringsInsufficientHexLength(uint256 value, uint256 length);

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toStringSigned(int256 value) internal pure returns (string memory) {
        return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, Math.log256(value) + 1);
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        uint256 localValue = value;
        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_DIGITS[localValue & 0xf];
            localValue >>= 4;
        }
        if (localValue != 0) {
            revert StringsInsufficientHexLength(value, length);
        }
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
     * representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
    }

    /**
     * @dev Returns true if the two strings are equal.
     */
    function equal(string memory a, string memory b) internal pure returns (bool) {
        return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
    }
}
Código Fuente del Contrato
Archivo 26 de 26: draft-IERC6093.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;

/**
 * @dev Standard ERC20 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
 */
interface IERC20Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC20InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC20InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     * @param allowance Amount of tokens a `spender` is allowed to operate with.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC20InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `spender` to be approved. Used in approvals.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC20InvalidSpender(address spender);
}

/**
 * @dev Standard ERC721 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
 */
interface IERC721Errors {
    /**
     * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
     * Used in balance queries.
     * @param owner Address of the current owner of a token.
     */
    error ERC721InvalidOwner(address owner);

    /**
     * @dev Indicates a `tokenId` whose `owner` is the zero address.
     * @param tokenId Identifier number of a token.
     */
    error ERC721NonexistentToken(uint256 tokenId);

    /**
     * @dev Indicates an error related to the ownership over a particular token. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param tokenId Identifier number of a token.
     * @param owner Address of the current owner of a token.
     */
    error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC721InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC721InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param tokenId Identifier number of a token.
     */
    error ERC721InsufficientApproval(address operator, uint256 tokenId);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC721InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC721InvalidOperator(address operator);
}

/**
 * @dev Standard ERC1155 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.
 */
interface IERC1155Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     * @param tokenId Identifier number of a token.
     */
    error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC1155InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC1155InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param owner Address of the current owner of a token.
     */
    error ERC1155MissingApprovalForAll(address operator, address owner);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC1155InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC1155InvalidOperator(address operator);

    /**
     * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
     * Used in batch transfers.
     * @param idsLength Length of the array of token identifiers
     * @param valuesLength Length of the array of token amounts
     */
    error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}
Configuraciones
{
  "compilationTarget": {
    "src/AttributeSummer.sol": "AttributeSummer"
  },
  "evmVersion": "paris",
  "libraries": {},
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "remappings": [
    ":@openzeppelin/=lib/openzeppelin-contracts/",
    ":@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    ":@patchwork/=lib/patchwork/src/",
    ":ds-test/=lib/forge-std/lib/ds-test/src/",
    ":erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    ":forge-std/=lib/forge-std/src/",
    ":lib/=lib/",
    ":openzeppelin-contracts/=lib/openzeppelin-contracts/",
    ":patchwork/=lib/patchwork/"
  ]
}
ABI
[{"inputs":[{"internalType":"address","name":"manager_","type":"address"},{"internalType":"address","name":"owner_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"AssignedFragmentCannotSetLocked","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"owner","type":"address"}],"name":"ERC721IncorrectOwner","type":"error"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ERC721InsufficientApproval","type":"error"},{"inputs":[{"internalType":"address","name":"approver","type":"address"}],"name":"ERC721InvalidApprover","type":"error"},{"inputs":[{"internalType":"address","name":"operator","type":"address"}],"name":"ERC721InvalidOperator","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"ERC721InvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"ERC721InvalidReceiver","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"ERC721InvalidSender","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ERC721NonexistentToken","type":"error"},{"inputs":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"FragmentAlreadyAssigned","type":"error"},{"inputs":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"FragmentNotAssigned","type":"error"},{"inputs":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"IncorrectNonce","type":"error"},{"inputs":[],"name":"InputLengthMismatch","type":"error"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"NotAuthorized","type":"error"},{"inputs":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"NotFrozen","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":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"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":"uint256","name":"_fromTokenId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"_toTokenId","type":"uint256"}],"name":"BatchMetadataUpdate","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Frozen","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Locked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"MetadataUpdate","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":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"permissions","type":"uint256"}],"name":"PermissionChange","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint16","name":"attributeId","type":"uint16"},{"indexed":false,"internalType":"uint8","name":"tier","type":"uint8"},{"indexed":false,"internalType":"string","name":"name","type":"string"},{"indexed":false,"internalType":"bool","name":"isPromoReserved","type":"bool"}],"name":"Register","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addr","type":"address"}],"name":"SchemaChange","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint32","name":"typeId","type":"uint32"},{"indexed":false,"internalType":"string","name":"name","type":"string"},{"indexed":false,"internalType":"string","name":"imageURI","type":"string"},{"indexed":false,"internalType":"uint256","name":"plunkPrice","type":"uint256"}],"name":"SetSticker","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint16","name":"attributeId","type":"uint16"}],"name":"SupplyLock","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Thawed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Unlocked","type":"event"},{"inputs":[{"internalType":"uint256","name":"ourTokenId","type":"uint256"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"targetOwner","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"string","name":"","type":"string"}],"name":"allowAssignment","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"by","type":"address"}],"name":"allowUse","outputs":[{"internalType":"bool","name":"use","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"ourTokenId","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"assign","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"frozen","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"ourTokenId","type":"uint256"}],"name":"getAssignedTo","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getFreezeNonce","outputs":[{"internalType":"uint256","name":"nonce","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getScopeName","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"imageURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"loadAttributeId","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"loadAttributeType","outputs":[{"internalType":"enum IAttribute.Type","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"loadMetadata","outputs":[{"components":[{"internalType":"enum IAttribute.Type","name":"attributeType","type":"uint8"},{"internalType":"uint16","name":"attributeId","type":"uint16"},{"internalType":"uint8","name":"tier","type":"uint8"},{"internalType":"string","name":"name","type":"string"}],"internalType":"struct IAttribute.Metadata","name":"data","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"loadName","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"loadPackedMetadata","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"slot","type":"uint256"}],"name":"loadPackedMetadataSlot","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"loadTier","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"locked","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"mint","outputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256","name":"quantity","type":"uint256"}],"name":"mintBatch","outputs":[{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"onAssignedTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"enum IAttribute.Type","name":"attributeType","type":"uint8"},{"internalType":"uint16","name":"attributeId","type":"uint16"},{"internalType":"uint8","name":"tier","type":"uint8"},{"internalType":"string","name":"name","type":"string"}],"internalType":"struct IAttribute.Metadata","name":"data","type":"tuple"}],"name":"packMetadata","outputs":[{"internalType":"uint256[]","name":"slots","type":"uint256[]"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"enum IAttribute.Type","name":"attributeType","type":"uint8"},{"internalType":"uint16","name":"attributeId","type":"uint16"},{"internalType":"uint8","name":"tier","type":"uint8"},{"internalType":"bool","name":"isPromo","type":"bool"},{"internalType":"string","name":"name","type":"string"}],"internalType":"struct IAttribute.Definition[]","name":"attributeDefs","type":"tuple[]"}],"name":"registerAttributes","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"safeTransferFromWithFreezeNonce","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"safeTransferFromWithFreezeNonce","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"schema","outputs":[{"components":[{"internalType":"uint256","name":"version","type":"uint256"},{"components":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"permissionId","type":"uint256"},{"internalType":"enum IPatchworkMetadata.FieldType","name":"fieldType","type":"uint8"},{"internalType":"uint256","name":"fieldCount","type":"uint256"},{"internalType":"enum IPatchworkMetadata.FieldVisibility","name":"visibility","type":"uint8"},{"internalType":"uint256","name":"slot","type":"uint256"},{"internalType":"uint256","name":"offset","type":"uint256"},{"internalType":"string","name":"key","type":"string"}],"internalType":"struct IPatchworkMetadata.MetadataSchemaEntry[]","name":"entries","type":"tuple[]"}],"internalType":"struct IPatchworkMetadata.MetadataSchema","name":"","type":"tuple"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"schemaURI","outputs":[{"internalType":"string","name":"","type":"string"}],"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":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bool","name":"frozen_","type":"bool"}],"name":"setFrozen","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bool","name":"locked_","type":"bool"}],"name":"setLocked","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"permissions","type":"uint256"}],"name":"setPermissions","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"typeId","type":"uint32"},{"components":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"imageURI","type":"string"},{"internalType":"uint256","name":"plunkPrice","type":"uint256"}],"internalType":"struct IStickerPack.StickerInfo","name":"info","type":"tuple"}],"name":"setSticker","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32[]","name":"typeIds","type":"uint32[]"},{"components":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"imageURI","type":"string"},{"internalType":"uint256","name":"plunkPrice","type":"uint256"}],"internalType":"struct IStickerPack.StickerInfo[]","name":"infos","type":"tuple[]"}],"name":"setStickerBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"uriRoot_","type":"string"}],"name":"setUriRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"typeId","type":"uint32"}],"name":"sticker","outputs":[{"components":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"imageURI","type":"string"},{"internalType":"uint256","name":"plunkPrice","type":"uint256"}],"internalType":"struct IStickerPack.StickerInfo","name":"info","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stickerCount","outputs":[{"internalType":"uint256","name":"count","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"components":[{"internalType":"enum IAttribute.Type","name":"attributeType","type":"uint8"},{"internalType":"uint16","name":"attributeId","type":"uint16"},{"internalType":"uint8","name":"tier","type":"uint8"},{"internalType":"string","name":"name","type":"string"}],"internalType":"struct IAttribute.Metadata","name":"data","type":"tuple"}],"name":"storeMetadata","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256[]","name":"data","type":"uint256[]"}],"name":"storePackedMetadata","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"slot","type":"uint256"},{"internalType":"uint256","name":"data","type":"uint256"}],"name":"storePackedMetadataSlot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"attributeId","type":"uint16"}],"name":"supplyLock","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":"tokenURI","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":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"transferFromWithFreezeNonce","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"unassign","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"unassignedOwnerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"slots","type":"uint256[]"}],"name":"unpackMetadata","outputs":[{"components":[{"internalType":"enum IAttribute.Type","name":"attributeType","type":"uint8"},{"internalType":"uint16","name":"attributeId","type":"uint16"},{"internalType":"uint8","name":"tier","type":"uint8"},{"internalType":"string","name":"name","type":"string"}],"internalType":"struct IAttribute.Metadata","name":"data","type":"tuple"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"updateOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]