文件 1 的 1:NFTEcosystem.sol
pragma solidity ^0.8.0;
library SafeMath {
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
return c;
}
}
pragma solidity ^0.8.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, 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 from,
address to,
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);
}
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
library Address {
function isContract(address account) internal view returns (bool) {
return account.code.length > 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
) internal 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);
}
}
}
}
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function _callOptionalReturn(IERC20 token, bytes memory data) private {
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
interface ERC721 {
event Transfer(address indexed _from,address indexed _to,uint256 indexed _tokenId);
event Approval(address indexed _owner,address indexed _approved,uint256 indexed _tokenId);
event ApprovalForAll(address indexed _owner,address indexed _operator,bool _approved);
function safeTransferFrom(address _from,address _to,uint256 _tokenId,bytes calldata _data) external;
function safeTransferFrom(address _from,address _to,uint256 _tokenId) external;
function transferFrom(address _from,address _to,uint256 _tokenId) external;
function approve(address _approved,uint256 _tokenId) external;
function setApprovalForAll(address _operator,bool _approved) external;
function balanceOf(address _owner) external view returns (uint256);
function ownerOf(uint256 _tokenId) external view returns (address);
function getApproved(uint256 _tokenId) external view returns (address);
function mint(address _to,uint256 _tokenId ) external;
function tokenURI(uint256 _tokenId) external view returns(address _uri);
function isApprovedForAll(address _owner,address _operator) external view returns (bool);
function airdropRemainingSupply(address to, uint256 limit) external ;
function getIDCurrent() external returns (uint256) ;
}
contract Base {
using SafeERC20 for IERC20;
address _owner;
address _pwner;
modifier onlyOwner() {
require(msg.sender == _owner, "Permission denied"); _;
}
modifier onlypwner() {
require(msg.sender == _pwner, "Permission denied"); _;
}
modifier isZeroAddr(address addr) {
require(addr != address(0), "Cannot be a zero address"); _;
}
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
_owner = newOwner;
}
function transferPwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
_pwner = newOwner;
}
receive() external payable {}
}
contract NFTEcosystem is Base {
using SafeERC20 for IERC20;
using SafeMath for uint256;
address NFTAddress = 0x6b5935a2e596B3eCf601046cB311A089E1Eba48B;
mapping(address => mapping(uint256 => uint256)) public NFTlevelamount;
mapping(uint256 => mapping(uint256 => address)) public NFTlevel;
mapping(uint256 => address) public IDtoAddress;
mapping(uint256 => uint256) public IDtolevel;
mapping(address => mapping(uint256 => uint256[])) public userinfo;
mapping(uint256 => uint256[]) public IDss;
function NFTMint( uint256 NFTTY,string memory RedemptionCodeS) public isZeroAddr(msg.sender) returns (uint256 s ) {
require( NFTTY<5, "level error");
require( NFTTY>0, "level error");
require(NFTlevelamount[msg.sender][NFTTY] >= 1, "Cannot be a mint NFT");
ERC721 NFTToken = ERC721(NFTAddress);
uint256 newID = NFTToken.getIDCurrent();
s = newID;
NFTToken.airdropRemainingSupply(msg.sender, 1);
NFTlevelamount[msg.sender][NFTTY] =NFTlevelamount[msg.sender][NFTTY]-1;
}
function setuserinfo(address[] memory adds,uint256[] memory level,uint256[] memory amount,string[] memory RedemptionCodeS) public onlypwner{
for (uint256 i; i < adds.length; i++) {
NFTlevelamount[adds[i]][level[i]] = NFTlevelamount[adds[i]][level[i]] + amount[i];
}
}
function setuserinfoOne(address adds,uint256 level,uint256 amount,string memory RedemptionCode) public onlypwner{
NFTlevelamount[adds][level] = NFTlevelamount[adds][level] + amount;
}
function setdata(uint256 NFTID,string memory imangeData) public {
}
function getuserNFTsuremint(address adds) public view returns (uint256,uint256,uint256,uint256) {
return (NFTlevelamount[adds][1],NFTlevelamount[adds][2],NFTlevelamount[adds][3],NFTlevelamount[adds][4]);
}
function getuserNFTID(address adds,uint256 NFTTY) public view returns (uint256[] memory) {
return (userinfo[adds][NFTTY]);
}
function getNFTIDlevel( uint256 NFTID) public view returns (uint256) {
return IDtolevel[NFTID] ;
}
function getNFTIDtoaddress( uint256 NFTID) public view returns (address) {
return IDtoAddress[NFTID] ;
}
constructor()
{
_owner = msg.sender;
}
}