根据审计报告修改合约

This commit is contained in:
CounterFire2023 2023-06-28 15:24:34 +08:00
parent fb0c3a2093
commit 7453ceeef4
3 changed files with 26 additions and 13 deletions

View File

@ -24,6 +24,8 @@ contract BENftMarket is Ownable, ReentrancyGuard, ERC1155Holder, ERC721Holder {
} }
mapping(address => bool) public erc721Supported; mapping(address => bool) public erc721Supported;
mapping(address => bool) public erc1155Supported; mapping(address => bool) public erc1155Supported;
mapping(address => bool) public erc721SupportedHistory;
mapping(address => bool) public erc1155SupportedHistory;
mapping(address => bool) public erc20Supported; mapping(address => bool) public erc20Supported;
mapping(uint256 => OrderInfo) public orderInfos; mapping(uint256 => OrderInfo) public orderInfos;
mapping(address => uint256) public nftPriceMaxLimit; 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]; 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; uint256 _transactionFee = (orderInfo.price * transactionFee) / ROUND;
tranFeeTotal = tranFeeTotal + _transactionFee; tranFeeTotal = tranFeeTotal + _transactionFee;
uint256 _transactionTax = (orderInfo.price * transactionTax) / ROUND; 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( IERC721(orderInfo.nftToken).safeTransferFrom(
address(this), address(this),
_msgSender(), _msgSender(),
orderInfo.tokenId orderInfo.tokenId
); );
} else if (erc1155Supported[orderInfo.nftToken]) { } else if (
erc1155Supported[orderInfo.nftToken] ||
erc1155SupportedHistory[orderInfo.nftToken]
) {
IERC1155(orderInfo.nftToken).safeTransferFrom( IERC1155(orderInfo.nftToken).safeTransferFrom(
address(this), address(this),
_msgSender(), _msgSender(),
@ -213,13 +222,19 @@ contract BENftMarket is Ownable, ReentrancyGuard, ERC1155Holder, ERC721Holder {
"NFTMarket: cancel caller is not owner" "NFTMarket: cancel caller is not owner"
); );
OrderInfo memory orderInfo = orderInfos[orderId]; OrderInfo memory orderInfo = orderInfos[orderId];
if (erc721Supported[orderInfo.nftToken]) { if (
erc721Supported[orderInfo.nftToken] ||
erc721SupportedHistory[orderInfo.nftToken]
) {
IERC721(orderInfo.nftToken).safeTransferFrom( IERC721(orderInfo.nftToken).safeTransferFrom(
address(this), address(this),
_msgSender(), _msgSender(),
orderInfo.tokenId orderInfo.tokenId
); );
} else if (erc1155Supported[orderInfo.nftToken]) { } else if (
erc1155Supported[orderInfo.nftToken] ||
erc1155SupportedHistory[orderInfo.nftToken]
) {
IERC1155(orderInfo.nftToken).safeTransferFrom( IERC1155(orderInfo.nftToken).safeTransferFrom(
address(this), address(this),
_msgSender(), _msgSender(),
@ -270,6 +285,7 @@ contract BENftMarket is Ownable, ReentrancyGuard, ERC1155Holder, ERC721Holder {
*/ */
function removeERC721Support(address nftToken) external onlyOwner { function removeERC721Support(address nftToken) external onlyOwner {
erc721Supported[nftToken] = false; erc721Supported[nftToken] = false;
erc1155SupportedHistory[nftToken] = true;
emit RemoveNFTSuppout(nftToken); emit RemoveNFTSuppout(nftToken);
} }
@ -286,6 +302,7 @@ contract BENftMarket is Ownable, ReentrancyGuard, ERC1155Holder, ERC721Holder {
*/ */
function removeERC1155Support(address nftToken) external onlyOwner { function removeERC1155Support(address nftToken) external onlyOwner {
erc1155Supported[nftToken] = false; erc1155Supported[nftToken] = false;
erc1155SupportedHistory[nftToken] = true;
emit RemoveNFTSuppout(nftToken); emit RemoveNFTSuppout(nftToken);
} }

View File

@ -108,13 +108,6 @@ contract NFT is AccessControl, ERC721Enumerable {
emit UnLock(tokenId); emit UnLock(tokenId);
} }
/**
* @dev Get lock status
*/
function isLocked(uint256 tokenId) external view returns (bool) {
return lockedTokens[tokenId];
}
/** /**
* @dev Set token URI * @dev Set token URI
*/ */

View File

@ -4,9 +4,11 @@ import "@openzeppelin/contracts/access/Ownable.sol";
contract TimeChecker is Ownable { contract TimeChecker is Ownable {
uint256 private _duration; uint256 private _duration;
uint256 private minDuration;
constructor() { constructor() {
_duration = 1 days; _duration = 1 days;
minDuration = 30 minutes;
} }
modifier timeValid(uint256 time) { modifier timeValid(uint256 time) {
@ -28,6 +30,7 @@ contract TimeChecker is Ownable {
* @dev Change duration value * @dev Change duration value
*/ */
function updateDuation(uint256 valNew) external onlyOwner { function updateDuation(uint256 valNew) external onlyOwner {
require(valNew > minDuration, "duration too short");
_duration = valNew; _duration = valNew;
} }
} }