nft的market增加tax

This commit is contained in:
zhl 2023-06-14 17:03:48 +08:00
parent 228833aed4
commit 0e48455ad9

View File

@ -10,7 +10,7 @@ import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
contract BENFTMarket is Ownable, ReentrancyGuard, ERC1155Holder,ERC721Holder {
contract BENFTMarket is Ownable, ReentrancyGuard, ERC1155Holder, ERC721Holder {
using SafeERC20 for IERC20;
struct OrderInfo {
@ -70,6 +70,7 @@ contract BENFTMarket is Ownable, ReentrancyGuard, ERC1155Holder,ERC721Holder {
event RemoveERC20Suppout(address erc20);
uint256 public tranFeeTotal;
uint256 public tranTaxTotal;
uint256 constant ROUND = 1000000;
uint256 public transactionFee = (3 * ROUND) / 100;
@ -78,8 +79,16 @@ contract BENFTMarket is Ownable, ReentrancyGuard, ERC1155Holder,ERC721Holder {
// max transaction fee is: 10%
uint256 public constant MAX_TRANSACTION_FEE = (10 * ROUND) / 100;
uint256 public transactionTax = (1 * ROUND) / 100;
// min transaction tax is: 0
uint256 public constant MIN_TRANSACTION_TAX = 0;
// max transaction tax is: 10%
uint256 public constant MAX_TRANSACTION_TAX = (10 * ROUND) / 100;
address public feeToAddress;
address public taxToAddress;
uint256 public incrId;
function sell(
@ -140,10 +149,10 @@ contract BENFTMarket is Ownable, ReentrancyGuard, ERC1155Holder,ERC721Holder {
OrderInfo memory orderInfo = orderInfos[orderId];
require(orderInfo.tokenId != 0, "NFTMarket: NFT does not exist");
uint256 _transactionFee = (orderInfo.price * transactionFee) / ROUND;
tranFeeTotal = tranFeeTotal + _transactionFee;
uint256 _amount = orderInfo.price - _transactionFee;
uint256 _transactionTax = (orderInfo.price * transactionTax) / ROUND;
tranTaxTotal = tranTaxTotal + _transactionTax;
uint256 _amount = orderInfo.price - _transactionFee - _transactionTax;
IERC20(orderInfo.currency).safeTransferFrom(
msg.sender,
@ -156,6 +165,12 @@ contract BENFTMarket is Ownable, ReentrancyGuard, ERC1155Holder,ERC721Holder {
feeToAddress,
_transactionFee
);
IERC20(orderInfo.currency).safeTransferFrom(
msg.sender,
taxToAddress,
_transactionTax
);
if (erc721Supported[orderInfo.nftToken]) {
IERC721(orderInfo.nftToken).safeTransferFrom(
address(this),
@ -216,7 +231,8 @@ contract BENFTMarket is Ownable, ReentrancyGuard, ERC1155Holder,ERC721Holder {
require(orderInfo.tokenId != 0, "NFTMarket: NFT does not exist");
require(orderInfo.owner == msg.sender, "NFTMarket: caller is not owner");
require(
price <= nftPriceMaxLimit[orderInfo.nftToken] || nftPriceMaxLimit[orderInfo.nftToken] == 0,
price <= nftPriceMaxLimit[orderInfo.nftToken] ||
nftPriceMaxLimit[orderInfo.nftToken] == 0,
"NFTMarket: Maximum price limit exceeded"
);
require(
@ -225,44 +241,71 @@ contract BENFTMarket is Ownable, ReentrancyGuard, ERC1155Holder,ERC721Holder {
);
uint256 priceOld = orderInfo.price;
orderInfo.price = price;
emit PriceUpdate(orderId, orderInfo.nftToken, orderInfo.tokenId, priceOld, price);
emit PriceUpdate(
orderId,
orderInfo.nftToken,
orderInfo.tokenId,
priceOld,
price
);
}
/**
* @dev Add ERC20 support
*/
function addERC721Support(address nftToken) external onlyOwner {
erc721Supported[nftToken] = true;
emit AddNFTSuppout(nftToken);
}
/**
* @dev Remove 721 NFT support
*/
function removeERC721Support(address nftToken) external onlyOwner {
erc721Supported[nftToken] = false;
emit RemoveNFTSuppout(nftToken);
}
/**
* @dev Add 1155 NFT support
*/
function addERC1155Support(address nftToken) external onlyOwner {
erc1155Supported[nftToken] = true;
emit AddNFTSuppout(nftToken);
}
/**
* @dev Remove 1155 NFT support
*/
function removeERC1155Support(address nftToken) external onlyOwner {
erc1155Supported[nftToken] = false;
emit RemoveNFTSuppout(nftToken);
}
/**
* @dev Add ERC20 support
*/
function addERC20Support(address erc20) external onlyOwner {
require(erc20 != address(0), "NFTMarket: ERC20 address is zero");
erc20Supported[erc20] = true;
emit AddERC20Suppout(erc20);
}
/**
* @dev Remove ERC20 support
*/
function removeERC20Support(address erc20) external onlyOwner {
erc20Supported[erc20] = false;
emit RemoveERC20Suppout(erc20);
}
function setNFTPriceMaxLimit(address nftToken, uint256 maxLimit)
external
onlyOwner
{
/**
* @dev Set the maximum price limit for NFT
*/
function setNFTPriceMaxLimit(
address nftToken,
uint256 maxLimit
) external onlyOwner {
require(
maxLimit >= nftPriceMinLimit[nftToken],
"NFTMarket: maxLimit can not be less than min limit!"
@ -270,10 +313,13 @@ contract BENFTMarket is Ownable, ReentrancyGuard, ERC1155Holder,ERC721Holder {
nftPriceMaxLimit[nftToken] = maxLimit;
}
function setNFTPriceMinLimit(address nftToken, uint256 minLimit)
external
onlyOwner
{
/**
* @dev Set the minimum price limit for NFT
*/
function setNFTPriceMinLimit(
address nftToken,
uint256 minLimit
) external onlyOwner {
if (nftPriceMaxLimit[nftToken] != 0) {
require(
minLimit <= nftPriceMaxLimit[nftToken],
@ -283,6 +329,9 @@ contract BENFTMarket is Ownable, ReentrancyGuard, ERC1155Holder,ERC721Holder {
nftPriceMinLimit[nftToken] = minLimit;
}
/**
* @dev Set the transaction fee
*/
function setTransactionFee(uint256 _transactionFee) external onlyOwner {
require(
_transactionFee >= MIN_TRANSACTION_FEE &&
@ -292,8 +341,37 @@ contract BENFTMarket is Ownable, ReentrancyGuard, ERC1155Holder,ERC721Holder {
transactionFee = _transactionFee;
}
/**
* @dev Set the fee received address
*/
function setFeeToAddress(address _feeToAddress) external onlyOwner {
require(_feeToAddress != address(0), "NFTMarket: fee received address can not be zero");
require(
_feeToAddress != address(0),
"NFTMarket: fee received address can not be zero"
);
feeToAddress = _feeToAddress;
}
/**
* @dev Set the transaction tax
*/
function setTransactionTax(uint256 _transactionTax) external onlyOwner {
require(
_transactionTax >= MIN_TRANSACTION_TAX &&
_transactionTax <= MAX_TRANSACTION_TAX,
"NFTMarket: _transactionTax must >= 0 and <= 10%"
);
transactionTax = _transactionTax;
}
/**
* @dev Set the tax received address
*/
function setTaxToAddress(address _taxToAddress) external onlyOwner {
require(
_taxToAddress != address(0),
"NFTMarket: tax received address can not be zero"
);
taxToAddress = _taxToAddress;
}
}