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