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

feat: mint duration #17

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions src/NFTMint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ contract NFTMint is Ownable {
error NFTMint_InvalidMerkleProof();
error NFTMint_FailedToTransferFunds();
error NFTMint_BuyerNotAcceptingERC1155();
error NFTMint_MintExpired();

event MintCreated(MintERC1155 indexed mint, MintArgs args);
event OrderPlaced(
Expand All @@ -29,6 +30,7 @@ contract NFTMint is Ownable {
uint256 feePerMint;
address payable owner;
address payable feeRecipient;
uint40 mintDuration;
bytes32 allowlistMerkleRoot;
uint256 perWalletLimit;
uint256 maxMints;
Expand All @@ -43,6 +45,7 @@ contract NFTMint is Ownable {
uint256 feePerMint;
address payable owner;
address payable feeRecipient;
uint40 mintExpiration;
uint256 perWalletLimit;
bytes32 allowlistMerkleRoot;
uint256 remainingMints;
Expand Down Expand Up @@ -89,6 +92,7 @@ contract NFTMint is Ownable {
mintInfo.feeRecipient = args.feeRecipient;
mintInfo.perWalletLimit = args.perWalletLimit;
mintInfo.allowlistMerkleRoot = args.allowlistMerkleRoot;
mintInfo.mintExpiration = uint40(block.timestamp + args.mintDuration);

emit MintCreated(newMint, args);
return newMint;
Expand Down Expand Up @@ -116,6 +120,10 @@ contract NFTMint is Ownable {

MintInfo storage mintInfo = mints[mint];

if (mintInfo.mintExpiration < block.timestamp) {
revert NFTMint_MintExpired();
}

uint256 modifiedAmount = Math.min(amount, mintInfo.remainingMints);
mintInfo.remainingMints -= modifiedAmount;
uint256 totalCost = (mintInfo.pricePerMint + mintInfo.feePerMint) * modifiedAmount;
Expand Down
14 changes: 14 additions & 0 deletions test/NFTMint.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ contract NFTMintTest is TestBase {
});

NFTMint.MintArgs memory mintArgs = NFTMint.MintArgs({
mintDuration: 1 days,
maxMints: 110,
editions: editions,
allowlistMerkleRoot: bytes32(0),
Expand Down Expand Up @@ -149,6 +150,19 @@ contract NFTMintTest is TestBase {
nftMint.order{ value: 0.011 ether }(mint, 1, "", new bytes32[](0));
}

function test_order_mintExpired() external {
MintERC1155 mint = test_createMint();

address minter = _randomAddress();

vm.deal(minter, 10 ether);
vm.prank(minter);

skip(2 days);
vm.expectRevert(NFTMint.NFTMint_MintExpired.selector);
nftMint.order{ value: 0.011 ether }(mint, 1, "", new bytes32[](0));
}

event OrderFilled(
MintERC1155 indexed mint, uint256 indexed orderId, address indexed to, uint256 amount, uint256[] amounts
);
Expand Down
Loading