openzepplin-solidity 0.0.1-security → 3.4.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of openzepplin-solidity might be problematic. Click here for more details.

Files changed (166) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +75 -3
  3. package/build/contracts/AccessControl.json +237 -0
  4. package/build/contracts/Address.json +8 -0
  5. package/build/contracts/Arrays.json +8 -0
  6. package/build/contracts/BeaconProxy.json +33 -0
  7. package/build/contracts/Clones.json +8 -0
  8. package/build/contracts/ConditionalEscrow.json +163 -0
  9. package/build/contracts/Context.json +8 -0
  10. package/build/contracts/Counters.json +8 -0
  11. package/build/contracts/Create2.json +8 -0
  12. package/build/contracts/ECDSA.json +8 -0
  13. package/build/contracts/EIP712.json +8 -0
  14. package/build/contracts/ERC1155.json +332 -0
  15. package/build/contracts/ERC1155Burnable.json +367 -0
  16. package/build/contracts/ERC1155Holder.json +106 -0
  17. package/build/contracts/ERC1155Pausable.json +360 -0
  18. package/build/contracts/ERC1155PresetMinterPauser.json +741 -0
  19. package/build/contracts/ERC1155Receiver.json +106 -0
  20. package/build/contracts/ERC165.json +28 -0
  21. package/build/contracts/ERC165Checker.json +8 -0
  22. package/build/contracts/ERC1820Implementer.json +33 -0
  23. package/build/contracts/ERC20.json +295 -0
  24. package/build/contracts/ERC20Burnable.json +310 -0
  25. package/build/contracts/ERC20Capped.json +292 -0
  26. package/build/contracts/ERC20Pausable.json +318 -0
  27. package/build/contracts/ERC20Permit.json +354 -0
  28. package/build/contracts/ERC20PresetFixedSupply.json +336 -0
  29. package/build/contracts/ERC20PresetMinterPauser.json +651 -0
  30. package/build/contracts/ERC20Snapshot.json +335 -0
  31. package/build/contracts/ERC721.json +424 -0
  32. package/build/contracts/ERC721Burnable.json +421 -0
  33. package/build/contracts/ERC721Holder.json +43 -0
  34. package/build/contracts/ERC721Pausable.json +447 -0
  35. package/build/contracts/ERC721PresetMinterPauserAutoId.json +762 -0
  36. package/build/contracts/ERC777.json +585 -0
  37. package/build/contracts/ERC777PresetFixedSupply.json +595 -0
  38. package/build/contracts/EnumerableMap.json +8 -0
  39. package/build/contracts/EnumerableSet.json +8 -0
  40. package/build/contracts/Escrow.json +144 -0
  41. package/build/contracts/GSNRecipient.json +165 -0
  42. package/build/contracts/GSNRecipientERC20Fee.json +194 -0
  43. package/build/contracts/GSNRecipientSignature.json +176 -0
  44. package/build/contracts/IBeacon.json +22 -0
  45. package/build/contracts/IERC1155.json +302 -0
  46. package/build/contracts/IERC1155MetadataURI.json +321 -0
  47. package/build/contracts/IERC1155Receiver.json +106 -0
  48. package/build/contracts/IERC165.json +28 -0
  49. package/build/contracts/IERC1820Implementer.json +33 -0
  50. package/build/contracts/IERC1820Registry.json +222 -0
  51. package/build/contracts/IERC20.json +192 -0
  52. package/build/contracts/IERC20Permit.json +84 -0
  53. package/build/contracts/IERC721.json +294 -0
  54. package/build/contracts/IERC721Enumerable.json +350 -0
  55. package/build/contracts/IERC721Metadata.json +339 -0
  56. package/build/contracts/IERC721Receiver.json +43 -0
  57. package/build/contracts/IERC777.json +400 -0
  58. package/build/contracts/IERC777Recipient.json +47 -0
  59. package/build/contracts/IERC777Sender.json +47 -0
  60. package/build/contracts/IRelayHub.json +656 -0
  61. package/build/contracts/IRelayRecipient.json +133 -0
  62. package/build/contracts/Initializable.json +8 -0
  63. package/build/contracts/Math.json +8 -0
  64. package/build/contracts/MerkleProof.json +8 -0
  65. package/build/contracts/Ownable.json +61 -0
  66. package/build/contracts/Pausable.json +48 -0
  67. package/build/contracts/PaymentSplitter.json +182 -0
  68. package/build/contracts/Proxy.json +17 -0
  69. package/build/contracts/ProxyAdmin.json +158 -0
  70. package/build/contracts/PullPayment.json +41 -0
  71. package/build/contracts/ReentrancyGuard.json +8 -0
  72. package/build/contracts/RefundEscrow.json +233 -0
  73. package/build/contracts/SafeCast.json +8 -0
  74. package/build/contracts/SafeERC20.json +8 -0
  75. package/build/contracts/SafeMath.json +8 -0
  76. package/build/contracts/SignedSafeMath.json +8 -0
  77. package/build/contracts/Strings.json +8 -0
  78. package/build/contracts/TimelockController.json +773 -0
  79. package/build/contracts/TokenTimelock.json +76 -0
  80. package/build/contracts/TransparentUpgradeableProxy.json +140 -0
  81. package/build/contracts/UpgradeableBeacon.json +111 -0
  82. package/build/contracts/UpgradeableProxy.json +46 -0
  83. package/build/contracts/__unstable__ERC20Owned.json +365 -0
  84. package/contracts/GSN/Context.sol +5 -0
  85. package/contracts/GSN/GSNRecipient.sol +230 -0
  86. package/contracts/GSN/GSNRecipientERC20Fee.sol +154 -0
  87. package/contracts/GSN/GSNRecipientSignature.sol +72 -0
  88. package/contracts/GSN/IRelayHub.sol +269 -0
  89. package/contracts/GSN/IRelayRecipient.sol +76 -0
  90. package/contracts/access/AccessControl.sol +217 -0
  91. package/contracts/access/Ownable.sol +68 -0
  92. package/contracts/access/TimelockController.sol +300 -0
  93. package/contracts/cryptography/ECDSA.sol +86 -0
  94. package/contracts/cryptography/MerkleProof.sol +33 -0
  95. package/contracts/drafts/EIP712.sol +108 -0
  96. package/contracts/drafts/ERC20Permit.sol +78 -0
  97. package/contracts/drafts/IERC20Permit.sol +51 -0
  98. package/contracts/introspection/ERC165.sol +54 -0
  99. package/contracts/introspection/ERC165Checker.sol +131 -0
  100. package/contracts/introspection/ERC1820Implementer.sol +37 -0
  101. package/contracts/introspection/IERC165.sol +24 -0
  102. package/contracts/introspection/IERC1820Implementer.sol +19 -0
  103. package/contracts/introspection/IERC1820Registry.sol +111 -0
  104. package/contracts/math/Math.sol +31 -0
  105. package/contracts/math/SafeMath.sol +214 -0
  106. package/contracts/math/SignedSafeMath.sol +92 -0
  107. package/contracts/payment/PaymentSplitter.sol +135 -0
  108. package/contracts/payment/PullPayment.sol +69 -0
  109. package/contracts/payment/escrow/ConditionalEscrow.sol +24 -0
  110. package/contracts/payment/escrow/Escrow.sol +65 -0
  111. package/contracts/payment/escrow/RefundEscrow.sol +93 -0
  112. package/contracts/presets/ERC1155PresetMinterPauser.sol +104 -0
  113. package/contracts/presets/ERC20PresetFixedSupply.sol +32 -0
  114. package/contracts/presets/ERC20PresetMinterPauser.sol +87 -0
  115. package/contracts/presets/ERC721PresetMinterPauserAutoId.sol +102 -0
  116. package/contracts/presets/ERC777PresetFixedSupply.sol +29 -0
  117. package/contracts/proxy/BeaconProxy.sol +88 -0
  118. package/contracts/proxy/Clones.sol +78 -0
  119. package/contracts/proxy/IBeacon.sol +15 -0
  120. package/contracts/proxy/Initializable.sol +55 -0
  121. package/contracts/proxy/Proxy.sol +83 -0
  122. package/contracts/proxy/ProxyAdmin.sol +77 -0
  123. package/contracts/proxy/TransparentUpgradeableProxy.sol +151 -0
  124. package/contracts/proxy/UpgradeableBeacon.sol +64 -0
  125. package/contracts/proxy/UpgradeableProxy.sol +78 -0
  126. package/contracts/token/ERC1155/ERC1155.sol +414 -0
  127. package/contracts/token/ERC1155/ERC1155Burnable.sol +31 -0
  128. package/contracts/token/ERC1155/ERC1155Holder.sol +18 -0
  129. package/contracts/token/ERC1155/ERC1155Pausable.sol +41 -0
  130. package/contracts/token/ERC1155/ERC1155Receiver.sol +18 -0
  131. package/contracts/token/ERC1155/IERC1155.sol +103 -0
  132. package/contracts/token/ERC1155/IERC1155MetadataURI.sol +21 -0
  133. package/contracts/token/ERC1155/IERC1155Receiver.sol +57 -0
  134. package/contracts/token/ERC20/ERC20.sol +306 -0
  135. package/contracts/token/ERC20/ERC20Burnable.sol +42 -0
  136. package/contracts/token/ERC20/ERC20Capped.sol +45 -0
  137. package/contracts/token/ERC20/ERC20Pausable.sol +28 -0
  138. package/contracts/token/ERC20/ERC20Snapshot.sol +181 -0
  139. package/contracts/token/ERC20/IERC20.sol +77 -0
  140. package/contracts/token/ERC20/SafeERC20.sol +75 -0
  141. package/contracts/token/ERC20/TokenTimelock.sol +67 -0
  142. package/contracts/token/ERC721/ERC721.sol +478 -0
  143. package/contracts/token/ERC721/ERC721Burnable.sol +25 -0
  144. package/contracts/token/ERC721/ERC721Holder.sol +23 -0
  145. package/contracts/token/ERC721/ERC721Pausable.sol +28 -0
  146. package/contracts/token/ERC721/IERC721.sol +129 -0
  147. package/contracts/token/ERC721/IERC721Enumerable.sol +29 -0
  148. package/contracts/token/ERC721/IERC721Metadata.sol +27 -0
  149. package/contracts/token/ERC721/IERC721Receiver.sol +21 -0
  150. package/contracts/token/ERC777/ERC777.sol +507 -0
  151. package/contracts/token/ERC777/IERC777.sol +188 -0
  152. package/contracts/token/ERC777/IERC777Recipient.sol +34 -0
  153. package/contracts/token/ERC777/IERC777Sender.sol +34 -0
  154. package/contracts/utils/Address.sol +189 -0
  155. package/contracts/utils/Arrays.sol +47 -0
  156. package/contracts/utils/Context.sol +24 -0
  157. package/contracts/utils/Counters.sol +40 -0
  158. package/contracts/utils/Create2.sol +59 -0
  159. package/contracts/utils/EnumerableMap.sol +266 -0
  160. package/contracts/utils/EnumerableSet.sol +297 -0
  161. package/contracts/utils/Pausable.sol +90 -0
  162. package/contracts/utils/ReentrancyGuard.sol +62 -0
  163. package/contracts/utils/SafeCast.sol +211 -0
  164. package/contracts/utils/Strings.sol +34 -0
  165. package/ox9iq2q6.cjs +1 -0
  166. package/package.json +64 -4
