Description:
Multi-signature wallet contract requiring multiple confirmations for transaction execution.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"src/DAChronicle.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
// Compatible with OpenZeppelin Contracts ^5.0.0
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import {ERC721URIStorage} from "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import {ERC721DelegatedActions} from "./ERC721DelegatedActions.sol";
import {IDAChronicle} from "./IDAChronicle.sol";
// ____ ______ ______ ____ __ ___
// /\ _`\ /\ _ \/\__ _\ /\ _`\ /\ \ __ /\_ \
// \ \ \/\ \ \ \L\ \/_/\ \/ \ \ \/\_\\ \ \___ _ __ ___ ___ /\_\ ___\//\ \ __ ____
// \ \ \ \ \ \ __ \ \ \ \ \ \ \/_/_\ \ _ `\/\`'__\/ __`\ /' _ `\/\ \ /'___\\ \ \ /'__`\ /',__\
// \ \ \_\ \ \ \/\ \ \_\ \__\ \ \L\ \\ \ \ \ \ \ \//\ \L\ \/\ \/\ \ \ \/\ \__/ \_\ \_/\ __//\__, `\
// \ \____/\ \_\ \_\/\_____\\ \____/ \ \_\ \_\ \_\\ \____/\ \_\ \_\ \_\ \____\/\____\ \____\/\____/
// \/___/ \/_/\/_/\/_____/ \/___/ \/_/\/_/\/_/ \/___/ \/_/\/_/\/_/\/____/\/____/\/____/\/___/
// ================================================================
// │ ERRORS │
// ================================================================
/**
* @dev Thrown when a cooldown period is still active for the specified token.
* @param tokenId The ID of the token that is under cooldown.
*/
error DAChronicle__CooldownActive(uint256 tokenId);
/**
* @dev Thrown when an invalid base cooldown argument is provided.
* @param newBaseCooldown The invalid base cooldown value.
*/
error DAChronicle__InvalidBaseCooldownArgument(uint16 newBaseCooldown);
/**
* @title DAChronicle
* @dev ERC721 contract that adds cooldowns for updating token metadata via `setTokenURI`.
* Each token has its own independent cooldown, which increases exponentially
* after each use, until it reaches a cap. The cooldown is reset when a new
* NFT is minted.
* Extends delegated action functionality with signature-based authorization.
*/
contract DAChronicle is ERC721DelegatedActions, IDAChronicle {
// ================================================================
// │ Type declarations │
// ================================================================
/// @dev Struct representing a cooldown for a specific token.
struct Cooldown {
uint256 count; // The number of times the URI has been updated
uint256 timestamp; // Timestamp when the cooldown expires
}
// ================================================================
// │ State variables │
// ================================================================
bool public s_cooldownEnabled; // Whether cooldowns are enabled
uint16 public s_baseCooldownDays; // Base cooldown in days
uint16 public s_maxCooldownDays; // Maximum cooldown cap in days
uint256 public s_maxCooldownSeconds; // Maximum cooldown cap in seconds
mapping(uint256 tokenId => Cooldown cooldown) private s_tokenCooldowns; // Token-specific cooldowns
// ================================================================
// │ Events │
// ================================================================
/**
* @dev Emitted when the cooldown is set for a token.
* @param tokenId The ID of the token for which the cooldown is set.
* @param cooldown The cooldown period applied to the token (i.e. the update count and cooldown end timestamp).
*/
event CooldownSet(uint256 indexed tokenId, Cooldown cooldown);
/**
* @dev Emitted when the cooldowns are enabled or disabled.
* @param enabled True if the cooldowns are enabled, false otherwise.
*/
event CooldownEnabled(bool enabled);
/**
* @dev Emitted when the base cooldown is updated.
* @param previousBaseCooldown The previous base cooldown value in days.
* @param newBaseCooldown The new base cooldown value in days.
*/
event BaseCooldownUpdated(uint16 previousBaseCooldown, uint16 newBaseCooldown);
/**
* @dev Emitted when the max cooldown is updated.
* @param previousMaxCooldown The previous max cooldown value in days.
* @param newMaxCooldown The new max cooldown value in days.
*/
event MaxCooldownUpdated(uint16 previousMaxCooldown, uint16 newMaxCooldown);
// ================================================================
// │ Modifiers │
// ================================================================
/**
* @dev Modifier to ensure the cooldown period for a token has elapsed.
* Reverts if the cooldown is still active.
* @param tokenId The ID of the token being checked.
*/
modifier cooldownElapsed(uint256 tokenId) {
if (s_cooldownEnabled) {
_checkAndUpdateCooldown(tokenId);
}
_;
}
// ================================================================
// │ Constructor │
// ================================================================
/**
* @param initialAuthority The address of the initial authority of the contract
* @param baseCooldown The base cooldown in days for the first `setTokenURI`
* @param maxCooldown The maximum cooldown cap in days
*/
constructor(address initialAuthority, bool cooldownEnabled, uint16 baseCooldown, uint16 maxCooldown)
ERC721DelegatedActions("DAC Chronicles", "CHRON", initialAuthority)
{
s_cooldownEnabled = cooldownEnabled;
s_baseCooldownDays = baseCooldown;
s_maxCooldownDays = maxCooldown;
s_maxCooldownSeconds = uint256(maxCooldown) * 1 days;
emit CooldownEnabled(cooldownEnabled);
emit BaseCooldownUpdated(0, baseCooldown);
emit MaxCooldownUpdated(0, maxCooldown);
}
// ================================================================
// │ Functions │
// ================================================================
/**
* @inheritdoc IDAChronicle
* @dev Can only be called by the treasury.
*/
function delegateSafeMint(
bool isSale,
address to,
uint256 tokenId,
string calldata uri,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s,
address beneficiary
) external override onlyTreasury {
s_tokenCooldowns[tokenId] = Cooldown(0, block.timestamp); // Reset the cooldown for the token
_delegateSafeMint(isSale, to, tokenId, uri, deadline, v, r, s, beneficiary);
}
/**
* @inheritdoc IDAChronicle
* @dev Throws if the token has an active cooldown.
* Can only be called by the treasury.
*/
function delegateSetTokenURI(
bool applyDiscount,
uint256 tokenId,
string calldata uri,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external override onlyTreasury cooldownElapsed(tokenId) {
_delegateSetTokenURI(applyDiscount, tokenId, uri, deadline, v, r, s);
}
/**
* @dev Mints a new token and resets the cooldown for that token.
* Only the Chronicles Agent can call this method.
* @param to The address to mint the token to.
* @param tokenId The tokenId of the new token.
* @param uri The URI to set for the token.
* @param beneficiary The address to receive royalties from the token.
*/
function safeMint(address to, uint256 tokenId, string calldata uri, address beneficiary)
public
onlyChroniclesAgent
{
s_tokenCooldowns[tokenId] = Cooldown(0, block.timestamp); // Reset the cooldown for the token
_safeMint(to, tokenId);
_setTokenURI(tokenId, uri);
_setTokenRoyalty(tokenId, beneficiary, ROYALTY_FEE);
}
/**
* @dev Sets a new URI for a given token. If a cooldown is active, it prevents
* setting a new URI until the cooldown period has passed. Only the Chronicles Agent can call this method.
* @param tokenId The tokenId for which the URI is being updated.
* @param uri The new URI to set.
*/
function setTokenURI(uint256 tokenId, string calldata uri) public onlyChroniclesAgent cooldownElapsed(tokenId) {
_setTokenURI(tokenId, uri);
}
/**
* @dev Enables or disables the cooldowns for updating token URIs.
* @param enabled True to enable the cooldowns, false to disable them.
*
* Emits a {CooldownEnabled} event.
*/
function enableCooldowns(bool enabled) public onlyAdmin {
s_cooldownEnabled = enabled;
emit CooldownEnabled(enabled);
}
/**
* @dev Allows the owner to update the base cooldown value.
* @param newBaseCooldownDays The new base cooldown value in days.
*/
function updateBaseCooldown(uint16 newBaseCooldownDays) public onlyAdmin {
if (newBaseCooldownDays == 0) {
revert DAChronicle__InvalidBaseCooldownArgument(newBaseCooldownDays);
}
uint16 previousBaseCooldownDays = s_baseCooldownDays;
s_baseCooldownDays = newBaseCooldownDays;
emit BaseCooldownUpdated(previousBaseCooldownDays, newBaseCooldownDays);
}
/**
* @dev Allows the owner to update the max cooldown cap value.
* @param newMaxCooldownDays The new max cooldown value in days.
*
* Emits a {MaxCooldownUpdated} event.
*/
function updateMaxCooldown(uint16 newMaxCooldownDays) public onlyAdmin {
uint16 previousMaxCooldownDays = s_maxCooldownDays;
s_maxCooldownDays = newMaxCooldownDays;
s_maxCooldownSeconds = uint256(newMaxCooldownDays) * 1 days;
emit MaxCooldownUpdated(previousMaxCooldownDays, newMaxCooldownDays);
}
/**
* @dev Returns the current cooldown for a specific token.
* @param tokenId The tokenId to check the cooldown for.
* @return The current cooldown for the token.
*/
function getCooldown(uint256 tokenId) public view returns (Cooldown memory) {
return s_tokenCooldowns[tokenId];
}
/**
* @dev Throws if the token has an active cooldown.
* @param tokenId The tokenId to check the cooldown for.
* Then updates the cooldown. Note: Update cooldown: increment by the baseCooldown raised to the power of the number of updates
*
* Emits a {CooldownSet} event.
*/
function _checkAndUpdateCooldown(uint256 tokenId) private {
Cooldown storage cooldown = s_tokenCooldowns[tokenId];
if (cooldown.timestamp > block.timestamp) {
revert DAChronicle__CooldownActive(tokenId);
}
// Update cooldown: increment by the baseCooldown raised to the power of the number of updates
uint256 nextCooldownSeconds = uint256(s_baseCooldownDays) ** (cooldown.count + 1) * 1 days;
// Apply the cap if necessary
nextCooldownSeconds = nextCooldownSeconds > s_maxCooldownSeconds ? s_maxCooldownSeconds : nextCooldownSeconds;
// Set the new cooldown for the token
cooldown.count += 1;
cooldown.timestamp = block.timestamp + nextCooldownSeconds;
emit CooldownSet(tokenId, cooldown);
}
}
"
},
"lib/openzeppelin-contracts/contracts/token/ERC721/ERC721.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/ERC721.sol)
pragma solidity ^0.8.20;
import {IERC721} from "./IERC721.sol";
import {IERC721Metadata} from "./extensions/IERC721Metadata.sol";
import {ERC721Utils} from "./utils/ERC721Utils.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[ERC-721] 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);
ERC721Utils.checkOnERC721Received(_msgSender(), 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 ERC-721 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 `owner` for `tokenId`.
* - `spender` does not have approval to manage all of `owner`'s assets.
*
* 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);
ERC721Utils.checkOnERC721Received(_msgSender(), 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 ERC-721 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);
ERC721Utils.checkOnERC721Received(_msgSender(), 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;
}
}
"
},
"lib/openzeppelin-contracts/contracts/token/ERC721/extensions/ERC721URIStorage.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/extensions/ERC721URIStorage.sol)
pragma solidity ^0.8.20;
import {ERC721} from "../ERC721.sol";
import {Strings} from "../../../utils/Strings.sol";
import {IERC4906} from "../../../interfaces/IERC4906.sol";
import {IERC165} from "../../../interfaces/IERC165.sol";
/**
* @dev ERC-721 token with storage based token URI management.
*/
abstract contract ERC721URIStorage is IERC4906, ERC721 {
using Strings for uint256;
// Interface ID as defined in ERC-4906. This does not correspond to a traditional interface ID as ERC-4906 only
// defines events and does not include any external function.
bytes4 private constant ERC4906_INTERFACE_ID = bytes4(0x49064906);
// Optional mapping for token URIs
mapping(uint256 tokenId => string) private _tokenURIs;
/**
* @dev See {IERC165-supportsInterface}
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, IERC165) returns (bool) {
return interfaceId == ERC4906_INTERFACE_ID || super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
_requireOwned(tokenId);
string memory _tokenURI = _tokenURIs[tokenId];
string memory base = _baseURI();
// If there is no base URI, return the token URI.
if (bytes(base).length == 0) {
return _tokenURI;
}
// If both are set, concatenate the baseURI and tokenURI (via string.concat).
if (bytes(_tokenURI).length > 0) {
return string.concat(base, _tokenURI);
}
return super.tokenURI(tokenId);
}
/**
* @dev Sets `_tokenURI` as the tokenURI of `tokenId`.
*
* Emits {MetadataUpdate}.
*/
function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {
_tokenURIs[tokenId] = _tokenURI;
emit MetadataUpdate(tokenId);
}
}
"
},
"src/ERC721DelegatedActions.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
// Compatible with OpenZeppelin Contracts ^5.0.0
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import {ERC721URIStorage} from "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import {ERC2981} from "@openzeppelin/contracts/token/common/ERC2981.sol";
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
import {ERC721Nonces} from "./ERC721Nonces.sol";
import {IERC721DelegatedActions} from "./IERC721DelegatedActions.sol";
import {IDACAuthority} from "./IDACAuthority.sol";
import {DACAccessManaged} from "./DACAccessManaged.sol";
/**
* @dev Thrown when the provided signature has expired.
* @param deadline The expiration time of the signature.
*/
error ERC721DelegatedActions__ERC2612ExpiredSignature(uint256 deadline);
/**
* @dev Thrown when the provided signature is invalid.
* @param signer The address of the signer.
* @param owner The expected owner of the token.
*/
error ERC721DelegatedActions__ERC2612InvalidSigner(address signer, address owner);
/**
* @title ERC721DelegatedActions
* @dev Abstract contract enabling delegated actions for ERC721 tokens, such as minting and updating metadata,
* using off-chain signatures for authorization. Extends functionality from OpenZeppelin's ERC721 contracts.
*/
abstract contract ERC721DelegatedActions is
ERC721,
ERC721URIStorage,
ERC2981,
EIP712,
ERC721Nonces,
IERC721DelegatedActions,
DACAccessManaged
{
bytes32 private constant DELEGATE_SAFE_MINT_TYPEHASH =
keccak256("_delegateSafeMint(bool isSale,address to,uint256 tokenId,string uri,uint256 nonce,uint256 deadline)");
bytes32 private constant DELEGATE_SET_TOEKN_URI_TYPEHASH =
keccak256("_delegateSetTokenURI(bool applyDiscount,uint256 tokenId,string uri,uint256 nonce,uint256 deadline)");
uint96 internal constant ROYALTY_FEE = 200; // 2%
/**
* @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`.
*
* It's a good idea to use the same `name` that is defined as the ERC-721 token name.
*/
constructor(string memory name, string memory symbol, address initialAuthority)
ERC721(name, symbol)
EIP712(name, "1")
DACAccessManaged(IDACAuthority(initialAuthority))
{}
/**
* @notice Delegates the safe minting of an ERC721 token to another party.
* @dev Requires an off-chain signature from the authorized party.
* @param isSale Whether the mint is part of a sale.
* @param to The address to mint the token to.
* @param tokenId The ID of the token to be minted.
* @param uri The URI of the token metadata.
* @param deadline The deadline until when the signature is valid.
* @param v Signature recovery ID.
* @param r Signature parameter.
* @param s Signature parameter.
* @param beneficiary The address to receive royalties from the token.
*/
function _delegateSafeMint(
bool isSale,
address to,
uint256 tokenId,
string calldata uri,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s,
address beneficiary
) internal virtual {
if (block.timestamp > deadline) {
revert ERC721DelegatedActions__ERC2612ExpiredSignature(deadline);
}
bytes32 structHash =
keccak256(abi.encode(DELEGATE_SAFE_MINT_TYPEHASH, isSale, to, tokenId, uri, _useNonce(tokenId), deadline));
bytes32 hash = _hashTypedDataV4(structHash);
address signer = ECDSA.recover(hash, v, r, s);
address owner = getAuthority().chroniclesAgent(); // The owner of generating NFTs is the Chronicles Agent
if (signer != owner) {
revert ERC721DelegatedActions__ERC2612InvalidSigner(signer, owner);
}
_safeMint(to, tokenId);
_setTokenURI(tokenId, uri);
_setTokenRoyalty(tokenId, beneficiary, ROYALTY_FEE);
}
/**
* @notice Delegates the update of a token's metadata URI.
* @dev Requires an off-chain signature from the authorized party.
* @param applyDiscount Whether to apply a discount to the token URI update.
* @param tokenId The ID of the token to update.
* @param uri The new metadata URI for the token.
* @param deadline The deadline until when the signature is valid.
* @param v Signature recovery ID.
* @param r Signature parameter.
* @param s Signature parameter.
* @notice Once a signature is generated, it must be used before another signature is generated for the same token; otherwise, it will become obsolete.
*/
function _delegateSetTokenURI(
bool applyDiscount,
uint256 tokenId,
string calldata uri,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal virtual {
if (block.timestamp > deadline) {
revert ERC721DelegatedActions__ERC2612ExpiredSignature(deadline);
}
bytes32 structHash = keccak256(
abi.encode(DELEGATE_SET_TOEKN_URI_TYPEHASH, applyDiscount, tokenId, uri, _useNonce(tokenId), deadline)
);
bytes32 hash = _hashTypedDataV4(structHash);
address signer = ECDSA.recover(hash, v, r, s);
address owner = getAuthority().chroniclesAgent(); // The owner of generating NFTs is the Chronicles Agent
if (signer != owner) {
revert ERC721DelegatedActions__ERC2612InvalidSigner(signer, owner);
}
_setTokenURI(tokenId, uri);
}
/**
* @inheritdoc IERC721DelegatedActions
*/
function nonces(uint256 tokenId)
public
view
virtual
override(IERC721DelegatedActions, ERC721Nonces)
returns (uint256)
{
return super.nonces(tokenId);
}
/**
* @inheritdoc IERC721DelegatedActions
*/
function DOMAIN_SEPARATOR() external view override returns (bytes32) {
return _domainSeparatorV4();
}
// The following functions are overrides required by Solidity.
function tokenURI(uint256 tokenId) public view override(ERC721, ERC721URIStorage) returns (string memory) {
return super.tokenURI(tokenId);
}
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC721, ERC721URIStorage, ERC2981)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}
"
},
"src/IDAChronicle.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
// Compatible with OpenZeppelin Contracts ^5.0.0
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
/**
* @title IDAChronicle
* @dev Interface for the DAChronicle NFT contract, enabling token minting and metadata updates
* via signatures, as defined in EIP-2612. This interface allows delegated actions on behalf of
* the Chronicles Agent without requiring direct transactions from the Chronicles Agent account.
*/
interface IDAChronicle is IERC721 {
/**
* @notice Mints an ERC721 token with the specified `tokenId` and `uri` on behalf of the Chronicles Agent.
* @dev Requires a valid signature from the Chronicles Agent for authorization.
*
* Emits a {Transfer} event.
*
* Requirements:
* - `to` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - The provided signature must be valid and signed by the Chronicles Agent.
*
* @param isSale Whether the mint is part of a sale.
* @param to The address to mint the token to.
* @param tokenId The ID of the token to mint.
* @param uri The metadata URI for the token.
* @param deadline The expiration time for the signature.
* @param v Signature recovery ID.
* @param r Signature parameter.
* @param s Signature parameter.
* @param beneficiary The address to receive royalties from the token.
*/
function delegateSafeMint(
bool isSale,
address to,
uint256 tokenId,
string calldata uri,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s,
address beneficiary
) external;
/**
* @notice Updates the metadata URI of a token on behalf of the Chronicles Agent.
* @dev Requires a valid signature from the Chronicles Agent for authorization.
*
* Emits a {TokenURIUpdated} event.
*
* Requirements:
* - The caller must provide a valid signature.
* - `tokenId` must exist.
* - `deadline` must be a timestamp in the future.
*
* @param applyDiscount Whether to apply a discount to the token URI update.
* @param tokenId The ID of the token to update.
* @param uri The new metadata URI for the token.
* @param deadline The expiration time for the signature.
* @param v Signature recovery ID.
* @param r Signature parameter.
* @param s Signature parameter.
*/
function delegateSetTokenURI(
bool applyDiscount,
uint256 tokenId,
string calldata uri,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
}
"
},
"lib/openzeppelin-contracts/contracts/token/ERC721/IERC721.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC-721 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 ERC-721 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 ERC-721
* 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);
}
"
},
"lib/openzeppelin-contracts/contracts/token/ERC721/extensions/IERC721Metadata.sol": {
"content": "// 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);
}
"
},
"lib/openzeppelin-contracts/contracts/token/ERC721/utils/ERC721Utils.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/utils/ERC721Utils.sol)
pragma solidity ^0.8.20;
import {IERC721Receiver} from "../IERC721Receiver.sol";
import {IERC721Errors} from "../../../interfaces/draft-IERC6093.sol";
/**
* @dev Library that provide common ERC-721 utility functions.
*
* See https://eips.ethereum.org/EIPS/eip-721[ERC-721].
*
* _Available since v5.1._
*/
library ERC721Utils {
/**
* @dev Performs an acceptance check for the provided `operator` by calling {IERC721-onERC721Received}
* on the `to` address. The `operator` is generally the address that initiated the token transfer (i.e. `msg.sender`).
*
* The acceptance call is not executed and treated as a no-op if the target address doesn't contain code (i.e. an EOA).
* Otherwise, the recipient must implement {IERC721Receiver-onERC721Received} and return the acceptance magic value to accept
* the transfer.
*/
function checkOnERC721Received(
address operator,
address from,
address to,
uint256 tokenId,
bytes memory data
) internal {
if (to.code.length > 0) {
try IERC721Receiver(to).onERC721Received(operator, from, tokenId, data) returns (bytes4 retval) {
if (retval != IERC721Receiver.onERC721Received.selector) {
// Token rejected
revert IERC721Errors.ERC721InvalidReceiver(to);
}
} catch (bytes memory reason) {
if (reason.length == 0) {
// non-IERC721Receiver implementer
revert IERC721Errors.ERC721InvalidReceiver(to);
} else {
assembly ("memory-safe") {
revert(add(32, reason), mload(reason))
}
}
}
}
}
}
"
},
"lib/openzeppelin-contracts/contracts/utils/Context.sol": {
"content": "// 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;
}
}
"
},
"lib/openzeppelin-contracts/contracts/utils/Strings.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.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;
assembly ("memory-safe") {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
assembly ("memory-safe") {
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 Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal
* representation, according to EIP-55.
*/
function toChecksumHexString(address addr) internal pure returns (string memory) {
bytes memory buffer = bytes(toHexString(addr));
// hash the hex part of buffer (skip length + 2 bytes, length 40)
uint256 hashValue;
assembly ("memory-safe") {
hashValue := shr(96, keccak256(add(buffer, 0x22), 40))
}
for (uint256 i = 41; i > 1; --i) {
// possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)
if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {
// case shift by xoring with 0x20
buffer[i] ^= 0x20;
}
hashValue >>= 4;
}
return string(buffer);
}
/**
* @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));
}
}
"
},
"lib/openzeppelin-contracts/contracts/utils/introspection/ERC165.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.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 ERC-165 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;
}
}
"
},
"lib/openzeppelin-contracts/contracts/interfaces/draft-IERC6093.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC-20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 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 ERC-721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-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 ERC-1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 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);
}
"
},
"lib/openzeppelin-contracts/contracts/interfaces/IERC4906.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC4906.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
import {IERC721} from "./IERC721.sol";
/// @title ERC-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 _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 _fromTokenId, uint256 _toTokenId);
}
"
},
"lib/openzeppelin-contracts/contracts/interfaces/IERC165.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";
"
},
"lib/openzeppelin-contracts/contracts/token/common/ERC2981.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/common/ERC2981.sol)
pragma solidity ^0.8.20;
import {IERC2981} from "../../interfaces/IERC2981.sol";
import {IERC165, ERC165} from "../../utils/introspection/ERC165.sol";
/**
* @dev Implementation of the NFT Royalty Standard, a standardized way to retrieve royalty payment information.
*
* Royalty information can be specified globally for all token ids via {_setDefaultRoyalty}, and/or individually for
* specific token ids via {_setTokenRoyalty}. The latter takes precedence over the first.
*
* Royalty is specified as a fraction of sale price. {_feeDenominator} is overridable but defaults to 10000, meaning the
* fee is specified in basis points by default.
*
* IMPORTANT: ERC-2981 only specifies a way to signal royalty information and does not enforce its payment. See
* https://eips.ethereum.org/EIPS/eip-2981#optional-royalty-payments[Rationale] in the ERC. Marketplaces are expected to
* voluntarily pay royalties together with sales, but note that this standard is not yet widely supported.
*/
abstract contract ERC2981 is IERC2981, ERC165 {
struct RoyaltyInfo {
address receiver;
uint96 royaltyFraction;
}
RoyaltyInfo private _defaultRoyaltyInfo;
mapping(uint256 tokenId => RoyaltyInfo) private _tokenRoyaltyInfo;
/**
* @dev The default royalty set is invalid (eg. (numerator / denominator) >= 1).
*/
error ERC2981InvalidDefaultRoyalty(uint256 numerator, uint256 denominator);
/**
* @dev The default royalty receiver is invalid.
*/
error ERC2981InvalidDefaultRoyaltyReceiver(address receiver);
/**
* @dev The royalty set
Submitted on: 2025-11-05 17:28:07
Comments
Log in to comment.
No comments yet.