Skip to content

Commit

Permalink
make code fit
Browse files Browse the repository at this point in the history
  • Loading branch information
iainnash committed Aug 2, 2023
1 parent f638164 commit 01e284a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 98 deletions.
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ zora_goerli = "https://testnet.rpc.zora.energy"
base_goerli = "https://goerli.base.org"
base = "https://developer-access-mainnet.base.org"
pgn_sepolia = "https://sepolia.publicgoods.network"
pgn = "https://rpc.publicgoods.network"
pgn = "https://rpc.publicgoods.network"
105 changes: 8 additions & 97 deletions src/ERC721Drop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ contract ERC721Drop is
uint8 constant SUPPLY_ROYALTY_FOR_EVERY_MINT = 1;

// /// @notice Empty string for blank comments
// string constant EMPTY_STRING = "";
string constant EMPTY_STRING = "";

/// @notice Market filter DAO address for opensea filter registry
address public immutable marketFilterDAOAddress;
Expand Down Expand Up @@ -460,7 +460,7 @@ contract ERC721Drop is
onlyPublicSaleActive
returns (uint256)
{
return _handlePurchase(msg.sender, quantity, "");
return _handleMintWithRewards(msg.sender, quantity, "", address(0));
}

/// @notice Purchase a quantity of tokens with a comment
Expand All @@ -474,7 +474,7 @@ contract ERC721Drop is
onlyPublicSaleActive
returns (uint256)
{
return _handlePurchase(msg.sender, quantity, comment);
return _handleMintWithRewards(msg.sender, quantity, comment, address(0));
}

/// @notice Purchase a quantity of tokens to a specified recipient, with an optional comment
Expand All @@ -489,7 +489,7 @@ contract ERC721Drop is
onlyPublicSaleActive
returns (uint256)
{
return _handlePurchase(recipient, quantity, comment);
return _handleMintWithRewards(recipient, quantity, comment, address(0));
}

/// @notice Mint a quantity of tokens with a comment that will pay out rewards
Expand All @@ -509,7 +509,7 @@ contract ERC721Drop is
return _handleMintWithRewards(recipient, quantity, comment, mintReferral);
}

function _handleMintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) internal returns (uint256) {
function _handleMintWithRewards(address recipient, uint256 quantity, string memory comment, address mintReferral) internal returns (uint256) {
_mintSupplyRoyalty(quantity);
_requireCanPurchaseQuantity(recipient, quantity);

Expand Down Expand Up @@ -541,38 +541,6 @@ contract ERC721Drop is
return firstMintedTokenId;
}

function _handlePurchase(address recipient, uint256 quantity, string memory comment) internal returns (uint256) {
_mintSupplyRoyalty(quantity);
_requireCanMintQuantity(quantity);
_requireCanPurchaseQuantity(recipient, quantity);

uint256 salePrice = salesConfig.publicSalePrice;

_requireLegacyFee(msg.value, salePrice, quantity);

_mintNFTs(recipient, quantity);
uint256 firstMintedTokenId = _lastMintedTokenId() - quantity;

_payoutZoraFee(quantity);

emit IERC721Drop.Sale({
to: recipient,
quantity: quantity,
pricePerToken: salePrice,
firstPurchasedTokenId: firstMintedTokenId
});
if(bytes(comment).length > 0) {
emit IERC721Drop.MintComment({
sender: _msgSender(),
tokenContract: address(this),
tokenId: firstMintedTokenId,
quantity: quantity,
comment: comment
});
}
return firstMintedTokenId;
}

/// @notice Function to mint NFTs
/// @dev (important: Does not enforce max supply limit, enforce that limit earlier)
/// @dev This batches in size of 8 as per recommended by ERC721A creators
Expand Down Expand Up @@ -666,7 +634,7 @@ contract ERC721Drop is
onlyPresaleActive
returns (uint256)
{
return _handlePurchasePresale(quantity, maxQuantity, pricePerToken, merkleProof, "");
return _handlePurchasePresaleWithRewards(quantity, maxQuantity, pricePerToken, merkleProof, "", address(0));
}

/// @notice Merkle-tree based presale purchase function with a comment
Expand All @@ -688,49 +656,7 @@ contract ERC721Drop is
onlyPresaleActive
returns (uint256)
{
return _handlePurchasePresale(quantity, maxQuantity, pricePerToken, merkleProof, comment);
}

function _handlePurchasePresale(
uint256 quantity,
uint256 maxQuantity,
uint256 pricePerToken,
bytes32[] calldata merkleProof,
string memory comment
) internal returns (uint256) {
_mintSupplyRoyalty(quantity);
_requireCanMintQuantity(quantity);

address msgSender = _msgSender();

_requireMerkleApproval(msgSender, maxQuantity, pricePerToken, merkleProof);

_requireLegacyFee(msg.value, pricePerToken, quantity);

_requireCanPurchasePresale(msgSender, quantity, maxQuantity);

_mintNFTs(msgSender, quantity);
uint256 firstMintedTokenId = _lastMintedTokenId() - quantity;

_payoutZoraFee(quantity);

emit IERC721Drop.Sale({
to: msgSender,
quantity: quantity,
pricePerToken: pricePerToken,
firstPurchasedTokenId: firstMintedTokenId
});
if (bytes(comment).length > 0) {
emit IERC721Drop.MintComment({
sender: msgSender,
tokenContract: address(this),
tokenId: firstMintedTokenId,
quantity: quantity,
comment: comment
});
}

return firstMintedTokenId;
return _handlePurchasePresaleWithRewards(quantity, maxQuantity, pricePerToken, merkleProof, comment, address(0));
}

/// @notice Merkle-tree based presale purchase function with a comment and protocol rewards
Expand Down Expand Up @@ -762,7 +688,7 @@ contract ERC721Drop is
uint256 maxQuantity,
uint256 pricePerToken,
bytes32[] calldata merkleProof,
string calldata comment,
string memory comment,
address mintReferral
) internal returns (uint256) {
_mintSupplyRoyalty(quantity);
Expand Down Expand Up @@ -1376,21 +1302,6 @@ contract ERC721Drop is
}
}

function _payoutZoraFee(uint256 quantity) internal {
// Transfer ZORA fee to recipient
(, uint256 zoraFee) = zoraFeeForAmount(quantity);
(bool success, ) = ZORA_MINT_FEE_RECIPIENT.call{value: zoraFee, gas: FUNDS_SEND_GAS_LIMIT}(
""
);
emit MintFeePayout(zoraFee, ZORA_MINT_FEE_RECIPIENT, success);
}

function _requireLegacyFee(uint256 msgValue, uint256 salePrice, uint256 quantity) internal view {
if (msgValue != (salePrice + ZORA_MINT_FEE) * quantity) {
revert Purchase_WrongPrice((salePrice + ZORA_MINT_FEE) * quantity);
}
}

function _requireCanMintQuantity(uint256 quantity) internal view {
if (quantity + _totalMinted() > config.editionSize) {
revert Mint_SoldOut();
Expand Down

0 comments on commit 01e284a

Please sign in to comment.