From 94af202fb583ce24249d2b55951de8070261f712 Mon Sep 17 00:00:00 2001 From: Chris Blanquera Date: Mon, 7 Mar 2022 12:38:33 +0800 Subject: [PATCH] gryph namespace for testing --- README.md | 24 +----- contracts/GryphNamespaces.sol | 151 ++++++++++++++++++++++++++++++++++ contracts/GryphVesting.sol | 2 +- data/blacklist.json | 52 ++++++++++++ 4 files changed, 205 insertions(+), 24 deletions(-) create mode 100644 contracts/GryphNamespaces.sol create mode 100644 data/blacklist.json diff --git a/README.md b/README.md index ab815b4..0470ad3 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,10 @@ # GRY.PH NFT Smart Contracts -The contract defined here are to allow auditors to evaluate the contracts that -are designed and specifically for the purpose of the GRY.PH project. It -specifies the process of digitizing collectable designs. Some of the business -requirements include the following. - - - Ability to cheaply define a set of tokens that can be minted for each design which include the following. - - Design information - - Token quantity limits - - Royalty Fees - - Ability to mint tokens cheaply or, - - Ability to facilitate air drops off chain and, - - Ability for buyers to redeem air drops and pay the minting costs. - - Ability for holders to list tokens in a decentralized manner and, - - Ability for buyers to purchase listed tokens on any NFT marketplace while having, - - Ability to distribute royalties no matter where it was exchanged - -# Considerations - - - Use ERC1155 instead of ERC721 - - Use Enjin or Polygon instead of Ethereum - - Rarible Compatibility - #### Compatibility Solidity ^0.8.0 - - Recommended v0.8.4 + - Recommended v0.8.9 ## 1. Install diff --git a/contracts/GryphNamespaces.sol b/contracts/GryphNamespaces.sol new file mode 100644 index 0000000..ddf859a --- /dev/null +++ b/contracts/GryphNamespaces.sol @@ -0,0 +1,151 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; +import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; + +import "@openzeppelin/contracts/utils/Address.sol"; +import "@openzeppelin/contracts/utils/Counters.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; + +// +// ______ _______ ____ ____ _______ ____ ____ +// .' ___ ||_ __ \ |_ _||_ _| |_ __ \|_ || _| +// / .' \_| | |__) | \ \ / / | |__) | | |__| | +// | | ____ | __ / \ \/ / | ___/ | __ | +// \ `.___] |_| | \ \_ _| |_ _ _| |_ _| | | |_ +// `._____.'|____| |___||______|(_)|_____| |____||____| +// +// CROSS CHAIN NFT MARKETPLACE +// https://www.gry.ph/ +// + +// ============ Errors ============ + +error InvalidName(); +error InvalidAmountSent(); + +contract GryphNamespaces is ERC721, Ownable, ReentrancyGuard { + using Counters for Counters.Counter; + // ============ Constants ============ + + uint256[] public PRICES = [ + 0.192 ether, //4 letters + 0.096 ether, //5 letters + 0.048 ether, //6 letters + 0.024 ether, //7 letters + 0.012 ether, //8 letters + 0.006 ether, //9 letters + 0.003 ether //10 letters or more + ]; + + // ============ Storage ============ + + Counters.Counter private _tokenIdTracker; + + //mapping of token id to name + mapping(uint256 => string) public tokenName; + + //mapping of name to token id + mapping(string => uint256) public reserved; + + //mapping of names to blacklist + mapping(string => bool) public blacklisted; + + // ============ Deploy ============ + + /** + * @dev Sets the erc721 required fields + */ + constructor() ERC721("Gryph Namespaces", "GNS") {} + + // ============ Write Methods ============ + + /** + * @dev Allows anyone to buy a name + */ + function buy(address recipient, string memory name) external payable { + //get the length of name + uint256 length = bytes(name).length; + //disallow length length less than 4 + if (length < 4) revert InvalidName(); + //get index + uint256 index = length - 4; + if (index >= PRICES.length) { + index = PRICES.length - 1; + } + //check price + if (msg.value < PRICES[index]) revert InvalidAmountSent(); + //okay to mint + _nameMint(recipient, name); + } + + // ============ Admin Methods ============ + + /** + * @dev Disallows `names` + */ + function blacklist(string[] memory names) public onlyOwner { + for (uint256 i = 0; i < names.length; i++) { + //we can't blacklist if the name is already reserved + if (reserved[names[i]] > 0) revert InvalidName(); + blacklisted[names[i]] = true; + } + } + + /** + * @dev Allow admin to mint a name without paying (used for airdrops) + */ + function mint(address recipient, string memory name) public onlyOwner { + _nameMint(recipient, name); + } + + /** + * @dev Allow `names` + */ + function whitelist(string[] memory names) public onlyOwner { + for (uint256 i = 0; i < names.length; i++) { + blacklisted[names[i]] = false; + } + } + + /** + * @dev Sends the entire contract balance to a `recipient` + */ + function withdraw(address recipient) + external virtual nonReentrant onlyOwner + { + Address.sendValue(payable(recipient), address(this).balance); + } + + /** + * @dev This contract should not hold any tokens in the first place. + * This method exists to transfer out tokens funds. + */ + function withdraw(IERC20 erc20, address recipient, uint256 amount) + external virtual nonReentrant onlyOwner + { + SafeERC20.safeTransfer(erc20, recipient, amount); + } + + // ============ Internal Methods ============ + + function _nameMint(address recipient, string memory name) internal { + //already reserved or blacklisted + if (reserved[name] > 0 || blacklisted[name]) revert InvalidName(); + // We cannot just use balanceOf to create the new tokenId because tokens + // can be burned (destroyed), so we need a separate counter. + // first increment + _tokenIdTracker.increment(); + //get token id + uint256 tokenId = _tokenIdTracker.current(); + //now mint + _safeMint(recipient, tokenId); + //now add name + tokenName[tokenId] = name; + reserved[name] = tokenId; + } +} \ No newline at end of file diff --git a/contracts/GryphVesting.sol b/contracts/GryphVesting.sol index 6b8fb8d..52fb45e 100644 --- a/contracts/GryphVesting.sol +++ b/contracts/GryphVesting.sol @@ -40,7 +40,7 @@ contract GryphVesting is AccessControlEnumerable, ReentrancyGuard { - //so we can invoke mint function in vest and invest + //used in release() using Address for address; // ============ Events ============ diff --git a/data/blacklist.json b/data/blacklist.json new file mode 100644 index 0000000..13c06ac --- /dev/null +++ b/data/blacklist.json @@ -0,0 +1,52 @@ +[ + "arvr", + "atom", + "avax", + "doge", + "bttc", + "busd", + "dash", + "fake", + "flow", + "game", + "help", + "land", + "link", + "luna", + "meta", + "near", + "play", + "sale", + "scam", + "shib", + "shop", + "swap", + "tron", + "tusd", + "usdt", + "usdc", + "about", + "chain", + "games", + "gryph", + "matic", + "music", + "sales", + "bitcoin", + "sports", + "fashion", + "polygon", + "presale", + "roadmap", + "support", + "business", + "ethereum", + "exchange", + "explorer", + "phishing", + "community", + "sidechain", + "whitelist", + "whitepaper", + "marketplace" +] \ No newline at end of file