Skip to content

Commit

Permalink
migrate ERC721AB to abstract contract
Browse files Browse the repository at this point in the history
  • Loading branch information
0xPilou committed Sep 28, 2023
1 parent c779b5e commit 80e9c33
Showing 1 changed file with 7 additions and 94 deletions.
101 changes: 7 additions & 94 deletions src/token/ERC721/ERC721AB.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import {ABEvents} from "src/libraries/ABEvents.sol";
import {IABVerifier} from "src/utils/IABVerifier.sol";
import {IABDataRegistry} from "src/utils/IABDataRegistry.sol";

contract ERC721AB is ERC721AUpgradeable, OwnableUpgradeable {
abstract contract ERC721AB is ERC721AUpgradeable, OwnableUpgradeable {
// _____ __ __
// / ___// /_____ _/ /____ _____
// \__ \/ __/ __ `/ __/ _ \/ ___/
Expand All @@ -71,9 +71,6 @@ contract ERC721AB is ERC721AUpgradeable, OwnableUpgradeable {
/// @dev Drop Identifier
uint256 public dropId;

/// @dev Supply cap for this collection
uint256 public maxSupply;

/// @dev Percentage ownership of the full master right for one token (to be divided by 1e6)
uint256 public sharePerToken;

Expand All @@ -86,24 +83,6 @@ contract ERC721AB is ERC721AUpgradeable, OwnableUpgradeable {
/// @dev Mapping storing the amount minted per wallet and per phase
mapping(address user => mapping(uint256 phaseId => uint256 minted)) public mintedPerPhase;

/// @dev ERC721AB implementation version
uint8 public constant IMPLEMENTATION_VERSION = 1;

// ______ __ __
// / ____/___ ____ _____/ /________ _______/ /_____ _____
// / / / __ \/ __ \/ ___/ __/ ___/ / / / ___/ __/ __ \/ ___/
// / /___/ /_/ / / / (__ ) /_/ / / /_/ / /__/ /_/ /_/ / /
// \____/\____/_/ /_/____/\__/_/ \__,_/\___/\__/\____/_/

/**
* @notice
* Contract Constructor
*/
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

/**
* @notice
* Contract Initializer (Minimal Proxy Contract)
Expand Down Expand Up @@ -152,38 +131,11 @@ contract ERC721AB is ERC721AUpgradeable, OwnableUpgradeable {
* @param _quantity quantity of tokens requested (must be less than max mint per phase)
* @param _signature signature to verify allowlist status
*/
function mint(address _to, uint256 _phaseId, uint256 _quantity, bytes calldata _signature) external payable {
// Check that the requested minting phase has started
if (!_isPhaseActive(_phaseId)) revert ABErrors.PHASE_NOT_ACTIVE();

// Get requested phase details
ABDataTypes.Phase memory phase = phases[_phaseId];

// Check that there are enough tokens available for sale
if (_totalMinted() + _quantity > maxSupply) {
revert ABErrors.NOT_ENOUGH_TOKEN_AVAILABLE();
}

// Check if the current phase is private
if (!phase.isPublic) {
// Check that the user is included in the allowlist
if (!abVerifier.verifySignature721(_to, address(this), _phaseId, _signature)) {
revert ABErrors.NOT_ELIGIBLE();
}
}

// Check that user did not mint / is not asking to mint more than the max mint per address for the current phase
if (mintedPerPhase[_to][_phaseId] + _quantity > phase.maxMint) revert ABErrors.MAX_MINT_PER_ADDRESS();

// Check that user is sending the correct amount of ETH (will revert if user send too much or not enough)
if (msg.value != phase.price * _quantity) revert ABErrors.INCORRECT_ETH_SENT();

// Set quantity minted for `_to` during the current phase
mintedPerPhase[_to][_phaseId] += _quantity;

// Mint `_quantity` amount to `_to` address
_mint(_to, _quantity);
}
function mint(address _to, uint256 _phaseId, uint256 _quantity, bytes calldata _signature)
external
payable
virtual
{}

// ____ __ ___ __ _
// / __ \____ / /_ __ / | ____/ /___ ___ (_)___
Expand Down Expand Up @@ -211,34 +163,7 @@ contract ERC721AB is ERC721AUpgradeable, OwnableUpgradeable {
address _genesisRecipient,
address _royaltyCurrency,
string calldata _baseUri
) external virtual onlyOwner {
// Check that the drop hasn't been already initialized
if (dropId != 0) revert ABErrors.DROP_ALREADY_INITIALIZED();

// Check that share per token & royalty currency are consistent
if (
(_sharePerToken == 0 && _royaltyCurrency != address(0))
|| (_royaltyCurrency == address(0) && _sharePerToken != 0)
) revert ABErrors.INVALID_PARAMETER();

// Register Drop within ABDropRegistry
dropId = abDataRegistry.registerDrop(publisher, _royaltyCurrency, 0);

// Set supply cap
maxSupply = _maxSupply;

// Set the royalty share
sharePerToken = _sharePerToken;

// Set base URI
baseTokenURI = _baseUri;

// Mint Genesis tokens to `_genesisRecipient` address
if (_mintGenesis > 0) {
if (_mintGenesis > _maxSupply) revert ABErrors.INVALID_PARAMETER();
_mint(_genesisRecipient, _mintGenesis);
}
}
) external virtual onlyOwner {}

/**
* @notice
Expand Down Expand Up @@ -334,18 +259,6 @@ contract ERC721AB is ERC721AUpgradeable, OwnableUpgradeable {
IERC20(_token).transfer(msg.sender, _amount);
}

/**
* @notice
* Set the maximum supply
* Only the contract owner can perform this operation
*
* @param _maxSupply new maximum supply to be set
*/
function setMaxSupply(uint256 _maxSupply) external onlyOwner {
if (_maxSupply < _totalMinted()) revert ABErrors.INVALID_PARAMETER();
maxSupply = _maxSupply;
}

// _ ___ ______ __ _
// | | / (_)__ _ __ / ____/_ ______ _____/ /_(_)___ ____ _____
// | | / / / _ \ | /| / / / /_ / / / / __ \/ ___/ __/ / __ \/ __ \/ ___/
Expand Down

0 comments on commit 80e9c33

Please sign in to comment.