Guest User

Untitled

a guest
Oct 9th, 2022
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 69.05 KB | None | 0 0
  1. // SPDX-License-Identifier: MIT
  2.  
  3. pragma solidity ^0.8.0;
  4.  
  5. /**
  6. * @dev String operations.
  7. */
  8. library Strings {
  9. bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
  10.  
  11. /**
  12. * @dev Converts a `uint256` to its ASCII `string` decimal representation.
  13. */
  14. function toString(uint256 value) internal pure returns (string memory) {
  15. // Inspired by OraclizeAPI's implementation - MIT licence
  16. // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
  17.  
  18. if (value == 0) {
  19. return "0";
  20. }
  21. uint256 temp = value;
  22. uint256 digits;
  23. while (temp != 0) {
  24. digits++;
  25. temp /= 10;
  26. }
  27. bytes memory buffer = new bytes(digits);
  28. while (value != 0) {
  29. digits -= 1;
  30. buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
  31. value /= 10;
  32. }
  33. return string(buffer);
  34. }
  35.  
  36. /**
  37. * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
  38. */
  39. function toHexString(uint256 value) internal pure returns (string memory) {
  40. if (value == 0) {
  41. return "0x00";
  42. }
  43. uint256 temp = value;
  44. uint256 length = 0;
  45. while (temp != 0) {
  46. length++;
  47. temp >>= 8;
  48. }
  49. return toHexString(value, length);
  50. }
  51.  
  52. /**
  53. * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
  54. */
  55. function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
  56. bytes memory buffer = new bytes(2 * length + 2);
  57. buffer[0] = "0";
  58. buffer[1] = "x";
  59. for (uint256 i = 2 * length + 1; i > 1; --i) {
  60. buffer[i] = _HEX_SYMBOLS[value & 0xf];
  61. value >>= 4;
  62. }
  63. require(value == 0, "Strings: hex length insufficient");
  64. return string(buffer);
  65. }
  66. }
  67.  
  68. /**
  69. * @dev Library for managing
  70. * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
  71. * types.
  72. *
  73. * Sets have the following properties:
  74. *
  75. * - Elements are added, removed, and checked for existence in constant time
  76. * (O(1)).
  77. * - Elements are enumerated in O(n). No guarantees are made on the ordering.
  78. *
  79. * ```
  80. * contract Example {
  81. * // Add the library methods
  82. * using EnumerableSet for EnumerableSet.AddressSet;
  83. *
  84. * // Declare a set state variable
  85. * EnumerableSet.AddressSet private mySet;
  86. * }
  87. * ```
  88. *
  89. * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
  90. * and `uint256` (`UintSet`) are supported.
  91. */
  92. library EnumerableSet {
  93. // To implement this library for multiple types with as little code
  94. // repetition as possible, we write it in terms of a generic Set type with
  95. // bytes32 values.
  96. // The Set implementation uses private functions, and user-facing
  97. // implementations (such as AddressSet) are just wrappers around the
  98. // underlying Set.
  99. // This means that we can only create new EnumerableSets for types that fit
  100. // in bytes32.
  101.  
  102. struct Set {
  103. // Storage of set values
  104. bytes32[] _values;
  105. // Position of the value in the `values` array, plus 1 because index 0
  106. // means a value is not in the set.
  107. mapping(bytes32 => uint256) _indexes;
  108. }
  109.  
  110. /**
  111. * @dev Add a value to a set. O(1).
  112. *
  113. * Returns true if the value was added to the set, that is if it was not
  114. * already present.
  115. */
  116. function _add(Set storage set, bytes32 value) private returns (bool) {
  117. if (!_contains(set, value)) {
  118. set._values.push(value);
  119. // The value is stored at length-1, but we add 1 to all indexes
  120. // and use 0 as a sentinel value
  121. set._indexes[value] = set._values.length;
  122. return true;
  123. } else {
  124. return false;
  125. }
  126. }
  127.  
  128. /**
  129. * @dev Removes a value from a set. O(1).
  130. *
  131. * Returns true if the value was removed from the set, that is if it was
  132. * present.
  133. */
  134. function _remove(Set storage set, bytes32 value) private returns (bool) {
  135. // We read and store the value's index to prevent multiple reads from the same storage slot
  136. uint256 valueIndex = set._indexes[value];
  137.  
  138. if (valueIndex != 0) {
  139. // Equivalent to contains(set, value)
  140. // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
  141. // the array, and then remove the last element (sometimes called as 'swap and pop').
  142. // This modifies the order of the array, as noted in {at}.
  143.  
  144. uint256 toDeleteIndex = valueIndex - 1;
  145. uint256 lastIndex = set._values.length - 1;
  146.  
  147. if (lastIndex != toDeleteIndex) {
  148. bytes32 lastvalue = set._values[lastIndex];
  149.  
  150. // Move the last value to the index where the value to delete is
  151. set._values[toDeleteIndex] = lastvalue;
  152. // Update the index for the moved value
  153. set._indexes[lastvalue] = valueIndex; // Replace lastvalue's index to valueIndex
  154. }
  155.  
  156. // Delete the slot where the moved value was stored
  157. set._values.pop();
  158.  
  159. // Delete the index for the deleted slot
  160. delete set._indexes[value];
  161.  
  162. return true;
  163. } else {
  164. return false;
  165. }
  166. }
  167.  
  168. /**
  169. * @dev Returns true if the value is in the set. O(1).
  170. */
  171. function _contains(Set storage set, bytes32 value) private view returns (bool) {
  172. return set._indexes[value] != 0;
  173. }
  174.  
  175. /**
  176. * @dev Returns the number of values on the set. O(1).
  177. */
  178. function _length(Set storage set) private view returns (uint256) {
  179. return set._values.length;
  180. }
  181.  
  182. /**
  183. * @dev Returns the value stored at position `index` in the set. O(1).
  184. *
  185. * Note that there are no guarantees on the ordering of values inside the
  186. * array, and it may change when more values are added or removed.
  187. *
  188. * Requirements:
  189. *
  190. * - `index` must be strictly less than {length}.
  191. */
  192. function _at(Set storage set, uint256 index) private view returns (bytes32) {
  193. return set._values[index];
  194. }
  195.  
  196. /**
  197. * @dev Return the entire set in an array
  198. *
  199. * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
  200. * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
  201. * this function has an unbounded cost, and using it as part of a state-changing function may render the function
  202. * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
  203. */
  204. function _values(Set storage set) private view returns (bytes32[] memory) {
  205. return set._values;
  206. }
  207.  
  208. // Bytes32Set
  209.  
  210. struct Bytes32Set {
  211. Set _inner;
  212. }
  213.  
  214. /**
  215. * @dev Add a value to a set. O(1).
  216. *
  217. * Returns true if the value was added to the set, that is if it was not
  218. * already present.
  219. */
  220. function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
  221. return _add(set._inner, value);
  222. }
  223.  
  224. /**
  225. * @dev Removes a value from a set. O(1).
  226. *
  227. * Returns true if the value was removed from the set, that is if it was
  228. * present.
  229. */
  230. function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
  231. return _remove(set._inner, value);
  232. }
  233.  
  234. /**
  235. * @dev Returns true if the value is in the set. O(1).
  236. */
  237. function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
  238. return _contains(set._inner, value);
  239. }
  240.  
  241. /**
  242. * @dev Returns the number of values in the set. O(1).
  243. */
  244. function length(Bytes32Set storage set) internal view returns (uint256) {
  245. return _length(set._inner);
  246. }
  247.  
  248. /**
  249. * @dev Returns the value stored at position `index` in the set. O(1).
  250. *
  251. * Note that there are no guarantees on the ordering of values inside the
  252. * array, and it may change when more values are added or removed.
  253. *
  254. * Requirements:
  255. *
  256. * - `index` must be strictly less than {length}.
  257. */
  258. function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
  259. return _at(set._inner, index);
  260. }
  261.  
  262. /**
  263. * @dev Return the entire set in an array
  264. *
  265. * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
  266. * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
  267. * this function has an unbounded cost, and using it as part of a state-changing function may render the function
  268. * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
  269. */
  270. function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
  271. return _values(set._inner);
  272. }
  273.  
  274. // AddressSet
  275.  
  276. struct AddressSet {
  277. Set _inner;
  278. }
  279.  
  280. /**
  281. * @dev Add a value to a set. O(1).
  282. *
  283. * Returns true if the value was added to the set, that is if it was not
  284. * already present.
  285. */
  286. function add(AddressSet storage set, address value) internal returns (bool) {
  287. return _add(set._inner, bytes32(uint256(uint160(value))));
  288. }
  289.  
  290. /**
  291. * @dev Removes a value from a set. O(1).
  292. *
  293. * Returns true if the value was removed from the set, that is if it was
  294. * present.
  295. */
  296. function remove(AddressSet storage set, address value) internal returns (bool) {
  297. return _remove(set._inner, bytes32(uint256(uint160(value))));
  298. }
  299.  
  300. /**
  301. * @dev Returns true if the value is in the set. O(1).
  302. */
  303. function contains(AddressSet storage set, address value) internal view returns (bool) {
  304. return _contains(set._inner, bytes32(uint256(uint160(value))));
  305. }
  306.  
  307. /**
  308. * @dev Returns the number of values in the set. O(1).
  309. */
  310. function length(AddressSet storage set) internal view returns (uint256) {
  311. return _length(set._inner);
  312. }
  313.  
  314. /**
  315. * @dev Returns the value stored at position `index` in the set. O(1).
  316. *
  317. * Note that there are no guarantees on the ordering of values inside the
  318. * array, and it may change when more values are added or removed.
  319. *
  320. * Requirements:
  321. *
  322. * - `index` must be strictly less than {length}.
  323. */
  324. function at(AddressSet storage set, uint256 index) internal view returns (address) {
  325. return address(uint160(uint256(_at(set._inner, index))));
  326. }
  327.  
  328. /**
  329. * @dev Return the entire set in an array
  330. *
  331. * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
  332. * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
  333. * this function has an unbounded cost, and using it as part of a state-changing function may render the function
  334. * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
  335. */
  336. function values(AddressSet storage set) internal view returns (address[] memory) {
  337. bytes32[] memory store = _values(set._inner);
  338. address[] memory result;
  339.  
  340. assembly {
  341. result := store
  342. }
  343.  
  344. return result;
  345. }
  346.  
  347. // UintSet
  348.  
  349. struct UintSet {
  350. Set _inner;
  351. }
  352.  
  353. /**
  354. * @dev Add a value to a set. O(1).
  355. *
  356. * Returns true if the value was added to the set, that is if it was not
  357. * already present.
  358. */
  359. function add(UintSet storage set, uint256 value) internal returns (bool) {
  360. return _add(set._inner, bytes32(value));
  361. }
  362.  
  363. /**
  364. * @dev Removes a value from a set. O(1).
  365. *
  366. * Returns true if the value was removed from the set, that is if it was
  367. * present.
  368. */
  369. function remove(UintSet storage set, uint256 value) internal returns (bool) {
  370. return _remove(set._inner, bytes32(value));
  371. }
  372.  
  373. /**
  374. * @dev Returns true if the value is in the set. O(1).
  375. */
  376. function contains(UintSet storage set, uint256 value) internal view returns (bool) {
  377. return _contains(set._inner, bytes32(value));
  378. }
  379.  
  380. /**
  381. * @dev Returns the number of values on the set. O(1).
  382. */
  383. function length(UintSet storage set) internal view returns (uint256) {
  384. return _length(set._inner);
  385. }
  386.  
  387. /**
  388. * @dev Returns the value stored at position `index` in the set. O(1).
  389. *
  390. * Note that there are no guarantees on the ordering of values inside the
  391. * array, and it may change when more values are added or removed.
  392. *
  393. * Requirements:
  394. *
  395. * - `index` must be strictly less than {length}.
  396. */
  397. function at(UintSet storage set, uint256 index) internal view returns (uint256) {
  398. return uint256(_at(set._inner, index));
  399. }
  400.  
  401. /**
  402. * @dev Return the entire set in an array
  403. *
  404. * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
  405. * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
  406. * this function has an unbounded cost, and using it as part of a state-changing function may render the function
  407. * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
  408. */
  409. function values(UintSet storage set) internal view returns (uint256[] memory) {
  410. bytes32[] memory store = _values(set._inner);
  411. uint256[] memory result;
  412.  
  413. assembly {
  414. result := store
  415. }
  416.  
  417. return result;
  418. }
  419. }
  420.  
  421. /**
  422. * @dev Interface of the ERC165 standard, as defined in the
  423. * https://eips.ethereum.org/EIPS/eip-165[EIP].
  424. *
  425. * Implementers can declare support of contract interfaces, which can then be
  426. * queried by others ({ERC165Checker}).
  427. *
  428. * For an implementation, see {ERC165}.
  429. */
  430. interface IERC165 {
  431. /**
  432. * @dev Returns true if this contract implements the interface defined by
  433. * `interfaceId`. See the corresponding
  434. * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
  435. * to learn more about how these ids are created.
  436. *
  437. * This function call must use less than 30 000 gas.
  438. */
  439. function supportsInterface(bytes4 interfaceId) external view returns (bool);
  440. }
  441.  
  442. /**
  443. * @dev Required interface of an ERC1155 compliant contract, as defined in the
  444. * https://eips.ethereum.org/EIPS/eip-1155[EIP].
  445. *
  446. * _Available since v3.1._
  447. */
  448. /**
  449. */
  450. interface IERC1155 is IERC165 {
  451. /**
  452. * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
  453. */
  454. event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
  455.  
  456. /**
  457. * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
  458. * transfers.
  459. */
  460. event TransferBatch(
  461. address indexed operator,
  462. address indexed from,
  463. address indexed to,
  464. uint256[] ids,
  465. uint256[] values
  466. );
  467.  
  468. /**
  469. * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
  470. * `approved`.
  471. */
  472. event ApprovalForAll(address indexed account, address indexed operator, bool approved);
  473.  
  474. /**
  475. * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
  476. *
  477. * If an {URI} event was emitted for `id`, the standard
  478. * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
  479. * returned by {IERC1155MetadataURI-uri}.
  480. */
  481. event URI(string value, uint256 indexed id);
  482.  
  483. /**
  484. * @dev Returns the amount of tokens of token type `id` owned by `account`.
  485. *
  486. * Requirements:
  487. *
  488. * - `account` cannot be the zero address.
  489. */
  490. function balanceOf(address account, uint256 id) external view returns (uint256);
  491.  
  492. /**
  493. * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
  494. *
  495. * Requirements:
  496. *
  497. * - `accounts` and `ids` must have the same length.
  498. */
  499. function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)
  500. external
  501. view
  502. returns (uint256[] memory);
  503.  
  504. /**
  505. * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
  506. *
  507. * Emits an {ApprovalForAll} event.
  508. *
  509. * Requirements:
  510. *
  511. * - `operator` cannot be the caller.
  512. */
  513. function setApprovalForAll(address operator, bool approved) external;
  514.  
  515. /**
  516. * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
  517. *
  518. * See {setApprovalForAll}.
  519. */
  520. function isApprovedForAll(address account, address operator) external view returns (bool);
  521.  
  522. /**
  523. * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
  524. *
  525. * Emits a {TransferSingle} event.
  526. *
  527. * Requirements:
  528. *
  529. * - `to` cannot be the zero address.
  530. * - If the caller is not `from`, it must be have been approved to spend ``from``'s tokens via {setApprovalForAll}.
  531. * - `from` must have a balance of tokens of type `id` of at least `amount`.
  532. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
  533. * acceptance magic value.
  534. */
  535. function safeTransferFrom(
  536. address from,
  537. address to,
  538. uint256 id,
  539. uint256 amount,
  540. bytes calldata data
  541. ) external;
  542.  
  543. /**
  544. * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
  545. *
  546. * Emits a {TransferBatch} event.
  547. *
  548. * Requirements:
  549. *
  550. * - `ids` and `amounts` must have the same length.
  551. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
  552. * acceptance magic value.
  553. */
  554. function safeBatchTransferFrom(
  555. address from,
  556. address to,
  557. uint256[] calldata ids,
  558. uint256[] calldata amounts,
  559. bytes calldata data
  560. ) external;
  561. }
  562.  
  563. /**
  564. * @dev _Available since v3.1._
  565. */
  566. /**
  567. */
  568. interface IERC1155Receiver is IERC165 {
  569. /**
  570. @dev Handles the receipt of a single ERC1155 token type. This function is
  571. called at the end of a `safeTransferFrom` after the balance has been updated.
  572. To accept the transfer, this must return
  573. `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
  574. (i.e. 0xf23a6e61, or its own function selector).
  575. @param operator The address which initiated the transfer (i.e. msg.sender)
  576. @param from The address which previously owned the token
  577. @param id The ID of the token being transferred
  578. @param value The amount of tokens being transferred
  579. @param data Additional data with no specified format
  580. @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
  581. */
  582. function onERC1155Received(
  583. address operator,
  584. address from,
  585. uint256 id,
  586. uint256 value,
  587. bytes calldata data
  588. ) external returns (bytes4);
  589.  
  590. /**
  591. @dev Handles the receipt of a multiple ERC1155 token types. This function
  592. is called at the end of a `safeBatchTransferFrom` after the balances have
  593. been updated. To accept the transfer(s), this must return
  594. `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
  595. (i.e. 0xbc197c81, or its own function selector).
  596. @param operator The address which initiated the batch transfer (i.e. msg.sender)
  597. @param from The address which previously owned the token
  598. @param ids An array containing ids of each token being transferred (order and length must match values array)
  599. @param values An array containing amounts of each token being transferred (order and length must match ids array)
  600. @param data Additional data with no specified format
  601. @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
  602. */
  603. function onERC1155BatchReceived(
  604. address operator,
  605. address from,
  606. uint256[] calldata ids,
  607. uint256[] calldata values,
  608. bytes calldata data
  609. ) external returns (bytes4);
  610. }
  611.  
  612.  
  613. /**
  614. * @dev Interface of the optional ERC1155MetadataExtension interface, as defined
  615. * in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP].
  616. *
  617. * _Available since v3.1._
  618. */
  619. /**
  620. */
  621. interface IERC1155MetadataURI is IERC1155 {
  622. /**
  623. * @dev Returns the URI for token type `id`.
  624. *
  625. * If the `\{id\}` substring is present in the URI, it must be replaced by
  626. * clients with the actual token type ID.
  627. */
  628. function uri(uint256 id) external view returns (string memory);
  629. }
  630.  
  631. /**
  632. * @dev Collection of functions related to the address type
  633. */
  634. library Address {
  635. /**
  636. * @dev Returns true if `account` is a contract.
  637. *
  638. * [IMPORTANT]
  639. * ====
  640. * It is unsafe to assume that an address for which this function returns
  641. * false is an externally-owned account (EOA) and not a contract.
  642. *
  643. * Among others, `isContract` will return false for the following
  644. * types of addresses:
  645. *
  646. * - an externally-owned account
  647. * - a contract in construction
  648. * - an address where a contract will be created
  649. * - an address where a contract lived, but was destroyed
  650. * ====
  651. */
  652. function isContract(address account) internal view returns (bool) {
  653. // This method relies on extcodesize, which returns 0 for contracts in
  654. // construction, since the code is only stored at the end of the
  655. // constructor execution.
  656.  
  657. uint256 size;
  658. assembly {
  659. size := extcodesize(account)
  660. }
  661. return size > 0;
  662. }
  663.  
  664. /**
  665. * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
  666. * `recipient`, forwarding all available gas and reverting on errors.
  667. *
  668. * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
  669. * of certain opcodes, possibly making contracts go over the 2300 gas limit
  670. * imposed by `transfer`, making them unable to receive funds via
  671. * `transfer`. {sendValue} removes this limitation.
  672. *
  673. * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
  674. *
  675. * IMPORTANT: because control is transferred to `recipient`, care must be
  676. * taken to not create reentrancy vulnerabilities. Consider using
  677. * {ReentrancyGuard} or the
  678. * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
  679. */
  680. function sendValue(address payable recipient, uint256 amount) internal {
  681. require(address(this).balance >= amount, "Address: insufficient balance");
  682.  
  683. (bool success, ) = recipient.call{value: amount}("");
  684. require(success, "Address: unable to send value, recipient may have reverted");
  685. }
  686.  
  687. /**
  688. * @dev Performs a Solidity function call using a low level `call`. A
  689. * plain `call` is an unsafe replacement for a function call: use this
  690. * function instead.
  691. *
  692. * If `target` reverts with a revert reason, it is bubbled up by this
  693. * function (like regular Solidity function calls).
  694. *
  695. * Returns the raw returned data. To convert to the expected return value,
  696. * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
  697. *
  698. * Requirements:
  699. *
  700. * - `target` must be a contract.
  701. * - calling `target` with `data` must not revert.
  702. *
  703. * _Available since v3.1._
  704. */
  705. function functionCall(address target, bytes memory data) internal returns (bytes memory) {
  706. return functionCall(target, data, "Address: low-level call failed");
  707. }
  708.  
  709. /**
  710. * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
  711. * `errorMessage` as a fallback revert reason when `target` reverts.
  712. *
  713. * _Available since v3.1._
  714. */
  715. function functionCall(
  716. address target,
  717. bytes memory data,
  718. string memory errorMessage
  719. ) internal returns (bytes memory) {
  720. return functionCallWithValue(target, data, 0, errorMessage);
  721. }
  722.  
  723. /**
  724. * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
  725. * but also transferring `value` wei to `target`.
  726. *
  727. * Requirements:
  728. *
  729. * - the calling contract must have an ETH balance of at least `value`.
  730. * - the called Solidity function must be `payable`.
  731. *
  732. * _Available since v3.1._
  733. */
  734. function functionCallWithValue(
  735. address target,
  736. bytes memory data,
  737. uint256 value
  738. ) internal returns (bytes memory) {
  739. return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
  740. }
  741.  
  742. /**
  743. * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
  744. * with `errorMessage` as a fallback revert reason when `target` reverts.
  745. *
  746. * _Available since v3.1._
  747. */
  748. function functionCallWithValue(
  749. address target,
  750. bytes memory data,
  751. uint256 value,
  752. string memory errorMessage
  753. ) internal returns (bytes memory) {
  754. require(address(this).balance >= value, "Address: insufficient balance for call");
  755. require(isContract(target), "Address: call to non-contract");
  756.  
  757. (bool success, bytes memory returndata) = target.call{value: value}(data);
  758. return verifyCallResult(success, returndata, errorMessage);
  759. }
  760.  
  761. /**
  762. * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
  763. * but performing a static call.
  764. *
  765. * _Available since v3.3._
  766. */
  767. function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
  768. return functionStaticCall(target, data, "Address: low-level static call failed");
  769. }
  770.  
  771. /**
  772. * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
  773. * but performing a static call.
  774. *
  775. * _Available since v3.3._
  776. */
  777. function functionStaticCall(
  778. address target,
  779. bytes memory data,
  780. string memory errorMessage
  781. ) internal view returns (bytes memory) {
  782. require(isContract(target), "Address: static call to non-contract");
  783.  
  784. (bool success, bytes memory returndata) = target.staticcall(data);
  785. return verifyCallResult(success, returndata, errorMessage);
  786. }
  787.  
  788. /**
  789. * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
  790. * but performing a delegate call.
  791. *
  792. * _Available since v3.4._
  793. */
  794. function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
  795. return functionDelegateCall(target, data, "Address: low-level delegate call failed");
  796. }
  797.  
  798. /**
  799. * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
  800. * but performing a delegate call.
  801. *
  802. * _Available since v3.4._
  803. */
  804. function functionDelegateCall(
  805. address target,
  806. bytes memory data,
  807. string memory errorMessage
  808. ) internal returns (bytes memory) {
  809. require(isContract(target), "Address: delegate call to non-contract");
  810.  
  811. (bool success, bytes memory returndata) = target.delegatecall(data);
  812. return verifyCallResult(success, returndata, errorMessage);
  813. }
  814.  
  815. /**
  816. * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
  817. * revert reason using the provided one.
  818. *
  819. * _Available since v4.3._
  820. */
  821. function verifyCallResult(
  822. bool success,
  823. bytes memory returndata,
  824. string memory errorMessage
  825. ) internal pure returns (bytes memory) {
  826. if (success) {
  827. return returndata;
  828. } else {
  829. // Look for revert reason and bubble it up if present
  830. if (returndata.length > 0) {
  831. // The easiest way to bubble the revert reason is using memory via assembly
  832.  
  833. assembly {
  834. let returndata_size := mload(returndata)
  835. revert(add(32, returndata), returndata_size)
  836. }
  837. } else {
  838. revert(errorMessage);
  839. }
  840. }
  841. }
  842. }
  843.  
  844. /**
  845. * @dev Provides information about the current execution context, including the
  846. * sender of the transaction and its data. While these are generally available
  847. * via msg.sender and msg.data, they should not be accessed in such a direct
  848. * manner, since when dealing with meta-transactions the account sending and
  849. * paying for execution may not be the actual sender (as far as an application
  850. * is concerned).
  851. *
  852. * This contract is only required for intermediate, library-like contracts.
  853. */
  854. abstract contract Context {
  855. function _msgSender() internal view virtual returns (address) {
  856. return msg.sender;
  857. }
  858.  
  859. function _msgData() internal view virtual returns (bytes calldata) {
  860. return msg.data;
  861. }
  862. }
  863.  
  864.  
  865. /**
  866. * @dev Implementation of the {IERC165} interface.
  867. *
  868. * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
  869. * for the additional interface id that will be supported. For example:
  870. *
  871. * ```solidity
  872. * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
  873. * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
  874. * }
  875. * ```
  876. *
  877. * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
  878. */
  879. /**
  880. */
  881. abstract contract ERC165 is IERC165 {
  882. /**
  883. * @dev See {IERC165-supportsInterface}.
  884. */
  885. function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
  886. return interfaceId == type(IERC165).interfaceId;
  887. }
  888. }
  889.  
  890. /**
  891. * @dev Implementation of the basic standard multi-token.
  892. * See https://eips.ethereum.org/EIPS/eip-1155
  893. * Originally based on code by Enjin: https://github.com/enjin/erc-1155
  894. *
  895. * _Available since v3.1._
  896. */
  897. /**
  898. */
  899. contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
  900. using Address for address;
  901.  
  902. // Mapping from token ID to account balances
  903. mapping(uint256 => mapping(address => uint256)) private _balances;
  904.  
  905. // Mapping from account to operator approvals
  906. mapping(address => mapping(address => bool)) private _operatorApprovals;
  907.  
  908. // Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json
  909. string private _uri;
  910.  
  911. /**
  912. * @dev See {_setURI}.
  913. */
  914. constructor(string memory uri_) {
  915. _setURI(uri_);
  916. }
  917.  
  918. /**
  919. * @dev See {IERC165-supportsInterface}.
  920. */
  921. function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
  922. return
  923. interfaceId == type(IERC1155).interfaceId ||
  924. interfaceId == type(IERC1155MetadataURI).interfaceId ||
  925. super.supportsInterface(interfaceId);
  926. }
  927.  
  928. /**
  929. * @dev See {IERC1155MetadataURI-uri}.
  930. *
  931. * This implementation returns the same URI for *all* token types. It relies
  932. * on the token type ID substitution mechanism
  933. * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
  934. *
  935. * Clients calling this function must replace the `\{id\}` substring with the
  936. * actual token type ID.
  937. */
  938. function uri(uint256) public view virtual override returns (string memory) {
  939. return _uri;
  940. }
  941.  
  942. /**
  943. * @dev See {IERC1155-balanceOf}.
  944. *
  945. * Requirements:
  946. *
  947. * - `account` cannot be the zero address.
  948. */
  949. function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
  950. require(account != address(0), "ERC1155: balance query for the zero address");
  951. return _balances[id][account];
  952. }
  953.  
  954. /**
  955. * @dev See {IERC1155-balanceOfBatch}.
  956. *
  957. * Requirements:
  958. *
  959. * - `accounts` and `ids` must have the same length.
  960. */
  961. function balanceOfBatch(address[] memory accounts, uint256[] memory ids)
  962. public
  963. view
  964. virtual
  965. override
  966. returns (uint256[] memory)
  967. {
  968. require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch");
  969.  
  970. uint256[] memory batchBalances = new uint256[](accounts.length);
  971.  
  972. for (uint256 i = 0; i < accounts.length; ++i) {
  973. batchBalances[i] = balanceOf(accounts[i], ids[i]);
  974. }
  975.  
  976. return batchBalances;
  977. }
  978.  
  979. /**
  980. * @dev See {IERC1155-setApprovalForAll}.
  981. */
  982. function setApprovalForAll(address operator, bool approved) public virtual override {
  983. require(_msgSender() != operator, "ERC1155: setting approval status for self");
  984.  
  985. _operatorApprovals[_msgSender()][operator] = approved;
  986. emit ApprovalForAll(_msgSender(), operator, approved);
  987. }
  988.  
  989. /**
  990. * @dev See {IERC1155-isApprovedForAll}.
  991. */
  992. function isApprovedForAll(address account, address operator) public view virtual override returns (bool) {
  993. return _operatorApprovals[account][operator];
  994. }
  995.  
  996. /**
  997. * @dev See {IERC1155-safeTransferFrom}.
  998. */
  999. function safeTransferFrom(
  1000. address from,
  1001. address to,
  1002. uint256 id,
  1003. uint256 amount,
  1004. bytes memory data
  1005. ) public virtual override {
  1006. require(
  1007. from == _msgSender() || isApprovedForAll(from, _msgSender()),
  1008. "ERC1155: caller is not owner nor approved"
  1009. );
  1010. _safeTransferFrom(from, to, id, amount, data);
  1011. }
  1012.  
  1013. /**
  1014. * @dev See {IERC1155-safeBatchTransferFrom}.
  1015. */
  1016. function safeBatchTransferFrom(
  1017. address from,
  1018. address to,
  1019. uint256[] memory ids,
  1020. uint256[] memory amounts,
  1021. bytes memory data
  1022. ) public virtual override {
  1023. require(
  1024. from == _msgSender() || isApprovedForAll(from, _msgSender()),
  1025. "ERC1155: transfer caller is not owner nor approved"
  1026. );
  1027. _safeBatchTransferFrom(from, to, ids, amounts, data);
  1028. }
  1029.  
  1030. /**
  1031. * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
  1032. *
  1033. * Emits a {TransferSingle} event.
  1034. *
  1035. * Requirements:
  1036. *
  1037. * - `to` cannot be the zero address.
  1038. * - `from` must have a balance of tokens of type `id` of at least `amount`.
  1039. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
  1040. * acceptance magic value.
  1041. */
  1042. function _safeTransferFrom(
  1043. address from,
  1044. address to,
  1045. uint256 id,
  1046. uint256 amount,
  1047. bytes memory data
  1048. ) internal virtual {
  1049. require(to != address(0), "ERC1155: transfer to the zero address");
  1050.  
  1051. address operator = _msgSender();
  1052.  
  1053. _beforeTokenTransfer(operator, from, to, _asSingletonArray(id), _asSingletonArray(amount), data);
  1054.  
  1055. uint256 fromBalance = _balances[id][from];
  1056. require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
  1057. unchecked {
  1058. _balances[id][from] = fromBalance - amount;
  1059. }
  1060. _balances[id][to] += amount;
  1061.  
  1062. emit TransferSingle(operator, from, to, id, amount);
  1063.  
  1064. _doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data);
  1065. }
  1066.  
  1067. /**
  1068. * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_safeTransferFrom}.
  1069. *
  1070. * Emits a {TransferBatch} event.
  1071. *
  1072. * Requirements:
  1073. *
  1074. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
  1075. * acceptance magic value.
  1076. */
  1077. function _safeBatchTransferFrom(
  1078. address from,
  1079. address to,
  1080. uint256[] memory ids,
  1081. uint256[] memory amounts,
  1082. bytes memory data
  1083. ) internal virtual {
  1084. require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
  1085. require(to != address(0), "ERC1155: transfer to the zero address");
  1086.  
  1087. address operator = _msgSender();
  1088.  
  1089. _beforeTokenTransfer(operator, from, to, ids, amounts, data);
  1090.  
  1091. for (uint256 i = 0; i < ids.length; ++i) {
  1092. uint256 id = ids[i];
  1093. uint256 amount = amounts[i];
  1094.  
  1095. uint256 fromBalance = _balances[id][from];
  1096. require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
  1097. unchecked {
  1098. _balances[id][from] = fromBalance - amount;
  1099. }
  1100. _balances[id][to] += amount;
  1101. }
  1102.  
  1103. emit TransferBatch(operator, from, to, ids, amounts);
  1104.  
  1105. _doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data);
  1106. }
  1107.  
  1108. /**
  1109. * @dev Sets a new URI for all token types, by relying on the token type ID
  1110. * substitution mechanism
  1111. * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
  1112. *
  1113. * By this mechanism, any occurrence of the `\{id\}` substring in either the
  1114. * URI or any of the amounts in the JSON file at said URI will be replaced by
  1115. * clients with the token type ID.
  1116. *
  1117. * For example, the `https://token-cdn-domain/\{id\}.json` URI would be
  1118. * interpreted by clients as
  1119. * `https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json`
  1120. * for token type ID 0x4cce0.
  1121. *
  1122. * See {uri}.
  1123. *
  1124. * Because these URIs cannot be meaningfully represented by the {URI} event,
  1125. * this function emits no events.
  1126. */
  1127. function _setURI(string memory newuri) internal virtual {
  1128. _uri = newuri;
  1129. }
  1130.  
  1131. /**
  1132. * @dev Creates `amount` tokens of token type `id`, and assigns them to `account`.
  1133. *
  1134. * Emits a {TransferSingle} event.
  1135. *
  1136. * Requirements:
  1137. *
  1138. * - `account` cannot be the zero address.
  1139. * - If `account` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
  1140. * acceptance magic value.
  1141. */
  1142. function _mint(
  1143. address account,
  1144. uint256 id,
  1145. uint256 amount,
  1146. bytes memory data
  1147. ) internal virtual {
  1148. require(account != address(0), "ERC1155: mint to the zero address");
  1149.  
  1150. address operator = _msgSender();
  1151.  
  1152. _beforeTokenTransfer(operator, address(0), account, _asSingletonArray(id), _asSingletonArray(amount), data);
  1153.  
  1154. _balances[id][account] += amount;
  1155. emit TransferSingle(operator, address(0), account, id, amount);
  1156.  
  1157. _doSafeTransferAcceptanceCheck(operator, address(0), account, id, amount, data);
  1158. }
  1159.  
  1160. /**
  1161. * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}.
  1162. *
  1163. * Requirements:
  1164. *
  1165. * - `ids` and `amounts` must have the same length.
  1166. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
  1167. * acceptance magic value.
  1168. */
  1169. function _mintBatch(
  1170. address to,
  1171. uint256[] memory ids,
  1172. uint256[] memory amounts,
  1173. bytes memory data
  1174. ) internal virtual {
  1175. require(to != address(0), "ERC1155: mint to the zero address");
  1176. require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
  1177.  
  1178. address operator = _msgSender();
  1179.  
  1180. _beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
  1181.  
  1182. for (uint256 i = 0; i < ids.length; i++) {
  1183. _balances[ids[i]][to] += amounts[i];
  1184. }
  1185.  
  1186. emit TransferBatch(operator, address(0), to, ids, amounts);
  1187.  
  1188. _doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);
  1189. }
  1190.  
  1191. /**
  1192. * @dev Destroys `amount` tokens of token type `id` from `account`
  1193. *
  1194. * Requirements:
  1195. *
  1196. * - `account` cannot be the zero address.
  1197. * - `account` must have at least `amount` tokens of token type `id`.
  1198. */
  1199. function _burn(
  1200. address account,
  1201. uint256 id,
  1202. uint256 amount
  1203. ) internal virtual {
  1204. require(account != address(0), "ERC1155: burn from the zero address");
  1205.  
  1206. address operator = _msgSender();
  1207.  
  1208. _beforeTokenTransfer(operator, account, address(0), _asSingletonArray(id), _asSingletonArray(amount), "");
  1209.  
  1210. uint256 accountBalance = _balances[id][account];
  1211. require(accountBalance >= amount, "ERC1155: burn amount exceeds balance");
  1212. unchecked {
  1213. _balances[id][account] = accountBalance - amount;
  1214. }
  1215.  
  1216. emit TransferSingle(operator, account, address(0), id, amount);
  1217. }
  1218.  
  1219. /**
  1220. * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}.
  1221. *
  1222. * Requirements:
  1223. *
  1224. * - `ids` and `amounts` must have the same length.
  1225. */
  1226. function _burnBatch(
  1227. address account,
  1228. uint256[] memory ids,
  1229. uint256[] memory amounts
  1230. ) internal virtual {
  1231. require(account != address(0), "ERC1155: burn from the zero address");
  1232. require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
  1233.  
  1234. address operator = _msgSender();
  1235.  
  1236. _beforeTokenTransfer(operator, account, address(0), ids, amounts, "");
  1237.  
  1238. for (uint256 i = 0; i < ids.length; i++) {
  1239. uint256 id = ids[i];
  1240. uint256 amount = amounts[i];
  1241.  
  1242. uint256 accountBalance = _balances[id][account];
  1243. require(accountBalance >= amount, "ERC1155: burn amount exceeds balance");
  1244. unchecked {
  1245. _balances[id][account] = accountBalance - amount;
  1246. }
  1247. }
  1248.  
  1249. emit TransferBatch(operator, account, address(0), ids, amounts);
  1250. }
  1251.  
  1252. /**
  1253. * @dev Hook that is called before any token transfer. This includes minting
  1254. * and burning, as well as batched variants.
  1255. *
  1256. * The same hook is called on both single and batched variants. For single
  1257. * transfers, the length of the `id` and `amount` arrays will be 1.
  1258. *
  1259. * Calling conditions (for each `id` and `amount` pair):
  1260. *
  1261. * - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
  1262. * of token type `id` will be transferred to `to`.
  1263. * - When `from` is zero, `amount` tokens of token type `id` will be minted
  1264. * for `to`.
  1265. * - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
  1266. * will be burned.
  1267. * - `from` and `to` are never both zero.
  1268. * - `ids` and `amounts` have the same, non-zero length.
  1269. *
  1270. * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
  1271. */
  1272. function _beforeTokenTransfer(
  1273. address operator,
  1274. address from,
  1275. address to,
  1276. uint256[] memory ids,
  1277. uint256[] memory amounts,
  1278. bytes memory data
  1279. ) internal virtual {}
  1280.  
  1281. function _doSafeTransferAcceptanceCheck(
  1282. address operator,
  1283. address from,
  1284. address to,
  1285. uint256 id,
  1286. uint256 amount,
  1287. bytes memory data
  1288. ) private {
  1289. if (to.isContract()) {
  1290. try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
  1291. if (response != IERC1155Receiver.onERC1155Received.selector) {
  1292. revert("ERC1155: ERC1155Receiver rejected tokens");
  1293. }
  1294. } catch Error(string memory reason) {
  1295. revert(reason);
  1296. } catch {
  1297. revert("ERC1155: transfer to non ERC1155Receiver implementer");
  1298. }
  1299. }
  1300. }
  1301.  
  1302. function _doSafeBatchTransferAcceptanceCheck(
  1303. address operator,
  1304. address from,
  1305. address to,
  1306. uint256[] memory ids,
  1307. uint256[] memory amounts,
  1308. bytes memory data
  1309. ) private {
  1310. if (to.isContract()) {
  1311. try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (
  1312. bytes4 response
  1313. ) {
  1314. if (response != IERC1155Receiver.onERC1155BatchReceived.selector) {
  1315. revert("ERC1155: ERC1155Receiver rejected tokens");
  1316. }
  1317. } catch Error(string memory reason) {
  1318. revert(reason);
  1319. } catch {
  1320. revert("ERC1155: transfer to non ERC1155Receiver implementer");
  1321. }
  1322. }
  1323. }
  1324.  
  1325. function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) {
  1326. uint256[] memory array = new uint256[](1);
  1327. array[0] = element;
  1328.  
  1329. return array;
  1330. }
  1331. }
  1332.  
  1333. /**
  1334. * @dev Extension of {ERC1155} that allows token holders to destroy both their
  1335. * own tokens and those that they have been approved to use.
  1336. *
  1337. * _Available since v3.1._
  1338. */
  1339. /**
  1340. */
  1341. abstract contract ERC1155Burnable is ERC1155 {
  1342. function burn(
  1343. address account,
  1344. uint256 id,
  1345. uint256 value
  1346. ) public virtual {
  1347. require(
  1348. account == _msgSender() || isApprovedForAll(account, _msgSender()),
  1349. "ERC1155: caller is not owner nor approved"
  1350. );
  1351.  
  1352. _burn(account, id, value);
  1353. }
  1354.  
  1355. function burnBatch(
  1356. address account,
  1357. uint256[] memory ids,
  1358. uint256[] memory values
  1359. ) public virtual {
  1360. require(
  1361. account == _msgSender() || isApprovedForAll(account, _msgSender()),
  1362. "ERC1155: caller is not owner nor approved"
  1363. );
  1364.  
  1365. _burnBatch(account, ids, values);
  1366. }
  1367. }
  1368.  
  1369. /**
  1370. * @dev Contract module which allows children to implement an emergency stop
  1371. * mechanism that can be triggered by an authorized account.
  1372. *
  1373. * This module is used through inheritance. It will make available the
  1374. * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
  1375. * the functions of your contract. Note that they will not be pausable by
  1376. * simply including this module, only once the modifiers are put in place.
  1377. */
  1378. /**
  1379. */
  1380. abstract contract Pausable is Context {
  1381. /**
  1382. * @dev Emitted when the pause is triggered by `account`.
  1383. */
  1384. event Paused(address account);
  1385.  
  1386. /**
  1387. * @dev Emitted when the pause is lifted by `account`.
  1388. */
  1389. event Unpaused(address account);
  1390.  
  1391. bool private _paused;
  1392.  
  1393. /**
  1394. * @dev Initializes the contract in unpaused state.
  1395. */
  1396. constructor() {
  1397. _paused = false;
  1398. }
  1399.  
  1400. /**
  1401. * @dev Returns true if the contract is paused, and false otherwise.
  1402. */
  1403. function paused() public view virtual returns (bool) {
  1404. return _paused;
  1405. }
  1406.  
  1407. /**
  1408. * @dev Modifier to make a function callable only when the contract is not paused.
  1409. *
  1410. * Requirements:
  1411. *
  1412. * - The contract must not be paused.
  1413. */
  1414. modifier whenNotPaused() {
  1415. require(!paused(), "Pausable: paused");
  1416. _;
  1417. }
  1418.  
  1419. /**
  1420. * @dev Modifier to make a function callable only when the contract is paused.
  1421. *
  1422. * Requirements:
  1423. *
  1424. * - The contract must be paused.
  1425. */
  1426. modifier whenPaused() {
  1427. require(paused(), "Pausable: not paused");
  1428. _;
  1429. }
  1430.  
  1431. /**
  1432. * @dev Triggers stopped state.
  1433. *
  1434. * Requirements:
  1435. *
  1436. * - The contract must not be paused.
  1437. */
  1438. function _pause() internal virtual whenNotPaused {
  1439. _paused = true;
  1440. emit Paused(_msgSender());
  1441. }
  1442.  
  1443. /**
  1444. * @dev Returns to normal state.
  1445. *
  1446. * Requirements:
  1447. *
  1448. * - The contract must be paused.
  1449. */
  1450. function _unpause() internal virtual whenPaused {
  1451. _paused = false;
  1452. emit Unpaused(_msgSender());
  1453. }
  1454. }
  1455.  
  1456. /**
  1457. * @dev ERC1155 token with pausable token transfers, minting and burning.
  1458. *
  1459. * Useful for scenarios such as preventing trades until the end of an evaluation
  1460. * period, or having an emergency switch for freezing all token transfers in the
  1461. * event of a large bug.
  1462. *
  1463. * _Available since v3.1._
  1464. */
  1465. /**
  1466. */
  1467. abstract contract ERC1155Pausable is ERC1155, Pausable {
  1468. /**
  1469. * @dev See {ERC1155-_beforeTokenTransfer}.
  1470. *
  1471. * Requirements:
  1472. *
  1473. * - the contract must not be paused.
  1474. */
  1475. function _beforeTokenTransfer(
  1476. address operator,
  1477. address from,
  1478. address to,
  1479. uint256[] memory ids,
  1480. uint256[] memory amounts,
  1481. bytes memory data
  1482. ) internal virtual override {
  1483. super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
  1484.  
  1485. require(!paused(), "ERC1155Pausable: token transfer while paused");
  1486. }
  1487. }
  1488.  
  1489. /**
  1490. * @dev Extension of ERC1155 that adds tracking of total supply per id.
  1491. *
  1492. * Useful for scenarios where Fungible and Non-fungible tokens have to be
  1493. * clearly identified. Note: While a totalSupply of 1 might mean the
  1494. * corresponding is an NFT, there is no guarantees that no other token with the
  1495. * same id are not going to be minted.
  1496. */
  1497. /**
  1498. */
  1499. abstract contract ERC1155Supply is ERC1155 {
  1500. mapping(uint256 => uint256) private _totalSupply;
  1501.  
  1502. /**
  1503. * @dev Total amount of tokens in with a given id.
  1504. */
  1505. function totalSupply(uint256 id) public view virtual returns (uint256) {
  1506. return _totalSupply[id];
  1507. }
  1508.  
  1509. /**
  1510. * @dev Indicates weither any token exist with a given id, or not.
  1511. */
  1512. function exists(uint256 id) public view virtual returns (bool) {
  1513. return ERC1155Supply.totalSupply(id) > 0;
  1514. }
  1515.  
  1516. /**
  1517. * @dev See {ERC1155-_mint}.
  1518. */
  1519. function _mint(
  1520. address account,
  1521. uint256 id,
  1522. uint256 amount,
  1523. bytes memory data
  1524. ) internal virtual override {
  1525. super._mint(account, id, amount, data);
  1526. _totalSupply[id] += amount;
  1527. }
  1528.  
  1529. /**
  1530. * @dev See {ERC1155-_mintBatch}.
  1531. */
  1532. function _mintBatch(
  1533. address to,
  1534. uint256[] memory ids,
  1535. uint256[] memory amounts,
  1536. bytes memory data
  1537. ) internal virtual override {
  1538. super._mintBatch(to, ids, amounts, data);
  1539. for (uint256 i = 0; i < ids.length; ++i) {
  1540. _totalSupply[ids[i]] += amounts[i];
  1541. }
  1542. }
  1543.  
  1544. /**
  1545. * @dev See {ERC1155-_burn}.
  1546. */
  1547. function _burn(
  1548. address account,
  1549. uint256 id,
  1550. uint256 amount
  1551. ) internal virtual override {
  1552. super._burn(account, id, amount);
  1553. _totalSupply[id] -= amount;
  1554. }
  1555.  
  1556. /**
  1557. * @dev See {ERC1155-_burnBatch}.
  1558. */
  1559. function _burnBatch(
  1560. address account,
  1561. uint256[] memory ids,
  1562. uint256[] memory amounts
  1563. ) internal virtual override {
  1564. super._burnBatch(account, ids, amounts);
  1565. for (uint256 i = 0; i < ids.length; ++i) {
  1566. _totalSupply[ids[i]] -= amounts[i];
  1567. }
  1568. }
  1569. }
  1570.  
  1571. /**
  1572. * @dev External interface of AccessControl declared to support ERC165 detection.
  1573. */
  1574. interface IAccessControl {
  1575. function hasRole(bytes32 role, address account) external view returns (bool);
  1576.  
  1577. function getRoleAdmin(bytes32 role) external view returns (bytes32);
  1578.  
  1579. function grantRole(bytes32 role, address account) external;
  1580.  
  1581. function revokeRole(bytes32 role, address account) external;
  1582.  
  1583. function renounceRole(bytes32 role, address account) external;
  1584. }
  1585.  
  1586. /**
  1587. * @dev Contract module that allows children to implement role-based access
  1588. * control mechanisms. This is a lightweight version that doesn't allow enumerating role
  1589. * members except through off-chain means by accessing the contract event logs. Some
  1590. * applications may benefit from on-chain enumerability, for those cases see
  1591. * {AccessControlEnumerable}.
  1592. *
  1593. * Roles are referred to by their `bytes32` identifier. These should be exposed
  1594. * in the external API and be unique. The best way to achieve this is by
  1595. * using `public constant` hash digests:
  1596. *
  1597. * ```
  1598. * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
  1599. * ```
  1600. *
  1601. * Roles can be used to represent a set of permissions. To restrict access to a
  1602. * function call, use {hasRole}:
  1603. *
  1604. * ```
  1605. * function foo() public {
  1606. * require(hasRole(MY_ROLE, msg.sender));
  1607. * ...
  1608. * }
  1609. * ```
  1610. *
  1611. * Roles can be granted and revoked dynamically via the {grantRole} and
  1612. * {revokeRole} functions. Each role has an associated admin role, and only
  1613. * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
  1614. *
  1615. * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
  1616. * that only accounts with this role will be able to grant or revoke other
  1617. * roles. More complex role relationships can be created by using
  1618. * {_setRoleAdmin}.
  1619. *
  1620. * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
  1621. * grant and revoke this role. Extra precautions should be taken to secure
  1622. * accounts that have been granted it.
  1623. */
  1624. /**
  1625. */
  1626. abstract contract AccessControl is Context, IAccessControl, ERC165 {
  1627. struct RoleData {
  1628. mapping(address => bool) members;
  1629. bytes32 adminRole;
  1630. }
  1631.  
  1632. mapping(bytes32 => RoleData) private _roles;
  1633.  
  1634. bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
  1635.  
  1636. /**
  1637. * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
  1638. *
  1639. * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
  1640. * {RoleAdminChanged} not being emitted signaling this.
  1641. *
  1642. * _Available since v3.1._
  1643. */
  1644. event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
  1645.  
  1646. /**
  1647. * @dev Emitted when `account` is granted `role`.
  1648. *
  1649. * `sender` is the account that originated the contract call, an admin role
  1650. * bearer except when using {_setupRole}.
  1651. */
  1652. event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
  1653.  
  1654. /**
  1655. * @dev Emitted when `account` is revoked `role`.
  1656. *
  1657. * `sender` is the account that originated the contract call:
  1658. * - if using `revokeRole`, it is the admin role bearer
  1659. * - if using `renounceRole`, it is the role bearer (i.e. `account`)
  1660. */
  1661. event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
  1662.  
  1663. /**
  1664. * @dev Modifier that checks that an account has a specific role. Reverts
  1665. * with a standardized message including the required role.
  1666. *
  1667. * The format of the revert reason is given by the following regular expression:
  1668. *
  1669. * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
  1670. *
  1671. * _Available since v4.1._
  1672. */
  1673. modifier onlyRole(bytes32 role) {
  1674. _checkRole(role, _msgSender());
  1675. _;
  1676. }
  1677.  
  1678. /**
  1679. * @dev See {IERC165-supportsInterface}.
  1680. */
  1681. function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
  1682. return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
  1683. }
  1684.  
  1685. /**
  1686. * @dev Returns `true` if `account` has been granted `role`.
  1687. */
  1688. function hasRole(bytes32 role, address account) public view override returns (bool) {
  1689. return _roles[role].members[account];
  1690. }
  1691.  
  1692. /**
  1693. * @dev Revert with a standard message if `account` is missing `role`.
  1694. *
  1695. * The format of the revert reason is given by the following regular expression:
  1696. *
  1697. * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
  1698. */
  1699. function _checkRole(bytes32 role, address account) internal view {
  1700. if (!hasRole(role, account)) {
  1701. revert(
  1702. string(
  1703. abi.encodePacked(
  1704. "AccessControl: account ",
  1705. Strings.toHexString(uint160(account), 20),
  1706. " is missing role ",
  1707. Strings.toHexString(uint256(role), 32)
  1708. )
  1709. )
  1710. );
  1711. }
  1712. }
  1713.  
  1714. /**
  1715. * @dev Returns the admin role that controls `role`. See {grantRole} and
  1716. * {revokeRole}.
  1717. *
  1718. * To change a role's admin, use {_setRoleAdmin}.
  1719. */
  1720. function getRoleAdmin(bytes32 role) public view override returns (bytes32) {
  1721. return _roles[role].adminRole;
  1722. }
  1723.  
  1724. /**
  1725. * @dev Grants `role` to `account`.
  1726. *
  1727. * If `account` had not been already granted `role`, emits a {RoleGranted}
  1728. * event.
  1729. *
  1730. * Requirements:
  1731. *
  1732. * - the caller must have ``role``'s admin role.
  1733. */
  1734. function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
  1735. _grantRole(role, account);
  1736. }
  1737.  
  1738. /**
  1739. * @dev Revokes `role` from `account`.
  1740. *
  1741. * If `account` had been granted `role`, emits a {RoleRevoked} event.
  1742. *
  1743. * Requirements:
  1744. *
  1745. * - the caller must have ``role``'s admin role.
  1746. */
  1747. function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
  1748. _revokeRole(role, account);
  1749. }
  1750.  
  1751. /**
  1752. * @dev Revokes `role` from the calling account.
  1753. *
  1754. * Roles are often managed via {grantRole} and {revokeRole}: this function's
  1755. * purpose is to provide a mechanism for accounts to lose their privileges
  1756. * if they are compromised (such as when a trusted device is misplaced).
  1757. *
  1758. * If the calling account had been granted `role`, emits a {RoleRevoked}
  1759. * event.
  1760. *
  1761. * Requirements:
  1762. *
  1763. * - the caller must be `account`.
  1764. */
  1765. function renounceRole(bytes32 role, address account) public virtual override {
  1766. require(account == _msgSender(), "AccessControl: can only renounce roles for self");
  1767.  
  1768. _revokeRole(role, account);
  1769. }
  1770.  
  1771. /**
  1772. * @dev Grants `role` to `account`.
  1773. *
  1774. * If `account` had not been already granted `role`, emits a {RoleGranted}
  1775. * event. Note that unlike {grantRole}, this function doesn't perform any
  1776. * checks on the calling account.
  1777. *
  1778. * [WARNING]
  1779. * ====
  1780. * This function should only be called from the constructor when setting
  1781. * up the initial roles for the system.
  1782. *
  1783. * Using this function in any other way is effectively circumventing the admin
  1784. * system imposed by {AccessControl}.
  1785. * ====
  1786. */
  1787. function _setupRole(bytes32 role, address account) internal virtual {
  1788. _grantRole(role, account);
  1789. }
  1790.  
  1791. /**
  1792. * @dev Sets `adminRole` as ``role``'s admin role.
  1793. *
  1794. * Emits a {RoleAdminChanged} event.
  1795. */
  1796. function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
  1797. bytes32 previousAdminRole = getRoleAdmin(role);
  1798. _roles[role].adminRole = adminRole;
  1799. emit RoleAdminChanged(role, previousAdminRole, adminRole);
  1800. }
  1801.  
  1802. function _grantRole(bytes32 role, address account) private {
  1803. if (!hasRole(role, account)) {
  1804. _roles[role].members[account] = true;
  1805. emit RoleGranted(role, account, _msgSender());
  1806. }
  1807. }
  1808.  
  1809. function _revokeRole(bytes32 role, address account) private {
  1810. if (hasRole(role, account)) {
  1811. _roles[role].members[account] = false;
  1812. emit RoleRevoked(role, account, _msgSender());
  1813. }
  1814. }
  1815. }
  1816.  
  1817. /**
  1818. * @dev External interface of AccessControlEnumerable declared to support ERC165 detection.
  1819. */
  1820. interface IAccessControlEnumerable {
  1821. function getRoleMember(bytes32 role, uint256 index) external view returns (address);
  1822.  
  1823. function getRoleMemberCount(bytes32 role) external view returns (uint256);
  1824. }
  1825.  
  1826. /**
  1827. * @dev Extension of {AccessControl} that allows enumerating the members of each role.
  1828. */
  1829. /**
  1830. */
  1831. abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {
  1832. using EnumerableSet for EnumerableSet.AddressSet;
  1833.  
  1834. mapping(bytes32 => EnumerableSet.AddressSet) private _roleMembers;
  1835.  
  1836. /**
  1837. * @dev See {IERC165-supportsInterface}.
  1838. */
  1839. function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
  1840. return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);
  1841. }
  1842.  
  1843. /**
  1844. * @dev Returns one of the accounts that have `role`. `index` must be a
  1845. * value between 0 and {getRoleMemberCount}, non-inclusive.
  1846. *
  1847. * Role bearers are not sorted in any particular way, and their ordering may
  1848. * change at any point.
  1849. *
  1850. * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
  1851. * you perform all queries on the same block. See the following
  1852. * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
  1853. * for more information.
  1854. */
  1855. function getRoleMember(bytes32 role, uint256 index) public view override returns (address) {
  1856. return _roleMembers[role].at(index);
  1857. }
  1858.  
  1859. /**
  1860. * @dev Returns the number of accounts that have `role`. Can be used
  1861. * together with {getRoleMember} to enumerate all bearers of a role.
  1862. */
  1863. function getRoleMemberCount(bytes32 role) public view override returns (uint256) {
  1864. return _roleMembers[role].length();
  1865. }
  1866.  
  1867. /**
  1868. * @dev Overload {grantRole} to track enumerable memberships
  1869. */
  1870. function grantRole(bytes32 role, address account) public virtual override {
  1871. super.grantRole(role, account);
  1872. _roleMembers[role].add(account);
  1873. }
  1874.  
  1875. /**
  1876. * @dev Overload {revokeRole} to track enumerable memberships
  1877. */
  1878. function revokeRole(bytes32 role, address account) public virtual override {
  1879. super.revokeRole(role, account);
  1880. _roleMembers[role].remove(account);
  1881. }
  1882.  
  1883. /**
  1884. * @dev Overload {renounceRole} to track enumerable memberships
  1885. */
  1886. function renounceRole(bytes32 role, address account) public virtual override {
  1887. super.renounceRole(role, account);
  1888. _roleMembers[role].remove(account);
  1889. }
  1890.  
  1891. /**
  1892. * @dev Overload {_setupRole} to track enumerable memberships
  1893. */
  1894. function _setupRole(bytes32 role, address account) internal virtual override {
  1895. super._setupRole(role, account);
  1896. _roleMembers[role].add(account);
  1897. }
  1898. }
  1899.  
  1900. /**
  1901. * @dev Contract module which provides a basic access control mechanism, where
  1902. * there is an account (an owner) that can be granted exclusive access to
  1903. * specific functions.
  1904. *
  1905. * By default, the owner account will be the one that deploys the contract. This
  1906. * can later be changed with {transferOwnership}.
  1907. *
  1908. * This module is used through inheritance. It will make available the modifier
  1909. * `onlyOwner`, which can be applied to your functions to restrict their use to
  1910. * the owner.
  1911. */
  1912. abstract contract Ownable is Context {
  1913. address private _owner;
  1914.  
  1915. event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
  1916.  
  1917. /**
  1918. * @dev Initializes the contract setting the deployer as the initial owner.
  1919. */
  1920. constructor() {
  1921. _setOwner(_msgSender());
  1922. }
  1923.  
  1924. /**
  1925. * @dev Returns the address of the current owner.
  1926. */
  1927. function owner() public view virtual returns (address) {
  1928. return _owner;
  1929. }
  1930.  
  1931. /**
  1932. * @dev Throws if called by any account other than the owner.
  1933. */
  1934. modifier onlyOwner() {
  1935. require(owner() == _msgSender(), "Ownable: caller is not the owner");
  1936. _;
  1937. }
  1938.  
  1939. /**
  1940. * @dev Leaves the contract without owner. It will not be possible to call
  1941. * `onlyOwner` functions anymore. Can only be called by the current owner.
  1942. *
  1943. * NOTE: Renouncing ownership will leave the contract without an owner,
  1944. * thereby removing any functionality that is only available to the owner.
  1945. */
  1946. function renounceOwnership() public virtual onlyOwner {
  1947. _setOwner(address(0));
  1948. }
  1949.  
  1950. /**
  1951. * @dev Transfers ownership of the contract to a new account (`newOwner`).
  1952. * Can only be called by the current owner.
  1953. */
  1954. function transferOwnership(address newOwner) public virtual onlyOwner {
  1955. require(newOwner != address(0), "Ownable: new owner is the zero address");
  1956. _setOwner(newOwner);
  1957. }
  1958.  
  1959. function _setOwner(address newOwner) private {
  1960. address oldOwner = _owner;
  1961. _owner = newOwner;
  1962. emit OwnershipTransferred(oldOwner, newOwner);
  1963. }
  1964. }
  1965.  
  1966. /**
  1967. * @dev {ERC1155} token, including:
  1968. *
  1969. * - ability for holders to burn (destroy) their tokens
  1970. * - a minter role that allows for token minting (creation)
  1971. * - a pauser role that allows to stop all token transfers
  1972. *
  1973. * This contract uses {AccessControl} to lock permissioned functions using the
  1974. * different roles - head to its documentation for details.
  1975. *
  1976. * The account that deploys the contract will be granted the minter and pauser
  1977. * roles, as well as the default admin role, which will let it grant both minter
  1978. * and pauser roles to other accounts.
  1979. */
  1980. contract MyErc1155Contract is Context, AccessControlEnumerable, ERC1155Burnable, ERC1155Pausable, Ownable {
  1981. bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
  1982. bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
  1983.  
  1984. /**
  1985. * @dev Grants `DEFAULT_ADMIN_ROLE`, `MINTER_ROLE`, and `PAUSER_ROLE` to the account that
  1986. * deploys the contract.
  1987. */
  1988. constructor(string memory uri) ERC1155(uri) {
  1989. _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
  1990.  
  1991. _setupRole(MINTER_ROLE, _msgSender());
  1992. _setupRole(PAUSER_ROLE, _msgSender());
  1993. }
  1994.  
  1995. /**
  1996. * @dev Creates `amount` new tokens for `to`, of token type `id`.
  1997. *
  1998. * See {ERC1155-_mint}.
  1999. *
  2000. * Requirements:
  2001. *
  2002. * - the caller must have the `MINTER_ROLE`.
  2003. */
  2004. function mint(
  2005. address to,
  2006. uint256 id,
  2007. uint256 amount,
  2008. bytes memory data
  2009. ) public virtual {
  2010. require(hasRole(MINTER_ROLE, _msgSender()), "ERC1155SC: must have minter role to mint");
  2011.  
  2012. _mint(to, id, amount, data);
  2013. }
  2014.  
  2015. /**
  2016. * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] variant of {mint}.
  2017. */
  2018. function mintBatch(
  2019. address to,
  2020. uint256[] memory ids,
  2021. uint256[] memory amounts,
  2022. bytes memory data
  2023. ) public virtual {
  2024. require(hasRole(MINTER_ROLE, _msgSender()), "ERC1155SC: must have minter role to mint");
  2025.  
  2026. _mintBatch(to, ids, amounts, data);
  2027. }
  2028.  
  2029. /**
  2030. * @dev Pauses all token transfers.
  2031. *
  2032. * See {ERC1155Pausable} and {Pausable-_pause}.
  2033. *
  2034. * Requirements:
  2035. *
  2036. * - the caller must have the `PAUSER_ROLE`.
  2037. */
  2038. function pause() public virtual {
  2039. require(hasRole(PAUSER_ROLE, _msgSender()), "ERC1155SC: must have pauser role to pause");
  2040. _pause();
  2041. }
  2042.  
  2043. /**
  2044. * @dev Unpauses all token transfers.
  2045. *
  2046. * See {ERC1155Pausable} and {Pausable-_unpause}.
  2047. *
  2048. * Requirements:
  2049. *
  2050. * - the caller must have the `PAUSER_ROLE`.
  2051. */
  2052. function unpause() public virtual {
  2053. require(hasRole(PAUSER_ROLE, _msgSender()), "ERC1155SC: must have pauser role to unpause");
  2054. _unpause();
  2055. }
  2056.  
  2057. /**
  2058. * @dev See {IERC165-supportsInterface}.
  2059. */
  2060. function supportsInterface(bytes4 interfaceId)
  2061. public
  2062. view
  2063. virtual
  2064. override(AccessControlEnumerable, ERC1155)
  2065. returns (bool)
  2066. {
  2067. return super.supportsInterface(interfaceId);
  2068. }
  2069.  
  2070. function _beforeTokenTransfer(
  2071. address operator,
  2072. address from,
  2073. address to,
  2074. uint256[] memory ids,
  2075. uint256[] memory amounts,
  2076. bytes memory data
  2077. ) internal virtual override(ERC1155, ERC1155Pausable) {
  2078. super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
  2079. }
  2080.  
  2081. function setUri(string memory newuri) public onlyOwner {
  2082. _setURI(newuri);
  2083. }
  2084.  
  2085.  
  2086. }
  2087.  
Add Comment
Please, Sign In to add comment