Skip to content

Commit

Permalink
chore: old orders publicly fillable
Browse files Browse the repository at this point in the history
  • Loading branch information
arr00 committed Jul 30, 2024
1 parent 509ef6b commit f32ab48
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "solhint:recommended",
"rules": {
"code-complexity": ["error", 9],
"code-complexity": ["error", 10],
"compiler-version": ["error", ">=0.8.0"],
"func-name-mixedcase": "off",
"func-visibility": ["error", { "ignoreConstructors": true }],
Expand Down
20 changes: 12 additions & 8 deletions src/NFTMint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ contract NFTMint is Ownable {
struct Order {
MintERC1155 mint;
address to;
uint40 orderTimestamp;
uint256 amount;
}

Expand All @@ -72,11 +73,7 @@ contract NFTMint is Ownable {
* @param args Arguments for the mint
*/
function createMint(MintArgs memory args) external returns (MintERC1155) {
MintERC1155 newMint = MintERC1155(
Clones.cloneDeterministic(
MINT_NFT_LOGIC, keccak256(abi.encodePacked(block.chainid, msg.sender, block.timestamp))
)
);
MintERC1155 newMint = MintERC1155(Clones.clone(MINT_NFT_LOGIC));
newMint.initialize(args.owner, args.name, args.imageURI, args.description, args.editions);

MintInfo storage mintInfo = mints[newMint];
Expand Down Expand Up @@ -138,7 +135,9 @@ contract NFTMint is Ownable {
revert NFTMint_BuyerNotAcceptingERC1155();
}

orders.push(Order({ to: msg.sender, mint: mint, amount: modifiedAmount }));
orders.push(
Order({ to: msg.sender, mint: mint, orderTimestamp: uint40(block.timestamp), amount: modifiedAmount })
);

(bool feeSuccess,) = mintInfo.feeRecipient.call{ value: mintInfo.feePerMint * modifiedAmount, gas: 100_000 }("");
(bool mintProceedsSuccess,) =
Expand All @@ -156,17 +155,22 @@ contract NFTMint is Ownable {
}

/**
* @notice Fill pending orders. Only callable by owner.
* @notice Fill pending orders. Orders older than 1 hour are fillable by anyone. Newer orders can only be filled by
* the owner.
* @param numOrdersToFill The maximum number of orders to fill. Specify 0 to fill all orders.
*/
function fillOrders(uint256 numOrdersToFill) external onlyOwner {
function fillOrders(uint256 numOrdersToFill) external {
uint256 nonce = 0;
uint256 nextOrderIdToFill_ = nextOrderIdToFill;
uint256 finalNextOrderToFill =
numOrdersToFill == 0 ? orders.length : Math.min(orders.length, nextOrderIdToFill_ + numOrdersToFill);

while (nextOrderIdToFill_ < finalNextOrderToFill) {
Order storage currentOrder = orders[nextOrderIdToFill_];
if (msg.sender != owner() && currentOrder.orderTimestamp + 1 hours > block.timestamp) {
// Only the owner can fill orders that are less than 1 hour old
break;
}
MintERC1155.Edition[] memory editions = currentOrder.mint.getAllEditions();

uint256[] memory ids = new uint256[](editions.length);
Expand Down
15 changes: 15 additions & 0 deletions test/NFTMint.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,20 @@ contract NFTMintTest is TestBase {
}
}

function test_fillOrdersPublic(address filler) external {
(MintERC1155 mint, address minter) = test_order();

vm.startPrank(filler);
nftMint.fillOrders(0);
assertEq(nftMint.nextOrderIdToFill(), 0);

skip(1 hours);
vm.expectEmit(true, true, true, false);
emit OrderFilled(mint, 0, minter, 5, new uint256[](0));
nftMint.fillOrders(0);

assertEq(nftMint.nextOrderIdToFill(), 1);
}

receive() external payable { }
}

0 comments on commit f32ab48

Please sign in to comment.