// 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;
}
}
// 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;
}
}
// 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))
}
}
}
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
import "@openzeppelin/contracts/utils/Strings.sol";
import "@patchwork/PatchworkLiteRef.sol";
import "@patchwork/Patchwork721.sol";
import "@patchwork/interfaces/IPatchworkProtocol.sol";
import "@patchwork/interfaces/IPatchworkSingleAssignable.sol";
import "@patchwork/PatchworkUtils.sol";
import "./IElephant.sol";
import "./IAttribute.sol";
/**
,------.,--. ,--. ,--.
| .---'| | ,---. ,---. | ,---. ,--,--.,--,--, ,-' '-. ,---.
| `--, | || .-. :| .-. || .-. |' ,-. || \'-. .-'( .-'
| `---.| |\ --.| '-' '| | | |\ '-' || || | | | .-' `)
`------'`--' `----'| |-' `--' `--' `--`--'`--''--' `--' `----'
`--'
by Runic Labs, Inc
*/
/**
@notice An Elephant
@author Runic Labs, Inc
*/
contract Elephant is IElephant, Patchwork721, PatchworkLiteRef {
/// next tokenId to mint
uint256 private _nextTokenId;
/// count of tokens burned
uint256 private _burnedCount;
constructor(address manager_, address owner_)
Patchwork721("elephants", "Elephants", "ELEPHANT", manager_, owner_)
PatchworkLiteRef()
{}
/**
@dev ERC-165
*/
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(Patchwork721, PatchworkLiteRef)
returns (bool)
{
return interfaceId == type(IElephant).interfaceId || Patchwork721.supportsInterface(interfaceId) || PatchworkLiteRef.supportsInterface(interfaceId);
}
/**
@dev baseURI for json (used by OpenZeppelin tokenURI())
*/
function _baseURI() internal pure override returns (string memory) {
return "https://elephants.fun/metadata/elephant/";
}
/**
@notice a schema URI for an elephant
@return string The schema URI
*/
function schemaURI() external pure returns (string memory) {
return "https://elephants.fun/schemas/elephant.json";
}
/**
@notice an image URI for an elephant
@param tokenId the tokenId of the elephant
@return string The image URI
*/
function imageURI(uint256 tokenId) external pure returns (string memory) {
return string.concat("https://elephants.fun/assets/elephant/", Strings.toString(tokenId));
}
/**
@notice gets the total supply
@return uint256 the supply
*/
function totalSupply() public view returns (uint256) {
return _nextTokenId - _burnedCount;
}
/**
@notice forges a new elephant
@param attributeAddresses the attribute addresses
@param tokenIds the attribute tokenIds
@return uint256 a new tokenId
*/
function forge(address[] calldata attributeAddresses, uint256[] calldata tokenIds) public returns (uint256) {
require(
attributeAddresses.length == tokenIds.length, "Attribute addresses and token Ids must be the same length"
);
address owner_ = msg.sender;
// Mint the elephant token
uint256 newTokenId = _nextTokenId;
_safeMint(owner_, newTokenId);
_metadataStorage[newTokenId] = new uint256[](3);
_nextTokenId++;
// Check first to save gas on revert
_checkRules(owner_, attributeAddresses, tokenIds);
IPatchworkProtocol(_manager).assignBatch(attributeAddresses, tokenIds, address(this), newTokenId);
// Emit a forge event that the node can watch for and generate art without waiting
emit Forge(owner_, newTokenId, attributeAddresses, tokenIds);
// Return address of and token Id of elephant
return newTokenId;
}
/**
@notice edits the attribute assignments for an elephant
@param tokenId the elephant tokenId
@param edits a list of edits to make
*/
function editAttributes(uint256 tokenId, AttributeEdit[] calldata edits) public {
for (uint256 i = 0; i < edits.length; i++) {
AttributeEdit memory edit = edits[i];
if (edit.action == ActionType.Add) {
_addAttribute(tokenId, edit.newAddress, edit.newTokenId);
} else if (edit.action == ActionType.Replace) {
_swapAttribute(tokenId, edit.oldAddress, edit.oldTokenId, edit.newAddress, edit.newTokenId);
} else if (edit.action == ActionType.Remove) {
_removeAttribute(tokenId, edit.oldAddress, edit.oldTokenId);
}
}
_commitChange(tokenId);
}
/**
@notice Swaps attribute assignments for an elephant
@param tokenId the elephant tokenId
@param currentAttrAddress the current attribute address to swap
@param currentAttrTokenId the current attribute tokenId to swap
@param newAttrAddress the new attribute address to swap
@param newAttrTokenId the new attribute tokenId to swap
*/
function swapAttribute(
uint256 tokenId,
address currentAttrAddress,
uint256 currentAttrTokenId,
address newAttrAddress,
uint256 newAttrTokenId
) public {
_swapAttribute(tokenId, currentAttrAddress, currentAttrTokenId, newAttrAddress, newAttrTokenId);
_commitChange(tokenId);
}
/**
@dev Swaps attribute assignments for an elephant
@param tokenId the elephant tokenId
@param currentAttrAddress the current attribute address to swap
@param currentAttrTokenId the current attribute tokenId to swap
@param newAttrAddress the new attribute address to swap
@param newAttrTokenId the new attribute tokenId to swap
*/
function _swapAttribute(
uint256 tokenId,
address currentAttrAddress,
uint256 currentAttrTokenId,
address newAttrAddress,
uint256 newAttrTokenId
) internal onlyTokenOwner(tokenId) {
(address target, uint256 metaTokenId) =
IPatchworkSingleAssignable(currentAttrAddress).getAssignedTo(currentAttrTokenId);
require(target == address(this) && metaTokenId == tokenId, "not assigned to this");
IPatchworkProtocol(_manager).unassignSingle(currentAttrAddress, currentAttrTokenId);
IPatchworkProtocol(_manager).assign(newAttrAddress, newAttrTokenId, address(this), tokenId);
}
/**
@notice Adds an attribute to an elephant
@param tokenId the elephant tokenId
@param newAttrAddress the new attribute address to add
@param newAttrTokenId the new attribute tokenId to add
*/
function addAttribute(uint256 tokenId, address newAttrAddress, uint256 newAttrTokenId) public {
_addAttribute(tokenId, newAttrAddress, newAttrTokenId);
_commitChange(tokenId);
}
/**
@dev Adds an attribute to an elephant
@param tokenId the elephant tokenId
@param newAttrAddress the new attribute address to add
@param newAttrTokenId the new attribute tokenId to add
*/
function _addAttribute(uint256 tokenId, address newAttrAddress, uint256 newAttrTokenId) internal onlyTokenOwner(tokenId) {
IPatchworkProtocol(_manager).assign(newAttrAddress, newAttrTokenId, address(this), tokenId);
}
/**
@notice Remove an attribute from an elephant
@param tokenId the elephant tokenId
@param attrAddress the attribute address to remove
@param attrTokenId the attribute tokenId to remove
*/
function removeAttribute(uint256 tokenId, address attrAddress, uint256 attrTokenId) public {
_removeAttribute(tokenId, attrAddress, attrTokenId);
_commitChange(tokenId);
}
/**
@dev Remove an attribute from an elephant
@param tokenId the elephant tokenId
@param attrAddress the attribute address to remove
@param attrTokenId the attribute tokenId to remove
*/
function _removeAttribute(uint256 tokenId, address attrAddress, uint256 attrTokenId) internal onlyTokenOwner(tokenId) {
IPatchworkProtocol(_manager).unassignSingle(attrAddress, attrTokenId);
}
/**
@dev Commits a change
@param tokenId the elephant tokenId
*/
function _commitChange(uint256 tokenId) internal {
(address[] memory attrAddresses, uint256[] memory attrTokenIds) = loadAttributes(tokenId);
address owner = ownerOf(tokenId);
_checkRules(owner, attrAddresses, attrTokenIds);
emit Change(owner, tokenId, attrAddresses, attrTokenIds);
emit MetadataUpdate(tokenId);
}
/**
@notice burns an elephant
@dev unassigns all assigned attributes
@dev deletes all metadata storage and ownership
@param tokenId the elephant tokenId
*/
function burn(uint256 tokenId) public onlyTokenOwner(tokenId) {
(address[] memory attrAddresses, uint256[] memory attrTokenIds) = loadAttributes(tokenId);
for (uint256 i = 0; i < 8; i++) {
if (attrAddresses[i] != address(0)) {
IPatchworkProtocol(_manager).unassignSingle(attrAddresses[i], attrTokenIds[i]);
}
}
emit Burn(ownerOf(tokenId), tokenId);
delete _metadataStorage[tokenId];
_burn(tokenId);
_burnedCount++;
}
/**
@dev enforces assignment rules
@param tokenOwner the owner of the elephant
@param attributeAddresses attribute addresses
@param tokenIds attribute tokenIds
*/
function _checkRules(address tokenOwner, address[] memory attributeAddresses, uint256[] memory tokenIds)
internal
view
{
// Initialize a struct for counting attribute types - can't use a map here b/c not storage
AttributeTypeCounts memory attributeTypeCounts;
// Check ownership of each attribute and assign
for (uint256 i = 0; i < attributeAddresses.length; i++) {
if (attributeAddresses[i] == address(0)) {
continue;
}
require(
IERC721(attributeAddresses[i]).ownerOf(tokenIds[i]) == tokenOwner,
"The owner must own all attribute tokens."
);
IAttribute.Type attrType = IAttribute(attributeAddresses[i]).loadAttributeType(tokenIds[i]);
// Increment the count of the current attribute type
if (attrType == IAttribute.Type.ACCESSORY) attributeTypeCounts.accessory++;
else if (attrType == IAttribute.Type.BACKGROUND) attributeTypeCounts.background++;
else if (attrType == IAttribute.Type.BASE) attributeTypeCounts.base++;
else if (attrType == IAttribute.Type.CLOTHING) attributeTypeCounts.clothes++;
else if (attrType == IAttribute.Type.EYES) attributeTypeCounts.eyes++;
else if (attrType == IAttribute.Type.HAT) attributeTypeCounts.hat++;
else if (attrType == IAttribute.Type.MOUTH) attributeTypeCounts.mouth++;
}
// Ensure there's only one of each attribute type
require(
attributeTypeCounts.accessory <= 1 && attributeTypeCounts.background <= 1 && attributeTypeCounts.base <= 1
&& attributeTypeCounts.clothes <= 1 && attributeTypeCounts.eyes <= 1 && attributeTypeCounts.hat <= 1
&& attributeTypeCounts.mouth <= 1,
"Only one of each attribute type is allowed."
);
// Ensure there are required attributes: background, base, eyes, and mouth
require(attributeTypeCounts.background == 1, "Background attribute required.");
require(attributeTypeCounts.base == 1, "Base attribute required.");
require(attributeTypeCounts.eyes == 1, "Eyes attribute required.");
require(attributeTypeCounts.mouth == 1, "Mouth attribute required.");
}
/**
@notice the patchwork metadata schema
@return MetadataSchema the schema
*/
function schema() external pure override returns (MetadataSchema memory) {
MetadataSchemaEntry[] memory entries = new MetadataSchemaEntry[](2);
entries[0] = MetadataSchemaEntry(0, 0, FieldType.LITEREF, 8, FieldVisibility.PUBLIC, 0, 0, "attributeLiteRefs");
entries[1] = MetadataSchemaEntry(1, 1, FieldType.CHAR32, 1, FieldVisibility.PUBLIC, 2, 0, "name");
return MetadataSchema(1, entries);
}
/**
@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[](3);
slots[0] = uint256(data.attributeLiteRefs[0]) | uint256(data.attributeLiteRefs[1]) << 64
| uint256(data.attributeLiteRefs[2]) << 128 | uint256(data.attributeLiteRefs[3]) << 192;
slots[1] = uint256(data.attributeLiteRefs[4]) | uint256(data.attributeLiteRefs[5]) << 64
| uint256(data.attributeLiteRefs[6]) << 128 | uint256(data.attributeLiteRefs[7]) << 192;
slots[2] = PatchworkUtils.strToUint256(data.name);
return slots;
}
/**
@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");
_metadataStorage[tokenId] = packMetadata(data);
}
/**
@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) {
uint256 slot = slots[0];
data.attributeLiteRefs[0] = uint64(slot);
data.attributeLiteRefs[1] = uint64(slot >> 64);
data.attributeLiteRefs[2] = uint64(slot >> 128);
data.attributeLiteRefs[3] = uint64(slot >> 192);
slot = slots[1];
data.attributeLiteRefs[4] = uint64(slot);
data.attributeLiteRefs[5] = uint64(slot >> 64);
data.attributeLiteRefs[6] = uint64(slot >> 128);
data.attributeLiteRefs[7] = uint64(slot >> 192);
data.name = PatchworkUtils.toString32(slots[2]);
return 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 load attributes for an elephant
@param tokenId the tokenId of the elephant
@return attributeAddresses the addresses of the attributes
@return attributeTokenIds the tokenIds of the attributes
*/
function loadAttributes(uint256 tokenId)
public
view
returns (address[] memory attributeAddresses, uint256[] memory attributeTokenIds)
{
uint256[] storage slots = _metadataStorage[tokenId];
attributeAddresses = new address[](8);
attributeTokenIds = new uint256[](8);
uint256 curSlotNumber = 0;
uint256 slot = slots[0];
for (uint256 i = 0; i < 8; i++) {
uint256 slotNumber = i / 4; // integer division will get the correct slot number
if (slotNumber > curSlotNumber) {
slot = slots[slotNumber];
curSlotNumber = slotNumber;
}
uint256 shift = (i % 4) * 64; // the remainder will give the correct shift
uint64 attributeLiteRef = uint64(slot >> shift);
(address attributeAddress, uint256 attributeTokenId) = getReferenceAddressAndTokenId(attributeLiteRef);
attributeAddresses[i] = attributeAddress;
attributeTokenIds[i] = attributeTokenId;
}
return (attributeAddresses, attributeTokenIds);
}
/**
@notice load an attribute for an elephant
@param tokenId the tokenId of the elephant
@param idx the index of the attribute
@return attributeAddress the attribute's address
@return attributeTokenId the attribute's tokenId
*/
function loadAttribute(uint256 tokenId, uint256 idx)
public
view
returns (address attributeAddress, uint256 attributeTokenId)
{
uint256 slot = idx / 4;
uint256 slotIdx = idx - slot * 4;
uint64 attributeLiteRef = uint64(_metadataStorage[tokenId][slot] >> (slotIdx * 64));
(attributeAddress, attributeTokenId) = getReferenceAddressAndTokenId(attributeLiteRef);
}
/**
@notice Loads an elephant 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][2]);
return PatchworkUtils.toString32(value);
}
/**
@notice Stores an elephant name for a tokenId
@param tokenId the tokenId to use
@param name the name
*/
function storeName(uint256 tokenId, string calldata name) public {
require(_checkTokenWriteAuth(tokenId), "not authorized");
_metadataStorage[tokenId][2] = PatchworkUtils.strToUint256(name);
emit MetadataUpdate(tokenId);
}
/**
@notice Adds a reference to a token
@param tokenId ID of the token
@param liteRef LiteRef to add
*/
function addReference(uint256 tokenId, uint64 liteRef) public override {
require(_checkTokenWriteAuth(tokenId), "not authorized");
uint256[] storage mdStorage = _metadataStorage[tokenId];
uint256 slot = mdStorage[0];
if (uint64(slot) == 0) {
mdStorage[0] = slot | liteRef;
} else if (uint64(slot >> 64) == 0) {
mdStorage[0] = slot | uint256(liteRef) << 64;
} else if (uint64(slot >> 128) == 0) {
mdStorage[0] = slot | uint256(liteRef) << 128;
} else if (uint64(slot >> 192) == 0) {
mdStorage[0] = slot | uint256(liteRef) << 192;
} else {
slot = mdStorage[1];
if (uint64(slot) == 0) {
mdStorage[1] = slot | liteRef;
} else if (uint64(slot >> 64) == 0) {
mdStorage[1] = slot | uint256(liteRef) << 64;
} else if (uint64(slot >> 128) == 0) {
mdStorage[1] = slot | uint256(liteRef) << 128;
} else if (uint64(slot >> 192) == 0) {
mdStorage[1] = slot | uint256(liteRef) << 192;
} else {
revert("No reference slots available");
}
}
// No metadata change event needed because it is handled an an entry function
}
/**
@notice Adds multiple references to a token
@param tokenId ID of the token
@param liteRefs Array of lite references to add
*/
function addReferenceBatch(uint256 tokenId, uint64[] calldata liteRefs) public override {
// This will overwrite all ref values starting at slot 0 idx 0
require(_checkTokenWriteAuth(tokenId), "not authorized");
uint256[] storage mdStorage = _metadataStorage[tokenId];
for (uint256 slotIdx = 0; slotIdx < 2; slotIdx++) {
require(mdStorage[slotIdx] == 0, "already have references");
uint256 slot = 0;
for (uint256 refPos = 0; refPos < 4; refPos++) {
uint256 refIdx = slotIdx * 4 + refPos;
if (refIdx >= liteRefs.length) {
break;
}
slot = slot | uint256(liteRefs[refIdx]) << (64 * refPos);
}
if (slot != 0) {
mdStorage[slotIdx] = slot;
}
}
// No metadata change event needed because this is only in a mint transaction
}
/**
@notice Removes a reference from a token
@param tokenId ID of the token
@param liteRef Lite reference to remove
*/
function removeReference(uint256 tokenId, uint64 liteRef) public override {
require(_checkTokenWriteAuth(tokenId), "not authorized");
uint256[] storage mdStorage = _metadataStorage[tokenId];
uint256 slot = mdStorage[0];
if (uint64(slot) == liteRef) {
mdStorage[0] = slot & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000000000000000;
} else if (uint64(slot >> 64) == liteRef) {
mdStorage[0] = slot & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF;
} else if (uint64(slot >> 128) == liteRef) {
mdStorage[0] = slot & 0xFFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
} else if (uint64(slot >> 192) == liteRef) {
mdStorage[0] = slot & 0x0000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
} else {
slot = mdStorage[1];
if (uint64(slot) == liteRef) {
mdStorage[1] = slot & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000000000000000;
} else if (uint64(slot >> 64) == liteRef) {
mdStorage[1] = slot & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF;
} else if (uint64(slot >> 128) == liteRef) {
mdStorage[1] = slot & 0xFFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
} else if (uint64(slot >> 192) == liteRef) {
mdStorage[1] = slot & 0x0000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
} else {
revert("No reference");
}
}
// No metadata change event needed because it is handled an an entry function
}
/**
@notice Loads a reference address and token ID at a given index
@param ourTokenId ID of the token
@param idx Index to load from
@return addr Address
@return tokenId Token ID
*/
function loadReferenceAddressAndTokenId(uint256 ourTokenId, uint256 idx) external view returns (address addr, uint256 tokenId) {
uint256[] storage slots = _metadataStorage[ourTokenId];
uint256 slotNumber = idx / 4;
uint256 shift = (idx % 4) * 64;
uint64 attributeLiteRef = uint64(slots[slotNumber] >> shift);
return getReferenceAddressAndTokenId(attributeLiteRef);
}
/**
@notice Loads all static references for a given token ID
@param tokenId ID of the token
@return addresses Array of addresses
@return tokenIds Array of token IDs
*/
function loadAllStaticReferences(uint256 tokenId)
override
public
view
returns (address[] memory addresses, uint256[] memory tokenIds)
{
return loadAttributes(tokenId);
}
/**
@notice Adds a reference to a token
@param tokenId ID of the token
@param liteRef LiteRef to add
@param targetMetadataId The metadata ID on the target to assign to
*/
function addReference(uint256 tokenId, uint64 liteRef, uint256 targetMetadataId) public {
if (targetMetadataId != 0) {
revert("Invalid metadata ID");
}
addReference(tokenId, liteRef);
}
/**
@notice Adds multiple references to a token
@param tokenId ID of the token
@param liteRefs Array of lite references to add
@param targetMetadataId The metadata ID on the target to assign to
*/
function addReferenceBatch(uint256 tokenId, uint64[] calldata liteRefs, uint256 targetMetadataId) public {
if (targetMetadataId != 0) {
revert("Invalid metadata ID");
}
addReferenceBatch(tokenId, liteRefs);
}
/**
@notice Removes a reference from a token
@param tokenId ID of the token
@param liteRef Lite reference to remove
@param targetMetadataId The metadata ID on the target to unassign from
*/
function removeReference(uint256 tokenId, uint64 liteRef, uint256 targetMetadataId) public {
if (targetMetadataId != 0) {
revert("Invalid metadata ID");
}
removeReference(tokenId, liteRef);
}
/**
@dev use Patchwork721's _checkWriteAuth()
*/
function _checkWriteAuth() internal view override(Patchwork721, PatchworkLiteRef) returns (bool allow) {
return Patchwork721._checkWriteAuth();
}
/**
@dev only allow token owner
*/
modifier onlyTokenOwner(uint256 tokenId) {
require(ownerOf(tokenId) == msg.sender, "not authorized");
_;
}
}
// 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);
}
// 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);
}
// 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);
}
// 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);
}
// 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);
}
// 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);
}
// 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);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
/**
@notice Interface for Elephant
@author Runic Labs, Inc
*/
interface IElephant {
/**
@notice Forge event
@param owner The tokenId owner
@param tokenId the elephant tokenId
@param attributeAddresses the attribute addresses
@param tokenIds the attribute tokenIds
*/
event Forge(address indexed owner, uint256 indexed tokenId, address[] attributeAddresses, uint256[] tokenIds);
/**
@notice Change event
@param owner The tokenId owner
@param tokenId the elephant tokenId
@param attributeAddresses the attribute addresses
@param tokenIds the attribute tokenIds
*/
event Change(address indexed owner, uint256 indexed tokenId, address[] attributeAddresses, uint256[] tokenIds);
/**
@notice Burn event
@param owner The tokenId owner
@param tokenId the elephant tokenId
*/
event Burn(address indexed owner, uint256 indexed tokenId);
/// Onchain attribute metadata
struct Metadata {
uint64[8] attributeLiteRefs;
string name;
}
/// Attribute type counts
struct AttributeTypeCounts {
uint256 accessory;
uint256 background;
uint256 base;
uint256 clothes;
uint256 eyes;
uint256 hat;
uint256 mouth;
}
/// Edit action types
enum ActionType {
Add,
Replace,
Remove
}
// Edits
struct AttributeEdit {
ActionType action;
address oldAddress;
uint256 oldTokenId;
address newAddress;
uint256 newTokenId;
}
/**
@notice gets the total supply
@return uint256 the supply
*/
function totalSupply() external view returns (uint256);
/**
@notice forges a new elephant
@param attributeAddresses the attribute addresses
@param tokenIds the attribute tokenIds
@return uint256 a new tokenId
*/
function forge(address[] calldata attributeAddresses, uint256[] calldata tokenIds) external returns (uint256);
/**
@notice edits the attribute assignments for an elephant
@param tokenId the elephant tokenId
@param edits a list of edits to make
*/
function editAttributes(uint256 tokenId, AttributeEdit[] calldata edits) external;
/**
@notice Swaps attribute assignments for an elephant
@param tokenId the elephant tokenId
@param currentAttrAddress the current attribute address to swap
@param currentAttrTokenId the current attribute tokenId to swap
@param newAttrAddress the new attribute address to swap
@param newAttrTokenId the new attribute tokenId to swap
*/
function swapAttribute(uint256 tokenId, address currentAttrAddress, uint256 currentAttrTokenId, address newAttrAddress, uint256 newAttrTokenId) external;
/**
@notice Adds an attribute to an elephant
@param tokenId the elephant tokenId
@param newAttrAddress the new attribute address to add
@param newAttrTokenId the new attribute tokenId to add
*/
function addAttribute(uint256 tokenId, address newAttrAddress, uint256 newAttrTokenId) external;
/**
@notice Remove an attribute from an elephant
@param tokenId the elephant tokenId
@param attrAddress the attribute address to remove
@param attrTokenId the attribute tokenId to remove
*/
function removeAttribute(uint256 tokenId, address attrAddress, uint256 attrTokenId) external;
/**
@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 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 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 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 load attributes for an elephant
@param tokenId the tokenId of the elephant
@return attributeAddresses the addresses of the attributes
@return attributeTokenIds the tokenIds of the attributes
*/
function loadAttributes(uint256 tokenId) external view returns (address[] memory attributeAddresses, uint256[] memory attributeTokenIds);
/**
@notice load an attribute for an elephant
@param tokenId the tokenId of the elephant
@param idx the index of the attribute
@return attributeAddress the attribute's address
@return attributeTokenId the attribute's tokenId
*/
function loadAttribute(uint256 tokenId, uint256 idx) external view returns (address attributeAddress, uint256 attributeTokenId);
/**
@notice Loads an elephant name for a tokenId
@param tokenId the tokenId to use
@return string the name
*/
function loadName(uint256 tokenId) external view returns (string memory);
/**
@notice Stores an elephant name for a tokenId
@param tokenId the tokenId to use
@param name the name
*/
function storeName(uint256 tokenId, string calldata name) external;
}
// 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;
}
// 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);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
/**
@title Patchwork Protocol LiteRef NFT Interface
@author Runic Labs, Inc
@notice Interface for contracts that have Lite Reference ID support
*/
interface IPatchworkLiteRef {
/**
@notice Emitted when a contract redacts a fragment
@param target the contract which issued the redaction
@param fragment the fragment that was redacted
*/
event Redact(address indexed target, address indexed fragment);
/**
@notice Emitted when a contract unredacts a fragment
@param target the contract which revoked the redaction
@param fragment the fragment that was unredacted
*/
event Unredact(address indexed target, address indexed fragment);
/**
@notice Emitted when a contract registers a fragment
@param target the contract that registered the fragment
@param fragment the fragment that was registered
@param idx the idx of the literef
*/
event Register(address indexed target, address indexed fragment, uint8 idx);
/**
@notice Registers a reference address
@param addr Address to register
@return id ID assigned to the address
*/
function registerReferenceAddress(address addr) external returns (uint8 id);
/**
@notice Gets the ID assigned to the address from registration
@param addr Registered address
@return id ID assigned to the address
@return redacted Redacted status
*/
function getReferenceId(address addr) external view returns (uint8 id, bool redacted);
/**
@notice Gets the address assigned to this id
@param id ID assigned to the address
@return addr Registered address
@return redacted Redacted status
*/
function getReferenceAddress(uint8 id) external view returns (address addr, bool redacted);
/**
@notice Redacts a reference address
@param id ID of the address to redact
*/
function redactReferenceAddress(uint8 id) external;
/**
@notice Unredacts a reference address
@param id ID of the address to unredact
*/
function unredactReferenceAddress(uint8 id) external;
/**
@notice Returns a lite reference for a given address and token ID
@param addr Address to get reference for
@param tokenId ID of the token
@return liteRef Lite reference
@return redacted Redacted status
*/
function getLiteReference(address addr, uint256 tokenId) external view returns (uint64 liteRef, bool redacted);
/**
@notice Returns an address and token ID for a given lite reference
@param liteRef Lite reference to get address and token ID for
@return addr Address
@return tokenId Token ID
*/
function getReferenceAddressAndTokenId(uint64 liteRef) external view returns (address addr, uint256 tokenId);
/**
@notice Adds a reference to a token
@param tokenId ID of the token
@param liteRef LiteRef to add
*/
function addReference(uint256 tokenId, uint64 liteRef) external;
/**
@notice Adds a reference to a token
@param tokenId ID of the token
@param liteRef LiteRef to add
@param targetMetadataId The metadata ID on the target to assign to
*/
function addReference(uint256 tokenId, uint64 liteRef, uint256 targetMetadataId) external;
/**
@notice Adds multiple references to a token
@param tokenId ID of the token
@param liteRefs Array of lite references to add
*/
function addReferenceBatch(uint256 tokenId, uint64[] calldata liteRefs) external;
/**
@notice Adds multiple references to a token
@param tokenId ID of the token
@param liteRefs Array of lite references to add
@param targetMetadataId The metadata ID on the target to assign to
*/
function addReferenceBatch(uint256 tokenId, uint64[] calldata liteRefs, uint256 targetMetadataId) external;
/**
@notice Removes a reference from a token
@param tokenId ID of the token
@param liteRef Lite reference to remove
*/
function removeReference(uint256 tokenId, uint64 liteRef) external;
/**
@notice Removes a reference from a token
@param tokenId ID of the token
@param liteRef Lite reference to remove
@param targetMetadataId The metadata ID on the target to unassign from
*/
function removeReference(uint256 tokenId, uint64 liteRef, uint256 targetMetadataId) external;
/**
@notice Loads a reference address and token ID at a given index
@param ourTokenId ID of the token
@param idx Index to load from
@return addr Address
@return tokenId Token ID
*/
function loadReferenceAddressAndTokenId(uint256 ourTokenId, uint256 idx) external view returns (address addr, uint256 tokenId);
/**
@notice Loads all static references for a given token ID
@param tokenId ID of the token
@return addresses Array of addresses
@return tokenIds Array of token IDs
*/
function loadAllStaticReferences(uint256 tokenId) external view returns (address[] memory addresses, uint256[] memory tokenIds);
/**
@notice Count all dynamic references for a given token ID
@param tokenId ID of the token
@return count the number of dynamic references
*/
function getDynamicReferenceCount(uint256 tokenId) external view returns (uint256 count);
/**
@notice Load a page of dynamic references for a given token ID
@param tokenId ID of the token
@param offset The starting offset 0-indexed
@param count The maximum number of references to return
@return addresses An array of reference addresses
@return tokenIds An array of reference token IDs
*/
function loadDynamicReferencePage(uint256 tokenId, uint256 offset, uint256 count) external view returns (address[] memory addresses, uint256[] memory tokenIds);
}
// 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;
}
// 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);
}
// 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 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;
}
// 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;
}
}
// 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);
}
}
// 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);
}
_;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import "./interfaces/IPatchworkLiteRef.sol";
import "./interfaces/IPatchworkProtocol.sol";
/**
@title PatchworkLiteRef
@dev base implementation of IPatchworkLiteRef
*/
abstract contract PatchworkLiteRef is IPatchworkLiteRef, ERC165 {
/// A mapping from reference IDs to their associated addresses.
mapping(uint8 => address) internal _referenceAddresses;
/// A reverse mapping from addresses to their corresponding reference IDs.
mapping(address => uint8) internal _referenceAddressIds;
/// A mapping indicating which reference IDs have been redacted.
mapping(uint8 => bool) internal _redactedReferenceIds;
/// The ID that will be used for the next reference added.
uint8 internal _nextReferenceId;
/**
@dev Constructor for the PatchworkLiteRef contract. Initializes the next reference ID to 1 to differentiate unregistered references.
*/
constructor() {
_nextReferenceId = 1; // Start at 1 so we can identify if we already have one registered
}
/**
@notice implements a permission check for functions of this abstract class to use
@return allow true if write is allowed, false if not
*/
function _checkWriteAuth() internal virtual returns (bool allow);
/**
@dev See {IERC165-supportsInterface}
*/
function supportsInterface(bytes4 interfaceID) public view virtual override returns (bool) {
return interfaceID == type(IPatchworkLiteRef).interfaceId ||
ERC165.supportsInterface(interfaceID);
}
/**
@dev See {IPatchworkLiteRef-registerReferenceAddress}
*/
function registerReferenceAddress(address addr) public virtual _mustHaveWriteAuth returns (uint8 id) {
uint8 refId = _nextReferenceId;
if (_nextReferenceId == 255) {
revert IPatchworkProtocol.OutOfIDs();
}
_nextReferenceId++;
if (_referenceAddressIds[addr] != 0) {
revert IPatchworkProtocol.FragmentAlreadyRegistered(addr);
}
_referenceAddresses[refId] = addr;
_referenceAddressIds[addr] = refId;
emit Register(address(this), addr, refId);
return refId;
}
/**
@dev See {IPatchworkLiteRef-getReferenceId}
*/
function getReferenceId(address addr) public virtual view returns (uint8 id, bool redacted) {
uint8 refId = _referenceAddressIds[addr];
return (refId, _redactedReferenceIds[refId]);
}
/**
@dev See {IPatchworkLiteRef-getReferenceAddress}
*/
function getReferenceAddress(uint8 id) public virtual view returns (address addr, bool redacted) {
return (_referenceAddresses[id], _redactedReferenceIds[id]);
}
/**
@dev See {IPatchworkLiteRef-redactReferenceAddress}
*/
function redactReferenceAddress(uint8 id) public virtual _mustHaveWriteAuth {
if (_referenceAddresses[id] == address(0)) {
revert IPatchworkProtocol.FragmentUnregistered(address(0));
}
_redactedReferenceIds[id] = true;
emit Redact(address(this), _referenceAddresses[id]);
}
/**
@dev See {IPatchworkLiteRef-unredactReferenceAddress}
*/
function unredactReferenceAddress(uint8 id) public virtual _mustHaveWriteAuth {
if (_referenceAddresses[id] == address(0)) {
revert IPatchworkProtocol.FragmentUnregistered(address(0));
}
_redactedReferenceIds[id] = false;
emit Unredact(address(this), _referenceAddresses[id]);
}
/**
@dev See {IPatchworkLiteRef-getLiteReference}
*/
function getLiteReference(address addr, uint256 tokenId) public virtual view returns (uint64 liteRef, bool redacted) {
uint8 refId = _referenceAddressIds[addr];
if (refId == 0) {
return (0, false);
}
if (tokenId > type(uint56).max) {
revert IPatchworkProtocol.UnsupportedTokenId(tokenId);
}
return (uint64(uint256(refId) << 56 | tokenId), _redactedReferenceIds[refId]);
}
/**
@dev See {IPatchworkLiteRef-getReferenceAddressAndTokenId}
*/
function getReferenceAddressAndTokenId(uint64 liteRef) public virtual view returns (address addr, uint256 tokenId) {
// <8 bits of refId, 56 bits of tokenId>
uint8 refId = uint8(liteRef >> 56);
tokenId = liteRef & 0x00FFFFFFFFFFFFFF; // 64 bit mask
return (_referenceAddresses[refId], tokenId);
}
/**
@dev See {IPatchworkLiteRef-loadAllStaticReferences}
*/
function loadAllStaticReferences(uint256 tokenId) public virtual view returns (address[] memory addresses, uint256[] memory tokenIds) {}
/**
@dev See {IPatchworkLiteRef-getDynamicReferenceCount}
*/
function getDynamicReferenceCount(uint256 tokenId) public virtual view returns (uint256 count) {}
/**
@dev See {IPatchworkLiteRef-loadDynamicReferencePage}
*/
function loadDynamicReferencePage(uint256 tokenId, uint256 offset, uint256 count) public virtual view returns (address[] memory addresses, uint256[] memory tokenIds) {}
modifier _mustHaveWriteAuth {
if (!_checkWriteAuth()) {
revert IPatchworkProtocol.NotAuthorized(msg.sender);
}
_;
}
}
// 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);
}
}
}
// 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);
}
}
}
// 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));
}
}
// 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);
}
{
"compilationTarget": {
"src/Elephant.sol": "Elephant"
},
"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/"
]
}
[{"inputs":[{"internalType":"address","name":"manager_","type":"address"},{"internalType":"address","name":"owner_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"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"}],"name":"FragmentAlreadyRegistered","type":"error"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"FragmentUnregistered","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":[{"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":[],"name":"OutOfIDs","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"UnsupportedTokenId","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":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Burn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"address[]","name":"attributeAddresses","type":"address[]"},{"indexed":false,"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"name":"Change","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"address[]","name":"attributeAddresses","type":"address[]"},{"indexed":false,"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"name":"Forge","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":"address","name":"target","type":"address"},{"indexed":true,"internalType":"address","name":"fragment","type":"address"}],"name":"Redact","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"target","type":"address"},{"indexed":true,"internalType":"address","name":"fragment","type":"address"},{"indexed":false,"internalType":"uint8","name":"idx","type":"uint8"}],"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":"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"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"target","type":"address"},{"indexed":true,"internalType":"address","name":"fragment","type":"address"}],"name":"Unredact","type":"event"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"newAttrAddress","type":"address"},{"internalType":"uint256","name":"newAttrTokenId","type":"uint256"}],"name":"addAttribute","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint64","name":"liteRef","type":"uint64"},{"internalType":"uint256","name":"targetMetadataId","type":"uint256"}],"name":"addReference","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint64","name":"liteRef","type":"uint64"}],"name":"addReference","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint64[]","name":"liteRefs","type":"uint64[]"}],"name":"addReferenceBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint64[]","name":"liteRefs","type":"uint64[]"},{"internalType":"uint256","name":"targetMetadataId","type":"uint256"}],"name":"addReferenceBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","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":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"components":[{"internalType":"enum IElephant.ActionType","name":"action","type":"uint8"},{"internalType":"address","name":"oldAddress","type":"address"},{"internalType":"uint256","name":"oldTokenId","type":"uint256"},{"internalType":"address","name":"newAddress","type":"address"},{"internalType":"uint256","name":"newTokenId","type":"uint256"}],"internalType":"struct IElephant.AttributeEdit[]","name":"edits","type":"tuple[]"}],"name":"editAttributes","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"attributeAddresses","type":"address[]"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"name":"forge","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","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":"tokenId","type":"uint256"}],"name":"getDynamicReferenceCount","outputs":[{"internalType":"uint256","name":"count","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":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getLiteReference","outputs":[{"internalType":"uint64","name":"liteRef","type":"uint64"},{"internalType":"bool","name":"redacted","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint8","name":"id","type":"uint8"}],"name":"getReferenceAddress","outputs":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"bool","name":"redacted","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint64","name":"liteRef","type":"uint64"}],"name":"getReferenceAddressAndTokenId","outputs":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"getReferenceId","outputs":[{"internalType":"uint8","name":"id","type":"uint8"},{"internalType":"bool","name":"redacted","type":"bool"}],"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":"pure","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":"loadAllStaticReferences","outputs":[{"internalType":"address[]","name":"addresses","type":"address[]"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"idx","type":"uint256"}],"name":"loadAttribute","outputs":[{"internalType":"address","name":"attributeAddress","type":"address"},{"internalType":"uint256","name":"attributeTokenId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"loadAttributes","outputs":[{"internalType":"address[]","name":"attributeAddresses","type":"address[]"},{"internalType":"uint256[]","name":"attributeTokenIds","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"offset","type":"uint256"},{"internalType":"uint256","name":"count","type":"uint256"}],"name":"loadDynamicReferencePage","outputs":[{"internalType":"address[]","name":"addresses","type":"address[]"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"loadMetadata","outputs":[{"components":[{"internalType":"uint64[8]","name":"attributeLiteRefs","type":"uint64[8]"},{"internalType":"string","name":"name","type":"string"}],"internalType":"struct IElephant.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":"ourTokenId","type":"uint256"},{"internalType":"uint256","name":"idx","type":"uint256"}],"name":"loadReferenceAddressAndTokenId","outputs":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"locked","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"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":"uint64[8]","name":"attributeLiteRefs","type":"uint64[8]"},{"internalType":"string","name":"name","type":"string"}],"internalType":"struct IElephant.Metadata","name":"data","type":"tuple"}],"name":"packMetadata","outputs":[{"internalType":"uint256[]","name":"slots","type":"uint256[]"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint8","name":"id","type":"uint8"}],"name":"redactReferenceAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"registerReferenceAddress","outputs":[{"internalType":"uint8","name":"id","type":"uint8"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"attrAddress","type":"address"},{"internalType":"uint256","name":"attrTokenId","type":"uint256"}],"name":"removeAttribute","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint64","name":"liteRef","type":"uint64"},{"internalType":"uint256","name":"targetMetadataId","type":"uint256"}],"name":"removeReference","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint64","name":"liteRef","type":"uint64"}],"name":"removeReference","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":"pure","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":"uint256","name":"tokenId","type":"uint256"},{"components":[{"internalType":"uint64[8]","name":"attributeLiteRefs","type":"uint64[8]"},{"internalType":"string","name":"name","type":"string"}],"internalType":"struct IElephant.Metadata","name":"data","type":"tuple"}],"name":"storeMetadata","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"string","name":"name","type":"string"}],"name":"storeName","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":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"currentAttrAddress","type":"address"},{"internalType":"uint256","name":"currentAttrTokenId","type":"uint256"},{"internalType":"address","name":"newAttrAddress","type":"address"},{"internalType":"uint256","name":"newAttrTokenId","type":"uint256"}],"name":"swapAttribute","outputs":[],"stateMutability":"nonpayable","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":"slots","type":"uint256[]"}],"name":"unpackMetadata","outputs":[{"components":[{"internalType":"uint64[8]","name":"attributeLiteRefs","type":"uint64[8]"},{"internalType":"string","name":"name","type":"string"}],"internalType":"struct IElephant.Metadata","name":"data","type":"tuple"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint8","name":"id","type":"uint8"}],"name":"unredactReferenceAddress","outputs":[],"stateMutability":"nonpayable","type":"function"}]