diff --git a/src/MintERC1155.sol b/src/MintERC1155.sol index 0d247ef..7c404b0 100644 --- a/src/MintERC1155.sol +++ b/src/MintERC1155.sol @@ -199,25 +199,38 @@ contract MintERC1155 is ERC1155Upgradeable, OwnableUpgradeable, ERC2981Upgradeab * @notice Check if the given address can receive tokens from this contract * @param to Address to check if receiving tokens is safe */ - function safeBatchTransferAcceptanceCheckOnMint(address to) external view returns (bool) { + function safeTransferAcceptanceCheckOnMint(address to) external view returns (bool) { + if (to.code.length == 0) return true; + + (bool success, bytes memory res) = to.staticcall{ gas: 400_000 }( + abi.encodeCall(IERC1155Receiver.onERC1155Received, (MINTER, address(0), 1, 1, "")) + ); + if (success) { + bytes4 response = abi.decode(res, (bytes4)); + if (response != IERC1155Receiver.onERC1155Received.selector) { + return false; + } + } else { + return false; + } + uint256[] memory idOrAmountArray = new uint256[](1); idOrAmountArray[0] = 1; - bytes memory callData = abi.encodeCall( - IERC1155Receiver.onERC1155BatchReceived, (MINTER, address(0), idOrAmountArray, idOrAmountArray, "") + (success, res) = to.staticcall{ gas: 400_000 }( + abi.encodeCall( + IERC1155Receiver.onERC1155BatchReceived, (MINTER, address(0), idOrAmountArray, idOrAmountArray, "") + ) ); - - if (to.code.length > 0) { - (bool success, bytes memory res) = to.staticcall{ gas: 400_000 }(callData); - if (success) { - bytes4 response = abi.decode(res, (bytes4)); - if (response != IERC1155Receiver.onERC1155BatchReceived.selector) { - return false; - } - } else { + if (success) { + bytes4 response = abi.decode(res, (bytes4)); + if (response != IERC1155Receiver.onERC1155BatchReceived.selector) { return false; } + } else { + return false; } + return true; } diff --git a/src/NFTMint.sol b/src/NFTMint.sol index 77a7623..5151328 100644 --- a/src/NFTMint.sol +++ b/src/NFTMint.sol @@ -194,7 +194,7 @@ contract NFTMint is Ownable { } } - if (!mint.safeBatchTransferAcceptanceCheckOnMint(msg.sender)) { + if (!mint.safeTransferAcceptanceCheckOnMint(msg.sender)) { revert NFTMint_BuyerNotAcceptingERC1155(); }