文件 1 的 16:Address.sol
pragma solidity ^0.8.0;
library Address {
function isContract(address account) internal view returns (bool) {
uint256 size;
assembly { size := extcodesize(account) }
return size > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
文件 2 的 16:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
this;
return msg.data;
}
}
文件 3 的 16:DIADataNFT.sol
pragma solidity 0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";
import "./DIASourceNFT.sol";
import "./Strings.sol";
contract DIADataNFT is Ownable, ERC1155 {
using Math for uint256;
using Strings for string;
address public DIASourceNFTAddr;
DIASourceNFT public diaSourceNFTImpl = DIASourceNFT(DIASourceNFTAddr);
address public DIAGenesisMinterAddr;
uint256 public constant NUM_PRIVILEGED_RANKS = 10;
uint256 public numMintedNFTs;
mapping (uint256 => address) rankMinter;
mapping (uint256 => uint256) rankClaims;
mapping (uint256 => uint) lastClaimPayout;
bool public exists;
bool public started;
bool public genesisPhase;
uint256 public sourceNFTId;
mapping (address => uint256) public mintsPerWallet;
uint256 public maxMintsPerWallet = 3;
address public paymentToken;
address public constant burnAddress = address(0x000000000000000000000000000000000000dEaD);
uint256 public burnAmount;
uint256 public mintingPoolAmount;
constructor(address _paymentToken, uint256 _burnAmount, uint256 _mintingPoolAmount, address _DIAGenesisMinterAddr, bytes memory metadataURI) ERC1155(string(metadataURI)) {
require(_paymentToken != address(0), "Payment token address is 0.");
paymentToken = _paymentToken;
burnAmount = _burnAmount;
mintingPoolAmount = _mintingPoolAmount;
DIAGenesisMinterAddr = _DIAGenesisMinterAddr;
}
event NewDataNFTCategory(uint256 sourceNFTId);
event MintedDataNFT(address owner, uint256 numMinted, uint256 newRank);
event ClaimedMintingPoolReward(uint256 rank, address claimer);
function uri(uint256 _id) public view override returns (string memory) {
if (_id > NUM_PRIVILEGED_RANKS) {
_id = NUM_PRIVILEGED_RANKS;
}
return string(abi.encodePacked(
super.uri(_id),
Strings.uint2str(_id),
".json"
));
}
function finishGenesisPhase() external onlyOwner {
genesisPhase = false;
}
function startMinting() external onlyOwner {
started = true;
}
function updateMaxMintsPerWallet(uint256 newValue) external onlyOwner {
maxMintsPerWallet = newValue;
}
function updateDIAGenesisMinterAddr(address newAddress) external onlyOwner {
DIAGenesisMinterAddr = newAddress;
}
function setSrcNFT(address _newAddress) external onlyOwner {
DIASourceNFTAddr = _newAddress;
diaSourceNFTImpl = DIASourceNFT(DIASourceNFTAddr);
}
function generateDataNFTCategory(uint256 _sourceNFTId) external {
require(diaSourceNFTImpl.balanceOf(msg.sender, _sourceNFTId) > 0);
exists = true;
genesisPhase = true;
started = false;
sourceNFTId = _sourceNFTId;
emit NewDataNFTCategory(_sourceNFTId);
}
function getRankClaim(uint256 newRank, uint256 max) public view returns (uint256) {
uint256 totalClaimsForMint = getTetrahedronSum(max);
uint256 rawRankClaim = (getInverseTetrahedronNumber(newRank, max) * mintingPoolAmount) / totalClaimsForMint;
if (newRank == 1 || newRank == 2) {
return ((getInverseTetrahedronNumber(1, max) * mintingPoolAmount) / totalClaimsForMint + (getInverseTetrahedronNumber(2, max) * mintingPoolAmount) / totalClaimsForMint) / 2;
} else if (newRank == 3 || newRank == 4 || newRank == 5) {
return ((getInverseTetrahedronNumber(3, max) * mintingPoolAmount) / totalClaimsForMint + (getInverseTetrahedronNumber(4, max) * mintingPoolAmount) / totalClaimsForMint + (getInverseTetrahedronNumber(5, max) * mintingPoolAmount) / totalClaimsForMint) / 3;
} else if (newRank == 6 || newRank == 7 || newRank == 8 || newRank == 9) {
return ((getInverseTetrahedronNumber(6, max) * mintingPoolAmount) / totalClaimsForMint + (getInverseTetrahedronNumber(7, max) * mintingPoolAmount) / totalClaimsForMint + (getInverseTetrahedronNumber(8, max) * mintingPoolAmount) / totalClaimsForMint + (getInverseTetrahedronNumber(9, max) * mintingPoolAmount) / totalClaimsForMint) / 4;
}
return rawRankClaim;
}
function _mintDataNFT(address _origin, uint256 _newRank) public returns (uint256) {
require(msg.sender == DIAGenesisMinterAddr, "Only callable from the genesis minter contract");
require(exists, "_mintDataNFT.Category must exist");
uint256 numMinted = numMintedNFTs;
if (numMinted < NUM_PRIVILEGED_RANKS) {
while (rankMinter[_newRank] != address(0)) {
_newRank = (_newRank + 1) % NUM_PRIVILEGED_RANKS;
}
} else {
_newRank = numMinted;
}
for (uint256 i = 0; i < Math.max(NUM_PRIVILEGED_RANKS, numMinted); i++) {
rankClaims[i] += getRankClaim(i, Math.max(NUM_PRIVILEGED_RANKS, numMinted));
}
require(mintsPerWallet[_origin] < maxMintsPerWallet, "Sender has used all its mints");
_mint(_origin, _newRank, 1, "");
rankMinter[_newRank] = _origin;
numMintedNFTs = numMinted + 1;
uint256 currSourceNFTId = sourceNFTId;
diaSourceNFTImpl.notifyDataNFTMint(currSourceNFTId);
mintsPerWallet[_origin] += 1;
emit MintedDataNFT(_origin, numMinted, _newRank);
return _newRank;
}
function getRankMinter(uint256 rank) external view returns (address) {
return rankMinter[rank];
}
function getLastClaimPayout(uint256 rank) external view returns (uint) {
return lastClaimPayout[rank];
}
function claimMintingPoolReward(uint256 rank) public {
require(!genesisPhase);
address claimer = msg.sender;
require(balanceOf(claimer, rank) > 0);
uint256 reward = rankClaims[rank];
require(ERC20(paymentToken).transfer(claimer, reward));
rankClaims[rank] = 0;
emit ClaimedMintingPoolReward(rank, claimer);
}
function getRewardAmount(uint256 rank) public view returns (uint) {
return rankClaims[rank];
}
function getTetrahedronNumber(uint256 n) internal pure returns (uint256) {
return (n * (n + 1) * (n + 2))/ 6;
}
function getInverseTetrahedronNumber(uint256 n, uint256 max) internal pure returns (uint256) {
return getTetrahedronNumber(max - n);
}
function getTetrahedronSum(uint256 n) internal pure returns (uint256) {
uint256 acc = 0;
for (uint256 i = 1; i <= n; i++) {
acc += getTetrahedronNumber(i);
}
return acc;
}
function getMintedNFTs() external view returns (uint) {
return numMintedNFTs;
}
}
文件 4 的 16:DIASourceNFT.sol
pragma solidity 0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract DIASourceNFT is Ownable, ERC1155 {
address public paymentToken;
mapping (address => bool) public dataNFTContractAddresses;
struct SourceNFTMetadata {
uint256 claimablePayout;
bool exists;
address admin;
uint256[] parentIds;
uint256[] parentPayoutShares;
uint256 payoutShare;
uint256 sourcePoolAmount;
}
mapping (uint256 => SourceNFTMetadata) public sourceNfts;
constructor(address newOwner) ERC1155("https://api.diadata.org/v1/nft/source_{id}.json") {
transferOwnership(newOwner);
}
function setMetadataUri(string memory metadataURI) onlyOwner external {
_setURI(metadataURI);
}
function getSourcePoolAmount(uint256 sourceNftId) external view returns (uint256) {
return sourceNfts[sourceNftId].sourcePoolAmount;
}
function setSourcePoolAmount(uint256 sourceNftId, uint256 newAmount) external {
require(sourceNfts[sourceNftId].admin == msg.sender, "Source Pool Amount can only be set by the sART admin");
sourceNfts[sourceNftId].sourcePoolAmount = newAmount;
}
function addDataNFTContractAddress(address newAddress) onlyOwner external {
require(newAddress != address(0), "New address is 0.");
dataNFTContractAddresses[newAddress] = true;
}
function removeDataNFTContractAddress(address oldAddress) onlyOwner external {
require(oldAddress != address(0), "Removed address is 0.");
dataNFTContractAddresses[oldAddress] = false;
}
function updateAdmin(uint256 sourceNftId, address newAdmin) external {
require(sourceNfts[sourceNftId].admin == msg.sender);
sourceNfts[sourceNftId].admin = newAdmin;
}
function addParent(uint256 sourceNftId, uint256 parentId, uint256 payoutShare) external {
require(sourceNfts[sourceNftId].admin == msg.sender);
require(sourceNfts[sourceNftId].payoutShare >= payoutShare);
require(sourceNfts[parentId].exists, "Parent NFT does not exist!");
sourceNfts[sourceNftId].payoutShare -= payoutShare;
sourceNfts[sourceNftId].parentPayoutShares.push(payoutShare);
sourceNfts[sourceNftId].parentIds.push(parentId);
}
function updateParentPayoutShare(uint256 sourceNftId, uint256 parentId, uint256 newPayoutShare) external {
require(sourceNfts[sourceNftId].admin == msg.sender);
uint256 arrayIndex = (2**256) - 1;
for (uint256 i = 0; i < sourceNfts[sourceNftId].parentPayoutShares.length; i++) {
if (sourceNfts[sourceNftId].parentIds[i] == parentId) {
arrayIndex = i;
break;
}
}
uint256 payoutDelta;
if (newPayoutShare >= sourceNfts[sourceNftId].parentPayoutShares[arrayIndex]) {
payoutDelta = newPayoutShare - sourceNfts[sourceNftId].parentPayoutShares[arrayIndex];
require(sourceNfts[sourceNftId].payoutShare >= payoutDelta, "Error: Not enough shares left to increase payout!");
sourceNfts[sourceNftId].payoutShare -= payoutDelta;
sourceNfts[sourceNftId].parentPayoutShares[arrayIndex] += payoutDelta;
} else {
payoutDelta = sourceNfts[sourceNftId].parentPayoutShares[arrayIndex] - newPayoutShare;
require(sourceNfts[sourceNftId].parentPayoutShares[arrayIndex] >= payoutDelta, "Error: Not enough shares left to decrease payout!");
sourceNfts[sourceNftId].payoutShare += payoutDelta;
sourceNfts[sourceNftId].parentPayoutShares[arrayIndex] -= payoutDelta;
}
}
function generateSourceToken(uint256 sourceNftId, address receiver) external onlyOwner {
sourceNfts[sourceNftId].exists = true;
sourceNfts[sourceNftId].admin = msg.sender;
sourceNfts[sourceNftId].payoutShare = 10000;
_mint(receiver, sourceNftId, 1, "");
}
function notifyDataNFTMint(uint256 sourceNftId) external {
require(dataNFTContractAddresses[msg.sender], "notifyDataNFTMint: Only data NFT contracts can be used to mint data NFTs");
require(sourceNfts[sourceNftId].exists, "notifyDataNFTMint: Source NFT does not exist!");
for (uint256 i = 0; i < sourceNfts[sourceNftId].parentIds.length; i++) {
uint256 currentParentId = sourceNfts[sourceNftId].parentIds[i];
sourceNfts[currentParentId].claimablePayout += (sourceNfts[sourceNftId].parentPayoutShares[i] * sourceNfts[sourceNftId].sourcePoolAmount) / 10000;
}
sourceNfts[sourceNftId].claimablePayout += (sourceNfts[sourceNftId].payoutShare * sourceNfts[sourceNftId].sourcePoolAmount) / 10000;
}
function claimRewards(uint256 sourceNftId) external {
address claimer = msg.sender;
require(sourceNfts[sourceNftId].admin == claimer);
uint256 payoutDataTokens = sourceNfts[sourceNftId].claimablePayout;
require(ERC20(paymentToken).transfer(claimer, payoutDataTokens), "Token transfer failed.");
sourceNfts[sourceNftId].claimablePayout = 0;
}
}
文件 5 的 16:ERC1155.sol
pragma solidity ^0.8.0;
import "./IERC1155.sol";
import "./IERC1155Receiver.sol";
import "./extensions/IERC1155MetadataURI.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/introspection/ERC165.sol";
contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
using Address for address;
mapping (uint256 => mapping(address => uint256)) private _balances;
mapping (address => mapping(address => bool)) private _operatorApprovals;
string private _uri;
constructor (string memory uri_) {
_setURI(uri_);
}
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IERC1155).interfaceId
|| interfaceId == type(IERC1155MetadataURI).interfaceId
|| super.supportsInterface(interfaceId);
}
function uri(uint256) public view virtual override returns (string memory) {
return _uri;
}
function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
require(account != address(0), "ERC1155: balance query for the zero address");
return _balances[id][account];
}
function balanceOfBatch(
address[] memory accounts,
uint256[] memory ids
)
public
view
virtual
override
returns (uint256[] memory)
{
require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch");
uint256[] memory batchBalances = new uint256[](accounts.length);
for (uint256 i = 0; i < accounts.length; ++i) {
batchBalances[i] = balanceOf(accounts[i], ids[i]);
}
return batchBalances;
}
function setApprovalForAll(address operator, bool approved) public virtual override {
require(_msgSender() != operator, "ERC1155: setting approval status for self");
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
function isApprovedForAll(address account, address operator) public view virtual override returns (bool) {
return _operatorApprovals[account][operator];
}
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
)
public
virtual
override
{
require(to != address(0), "ERC1155: transfer to the zero address");
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: caller is not owner nor approved"
);
address operator = _msgSender();
_beforeTokenTransfer(operator, from, to, _asSingletonArray(id), _asSingletonArray(amount), data);
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
_balances[id][from] = fromBalance - amount;
_balances[id][to] += amount;
emit TransferSingle(operator, from, to, id, amount);
_doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data);
}
function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
)
public
virtual
override
{
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
require(to != address(0), "ERC1155: transfer to the zero address");
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: transfer caller is not owner nor approved"
);
address operator = _msgSender();
_beforeTokenTransfer(operator, from, to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; ++i) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
_balances[id][from] = fromBalance - amount;
_balances[id][to] += amount;
}
emit TransferBatch(operator, from, to, ids, amounts);
_doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data);
}
function _setURI(string memory newuri) internal virtual {
_uri = newuri;
}
function _mint(address account, uint256 id, uint256 amount, bytes memory data) internal virtual {
require(account != address(0), "ERC1155: mint to the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, address(0), account, _asSingletonArray(id), _asSingletonArray(amount), data);
_balances[id][account] += amount;
emit TransferSingle(operator, address(0), account, id, amount);
_doSafeTransferAcceptanceCheck(operator, address(0), account, id, amount, data);
}
function _mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) internal virtual {
require(to != address(0), "ERC1155: mint to the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
for (uint i = 0; i < ids.length; i++) {
_balances[ids[i]][to] += amounts[i];
}
emit TransferBatch(operator, address(0), to, ids, amounts);
_doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);
}
function _burn(address account, uint256 id, uint256 amount) internal virtual {
require(account != address(0), "ERC1155: burn from the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, account, address(0), _asSingletonArray(id), _asSingletonArray(amount), "");
uint256 accountBalance = _balances[id][account];
require(accountBalance >= amount, "ERC1155: burn amount exceeds balance");
_balances[id][account] = accountBalance - amount;
emit TransferSingle(operator, account, address(0), id, amount);
}
function _burnBatch(address account, uint256[] memory ids, uint256[] memory amounts) internal virtual {
require(account != address(0), "ERC1155: burn from the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, account, address(0), ids, amounts, "");
for (uint i = 0; i < ids.length; i++) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 accountBalance = _balances[id][account];
require(accountBalance >= amount, "ERC1155: burn amount exceeds balance");
_balances[id][account] = accountBalance - amount;
}
emit TransferBatch(operator, account, address(0), ids, amounts);
}
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
)
internal
virtual
{ }
function _doSafeTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
)
private
{
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
if (response != IERC1155Receiver(to).onERC1155Received.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non ERC1155Receiver implementer");
}
}
}
function _doSafeBatchTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
)
private
{
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (bytes4 response) {
if (response != IERC1155Receiver(to).onERC1155BatchReceived.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non ERC1155Receiver implementer");
}
}
}
function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) {
uint256[] memory array = new uint256[](1);
array[0] = element;
return array;
}
}
文件 6 的 16:ERC165.sol
pragma solidity ^0.8.0;
import "./IERC165.sol";
abstract contract ERC165 is IERC165 {
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
文件 7 的 16:ERC20.sol
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
constructor (string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
function name() public view virtual override returns (string memory) {
return _name;
}
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
function decimals() public view virtual override returns (uint8) {
return 18;
}
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
uint256 currentAllowance = _allowances[sender][_msgSender()];
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
_approve(sender, _msgSender(), currentAllowance - amount);
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
uint256 currentAllowance = _allowances[_msgSender()][spender];
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
_approve(_msgSender(), spender, currentAllowance - subtractedValue);
return true;
}
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
uint256 senderBalance = _balances[sender];
require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
_balances[sender] = senderBalance - amount;
_balances[recipient] += amount;
emit Transfer(sender, recipient, amount);
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
_balances[account] += amount;
emit Transfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
_balances[account] = accountBalance - amount;
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}
文件 8 的 16:IERC1155.sol
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
interface IERC1155 is IERC165 {
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
event TransferBatch(address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values);
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
event URI(string value, uint256 indexed id);
function balanceOf(address account, uint256 id) external view returns (uint256);
function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids) external view returns (uint256[] memory);
function setApprovalForAll(address operator, bool approved) external;
function isApprovedForAll(address account, address operator) external view returns (bool);
function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) external;
function safeBatchTransferFrom(address from, address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data) external;
}
文件 9 的 16:IERC1155MetadataURI.sol
pragma solidity ^0.8.0;
import "../IERC1155.sol";
interface IERC1155MetadataURI is IERC1155 {
function uri(uint256 id) external view returns (string memory);
}
文件 10 的 16:IERC1155Receiver.sol
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
interface IERC1155Receiver is IERC165 {
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
)
external
returns(bytes4);
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
)
external
returns(bytes4);
}
文件 11 的 16:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 12 的 16:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
文件 13 的 16:IERC20Metadata.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
interface IERC20Metadata is IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
}
文件 14 的 16:Math.sol
pragma solidity ^0.8.0;
library Math {
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
}
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
function average(uint256 a, uint256 b) internal pure returns (uint256) {
return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
}
}
文件 15 的 16:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
文件 16 的 16:Strings.sol
pragma solidity 0.8.0;
library Strings {
function uint2str(uint _i) internal pure returns (string memory _uintAsString) {
if (_i == 0) {
return "0";
}
uint j = _i;
uint len;
while (j != 0) {
len++;
j /= 10;
}
bytes memory bstr = new bytes(len);
uint k = len;
while (_i != 0) {
k = k-1;
uint8 temp = (48 + uint8(_i - _i / 10 * 10));
bytes1 b1 = bytes1(temp);
bstr[k] = b1;
_i /= 10;
}
return string(bstr);
}
}
{
"compilationTarget": {
"contracts/DIADataNFT.sol": "DIADataNFT"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 20000
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_paymentToken","type":"address"},{"internalType":"uint256","name":"_burnAmount","type":"uint256"},{"internalType":"uint256","name":"_mintingPoolAmount","type":"uint256"},{"internalType":"address","name":"_DIAGenesisMinterAddr","type":"address"},{"internalType":"bytes","name":"metadataURI","type":"bytes"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"rank","type":"uint256"},{"indexed":false,"internalType":"address","name":"claimer","type":"address"}],"name":"ClaimedMintingPoolReward","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"numMinted","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newRank","type":"uint256"}],"name":"MintedDataNFT","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"sourceNFTId","type":"uint256"}],"name":"NewDataNFTCategory","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"values","type":"uint256[]"}],"name":"TransferBatch","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"TransferSingle","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"value","type":"string"},{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"URI","type":"event"},{"inputs":[],"name":"DIAGenesisMinterAddr","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DIASourceNFTAddr","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"NUM_PRIVILEGED_RANKS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_origin","type":"address"},{"internalType":"uint256","name":"_newRank","type":"uint256"}],"name":"_mintDataNFT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"accounts","type":"address[]"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"}],"name":"balanceOfBatch","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"burnAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"burnAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"rank","type":"uint256"}],"name":"claimMintingPoolReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"diaSourceNFTImpl","outputs":[{"internalType":"contract DIASourceNFT","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"exists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"finishGenesisPhase","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_sourceNFTId","type":"uint256"}],"name":"generateDataNFTCategory","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"genesisPhase","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"rank","type":"uint256"}],"name":"getLastClaimPayout","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMintedNFTs","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"newRank","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"getRankClaim","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"rank","type":"uint256"}],"name":"getRankMinter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"rank","type":"uint256"}],"name":"getRewardAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxMintsPerWallet","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mintingPoolAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"mintsPerWallet","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"numMintedNFTs","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paymentToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeBatchTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newAddress","type":"address"}],"name":"setSrcNFT","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sourceNFTId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"startMinting","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"started","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newAddress","type":"address"}],"name":"updateDIAGenesisMinterAddr","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newValue","type":"uint256"}],"name":"updateMaxMintsPerWallet","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_id","type":"uint256"}],"name":"uri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}]