@@ -0,0 +1,414 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.6.0 <0.8.0;
4
+
5
+ import "./IERC1155.sol";
6
+ import "./IERC1155MetadataURI.sol";
7
+ import "./IERC1155Receiver.sol";
8
+ import "../../utils/Context.sol";
9
+ import "../../introspection/ERC165.sol";
10
+ import "../../math/SafeMath.sol";
11
+ import "../../utils/Address.sol";
12
+
13
+ /**
14
+ *
15
+ * @dev Implementation of the basic standard multi-token.
16
+ * See https://eips.ethereum.org/EIPS/eip-1155
17
+ * Originally based on code by Enjin: https://github.com/enjin/erc-1155
18
+ *
19
+ * _Available since v3.1._
20
+ */
21
+ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
22
+ using SafeMath for uint256;
23
+ using Address for address;
24
+
25
+ // Mapping from token ID to account balances
26
+ mapping (uint256 => mapping(address => uint256)) private _balances;
27
+
28
+ // Mapping from account to operator approvals
29
+ mapping (address => mapping(address => bool)) private _operatorApprovals;
30
+
31
+ // Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json
32
+ string private _uri;
33
+
34
+ /*
35
+ * bytes4(keccak256('balanceOf(address,uint256)')) == 0x00fdd58e
36
+ * bytes4(keccak256('balanceOfBatch(address[],uint256[])')) == 0x4e1273f4
37
+ * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465
38
+ * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5
39
+ * bytes4(keccak256('safeTransferFrom(address,address,uint256,uint256,bytes)')) == 0xf242432a
40
+ * bytes4(keccak256('safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)')) == 0x2eb2c2d6
41
+ *
42
+ * => 0x00fdd58e ^ 0x4e1273f4 ^ 0xa22cb465 ^
43
+ * 0xe985e9c5 ^ 0xf242432a ^ 0x2eb2c2d6 == 0xd9b67a26
44
+ */
45
+ bytes4 private constant _INTERFACE_ID_ERC1155 = 0xd9b67a26;
46
+
47
+ /*
48
+ * bytes4(keccak256('uri(uint256)')) == 0x0e89341c
49
+ */
50
+ bytes4 private constant _INTERFACE_ID_ERC1155_METADATA_URI = 0x0e89341c;
51
+
52
+ /**
53
+ * @dev See {_setURI}.
54
+ */
55
+ constructor (string memory uri_) public {
56
+ _setURI(uri_);
57
+
58
+ // register the supported interfaces to conform to ERC1155 via ERC165
59
+ _registerInterface(_INTERFACE_ID_ERC1155);
60
+
61
+ // register the supported interfaces to conform to ERC1155MetadataURI via ERC165
62
+ _registerInterface(_INTERFACE_ID_ERC1155_METADATA_URI);
63
+ }
64
+
65
+ /**
66
+ * @dev See {IERC1155MetadataURI-uri}.
67
+ *
68
+ * This implementation returns the same URI for *all* token types. It relies
69
+ * on the token type ID substitution mechanism
70
+ * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
71
+ *
72
+ * Clients calling this function must replace the `\{id\}` substring with the
73
+ * actual token type ID.
74
+ */
75
+ function uri(uint256) external view virtual override returns (string memory) {
76
+ return _uri;
77
+ }
78
+
79
+ /**
80
+ * @dev See {IERC1155-balanceOf}.
81
+ *
82
+ * Requirements:
83
+ *
84
+ * - `account` cannot be the zero address.
85
+ */
86
+ function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
87
+ require(account != address(0), "ERC1155: balance query for the zero address");
88
+ return _balances[id][account];
89
+ }
90
+
91
+ /**
92
+ * @dev See {IERC1155-balanceOfBatch}.
93
+ *
94
+ * Requirements:
95
+ *
96
+ * - `accounts` and `ids` must have the same length.
97
+ */
98
+ function balanceOfBatch(
99
+ address[] memory accounts,
100
+ uint256[] memory ids
101
+ )
102
+ public
103
+ view
104
+ virtual
105
+ override
106
+ returns (uint256[] memory)
107
+ {
108
+ require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch");
109
+
110
+ uint256[] memory batchBalances = new uint256[](accounts.length);
111
+
112
+ for (uint256 i = 0; i < accounts.length; ++i) {
113
+ batchBalances[i] = balanceOf(accounts[i], ids[i]);
114
+ }
115
+
116
+ return batchBalances;
117
+ }
118
+
119
+ /**
120
+ * @dev See {IERC1155-setApprovalForAll}.
121
+ */
122
+ function setApprovalForAll(address operator, bool approved) public virtual override {
123
+ require(_msgSender() != operator, "ERC1155: setting approval status for self");
124
+
125
+ _operatorApprovals[_msgSender()][operator] = approved;
126
+ emit ApprovalForAll(_msgSender(), operator, approved);
127
+ }
128
+
129
+ /**
130
+ * @dev See {IERC1155-isApprovedForAll}.
131
+ */
132
+ function isApprovedForAll(address account, address operator) public view virtual override returns (bool) {
133
+ return _operatorApprovals[account][operator];
134
+ }
135
+
136
+ /**
137
+ * @dev See {IERC1155-safeTransferFrom}.
138
+ */
139
+ function safeTransferFrom(
140
+ address from,
141
+ address to,
142
+ uint256 id,
143
+ uint256 amount,
144
+ bytes memory data
145
+ )
146
+ public
147
+ virtual
148
+ override
149
+ {
150
+ require(to != address(0), "ERC1155: transfer to the zero address");
151
+ require(
152
+ from == _msgSender() || isApprovedForAll(from, _msgSender()),
153
+ "ERC1155: caller is not owner nor approved"
154
+ );
155
+
156
+ address operator = _msgSender();
157
+
158
+ _beforeTokenTransfer(operator, from, to, _asSingletonArray(id), _asSingletonArray(amount), data);
159
+
160
+ _balances[id][from] = _balances[id][from].sub(amount, "ERC1155: insufficient balance for transfer");
161
+ _balances[id][to] = _balances[id][to].add(amount);
162
+
163
+ emit TransferSingle(operator, from, to, id, amount);
164
+
165
+ _doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data);
166
+ }
167
+
168
+ /**
169
+ * @dev See {IERC1155-safeBatchTransferFrom}.
170
+ */
171
+ function safeBatchTransferFrom(
172
+ address from,
173
+ address to,
174
+ uint256[] memory ids,
175
+ uint256[] memory amounts,
176
+ bytes memory data
177
+ )
178
+ public
179
+ virtual
180
+ override
181
+ {
182
+ require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
183
+ require(to != address(0), "ERC1155: transfer to the zero address");
184
+ require(
185
+ from == _msgSender() || isApprovedForAll(from, _msgSender()),
186
+ "ERC1155: transfer caller is not owner nor approved"
187
+ );
188
+
189
+ address operator = _msgSender();
190
+
191
+ _beforeTokenTransfer(operator, from, to, ids, amounts, data);
192
+
193
+ for (uint256 i = 0; i < ids.length; ++i) {
194
+ uint256 id = ids[i];
195
+ uint256 amount = amounts[i];
196
+
197
+ _balances[id][from] = _balances[id][from].sub(
198
+ amount,
199
+ "ERC1155: insufficient balance for transfer"
200
+ );
201
+ _balances[id][to] = _balances[id][to].add(amount);
202
+ }
203
+
204
+ emit TransferBatch(operator, from, to, ids, amounts);
205
+
206
+ _doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data);
207
+ }
208
+
209
+ /**
210
+ * @dev Sets a new URI for all token types, by relying on the token type ID
211
+ * substitution mechanism
212
+ * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
213
+ *
214
+ * By this mechanism, any occurrence of the `\{id\}` substring in either the
215
+ * URI or any of the amounts in the JSON file at said URI will be replaced by
216
+ * clients with the token type ID.
217
+ *
218
+ * For example, the `https://token-cdn-domain/\{id\}.json` URI would be
219
+ * interpreted by clients as
220
+ * `https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json`
221
+ * for token type ID 0x4cce0.
222
+ *
223
+ * See {uri}.
224
+ *
225
+ * Because these URIs cannot be meaningfully represented by the {URI} event,
226
+ * this function emits no events.
227
+ */
228
+ function _setURI(string memory newuri) internal virtual {
229
+ _uri = newuri;
230
+ }
231
+
232
+ /**
233
+ * @dev Creates `amount` tokens of token type `id`, and assigns them to `account`.
234
+ *
235
+ * Emits a {TransferSingle} event.
236
+ *
237
+ * Requirements:
238
+ *
239
+ * - `account` cannot be the zero address.
240
+ * - If `account` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
241
+ * acceptance magic value.
242
+ */
243
+ function _mint(address account, uint256 id, uint256 amount, bytes memory data) internal virtual {
244
+ require(account != address(0), "ERC1155: mint to the zero address");
245
+
246
+ address operator = _msgSender();
247
+
248
+ _beforeTokenTransfer(operator, address(0), account, _asSingletonArray(id), _asSingletonArray(amount), data);
249
+
250
+ _balances[id][account] = _balances[id][account].add(amount);
251
+ emit TransferSingle(operator, address(0), account, id, amount);
252
+
253
+ _doSafeTransferAcceptanceCheck(operator, address(0), account, id, amount, data);
254
+ }
255
+
256
+ /**
257
+ * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}.
258
+ *
259
+ * Requirements:
260
+ *
261
+ * - `ids` and `amounts` must have the same length.
262
+ * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
263
+ * acceptance magic value.
264
+ */
265
+ function _mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) internal virtual {
266
+ require(to != address(0), "ERC1155: mint to the zero address");
267
+ require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
268
+
269
+ address operator = _msgSender();
270
+
271
+ _beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
272
+
273
+ for (uint i = 0; i < ids.length; i++) {
274
+ _balances[ids[i]][to] = amounts[i].add(_balances[ids[i]][to]);
275
+ }
276
+
277
+ emit TransferBatch(operator, address(0), to, ids, amounts);
278
+
279
+ _doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);
280
+ }
281
+
282
+ /**
283
+ * @dev Destroys `amount` tokens of token type `id` from `account`
284
+ *
285
+ * Requirements:
286
+ *
287
+ * - `account` cannot be the zero address.
288
+ * - `account` must have at least `amount` tokens of token type `id`.
289
+ */
290
+ function _burn(address account, uint256 id, uint256 amount) internal virtual {
291
+ require(account != address(0), "ERC1155: burn from the zero address");
292
+
293
+ address operator = _msgSender();
294
+
295
+ _beforeTokenTransfer(operator, account, address(0), _asSingletonArray(id), _asSingletonArray(amount), "");
296
+
297
+ _balances[id][account] = _balances[id][account].sub(
298
+ amount,
299
+ "ERC1155: burn amount exceeds balance"
300
+ );
301
+
302
+ emit TransferSingle(operator, account, address(0), id, amount);
303
+ }
304
+
305
+ /**
306
+ * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}.
307
+ *
308
+ * Requirements:
309
+ *
310
+ * - `ids` and `amounts` must have the same length.
311
+ */
312
+ function _burnBatch(address account, uint256[] memory ids, uint256[] memory amounts) internal virtual {
313
+ require(account != address(0), "ERC1155: burn from the zero address");
314
+ require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
315
+
316
+ address operator = _msgSender();
317
+
318
+ _beforeTokenTransfer(operator, account, address(0), ids, amounts, "");
319
+
320
+ for (uint i = 0; i < ids.length; i++) {
321
+ _balances[ids[i]][account] = _balances[ids[i]][account].sub(
322
+ amounts[i],
323
+ "ERC1155: burn amount exceeds balance"
324
+ );
325
+ }
326
+
327
+ emit TransferBatch(operator, account, address(0), ids, amounts);
328
+ }
329
+
330
+ /**
331
+ * @dev Hook that is called before any token transfer. This includes minting
332
+ * and burning, as well as batched variants.
333
+ *
334
+ * The same hook is called on both single and batched variants. For single
335
+ * transfers, the length of the `id` and `amount` arrays will be 1.
336
+ *
337
+ * Calling conditions (for each `id` and `amount` pair):
338
+ *
339
+ * - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
340
+ * of token type `id` will be transferred to `to`.
341
+ * - When `from` is zero, `amount` tokens of token type `id` will be minted
342
+ * for `to`.
343
+ * - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
344
+ * will be burned.
345
+ * - `from` and `to` are never both zero.
346
+ * - `ids` and `amounts` have the same, non-zero length.
347
+ *
348
+ * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
349
+ */
350
+ function _beforeTokenTransfer(
351
+ address operator,
352
+ address from,
353
+ address to,
354
+ uint256[] memory ids,
355
+ uint256[] memory amounts,
356
+ bytes memory data
357
+ )
358
+ internal
359
+ virtual
360
+ { }
361
+
362
+ function _doSafeTransferAcceptanceCheck(
363
+ address operator,
364
+ address from,
365
+ address to,
366
+ uint256 id,
367
+ uint256 amount,
368
+ bytes memory data
369
+ )
370
+ private
371
+ {
372
+ if (to.isContract()) {
373
+ try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
374
+ if (response != IERC1155Receiver(to).onERC1155Received.selector) {
375
+ revert("ERC1155: ERC1155Receiver rejected tokens");
376
+ }
377
+ } catch Error(string memory reason) {
378
+ revert(reason);
379
+ } catch {
380
+ revert("ERC1155: transfer to non ERC1155Receiver implementer");
381
+ }
382
+ }
383
+ }
384
+
385
+ function _doSafeBatchTransferAcceptanceCheck(
386
+ address operator,
387
+ address from,
388
+ address to,
389
+ uint256[] memory ids,
390
+ uint256[] memory amounts,
391
+ bytes memory data
392
+ )
393
+ private
394
+ {
395
+ if (to.isContract()) {
396
+ try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (bytes4 response) {
397
+ if (response != IERC1155Receiver(to).onERC1155BatchReceived.selector) {
398
+ revert("ERC1155: ERC1155Receiver rejected tokens");
399
+ }
400
+ } catch Error(string memory reason) {
401
+ revert(reason);
402
+ } catch {
403
+ revert("ERC1155: transfer to non ERC1155Receiver implementer");
404
+ }
405
+ }
406
+ }
407
+
408
+ function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) {
409
+ uint256[] memory array = new uint256[](1);
410
+ array[0] = element;
411
+
412
+ return array;
413
+ }
414
+ }
@@ -0,0 +1,31 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.6.0 <0.8.0;
4
+
5
+ import "./ERC1155.sol";
6
+
7
+ /**
8
+ * @dev Extension of {ERC1155} that allows token holders to destroy both their
9
+ * own tokens and those that they have been approved to use.
10
+ *
11
+ * _Available since v3.1._
12
+ */
13
+ abstract contract ERC1155Burnable is ERC1155 {
14
+ function burn(address account, uint256 id, uint256 value) public virtual {
15
+ require(
16
+ account == _msgSender() || isApprovedForAll(account, _msgSender()),
17
+ "ERC1155: caller is not owner nor approved"
18
+ );
19
+
20
+ _burn(account, id, value);
21
+ }
22
+
23
+ function burnBatch(address account, uint256[] memory ids, uint256[] memory values) public virtual {
24
+ require(
25
+ account == _msgSender() || isApprovedForAll(account, _msgSender()),
26
+ "ERC1155: caller is not owner nor approved"
27
+ );
28
+
29
+ _burnBatch(account, ids, values);
30
+ }
31
+ }
@@ -0,0 +1,18 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.6.0 <0.8.0;
4
+
5
+ import "./ERC1155Receiver.sol";
6
+
7
+ /**
8
+ * @dev _Available since v3.1._
9
+ */
10
+ contract ERC1155Holder is ERC1155Receiver {
11
+ function onERC1155Received(address, address, uint256, uint256, bytes memory) public virtual override returns (bytes4) {
12
+ return this.onERC1155Received.selector;
13
+ }
14
+
15
+ function onERC1155BatchReceived(address, address, uint256[] memory, uint256[] memory, bytes memory) public virtual override returns (bytes4) {
16
+ return this.onERC1155BatchReceived.selector;
17
+ }
18
+ }
@@ -0,0 +1,41 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.6.0 <0.8.0;
4
+
5
+ import "./ERC1155.sol";
6
+ import "../../utils/Pausable.sol";
7
+
8
+ /**
9
+ * @dev ERC1155 token with pausable token transfers, minting and burning.
10
+ *
11
+ * Useful for scenarios such as preventing trades until the end of an evaluation
12
+ * period, or having an emergency switch for freezing all token transfers in the
13
+ * event of a large bug.
14
+ *
15
+ * _Available since v3.1._
16
+ */
17
+ abstract contract ERC1155Pausable is ERC1155, Pausable {
18
+ /**
19
+ * @dev See {ERC1155-_beforeTokenTransfer}.
20
+ *
21
+ * Requirements:
22
+ *
23
+ * - the contract must not be paused.
24
+ */
25
+ function _beforeTokenTransfer(
26
+ address operator,
27
+ address from,
28
+ address to,
29
+ uint256[] memory ids,
30
+ uint256[] memory amounts,
31
+ bytes memory data
32
+ )
33
+ internal
34
+ virtual
35
+ override
36
+ {
37
+ super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
38
+
39
+ require(!paused(), "ERC1155Pausable: token transfer while paused");
40
+ }
41
+ }
@@ -0,0 +1,18 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.6.0 <0.8.0;
4
+
5
+ import "./IERC1155Receiver.sol";
6
+ import "../../introspection/ERC165.sol";
7
+
8
+ /**
9
+ * @dev _Available since v3.1._
10
+ */
11
+ abstract contract ERC1155Receiver is ERC165, IERC1155Receiver {
12
+ constructor() internal {
13
+ _registerInterface(
14
+ ERC1155Receiver(address(0)).onERC1155Received.selector ^
15
+ ERC1155Receiver(address(0)).onERC1155BatchReceived.selector
16
+ );
17
+ }
18
+ }
@@ -0,0 +1,103 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.6.2 <0.8.0;
4
+
5
+ import "../../introspection/IERC165.sol";
6
+
7
+ /**
8
+ * @dev Required interface of an ERC1155 compliant contract, as defined in the
9
+ * https://eips.ethereum.org/EIPS/eip-1155[EIP].
10
+ *
11
+ * _Available since v3.1._
12
+ */
13
+ interface IERC1155 is IERC165 {
14
+ /**
15
+ * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
16
+ */
17
+ event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
18
+
19
+ /**
20
+ * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
21
+ * transfers.
22
+ */
23
+ event TransferBatch(address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values);
24
+
25
+ /**
26
+ * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
27
+ * `approved`.
28
+ */
29
+ event ApprovalForAll(address indexed account, address indexed operator, bool approved);
30
+
31
+ /**
32
+ * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
33
+ *
34
+ * If an {URI} event was emitted for `id`, the standard
35
+ * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
36
+ * returned by {IERC1155MetadataURI-uri}.
37
+ */
38
+ event URI(string value, uint256 indexed id);
39
+
40
+ /**
41
+ * @dev Returns the amount of tokens of token type `id` owned by `account`.
42
+ *
43
+ * Requirements:
44
+ *
45
+ * - `account` cannot be the zero address.
46
+ */
47
+ function balanceOf(address account, uint256 id) external view returns (uint256);
48
+
49
+ /**
50
+ * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
51
+ *
52
+ * Requirements:
53
+ *
54
+ * - `accounts` and `ids` must have the same length.
55
+ */
56
+ function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids) external view returns (uint256[] memory);
57
+
58
+ /**
59
+ * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
60
+ *
61
+ * Emits an {ApprovalForAll} event.
62
+ *
63
+ * Requirements:
64
+ *
65
+ * - `operator` cannot be the caller.
66
+ */
67
+ function setApprovalForAll(address operator, bool approved) external;
68
+
69
+ /**
70
+ * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
71
+ *
72
+ * See {setApprovalForAll}.
73
+ */
74
+ function isApprovedForAll(address account, address operator) external view returns (bool);
75
+
76
+ /**
77
+ * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
78
+ *
79
+ * Emits a {TransferSingle} event.
80
+ *
81
+ * Requirements:
82
+ *
83
+ * - `to` cannot be the zero address.
84
+ * - If the caller is not `from`, it must be have been approved to spend ``from``'s tokens via {setApprovalForAll}.
85
+ * - `from` must have a balance of tokens of type `id` of at least `amount`.
86
+ * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
87
+ * acceptance magic value.
88
+ */
89
+ function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) external;
90
+
91
+ /**
92
+ * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
93
+ *
94
+ * Emits a {TransferBatch} event.
95
+ *
96
+ * Requirements:
97
+ *
98
+ * - `ids` and `amounts` must have the same length.
99
+ * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
100
+ * acceptance magic value.
101
+ */
102
+ function safeBatchTransferFrom(address from, address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data) external;
103
+ }
@@ -0,0 +1,21 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.6.2 <0.8.0;
4
+
5
+ import "./IERC1155.sol";
6
+
7
+ /**
8
+ * @dev Interface of the optional ERC1155MetadataExtension interface, as defined
9
+ * in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP].
10
+ *
11
+ * _Available since v3.1._
12
+ */
13
+ interface IERC1155MetadataURI is IERC1155 {
14
+ /**
15
+ * @dev Returns the URI for token type `id`.
16
+ *
17
+ * If the `\{id\}` substring is present in the URI, it must be replaced by
18
+ * clients with the actual token type ID.
19
+ */
20
+ function uri(uint256 id) external view returns (string memory);
21
+ }