From 7453ceeef4fd40b9af727708b930e2555fb0baa2 Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Wed, 28 Jun 2023 15:24:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E5=AE=A1=E8=AE=A1=E6=8A=A5?= =?UTF-8?q?=E5=91=8A=E4=BF=AE=E6=94=B9=E5=90=88=E7=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contracts/market/BENftMarket.sol | 29 +++++++++++++++++++++++------ contracts/tokens/erc721/NFT.sol | 7 ------- contracts/utils/TimeChecker.sol | 3 +++ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/contracts/market/BENftMarket.sol b/contracts/market/BENftMarket.sol index 3ac4265..f943182 100644 --- a/contracts/market/BENftMarket.sol +++ b/contracts/market/BENftMarket.sol @@ -24,6 +24,8 @@ contract BENftMarket is Ownable, ReentrancyGuard, ERC1155Holder, ERC721Holder { } mapping(address => bool) public erc721Supported; mapping(address => bool) public erc1155Supported; + mapping(address => bool) public erc721SupportedHistory; + mapping(address => bool) public erc1155SupportedHistory; mapping(address => bool) public erc20Supported; mapping(uint256 => OrderInfo) public orderInfos; mapping(address => uint256) public nftPriceMaxLimit; @@ -145,9 +147,10 @@ contract BENftMarket is Ownable, ReentrancyGuard, ERC1155Holder, ERC721Holder { ); } - function buy(uint256 orderId) external nonReentrant { + function buy(uint256 orderId, uint256 price) external nonReentrant { OrderInfo memory orderInfo = orderInfos[orderId]; - require(orderInfo.tokenId != 0, "NFTMarket: NFT does not exist"); + require(orderInfo.orderId != 0, "NFTMarket: order info does not exist"); + require(orderInfo.price == price, "NFTMarket: Price error"); uint256 _transactionFee = (orderInfo.price * transactionFee) / ROUND; tranFeeTotal = tranFeeTotal + _transactionFee; uint256 _transactionTax = (orderInfo.price * transactionTax) / ROUND; @@ -178,13 +181,19 @@ contract BENftMarket is Ownable, ReentrancyGuard, ERC1155Holder, ERC721Holder { ); } - if (erc721Supported[orderInfo.nftToken]) { + if ( + erc721Supported[orderInfo.nftToken] || + erc721SupportedHistory[orderInfo.nftToken] + ) { IERC721(orderInfo.nftToken).safeTransferFrom( address(this), _msgSender(), orderInfo.tokenId ); - } else if (erc1155Supported[orderInfo.nftToken]) { + } else if ( + erc1155Supported[orderInfo.nftToken] || + erc1155SupportedHistory[orderInfo.nftToken] + ) { IERC1155(orderInfo.nftToken).safeTransferFrom( address(this), _msgSender(), @@ -213,13 +222,19 @@ contract BENftMarket is Ownable, ReentrancyGuard, ERC1155Holder, ERC721Holder { "NFTMarket: cancel caller is not owner" ); OrderInfo memory orderInfo = orderInfos[orderId]; - if (erc721Supported[orderInfo.nftToken]) { + if ( + erc721Supported[orderInfo.nftToken] || + erc721SupportedHistory[orderInfo.nftToken] + ) { IERC721(orderInfo.nftToken).safeTransferFrom( address(this), _msgSender(), orderInfo.tokenId ); - } else if (erc1155Supported[orderInfo.nftToken]) { + } else if ( + erc1155Supported[orderInfo.nftToken] || + erc1155SupportedHistory[orderInfo.nftToken] + ) { IERC1155(orderInfo.nftToken).safeTransferFrom( address(this), _msgSender(), @@ -270,6 +285,7 @@ contract BENftMarket is Ownable, ReentrancyGuard, ERC1155Holder, ERC721Holder { */ function removeERC721Support(address nftToken) external onlyOwner { erc721Supported[nftToken] = false; + erc1155SupportedHistory[nftToken] = true; emit RemoveNFTSuppout(nftToken); } @@ -286,6 +302,7 @@ contract BENftMarket is Ownable, ReentrancyGuard, ERC1155Holder, ERC721Holder { */ function removeERC1155Support(address nftToken) external onlyOwner { erc1155Supported[nftToken] = false; + erc1155SupportedHistory[nftToken] = true; emit RemoveNFTSuppout(nftToken); } diff --git a/contracts/tokens/erc721/NFT.sol b/contracts/tokens/erc721/NFT.sol index d3b045c..ac65aa6 100644 --- a/contracts/tokens/erc721/NFT.sol +++ b/contracts/tokens/erc721/NFT.sol @@ -108,13 +108,6 @@ contract NFT is AccessControl, ERC721Enumerable { emit UnLock(tokenId); } - /** - * @dev Get lock status - */ - function isLocked(uint256 tokenId) external view returns (bool) { - return lockedTokens[tokenId]; - } - /** * @dev Set token URI */ diff --git a/contracts/utils/TimeChecker.sol b/contracts/utils/TimeChecker.sol index 76843f7..1306890 100644 --- a/contracts/utils/TimeChecker.sol +++ b/contracts/utils/TimeChecker.sol @@ -4,9 +4,11 @@ import "@openzeppelin/contracts/access/Ownable.sol"; contract TimeChecker is Ownable { uint256 private _duration; + uint256 private minDuration; constructor() { _duration = 1 days; + minDuration = 30 minutes; } modifier timeValid(uint256 time) { @@ -28,6 +30,7 @@ contract TimeChecker is Ownable { * @dev Change duration value */ function updateDuation(uint256 valNew) external onlyOwner { + require(valNew > minDuration, "duration too short"); _duration = valNew; } }