Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Opensea's Operator Filter Registry #423

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 38 additions & 8 deletions smart-contract/contracts/YourNftToken.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// SPDX-License-Identifier: MIT
// Modified by datboi1337 to make compliant with Opensea Operator Filter Registry

pragma solidity >=0.8.9 <0.9.0;
pragma solidity >=0.8.13 <0.9.0;

import 'erc721a/contracts/extensions/ERC721AQueryable.sol';
import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/utils/cryptography/MerkleProof.sol';
import "@openzeppelin/contracts/utils/Strings.sol";
import '@openzeppelin/contracts/security/ReentrancyGuard.sol';
import 'operator-filter-registry/src/DefaultOperatorFilterer.sol';

contract YourNftToken is ERC721AQueryable, Ownable, ReentrancyGuard {
contract YourNftToken is ERC721AQueryable, Ownable, ReentrancyGuard, DefaultOperatorFilterer {

using Strings for uint256;

Expand Down Expand Up @@ -40,6 +43,7 @@ contract YourNftToken is ERC721AQueryable, Ownable, ReentrancyGuard {
setHiddenMetadataUri(_hiddenMetadataUri);
}

// ~~~~~~~~~~~~~~~~~~~~ Modifiers ~~~~~~~~~~~~~~~~~~~~
modifier mintCompliance(uint256 _mintAmount) {
require(_mintAmount > 0 && _mintAmount <= maxMintAmountPerTx, 'Invalid mint amount!');
require(totalSupply() + _mintAmount <= maxSupply, 'Max supply exceeded!');
Expand All @@ -51,6 +55,7 @@ contract YourNftToken is ERC721AQueryable, Ownable, ReentrancyGuard {
_;
}

// ~~~~~~~~~~~~~~~~~~~~ Mint Functions ~~~~~~~~~~~~~~~~~~~~
function whitelistMint(uint256 _mintAmount, bytes32[] calldata _merkleProof) public payable mintCompliance(_mintAmount) mintPriceCompliance(_mintAmount) {
// Verify whitelist requirements
require(whitelistMintEnabled, 'The whitelist sale is not enabled!');
Expand All @@ -68,15 +73,21 @@ contract YourNftToken is ERC721AQueryable, Ownable, ReentrancyGuard {
_safeMint(_msgSender(), _mintAmount);
}

function mintForAddress(uint256 _mintAmount, address _receiver) public mintCompliance(_mintAmount) onlyOwner {
function mintForAddress(uint256 _mintAmount, address _receiver) public onlyOwner {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why you removed mintCompliance modifier from this function?

Also, if this is ok shouldn't you have the other require there? i.e:

function mintForAddress(uint256 _mintAmount, address _receiver) public onlyOwner { 
    require(_mintAmount > 0 && _mintAmount <= maxMintAmountPerTx, 'Invalid mint amount!');
    require(totalSupply() + _mintAmount <= maxSupply, 'Max supply exceeded!');

    _safeMint(_receiver, _mintAmount);
}

Copy link
Author

@datboi-1337 datboi-1337 Mar 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated to the Opernsea filter, just a general tweak that I have found people have issues with sometimes. I did briefly mention it in the push, but this change simply removes the restriction from the owner to mint more than the current maxMintAmountPerTx. It still ensures that maxSupply will not be exceeded, but allows the contract owner to mint multiple tokens, even if maxMintAmountPerTx is set to 1, for example.

require(totalSupply() + _mintAmount <= maxSupply, 'Max supply exceeded!');
_safeMint(_receiver, _mintAmount);
}

// ~~~~~~~~~~~~~~~~~~~~ Various checks ~~~~~~~~~~~~~~~~~~~~
function _startTokenId() internal view virtual override returns (uint256) {
return 1;
}

function tokenURI(uint256 _tokenId) public view virtual override returns (string memory) {
function _baseURI() internal view virtual override(ERC721A) returns (string memory) {
return uriPrefix;
}

function tokenURI(uint256 _tokenId) public view virtual override(ERC721A, IERC721A) returns (string memory) {
require(_exists(_tokenId), 'ERC721Metadata: URI query for nonexistent token');

if (revealed == false) {
Expand All @@ -89,6 +100,7 @@ contract YourNftToken is ERC721AQueryable, Ownable, ReentrancyGuard {
: '';
}

// ~~~~~~~~~~~~~~~~~~~~ onlyOwner Functions ~~~~~~~~~~~~~~~~~~~~
function setRevealed(bool _state) public onlyOwner {
revealed = _state;
}
Expand Down Expand Up @@ -125,6 +137,28 @@ contract YourNftToken is ERC721AQueryable, Ownable, ReentrancyGuard {
whitelistMintEnabled = _state;
}

// ~~~~~~~~~~~~~~~~~~~~ Opensea Operator Filter Registry Functions ~~~~~~~~~~~~~~~~~~~~
function setApprovalForAll(address operator, bool approved) public override(ERC721A, IERC721A) onlyAllowedOperatorApproval(operator) {
super.setApprovalForAll(operator, approved);
}

function approve(address operator, uint256 tokenId) public payable override(ERC721A, IERC721A) onlyAllowedOperatorApproval(operator) {
super.approve(operator, tokenId);
}

function transferFrom(address from, address to, uint256 tokenId) public payable override(ERC721A, IERC721A) onlyAllowedOperator(from) {
super.transferFrom(from, to, tokenId);
}

function safeTransferFrom(address from, address to, uint256 tokenId) public payable override(ERC721A, IERC721A) onlyAllowedOperator(from) {
super.safeTransferFrom(from, to, tokenId);
}

function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public payable override(ERC721A, IERC721A) onlyAllowedOperator(from) {
super.safeTransferFrom(from, to, tokenId, data);
}

// ~~~~~~~~~~~~~~~~~~~~ Withdraw Functions ~~~~~~~~~~~~~~~~~~~~
function withdraw() public onlyOwner nonReentrant {
// This will pay HashLips Lab Team 5% of the initial sale.
// By leaving the following lines as they are you will contribute to the
Expand All @@ -141,8 +175,4 @@ contract YourNftToken is ERC721AQueryable, Ownable, ReentrancyGuard {
require(os);
// =============================================================================
}

function _baseURI() internal view virtual override returns (string memory) {
return uriPrefix;
}
}
2 changes: 1 addition & 1 deletion smart-contract/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ task('rename-contract', 'Renames the smart contract replacing all occurrences in

const config: HardhatUserConfig = {
solidity: {
version: '0.8.9',
version: '0.8.13',
settings: {
optimizer: {
enabled: true,
Expand Down
Loading