dexorder
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/utils/ERC1155Holder.sol)
|
||||
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
import {IERC165, ERC165} from "../../../utils/introspection/ERC165.sol";
|
||||
import {IERC1155Receiver} from "../IERC1155Receiver.sol";
|
||||
|
||||
/**
|
||||
* @dev Simple implementation of `IERC1155Receiver` that will allow a contract to hold ERC-1155 tokens.
|
||||
*
|
||||
* IMPORTANT: When inheriting this contract, you must include a way to use the received tokens, otherwise they will be
|
||||
* stuck.
|
||||
*/
|
||||
abstract contract ERC1155Holder is ERC165, IERC1155Receiver {
|
||||
/**
|
||||
* @dev See {IERC165-supportsInterface}.
|
||||
*/
|
||||
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
|
||||
return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);
|
||||
}
|
||||
|
||||
function onERC1155Received(
|
||||
address,
|
||||
address,
|
||||
uint256,
|
||||
uint256,
|
||||
bytes memory
|
||||
) public virtual override returns (bytes4) {
|
||||
return this.onERC1155Received.selector;
|
||||
}
|
||||
|
||||
function onERC1155BatchReceived(
|
||||
address,
|
||||
address,
|
||||
uint256[] memory,
|
||||
uint256[] memory,
|
||||
bytes memory
|
||||
) public virtual override returns (bytes4) {
|
||||
return this.onERC1155BatchReceived.selector;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
import {IERC1155Receiver} from "../IERC1155Receiver.sol";
|
||||
import {IERC1155Errors} from "../../../interfaces/draft-IERC6093.sol";
|
||||
|
||||
/**
|
||||
* @dev Library that provide common ERC-1155 utility functions.
|
||||
*
|
||||
* See https://eips.ethereum.org/EIPS/eip-1155[ERC-1155].
|
||||
*/
|
||||
library ERC1155Utils {
|
||||
/**
|
||||
* @dev Performs an acceptance check for the provided `operator` by calling {IERC1155-onERC1155Received}
|
||||
* on the `to` address. The `operator` is generally the address that initiated the token transfer (i.e. `msg.sender`).
|
||||
*
|
||||
* The acceptance call is not executed and treated as a no-op if the target address is doesn't contain code (i.e. an EOA).
|
||||
* Otherwise, the recipient must implement {IERC1155Receiver-onERC1155Received} and return the acceptance magic value to accept
|
||||
* the transfer.
|
||||
*/
|
||||
function checkOnERC1155Received(
|
||||
address operator,
|
||||
address from,
|
||||
address to,
|
||||
uint256 id,
|
||||
uint256 value,
|
||||
bytes memory data
|
||||
) internal {
|
||||
if (to.code.length > 0) {
|
||||
try IERC1155Receiver(to).onERC1155Received(operator, from, id, value, data) returns (bytes4 response) {
|
||||
if (response != IERC1155Receiver.onERC1155Received.selector) {
|
||||
// Tokens rejected
|
||||
revert IERC1155Errors.ERC1155InvalidReceiver(to);
|
||||
}
|
||||
} catch (bytes memory reason) {
|
||||
if (reason.length == 0) {
|
||||
// non-IERC1155Receiver implementer
|
||||
revert IERC1155Errors.ERC1155InvalidReceiver(to);
|
||||
} else {
|
||||
/// @solidity memory-safe-assembly
|
||||
assembly {
|
||||
revert(add(32, reason), mload(reason))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Performs a batch acceptance check for the provided `operator` by calling {IERC1155-onERC1155BatchReceived}
|
||||
* on the `to` address. The `operator` is generally the address that initiated the token transfer (i.e. `msg.sender`).
|
||||
*
|
||||
* The acceptance call is not executed and treated as a no-op if the target address is doesn't contain code (i.e. an EOA).
|
||||
* Otherwise, the recipient must implement {IERC1155Receiver-onERC1155Received} and return the acceptance magic value to accept
|
||||
* the transfer.
|
||||
*/
|
||||
function checkOnERC1155BatchReceived(
|
||||
address operator,
|
||||
address from,
|
||||
address to,
|
||||
uint256[] memory ids,
|
||||
uint256[] memory values,
|
||||
bytes memory data
|
||||
) internal {
|
||||
if (to.code.length > 0) {
|
||||
try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, values, data) returns (
|
||||
bytes4 response
|
||||
) {
|
||||
if (response != IERC1155Receiver.onERC1155BatchReceived.selector) {
|
||||
// Tokens rejected
|
||||
revert IERC1155Errors.ERC1155InvalidReceiver(to);
|
||||
}
|
||||
} catch (bytes memory reason) {
|
||||
if (reason.length == 0) {
|
||||
// non-IERC1155Receiver implementer
|
||||
revert IERC1155Errors.ERC1155InvalidReceiver(to);
|
||||
} else {
|
||||
/// @solidity memory-safe-assembly
|
||||
assembly {
|
||||
revert(add(32, reason), mload(reason))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user