|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +pragma solidity ^0.8.0; |
| 3 | + |
| 4 | +/** |
| 5 | + @title ERC-1155 Multi Token Standard |
| 6 | + @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1155.md |
| 7 | + Note: The ERC-165 identifier for this interface is 0xd9b67a26. |
| 8 | + */ |
| 9 | +/* is ERC165 */ |
| 10 | +interface IERC1155 { |
| 11 | + /** |
| 12 | + @dev Either `TransferSingle` or `TransferBatch` MUST emit when tokens are transferred, including zero value transfers as well as minting or burning (see "Safe Transfer Rules" section of the standard). |
| 13 | + The `_operator` argument MUST be msg.sender. |
| 14 | + The `_from` argument MUST be the address of the holder whose balance is decreased. |
| 15 | + The `_to` argument MUST be the address of the recipient whose balance is increased. |
| 16 | + The `_id` argument MUST be the token type being transferred. |
| 17 | + The `_value` argument MUST be the number of tokens the holder balance is decreased by and match what the recipient balance is increased by. |
| 18 | + When minting/creating tokens, the `_from` argument MUST be set to `0x0` (i.e. zero address). |
| 19 | + When burning/destroying tokens, the `_to` argument MUST be set to `0x0` (i.e. zero address). |
| 20 | + */ |
| 21 | + event TransferSingle( |
| 22 | + address indexed _operator, |
| 23 | + address indexed _from, |
| 24 | + address indexed _to, |
| 25 | + uint256 _id, |
| 26 | + uint256 _value |
| 27 | + ); |
| 28 | + |
| 29 | + /** |
| 30 | + @dev Either `TransferSingle` or `TransferBatch` MUST emit when tokens are transferred, including zero value transfers as well as minting or burning (see "Safe Transfer Rules" section of the standard). |
| 31 | + The `_operator` argument MUST be msg.sender. |
| 32 | + The `_from` argument MUST be the address of the holder whose balance is decreased. |
| 33 | + The `_to` argument MUST be the address of the recipient whose balance is increased. |
| 34 | + The `_ids` argument MUST be the list of tokens being transferred. |
| 35 | + The `_values` argument MUST be the list of number of tokens (matching the list and order of tokens specified in _ids) the holder balance is decreased by and match what the recipient balance is increased by. |
| 36 | + When minting/creating tokens, the `_from` argument MUST be set to `0x0` (i.e. zero address). |
| 37 | + When burning/destroying tokens, the `_to` argument MUST be set to `0x0` (i.e. zero address). |
| 38 | + */ |
| 39 | + event TransferBatch( |
| 40 | + address indexed _operator, |
| 41 | + address indexed _from, |
| 42 | + address indexed _to, |
| 43 | + uint256[] _ids, |
| 44 | + uint256[] _values |
| 45 | + ); |
| 46 | + |
| 47 | + /** |
| 48 | + @dev MUST emit when approval for a second party/operator address to manage all tokens for an owner address is enabled or disabled (absense of an event assumes disabled). |
| 49 | + */ |
| 50 | + event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved); |
| 51 | + |
| 52 | + /** |
| 53 | + @dev MUST emit when the URI is updated for a token ID. |
| 54 | + URIs are defined in RFC 3986. |
| 55 | + The URI MUST point a JSON file that conforms to the "ERC-1155 Metadata URI JSON Schema". |
| 56 | + */ |
| 57 | + event URI(string _value, uint256 indexed _id); |
| 58 | + |
| 59 | + /** |
| 60 | + @notice Transfers `_value` amount of an `_id` from the `_from` address to the `_to` address specified (with safety call). |
| 61 | + @dev Caller must be approved to manage the tokens being transferred out of the `_from` account (see "Approval" section of the standard). |
| 62 | + MUST revert if `_to` is the zero address. |
| 63 | + MUST revert if balance of holder for token `_id` is lower than the `_value` sent. |
| 64 | + MUST revert on any other error. |
| 65 | + MUST emit the `TransferSingle` event to reflect the balance change (see "Safe Transfer Rules" section of the standard). |
| 66 | + After the above conditions are met, this function MUST check if `_to` is a smart contract (e.g. code size > 0). If so, it MUST call `onERC1155Received` on `_to` and act appropriately (see "Safe Transfer Rules" section of the standard). |
| 67 | + @param _from Source address |
| 68 | + @param _to Target address |
| 69 | + @param _id ID of the token type |
| 70 | + @param _value Transfer amount |
| 71 | + @param _data Additional data with no specified format, MUST be sent unaltered in call to `onERC1155Received` on `_to` |
| 72 | + */ |
| 73 | + function safeTransferFrom( |
| 74 | + address _from, |
| 75 | + address _to, |
| 76 | + uint256 _id, |
| 77 | + uint256 _value, |
| 78 | + bytes calldata _data |
| 79 | + ) external; |
| 80 | + |
| 81 | + /** |
| 82 | + @notice Transfers `_values` amount(s) of `_ids` from the `_from` address to the `_to` address specified (with safety call). |
| 83 | + @dev Caller must be approved to manage the tokens being transferred out of the `_from` account (see "Approval" section of the standard). |
| 84 | + MUST revert if `_to` is the zero address. |
| 85 | + MUST revert if length of `_ids` is not the same as length of `_values`. |
| 86 | + MUST revert if any of the balance(s) of the holder(s) for token(s) in `_ids` is lower than the respective amount(s) in `_values` sent to the recipient. |
| 87 | + MUST revert on any other error. |
| 88 | + MUST emit `TransferSingle` or `TransferBatch` event(s) such that all the balance changes are reflected (see "Safe Transfer Rules" section of the standard). |
| 89 | + Balance changes and events MUST follow the ordering of the arrays (_ids[0]/_values[0] before _ids[1]/_values[1], etc). |
| 90 | + After the above conditions for the transfer(s) in the batch are met, this function MUST check if `_to` is a smart contract (e.g. code size > 0). If so, it MUST call the relevant `ERC1155TokenReceiver` hook(s) on `_to` and act appropriately (see "Safe Transfer Rules" section of the standard). |
| 91 | + @param _from Source address |
| 92 | + @param _to Target address |
| 93 | + @param _ids IDs of each token type (order and length must match _values array) |
| 94 | + @param _values Transfer amounts per token type (order and length must match _ids array) |
| 95 | + @param _data Additional data with no specified format, MUST be sent unaltered in call to the `ERC1155TokenReceiver` hook(s) on `_to` |
| 96 | + */ |
| 97 | + function safeBatchTransferFrom( |
| 98 | + address _from, |
| 99 | + address _to, |
| 100 | + uint256[] calldata _ids, |
| 101 | + uint256[] calldata _values, |
| 102 | + bytes calldata _data |
| 103 | + ) external; |
| 104 | + |
| 105 | + /** |
| 106 | + @notice Get the balance of an account's Tokens. |
| 107 | + @param _owner The address of the token holder |
| 108 | + @param _id ID of the Token |
| 109 | + @return The _owner's balance of the Token type requested |
| 110 | + */ |
| 111 | + function balanceOf(address _owner, uint256 _id) external view returns (uint256); |
| 112 | + |
| 113 | + /** |
| 114 | + @notice Get the balance of multiple account/token pairs |
| 115 | + @param _owners The addresses of the token holders |
| 116 | + @param _ids ID of the Tokens |
| 117 | + @return The _owner's balance of the Token types requested (i.e. balance for each (owner, id) pair) |
| 118 | + */ |
| 119 | + function balanceOfBatch(address[] calldata _owners, uint256[] calldata _ids) |
| 120 | + external |
| 121 | + view |
| 122 | + returns (uint256[] memory); |
| 123 | + |
| 124 | + /** |
| 125 | + @notice Enable or disable approval for a third party ("operator") to manage all of the caller's tokens. |
| 126 | + @dev MUST emit the ApprovalForAll event on success. |
| 127 | + @param _operator Address to add to the set of authorized operators |
| 128 | + @param _approved True if the operator is approved, false to revoke approval |
| 129 | + */ |
| 130 | + function setApprovalForAll(address _operator, bool _approved) external; |
| 131 | + |
| 132 | + /** |
| 133 | + @notice Queries the approval status of an operator for a given owner. |
| 134 | + @param _owner The owner of the Tokens |
| 135 | + @param _operator Address of authorized operator |
| 136 | + @return True if the operator is approved, false if not |
| 137 | + */ |
| 138 | + function isApprovedForAll(address _owner, address _operator) external view returns (bool); |
| 139 | +} |
0 commit comments