Skip to content

Commit

Permalink
Change ERC721Common to ERC721ACommon. (#31)
Browse files Browse the repository at this point in the history
* Change ERC721Common to ERC721ACommon.

Both ERC721CommonAutoIncrement and ERC721CommonEnumerable are removed. The former is
the default behaviour of ERC721A and the latter is generally unnecessary (+ goes
against the point of ERC721A).

* Remove unnecessary import
  • Loading branch information
aschlosberg authored Apr 7, 2022
1 parent f020acc commit 815e7d9
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 400 deletions.
54 changes: 54 additions & 0 deletions contracts/erc721/ERC721ACommon.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 the ethier authors (github.com/divergencetech/ethier)
pragma solidity >=0.8.0 <0.9.0;

import "./ERC721APreApproval.sol";
import "../utils/OwnerPausable.sol";

/**
@notice An ERC721A contract with common functionality:
- OpenSea gas-free listings
- Pausable with toggling functions exposed to Owner only
*/
contract ERC721ACommon is ERC721APreApproval, OwnerPausable {
constructor(string memory name, string memory symbol)
ERC721A(name, symbol)
{} // solhint-disable-line no-empty-blocks

/// @notice Requires that the token exists.
modifier tokenExists(uint256 tokenId) {
require(ERC721A._exists(tokenId), "ERC721ACommon: Token doesn't exist");
_;
}

/// @notice Requires that msg.sender owns or is approved for the token.
modifier onlyApprovedOrOwner(uint256 tokenId) {
require(
_ownershipOf(tokenId).addr == _msgSender() ||
getApproved(tokenId) == _msgSender(),
"ERC721ACommon: Not approved nor owner"
);
_;
}

function _beforeTokenTransfers(
address from,
address to,
uint256 startTokenId,
uint256 quantity
) internal virtual override {
require(!paused(), "ERC721ACommon: paused");
super._beforeTokenTransfers(from, to, startTokenId, quantity);
}

/// @notice Overrides supportsInterface as required by inheritance.
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC721A)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pragma solidity >=0.8.0 <0.9.0;

import "../thirdparty/opensea/OpenSeaGasFreeListing.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "erc721a/contracts/ERC721A.sol";

/// @notice Pre-approval of OpenSea proxies for gas-less listing
/// @dev This wrapper allows users to revoke the pre-approval of their
Expand All @@ -15,7 +15,7 @@ import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
/// @dev This wrapper optimizes for the following scenario:
/// - The majority of users already have a wyvern proxy
/// - Most of them want to transfer tokens via wyvern exchanges
abstract contract ERC721PreApproval is ERC721 {
abstract contract ERC721APreApproval is ERC721A {
/// @dev It is important that Active remains at first position, since this
/// is the scenario that we are trying to optimize for.
enum State {
Expand Down Expand Up @@ -57,18 +57,19 @@ abstract contract ERC721PreApproval is ERC721 {
state[owner] = approved ? State.Active : State.Inactive;
emit ApprovalForAll(owner, operator, approved);
} else {
super._setApprovalForAll(owner, operator, approved);
super.setApprovalForAll(operator, approved);
}
}

/// @dev Checks if the receiver has an existing proxy. If not, the
/// pre-approval is disabled.
function _beforeTokenTransfer(
function _beforeTokenTransfers(
address from,
address to,
uint256 tokenId
uint256 startTokenId,
uint256 quantity
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
super._beforeTokenTransfers(from, to, startTokenId, quantity);

// Exclude burns and inactive pre-approvals
if (to == address(0) || state[to] == State.Inactive) {
Expand Down
71 changes: 0 additions & 71 deletions contracts/erc721/ERC721Common.sol

This file was deleted.

47 changes: 0 additions & 47 deletions contracts/erc721/ERC721CommonAutoIncrement.sol

This file was deleted.

64 changes: 0 additions & 64 deletions contracts/erc721/ERC721CommonEnumerable.sol

This file was deleted.

2 changes: 1 addition & 1 deletion ethtest/revert/revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (

// Checkers for ethier libraries and contracts.
const (
ERC721ApproveOrOwner = Checker("ERC721Common: Not approved nor owner")
ERC721ApproveOrOwner = Checker("ERC721ACommon: Not approved nor owner")
InvalidSignature = Checker("SignatureChecker: Invalid signature")
NotStarted = Checker("LinearDutchAuction: Not started")
SoldOut = Checker("Seller: Sold out")
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"dependencies": {
"@chainlink/contracts": "^0.3.0",
"@openzeppelin/contracts": "^4.4.1",
"@openzeppelin/contracts-upgradeable": "^4.4.1"
"@openzeppelin/contracts-upgradeable": "^4.4.1",
"erc721a": "^3.1.0"
},
"directories": {
"test": "tests"
Expand Down
43 changes: 43 additions & 0 deletions tests/erc721/TestableERC721ACommon.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2021 the ethier authors (github.com/divergencetech/ethier)
pragma solidity >=0.8.0 <0.9.0;

import "../../contracts/erc721/ERC721ACommon.sol";
import "../../contracts/erc721/BaseTokenURI.sol";

/// @notice Exposes a functions modified with the modifiers under test.
contract TestableERC721ACommon is ERC721ACommon, BaseTokenURI {
// solhint-disable-next-line no-empty-blocks
constructor() ERC721ACommon("Token", "JRR") BaseTokenURI("") {}

function mint() public {
mintN(1);
}

function mintN(uint256 num) public {
ERC721A._safeMint(msg.sender, num);
}

function burn(uint256 tokenId) public {
ERC721A._burn(tokenId);
}

/// @dev For testing the tokenExists() modifier.
// solhint-disable-next-line no-empty-blocks
function mustExist(uint256 tokenId) public view tokenExists(tokenId) {}

/// @dev For testing the onlyApprovedOrOwner() modifier.
function mustBeApprovedOrOwner(uint256 tokenId)
public
onlyApprovedOrOwner(tokenId)
{} // solhint-disable-line no-empty-blocks

function _baseURI()
internal
view
override(ERC721A, BaseTokenURI)
returns (string memory)
{
return BaseTokenURI._baseURI();
}
}
Loading

0 comments on commit 815e7d9

Please sign in to comment.