Facebook
From wtewtwt, 2 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 165
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.0;
  3. import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
  4. import "@openzeppelin/contracts/access/Ownable.sol";
  5.  
  6.  
  7. contract IsotopicAsset is ERC721Enumerable, Ownable {
  8.   using Strings for uint256;
  9.  
  10.   string public baseURI;  
  11.   string public baseExtension = ".json";
  12.  
  13.   bool public paused;
  14.  
  15.   mapping(address => uint256) public whitelisted;
  16.   mapping(address => uint256) public balance;
  17.  
  18.  
  19.   event BaseURIChanged(string indexed _oldBaseURI, string indexed _newBaseURI);
  20.   event BaseExtensionChanged(string indexed _oldBaseExtension, string indexed _newBaseExtension);
  21.   event PausedChanged(bool indexed _oldPaused, bool indexed _newPaused);
  22.  
  23.   constructor(  
  24.     string memory _name,
  25.     string memory _symbol,
  26.     string memory _initBaseURI,
  27.     bool _paused
  28.   ) ERC721(_name, _symbol) {
  29.     setBaseURI(_initBaseURI);
  30.     paused = _paused;
  31.   }
  32.  
  33.   function _baseURI() internal view virtual override returns (string memory) {
  34.     return baseURI;
  35.   }
  36.  
  37.  
  38.   function mint(address _to, uint256 _mintAmount) public {  
  39.     uint256 supply = totalSupply();
  40.     require(!paused);
  41.     require(_mintAmount > 0);
  42.  
  43.     if (msg.sender != owner()) {
  44.         require(whitelisted[msg.sender] >= _mintAmount, "only whitelist addresses can mint");
  45.     }
  46.  
  47.     for (uint256 i = 1; i <= _mintAmount; i++) {
  48.       _safeMint(_to, supply + i);
  49.     }
  50.  
  51.     if (msg.sender != owner()){
  52.         whitelisted[msg.sender] -= _mintAmount;
  53.     }
  54.  
  55.     balance[_to] += _mintAmount;
  56.   }
  57.  
  58.  
  59.   function walletOfOwner(address _owner) public view returns (uint256[] memory)
  60.   {
  61.     uint256 ownerTokenCount = balanceOf(_owner);
  62.     uint256[] memory tokenIds = new uint256[](ownerTokenCount);
  63.     for (uint256 i; i < ownerTokenCount; i++) {
  64.       tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
  65.     }
  66.     return tokenIds;
  67.   }
  68.  
  69.   function tokenURI(uint256 tokenId) public view virtual override returns (string memory)
  70.   {
  71.     require(
  72.       _exists(tokenId),
  73.       "ERC721Metadata: URI query for nonexistent token"
  74.     );
  75.  
  76.     string memory currentBaseURI = _baseURI();
  77.     return bytes(currentBaseURI).length > 0 ? string(abi.encodePacked(currentBaseURI, baseExtension)) : "";
  78.   }
  79.  
  80.   function setBaseURI(string memory _newBaseURI) public onlyOwner {
  81.     string memory oldBaseURI = baseURI;
  82.     baseURI = _newBaseURI;
  83.     emit BaseURIChanged(oldBaseURI, _newBaseURI);
  84.   }
  85.  
  86.   function setBaseExtension(string memory _newBaseExtension) public onlyOwner {
  87.     string memory oldBaseExtension = baseExtension;
  88.     baseExtension = _newBaseExtension;
  89.     emit BaseExtensionChanged(oldBaseExtension, _newBaseExtension);
  90.   }
  91.  
  92.   function pause(bool _state) public onlyOwner {  
  93.     bool oldPaused = paused;
  94.     paused = _state;
  95.     emit PausedChanged(oldPaused, _state);
  96.   }
  97.  
  98.  function setUserWhitelistAmount(address _user, uint256 _amount) public onlyOwner {
  99.     whitelisted[_user] = _amount;
  100.   }
  101.  
  102.   function increaseUserWhitelistAmount(address _user, uint256 _amount) public onlyOwner {
  103.     whitelisted[_user] += _amount;
  104.   }
  105.  
  106.   function getUserWhitelistAmount(address _user) public view returns (uint256){
  107.     return whitelisted[_user];
  108.   }
  109.  
  110.   function transferWhitelists(address _to, uint256 _amount) public {
  111.     require(whitelisted[msg.sender] >= _amount, "Cannot transfer more whitelists than available.");
  112.     whitelisted[_to] += _amount;
  113.     whitelisted[msg.sender] -= _amount;
  114.   }
  115. }