|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity >=0.8.30; |
| 3 | + |
| 4 | +/// @title ERC-1155 Multi Token Standard Interface |
| 5 | +/// @notice Interface for ERC-1155 token contracts with custom errors |
| 6 | +/// @dev This interface includes all custom errors used by ERC-1155 implementations (ERC-6093) |
| 7 | +interface IERC1155 { |
| 8 | + /// @notice Error indicating insufficient balance for a transfer. |
| 9 | + /// @param _sender Address attempting the transfer. |
| 10 | + /// @param _balance Current balance of the sender. |
| 11 | + /// @param _needed Amount required to complete the operation. |
| 12 | + /// @param _tokenId The token ID involved. |
| 13 | + error ERC1155InsufficientBalance(address _sender, uint256 _balance, uint256 _needed, uint256 _tokenId); |
| 14 | + |
| 15 | + /// @notice Error indicating the sender address is invalid. |
| 16 | + /// @param _sender Invalid sender address. |
| 17 | + error ERC1155InvalidSender(address _sender); |
| 18 | + |
| 19 | + /// @notice Error indicating the receiver address is invalid. |
| 20 | + /// @param _receiver Invalid receiver address. |
| 21 | + error ERC1155InvalidReceiver(address _receiver); |
| 22 | + |
| 23 | + /// @notice Error indicating missing approval for an operator. |
| 24 | + /// @param _operator Address attempting the operation. |
| 25 | + /// @param _owner The token owner. |
| 26 | + error ERC1155MissingApprovalForAll(address _operator, address _owner); |
| 27 | + |
| 28 | + /// @notice Error indicating the approver address is invalid. |
| 29 | + /// @param _approver Invalid approver address. |
| 30 | + error ERC1155InvalidApprover(address _approver); |
| 31 | + |
| 32 | + /// @notice Error indicating the operator address is invalid. |
| 33 | + /// @param _operator Invalid operator address. |
| 34 | + error ERC1155InvalidOperator(address _operator); |
| 35 | + |
| 36 | + /// @notice Error indicating array length mismatch in batch operations. |
| 37 | + /// @param _idsLength Length of the ids array. |
| 38 | + /// @param _valuesLength Length of the values array. |
| 39 | + error ERC1155InvalidArrayLength(uint256 _idsLength, uint256 _valuesLength); |
| 40 | + /// @notice Emitted when `value` amount of tokens of type `id` are transferred from `from` to `to` by `operator`. |
| 41 | + /// @param _operator The address which initiated the transfer. |
| 42 | + /// @param _from The address which previously owned the token. |
| 43 | + /// @param _to The address which now owns the token. |
| 44 | + /// @param _id The token type being transferred. |
| 45 | + /// @param _value The amount of tokens transferred. |
| 46 | + |
| 47 | + event TransferSingle( |
| 48 | + address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _value |
| 49 | + ); |
| 50 | + |
| 51 | + /// @notice Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all transfers. |
| 52 | + /// @param _operator The address which initiated the batch transfer. |
| 53 | + /// @param _from The address which previously owned the tokens. |
| 54 | + /// @param _to The address which now owns the tokens. |
| 55 | + /// @param _ids The token types being transferred. |
| 56 | + /// @param _values The amounts of tokens transferred. |
| 57 | + event TransferBatch( |
| 58 | + address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _values |
| 59 | + ); |
| 60 | + |
| 61 | + /// @notice Emitted when `account` grants or revokes permission to `operator` to transfer their tokens. |
| 62 | + /// @param _account The token owner granting/revoking approval. |
| 63 | + /// @param _operator The address being approved/revoked. |
| 64 | + /// @param _approved True if approval is granted, false if revoked. |
| 65 | + event ApprovalForAll(address indexed _account, address indexed _operator, bool _approved); |
| 66 | + |
| 67 | + /// @notice Emitted when the URI for token type `id` changes to `value`. |
| 68 | + /// @param _value The new URI for the token type. |
| 69 | + /// @param _id The token type whose URI changed. |
| 70 | + event URI(string _value, uint256 indexed _id); |
| 71 | + |
| 72 | + /// @notice Returns the amount of tokens of token type `id` owned by `account`. |
| 73 | + /// @param _account The address to query the balance of. |
| 74 | + /// @param _id The token type to query. |
| 75 | + /// @return The balance of the token type. |
| 76 | + function balanceOf(address _account, uint256 _id) external view returns (uint256); |
| 77 | + |
| 78 | + /// @notice Batched version of {balanceOf}. |
| 79 | + /// @param _accounts The addresses to query the balances of (order and length must match _ids array). |
| 80 | + /// @param _ids The token types to query (order and length must match _accounts array). |
| 81 | + /// @return The balances of the token types. |
| 82 | + function balanceOfBatch(address[] calldata _accounts, uint256[] calldata _ids) |
| 83 | + external |
| 84 | + view |
| 85 | + returns (uint256[] memory); |
| 86 | + |
| 87 | + /// @notice Grants or revokes permission to `operator` to transfer the caller's tokens. |
| 88 | + /// @param _operator The address to grant/revoke approval to. |
| 89 | + /// @param _approved True to approve, false to revoke. |
| 90 | + function setApprovalForAll(address _operator, bool _approved) external; |
| 91 | + |
| 92 | + /// @notice Returns true if `operator` is approved to transfer `account`'s tokens. |
| 93 | + /// @param _account The token owner. |
| 94 | + /// @param _operator The operator to query. |
| 95 | + /// @return True if the operator is approved, false otherwise. |
| 96 | + function isApprovedForAll(address _account, address _operator) external view returns (bool); |
| 97 | + |
| 98 | + /// @notice Transfers `value` amount of token type `id` from `from` to `to`. |
| 99 | + /// @param _from The address to transfer from. |
| 100 | + /// @param _to The address to transfer to. |
| 101 | + /// @param _id The token type to transfer. |
| 102 | + /// @param _value The amount to transfer. |
| 103 | + /// @param _data Additional data with no specified format. |
| 104 | + function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _value, bytes calldata _data) external; |
| 105 | + |
| 106 | + /// @notice Batched version of {safeTransferFrom}. |
| 107 | + /// @param _from The address to transfer from. |
| 108 | + /// @param _to The address to transfer to. |
| 109 | + /// @param _ids The token types to transfer (order and length must match _values array). |
| 110 | + /// @param _values The amounts to transfer (order and length must match _ids array). |
| 111 | + /// @param _data Additional data with no specified format. |
| 112 | + function safeBatchTransferFrom( |
| 113 | + address _from, |
| 114 | + address _to, |
| 115 | + uint256[] calldata _ids, |
| 116 | + uint256[] calldata _values, |
| 117 | + bytes calldata _data |
| 118 | + ) external; |
| 119 | + |
| 120 | + /// @notice Returns the URI for token type `id`. |
| 121 | + /// @param _id The token type to query. |
| 122 | + /// @return The URI for the token type. |
| 123 | + function uri(uint256 _id) external view returns (string memory); |
| 124 | +} |
0 commit comments