Skip to content

Commit

Permalink
Revert if not passing in empty arrays when claiming
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSamWitch committed Feb 14, 2024
1 parent 6c8f4a3 commit ce32261
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
17 changes: 11 additions & 6 deletions contracts/SamWitchOrderBook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ contract SamWitchOrderBook is ISamWitchOrderBook, ERC1155Holder, UUPSUpgradeable

// Send the NFTs
if (nftsFromUs != 0) {
// reset the size
// shrink the size
assembly ("memory-safe") {
mstore(nftIdsFromUs, nftsFromUs)
mstore(nftAmountsFromUs, nftsFromUs)
Expand Down Expand Up @@ -280,12 +280,13 @@ contract SamWitchOrderBook is ISamWitchOrderBook, ERC1155Holder, UUPSUpgradeable
amount += claimableAmount;
}

if (amount != 0) {
(uint royalty, uint dev, uint burn) = _calcFees(amount);
uint fees = royalty.add(dev).add(burn);
token.safeTransfer(_msgSender(), amount.sub(fees));
emit ClaimedTokens(_msgSender(), _orderIds, amount, fees);
if (amount == 0) {
revert NothingToClaim();
}
(uint royalty, uint dev, uint burn) = _calcFees(amount);
uint fees = royalty.add(dev).add(burn);
token.safeTransfer(_msgSender(), amount.sub(fees));
emit ClaimedTokens(_msgSender(), _orderIds, amount, fees);
}

/// @notice Claim NFTs associated with filled or partially filled orders
Expand All @@ -301,6 +302,10 @@ contract SamWitchOrderBook is ISamWitchOrderBook, ERC1155Holder, UUPSUpgradeable
revert LengthMismatch();
}

if (_tokenIds.length == 0) {
revert NothingToClaim();
}

uint[] memory nftAmountsFromUs = new uint[](_tokenIds.length);
for (uint i = 0; i < _tokenIds.length; ++i) {
uint40 orderId = uint40(_orderIds[i]);
Expand Down
10 changes: 10 additions & 0 deletions test/SamWitchOrderBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2214,6 +2214,11 @@ describe("SamWitchOrderBook", function () {
await expect(orderBook.claimTokens(orders)).to.not.be.reverted;
});

it("Claiming no tokens, empty order id array argument", async function () {
const {orderBook} = await loadFixture(deployContractsFixture);
await expect(orderBook.claimTokens([1])).to.be.revertedWithCustomError(orderBook, "NothingToClaim");
});

it("Claim NFTs", async function () {
const {orderBook, owner, alice, tokenId} = await loadFixture(deployContractsFixture);

Expand Down Expand Up @@ -2453,6 +2458,11 @@ describe("SamWitchOrderBook", function () {
tokenIds.pop();
await expect(orderBook.claimNFTs(orders, tokenIds)).to.not.be.reverted;
});

it("Claiming no nfts, empty order id array argument", async function () {
const {orderBook} = await loadFixture(deployContractsFixture);
await expect(orderBook.claimNFTs([], [])).to.be.revertedWithCustomError(orderBook, "NothingToClaim");
});
});

it("Max brush price", async function () {
Expand Down

0 comments on commit ce32261

Please sign in to comment.