About
Stats
Public Functions
31
Event Types
4
Code Size
105,540 bytes
Library Use
Uses SafeMath for uint256.
Uses SafeMath for uint32.
Uses SafeERC20 for IERC20.
Uses Counters for Counters.Counter.
Uses EnumerableSet for EnumerableSet.UintSet.
Uses EnumerableMap for EnumerableMap.UintToAddressMap.
Events (4) keyboard_arrow_up
Constants (5) keyboard_arrow_up
State Variables (27) keyboard_arrow_up
Functions
owner keyboard_arrow_up
renounceOwnership keyboard_arrow_up
transferOwnership keyboard_arrow_up
Modifiers help
onlyOwner checks for the following:
Source Code
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
supportsInterface keyboard_arrow_up
balanceOf keyboard_arrow_up
Source Code
function balanceOf(address owner) public view override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _holderTokens[owner].length();
}
ownerOf keyboard_arrow_up
name keyboard_arrow_up
symbol keyboard_arrow_up
tokenURI keyboard_arrow_up
Requirements help
null
Source Code
function tokenURI(uint256 tokenId)
public
view
override
returns (string memory)
{
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory _tokenURI = _tokenURIs[tokenId];
// If there is no base URI, return the token URI.
if (bytes(_baseURI).length == 0) {
return _tokenURI;
}
// If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
if (bytes(_tokenURI).length > 0) {
return string(abi.encodePacked(_baseURI, _tokenURI));
}
// If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI.
return string(abi.encodePacked(_baseURI, tokenId.toString()));
}
baseURI keyboard_arrow_up
tokenOfOwnerByIndex keyboard_arrow_up
totalSupply keyboard_arrow_up
tokenByIndex keyboard_arrow_up
approve keyboard_arrow_up
Requirements help
Source Code
function approve(address to, uint256 tokenId) public virtual override {
address owner = ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
}
getApproved keyboard_arrow_up
Requirements help
null
Source Code
function getApproved(uint256 tokenId) public view override returns (address) {
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
return _tokenApprovals[tokenId];
}
setApprovalForAll keyboard_arrow_up
Requirements help
Source Code
function setApprovalForAll(address operator, bool approved)
public
virtual
override
{
require(operator != _msgSender(), "ERC721: approve to caller");
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
isApprovedForAll keyboard_arrow_up
transferFrom keyboard_arrow_up
Requirements help
Source Code
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
//solhint-disable-next-line max-line-length
require(
_isApprovedOrOwner(_msgSender(), tokenId),
"ERC721: transfer caller is not owner nor approved"
);
_transfer(from, to, tokenId);
}
safeTransferFrom keyboard_arrow_up
Requirements help
Source Code
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
safeTransferFrom keyboard_arrow_up
Requirements help
Source Code
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public virtual override {
require(
_isApprovedOrOwner(_msgSender(), tokenId),
"ERC721: transfer caller is not owner nor approved"
);
_safeTransfer(from, to, tokenId, _data);
}
initProduct keyboard_arrow_up
Parameters help
Modifiers help
onlyOwner checks for the following:
Requirements help
Source Code
function initProduct(
address _mainAddr,
address _dnftTokenAddr,
address _uniswapAddr,
uint16 _id,
address _costTokenAddr,
uint256 _cost,
uint32 _totalReturnRate,
uint256 _maxMintTime,
uint256 _maxTokenSize
) external onlyOwner {
require(!_init, "repeat init");
require(_maxTokenSize < 1E6, "product total supply must be < 1E6");
mainAddr = _mainAddr;
pid = _id;
costTokenAddr = _costTokenAddr;
cost = _cost;
maxTokenSize = _maxTokenSize;
maxMintTime = _maxMintTime;
totalReturnRate = _totalReturnRate;
dnftTokenAddr = _dnftTokenAddr;
uniswapAddr = _uniswapAddr;
if (_costTokenAddr != address(0)) {
costTokenDecimals = IERC20Token(_costTokenAddr).decimals();
} else {
costTokenDecimals = 18;
}
mintTimeInterval = 1 minutes;
mintPerTimeValue = totalReturnRate.mul(cost).div(100).div(
maxMintTime.div(mintTimeInterval)
);
}
getDNFTPrice keyboard_arrow_up
tokensOfOwner keyboard_arrow_up
Source Code
function tokensOfOwner(address owner)
external
view
returns (Lib.ProductTokenDetail[] memory)
{
EnumerableSet.UintSet storage mintTokens = _tokenMints[owner];
uint256 holdLength = balanceOf(owner);
uint256 tokenLengthSize = mintTokens.length() + holdLength;
if (tokenLengthSize == 0) {
Lib.ProductTokenDetail[] memory zt = new Lib.ProductTokenDetail[](0);
return zt;
}
Lib.ProductTokenDetail[] memory tokens = new Lib.ProductTokenDetail[](
tokenLengthSize
);
uint256 i = 0;
while (i < mintTokens.length()) {
tokens[i] = _tokenDetails[mintTokens.at(i)];
i++;
}
uint256 j = 0;
while (j < holdLength) {
tokens[i] = _tokenDetails[tokenOfOwnerByIndex(owner, j)];
i++;
j++;
}
return tokens;
}
tokenDetailOf keyboard_arrow_up
tokenMintHistoryOf keyboard_arrow_up
withdrawToken keyboard_arrow_up
Modifiers help
onlyMain checks for the following:
Source Code
function withdrawToken(
address payable to,
address token,
uint256 value
) external onlyMain {
if (token == address(0)) to.transfer(value);
else IERC20(token).safeTransfer(to, value);
}
buy keyboard_arrow_up
Modifiers help
onlyMain checks for the following:
Requirements help
null
null
Source Code
function buy(address to) external onlyMain returns (uint256) {
require(_tokenIds.current() < maxTokenSize, "product not enough");
_tokenIds.increment();
uint256 tid = pid * 1E6 + _tokenIds.current();
Lib.ProductTokenDetail memory detail;
detail.id = tid;
detail.propA = Lib.random(0, 10000);
detail.propB = Lib.random(0, 10000);
detail.propC = Lib.random(0, 10000);
_tokenDetails[tid] = detail;
_safeMint(to, tid);
_setTokenURI(tid, Strings.toString(tid));
return tid;
}
mintBegin keyboard_arrow_up
Modifiers help
onlyMain checks for the following:
Requirements help
null
UNKNOWN VALUE
must not be equal to
UNKNOWN VALUE
Source Code
function mintBegin(address from, uint256 tokenId) external onlyMain {
require(
_isApprovedOrOwner(from, tokenId),
"ERC721: transfer caller is not owner nor approved"
);
Lib.ProductTokenDetail storage detail = _tokenDetails[tokenId];
require(detail.mining == false, "Token already mining.");
require(detail.totalTime < maxMintTime, "Token already dead.");
detail.mining = true;
detail.currMining.minter = from;
detail.currMining.beginTime = block.timestamp;
detail.currMining.endTime = 0;
detail.currMining.withdrawTime = detail.currMining.beginTime;
_tokenMints[from].add(tokenId);
_transfer(from, address(this), tokenId);
}
canWithdrawValue keyboard_arrow_up
mintWithdraw keyboard_arrow_up
redeem keyboard_arrow_up
Modifiers help
onlyMain checks for the following:
Requirements help
null
UNKNOWN VALUE
must not be equal to
UNKNOWN VALUE
null
Source Code
function redeem(address from, uint256 tokenId)
external
onlyMain
returns (uint256, uint256)
{
_onlyMinter(from, tokenId);
(uint256 withdrawNum, uint256 timeNum) = _mintWithdraw(from, tokenId);
Lib.ProductTokenDetail storage detail = _tokenDetails[tokenId];
detail.mining = false;
detail.currMining.endTime = block.timestamp;
_tokenMintHistories[tokenId].push(detail.currMining);
_tokenMints[from].remove(tokenId);
Lib.ProductMintItem memory currItem;
detail.currMining = currItem;
_safeTransfer(address(this), from, tokenId, "");
return (withdrawNum, timeNum);
}
Internal Functions
Internal functions are parts of the contract that can't be used directly, but instead are used by the public functions listed above.
internal DNFTProduct._onlyMinter keyboard_arrow_up
Requirements help
Source Code
function _onlyMinter(address from, uint256 tokenId) private view {
require(
_isApprovedOrOwner(address(this), tokenId),
"ERC721: transfer caller is not owner nor approved"
);
require(_tokenDetails[tokenId].mining == true, "Token no mining.");
require(
_tokenDetails[tokenId].currMining.minter == from,
"Token mine is not owner."
);
}
internal DNFTProduct._getUniswapPrice keyboard_arrow_up
Parameters help
Requirements help
Source Code
function _getUniswapPrice(
IUniswapV2Router02 r02,
uint256 _tv1,
address token1,
address token2
) private view returns (uint256) {
uint256 tv1 = _tv1;
IUniswapV2Factory f = IUniswapV2Factory(r02.factory());
address pairAddr = f.getPair(token1, token2);
require(pairAddr != address(0), "DNFT uniswap pair not exists.");
IERC20Token t1 = IERC20Token(token1);
IERC20Token t2 = IERC20Token(token2);
uint256 tb1 = t1.balanceOf(pairAddr);
uint256 tb2 = t2.balanceOf(pairAddr);
require(tb1 > 0 && tb2 > 0, "Pair token balance < 0");
uint256 td1 = 10**t1.decimals();
return td1.mul(tv1).div(tb1).mul(tb2).div(td1);
}
internal DNFTProduct._getDNFTPrice keyboard_arrow_up
Parameters help
This function has no parameters.
Source Code
function _getDNFTPrice() private view returns (uint256) {
if (costTokenAddr == address(dnftTokenAddr)) return 1E8;
if (uniswapAddr == address(0)) {
return 1000 * 1E8;
}
IUniswapV2Router02 r02 = IUniswapV2Router02(uniswapAddr);
address wethAddr = r02.WETH();
uint256 oneEthDnftPrice = _getUniswapPrice(
r02,
1E18,
wethAddr,
address(dnftTokenAddr)
);
if (costTokenAddr == address(0)) {
return oneEthDnftPrice;
} else {
uint256 oneEthTokenPrice = _getUniswapPrice(
r02,
1E18,
wethAddr,
costTokenAddr
);
if (costTokenDecimals == 8)
return ((oneEthDnftPrice * 1E8) / oneEthTokenPrice);
if (costTokenDecimals < 8)
return ((oneEthDnftPrice * 1E8) /
oneEthTokenPrice /
(10**(8 - uint256(costTokenDecimals))));
return
((oneEthDnftPrice * 1E8) / oneEthTokenPrice) *
(10**(uint256(costTokenDecimals) - 8));
}
}
internal DNFTProduct._canWithdrawValue keyboard_arrow_up
Source Code
function _canWithdrawValue(uint256 tokenId)
private
view
returns (uint256 timeNum, uint256 dnftNum)
{
uint256 price = _getDNFTPrice();
Lib.ProductTokenDetail storage detail = _tokenDetails[tokenId];
uint256 freeTimeNum = (maxMintTime.sub(detail.totalTime)).div(
mintTimeInterval
);
if (freeTimeNum <= 0) {
return (0, 0);
}
timeNum = block.timestamp.sub(detail.currMining.withdrawTime).div(
mintTimeInterval
);
if (timeNum > freeTimeNum) {
timeNum = freeTimeNum;
}
if (timeNum <= 0) {
return (0, 0);
}
uint256 decimal = 18;
if (costTokenAddr != address(0)) decimal = uint256(costTokenDecimals);
dnftNum = mintPerTimeValue.mul(price).mul(timeNum).div(10**decimal);
if (dnftNum <= 0) {
return (0, 0);
}
}
internal DNFTProduct._mintWithdraw keyboard_arrow_up
Source Code
function _mintWithdraw(address player, uint256 tokenId)
private
returns (uint256, uint256)
{
(uint256 timeNum, uint256 dnftNum) = _canWithdrawValue(tokenId);
if (dnftNum <= 0) return (dnftNum, timeNum);
Lib.ProductTokenDetail storage detail = _tokenDetails[tokenId];
detail.totalValue = detail.totalValue.add(dnftNum);
detail.currMining.totalValue = detail.currMining.totalValue.add(dnftNum);
uint256 useTime = timeNum.mul(mintTimeInterval);
detail.currMining.withdrawTime = detail.currMining.withdrawTime.add(useTime);
detail.totalTime = detail.totalTime.add(useTime);
IERC20Token(dnftTokenAddr).transfer(player, dnftNum);
return (dnftNum, timeNum);
}
internal ERC721._safeTransfer keyboard_arrow_up
Requirements help
Source Code
function _safeTransfer(
address from,
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_transfer(from, to, tokenId);
require(
_checkOnERC721Received(from, to, tokenId, _data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
internal ERC721._exists keyboard_arrow_up
internal ERC721._isApprovedOrOwner keyboard_arrow_up
Requirements help
null
Source Code
function _isApprovedOrOwner(address spender, uint256 tokenId)
internal
view
returns (bool)
{
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
address owner = ownerOf(tokenId);
return (spender == owner ||
getApproved(tokenId) == spender ||
isApprovedForAll(owner, spender));
}
internal ERC721._safeMint keyboard_arrow_up
Requirements help
Source Code
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
internal ERC721._safeMint keyboard_arrow_up
Requirements help
Source Code
function _safeMint(
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, _data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
internal ERC721._mint keyboard_arrow_up
Requirements help
Source Code
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_holderTokens[to].add(tokenId);
_tokenOwners.set(tokenId, to);
emit Transfer(address(0), to, tokenId);
}
internal ERC721._burn keyboard_arrow_up
Source Code
function _burn(uint256 tokenId) internal virtual {
address owner = ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
// Clear approvals
_approve(address(0), tokenId);
// Clear metadata (if any)
if (bytes(_tokenURIs[tokenId]).length != 0) {
delete _tokenURIs[tokenId];
}
_holderTokens[owner].remove(tokenId);
_tokenOwners.remove(tokenId);
emit Transfer(owner, address(0), tokenId);
}
internal ERC721._transfer keyboard_arrow_up
Requirements help
Source Code
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(
ownerOf(tokenId) == from,
"ERC721: transfer of token that is not own"
);
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
// Clear approvals from the previous owner
_approve(address(0), tokenId);
_holderTokens[from].remove(tokenId);
_holderTokens[to].add(tokenId);
_tokenOwners.set(tokenId, to);
emit Transfer(from, to, tokenId);
}
internal ERC721._setTokenURI keyboard_arrow_up
Requirements help
null
Source Code
function _setTokenURI(uint256 tokenId, string memory _tokenURI)
internal
virtual
{
require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token");
_tokenURIs[tokenId] = _tokenURI;
}
internal ERC721._setBaseURI keyboard_arrow_up
internal ERC721._checkOnERC721Received keyboard_arrow_up
Source Code
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory _data
) private returns (bool) {
if (!to.isContract()) {
return true;
}
bytes memory returndata = to.functionCall(
abi.encodeWithSelector(
IERC721Receiver(to).onERC721Received.selector,
_msgSender(),
from,
tokenId,
_data
),
"ERC721: transfer to non ERC721Receiver implementer"
);
bytes4 retval = abi.decode(returndata, (bytes4));
return (retval == _ERC721_RECEIVED);
}
internal ERC721._approve keyboard_arrow_up
internal ERC721._beforeTokenTransfer keyboard_arrow_up
internal Context._msgSender keyboard_arrow_up
internal Context._msgData keyboard_arrow_up
Parameters help
This function has no parameters.
Source Code
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
internal ERC165._registerInterface keyboard_arrow_up
Requirements help
Source Code
function _registerInterface(bytes4 interfaceId) internal virtual {
require(interfaceId != 0xffffffff, "ERC165: invalid interface id");
_supportedInterfaces[interfaceId] = true;
}
internal Context._msgSender keyboard_arrow_up
internal Context._msgData keyboard_arrow_up
Parameters help
This function has no parameters.
Source Code
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}