|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.22; |
| 3 | + |
| 4 | +import {ERC1155} from "solady/src/tokens/ERC1155.sol"; |
| 5 | + |
| 6 | +/// @title ERC1155ConduitPreapprovedCloneable |
| 7 | +/// @notice ERC1155 token with the MagicEden conduit preapproved for seamless transactions. |
| 8 | +abstract contract ERC1155ConduitPreapprovedCloneable is ERC1155 { |
| 9 | + /// @dev The canonical MagicEden conduit address. |
| 10 | + address internal constant _CONDUIT = 0x2052f8A2Ff46283B30084e5d84c89A2fdBE7f74b; |
| 11 | + |
| 12 | + /// @notice Safely transfers `amount` tokens of type `id` from `from` to `to`. |
| 13 | + /// @param from The address holding the tokens. |
| 14 | + /// @param to The address to transfer the tokens to. |
| 15 | + /// @param id The token type identifier. |
| 16 | + /// @param amount The number of tokens to transfer. |
| 17 | + /// @param data Additional data with no specified format. |
| 18 | + function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) |
| 19 | + public |
| 20 | + virtual |
| 21 | + override |
| 22 | + { |
| 23 | + _safeTransfer(_by(), from, to, id, amount, data); |
| 24 | + } |
| 25 | + |
| 26 | + /// @notice Safely transfers a batch of tokens from `from` to `to`. |
| 27 | + /// @param from The address holding the tokens. |
| 28 | + /// @param to The address to transfer the tokens to. |
| 29 | + /// @param ids An array of token type identifiers. |
| 30 | + /// @param amounts An array of amounts to transfer for each token type. |
| 31 | + /// @param data Additional data with no specified format. |
| 32 | + function safeBatchTransferFrom( |
| 33 | + address from, |
| 34 | + address to, |
| 35 | + uint256[] calldata ids, |
| 36 | + uint256[] calldata amounts, |
| 37 | + bytes calldata data |
| 38 | + ) public virtual override { |
| 39 | + _safeBatchTransfer(_by(), from, to, ids, amounts, data); |
| 40 | + } |
| 41 | + |
| 42 | + /// @notice Checks if `operator` is approved to manage all of `owner`'s tokens. |
| 43 | + /// @param owner The address owning the tokens. |
| 44 | + /// @param operator The address to query for approval. |
| 45 | + /// @return True if `operator` is approved, otherwise false. |
| 46 | + function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { |
| 47 | + if (operator == _CONDUIT) return true; |
| 48 | + return ERC1155.isApprovedForAll(owner, operator); |
| 49 | + } |
| 50 | + |
| 51 | + /// @dev Determines the address initiating the transfer. |
| 52 | + /// If the caller is the predefined conduit, returns address(0), else returns the caller's address. |
| 53 | + /// @return result The address initiating the transfer. |
| 54 | + function _by() internal view virtual returns (address result) { |
| 55 | + assembly { |
| 56 | + // `msg.sender == _CONDUIT ? address(0) : msg.sender`. |
| 57 | + result := mul(iszero(eq(caller(), _CONDUIT)), caller()) |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments