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

Remove duplicate code to make contract fit #145

Closed
wants to merge 56 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
ce66a42
chore: add zora rewards package
kulkarohan Jun 6, 2023
6b9ac3d
chore: update remappings
kulkarohan Jun 6, 2023
943cd74
refactor: add ERC721Rewards extension
kulkarohan Jun 6, 2023
d8f6939
chore: update dependencies
kulkarohan Jun 6, 2023
bbe8f11
chore: add zora rewards to scripts
kulkarohan Jun 7, 2023
21c7bbe
chore: update existing tests
kulkarohan Jun 7, 2023
4e6a9aa
feat: add purchaseWithRewards
kulkarohan Jun 7, 2023
9ae43f0
chore: update dependencies
kulkarohan Jun 7, 2023
55403c9
fix: add finder and lister params
kulkarohan Jun 7, 2023
49f3adf
chore: add rewards tests
kulkarohan Jun 7, 2023
a19b9a7
chore: reduce optimizer runs
kulkarohan Jun 7, 2023
54d322f
chore: update dependencies
kulkarohan Jun 14, 2023
b811ac7
Merge branch 'main' into zora-rewards
kulkarohan Jun 15, 2023
8e6b82c
chore: update runs
kulkarohan Jun 15, 2023
79555ea
fix: handle supply royaltes when purchasing with rewards
kulkarohan Jun 15, 2023
f796d1e
chore: update tests
kulkarohan Jun 15, 2023
1ea8b27
chore: update OZ dependency location
kulkarohan Jun 27, 2023
77ab5c3
chore: update rewards tests
kulkarohan Jun 27, 2023
a907094
Merge branch 'main' into zora-rewards
kulkarohan Jul 4, 2023
16f9300
refactor: add recipient to purchase w rewards
kulkarohan Jul 4, 2023
573cb33
chore: update rewards dep
kulkarohan Jul 4, 2023
b3e725d
refactor: update lister to origin
kulkarohan Jul 4, 2023
51aef58
chore: update tests
kulkarohan Jul 4, 2023
606197d
chore: add zora rewards to chain configs
kulkarohan Jul 4, 2023
80446d8
refactor: change purchase to mint w/ rewards
kulkarohan Jul 5, 2023
1d916cb
refactor: update referral names
kulkarohan Jul 19, 2023
6f14c57
Merge branch 'main' into zora-rewards
kulkarohan Jul 20, 2023
c21c8a3
chore: add pgn
kulkarohan Jul 28, 2023
aff942d
chore: add rewards to deploy config
kulkarohan Jul 28, 2023
8b9f79b
chore: update dependencies
kulkarohan Jul 28, 2023
f3a9c01
refactor: set create referral on initialization
kulkarohan Jul 28, 2023
630c4c3
refactor: add create referral to factory
kulkarohan Jul 28, 2023
517fea9
chore: update scripts w/ default create referral
kulkarohan Jul 28, 2023
115fc54
chore: update tests
kulkarohan Jul 28, 2023
c8876f3
chore: update create referral tests
kulkarohan Jul 28, 2023
821491e
refactor: add common helpers
kulkarohan Jul 28, 2023
8d85761
chore: update deps
kulkarohan Jul 28, 2023
bdf9a7f
chore: update deps
kulkarohan Jul 28, 2023
a879d55
refactor: add rewards storage
kulkarohan Jul 28, 2023
56bbac5
chore: update runs
kulkarohan Jul 28, 2023
3221408
chore: update protocol rewards
kulkarohan Jul 28, 2023
8a69a89
chore: update deploy config
kulkarohan Jul 28, 2023
d8a66df
chore: update naming
kulkarohan Jul 28, 2023
24030ec
chore: update versions
kulkarohan Jul 28, 2023
48197ec
refactor: do not force create referral via factory
kulkarohan Jul 28, 2023
f5b995e
chore: update goerli deploy
kulkarohan Jul 28, 2023
c7cd561
chore: update zora goerli deploy
kulkarohan Jul 28, 2023
7107a68
chore: update op goerli deploy
kulkarohan Jul 29, 2023
7644578
chore: update base goerli deploy
kulkarohan Jul 30, 2023
ab68524
chore: update deps
kulkarohan Jul 31, 2023
ec70925
chore: update goerli deploy
kulkarohan Aug 1, 2023
c009127
chore: update zora goerli deploy
kulkarohan Aug 1, 2023
cffe9e3
chore: update op goerli deploy
kulkarohan Aug 1, 2023
f638164
chore: update base goerli deploy
kulkarohan Aug 1, 2023
01e284a
make code fit
iainnash Aug 2, 2023
99c5bea
rebase merge fixes
iainnash Sep 21, 2023
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
8 changes: 5 additions & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[profile.default]
solc_version = '0.8.17'
optimizer = true
optimizer_runs = 300
optimizer_runs = 500
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice

via_ir = true
out = 'out'
test = 'test'
Expand Down Expand Up @@ -30,8 +30,10 @@ optimism = "https://opt-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}"
optimism_goerli = "https://opt-goerli.g.alchemy.com/v2/${ALCHEMY_KEY}"

zora = "https://rpc.zora.energy"
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"
base = "https://base-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}"
base_goerli = "https://base-goerli.g.alchemy.com/v2/${ALCHEMY_KEY}"
pgn = "https://rpc.publicgoods.network"
Expand Down
1 change: 0 additions & 1 deletion lib/openzeppelin-contracts
Submodule openzeppelin-contracts deleted from c239e1
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@
},
"dependencies": {
"@dotenv/cli": "^2.2.2",
<<<<<<< HEAD
"@zoralabs/protocol-rewards": "^1.0.1",
=======
Copy link
Collaborator

Choose a reason for hiding this comment

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

broken rebase

"@zoralabs/protocol-rewards": "^1.0.2",
>>>>>>> origin/main
"ds-test": "https://github.com/dapphub/ds-test#cd98eff28324bfac652e63a239a60632a761790b",
"forge-std": "https://github.com/foundry-rs/forge-std#cd7d533f9a0ee0ec02ad81e0a8f262bc4203c653"
}
Expand Down
2 changes: 2 additions & 0 deletions script/TestUpgradeAndMint.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {ERC721DropProxy} from "../src/ERC721DropProxy.sol";
contract DeployNewERC721Drop is Script {
using Strings for uint256;

address internal DEFAULT_CREATE_REFERRAL = address(0);

string configFile;

function _getKey(string memory key) internal returns (address result) {
Expand Down
93 changes: 64 additions & 29 deletions src/ERC721Drop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,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 Only allow for users with admin access
modifier onlyAdmin() {
Expand Down Expand Up @@ -452,7 +452,7 @@ contract ERC721Drop is
onlyPublicSaleActive
returns (uint256)
{
return _handlePurchase(msg.sender, quantity, "");
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we remove this _handlePurchase function?

return _handleMintWithRewards(msg.sender, quantity, "", address(0));
}

/// @notice Purchase a quantity of tokens with a comment
Expand All @@ -466,7 +466,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 @@ -481,7 +481,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 Down Expand Up @@ -528,9 +528,8 @@ contract ERC721Drop is
_requireLegacyFee(msg.value, salePrice, quantity);

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

_payoutZoraFee(quantity);
uint256 firstMintedTokenId = _lastMintedTokenId() - quantity;

_emitSaleEvents(_msgSender(), recipient, quantity, salePrice, firstMintedTokenId, comment);

Expand Down Expand Up @@ -630,7 +629,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 @@ -652,15 +651,40 @@ contract ERC721Drop is
onlyPresaleActive
returns (uint256)
{
return _handlePurchasePresale(quantity, maxQuantity, pricePerToken, merkleProof, comment);
return _handlePurchasePresaleWithRewards(quantity, maxQuantity, pricePerToken, merkleProof, comment, address(0));
}

function _handlePurchasePresale(
/// @notice Merkle-tree based presale purchase function with a comment and protocol rewards
/// @param quantity quantity to purchase
/// @param maxQuantity max quantity that can be purchased via merkle proof #
/// @param pricePerToken price that each token is purchased at
/// @param merkleProof proof for presale mint
/// @param comment comment to include in the IERC721Drop.Sale event
/// @param mintReferral The facilitator of the mint
function purchasePresaleWithRewards(
uint256 quantity,
uint256 maxQuantity,
uint256 pricePerToken,
bytes32[] calldata merkleProof,
string memory comment
string calldata comment,
address mintReferral
)
external
payable
nonReentrant
onlyPresaleActive
returns (uint256)
{
return _handlePurchasePresaleWithRewards(quantity, maxQuantity, pricePerToken, merkleProof, comment, mintReferral);
}

function _handlePurchasePresaleWithRewards(
uint256 quantity,
uint256 maxQuantity,
uint256 pricePerToken,
bytes32[] calldata merkleProof,
string memory comment,
address mintReferral
) internal returns (uint256) {
_mintSupplyRoyalty(quantity);
_requireCanMintQuantity(quantity);
Expand All @@ -669,15 +693,15 @@ contract ERC721Drop is

_requireMerkleApproval(msgSender, maxQuantity, pricePerToken, merkleProof);

_requireLegacyFee(msg.value, pricePerToken, quantity);

_requireCanPurchasePresale(msgSender, quantity, maxQuantity);

_handleRewards(msg.value, quantity, pricePerToken, config.fundsRecipient, mintReferral, createReferral);

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

_payoutZoraFee(quantity);
uint256 firstMintedTokenId = _lastMintedTokenId() - quantity;


emit IERC721Drop.Sale({
to: msgSender,
quantity: quantity,
Expand Down Expand Up @@ -732,21 +756,29 @@ contract ERC721Drop is
_mintSupplyRoyalty(quantity);
_requireCanMintQuantity(quantity);

address msgSender = _msgSender();

_requireMerkleApproval(msgSender, maxQuantity, pricePerToken, merkleProof);

_requireCanPurchasePresale(msgSender, quantity, maxQuantity);

_handleRewards(msg.value, quantity, pricePerToken, config.fundsRecipient != address(0) ? config.fundsRecipient : address(this), createReferral, mintReferral);

_mintNFTs(msgSender, quantity);

uint256 firstMintedTokenId = _lastMintedTokenId() - quantity;

_emitSaleEvents(msgSender, msgSender, quantity, pricePerToken, firstMintedTokenId, comment);

return firstMintedTokenId;
<<<<<<< HEAD
Copy link
Collaborator

Choose a reason for hiding this comment

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

broken rebase :(

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

was trying to get this diff better, didn't work, ignore for now

/// @notice Hook to filter operators (no-op if no filters are registered)
/// @dev Part of ERC721A token hooks
/// @param from Transfer from user
function _beforeTokenTransfers(
address from,
address,
uint256,
uint256
) internal virtual override {
if (
from != address(0) && // skip on mints
from != msg.sender // skip on transfers from sender
) {
if (
!operatorFilterRegistry.isOperatorAllowed(
address(this),
msg.sender
)
) {
revert OperatorNotAllowed(msg.sender);
}
}
}

/**
Expand Down Expand Up @@ -1272,6 +1304,8 @@ contract ERC721Drop is
}
}

<<<<<<< HEAD
=======
function _payoutZoraFee(uint256 quantity) internal {
// Transfer ZORA fee to recipient
(, uint256 zoraFee) = zoraFeeForAmount(quantity);
Expand All @@ -1287,6 +1321,7 @@ contract ERC721Drop is
}
}

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