Skip to content

Commit

Permalink
Allow removing a tokenId and check that orders can still be cancelled…
Browse files Browse the repository at this point in the history
… just not taken from
  • Loading branch information
0xSamWitch committed Feb 13, 2024
1 parent f0733ba commit ef8d16f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
5 changes: 4 additions & 1 deletion contracts/SamWitchOrderBook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,10 @@ contract SamWitchOrderBook is ISamWitchOrderBook, ERC1155Holder, UUPSUpgradeable

for (uint i = 0; i < _tokenIds.length; ++i) {
// Cannot change tick once set
if (tokenIdInfo[_tokenIds[i]].tick != 0 && tokenIdInfo[_tokenIds[i]].tick != _tokenIdInfos[i].tick) {
uint existingTick = tokenIdInfo[_tokenIds[i]].tick;
uint newTick = _tokenIdInfos[i].tick;

if (existingTick != 0 && newTick != 0 && existingTick != newTick) {
revert TickCannotBeChanged();
}

Expand Down
52 changes: 52 additions & 0 deletions test/SamWitchOrderBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,58 @@ describe.only("SamWitchOrderBook", function () {
const orderId = 1;
await expect(orderBook.cancelOrders([orderId], [])).to.be.revertedWithCustomError(orderBook, "LengthMismatch");
});

it.only("Remove an item, check the order can still be cancelled just not fulfilled", async function () {
const {orderBook, tokenId, brush, owner, alice} = await loadFixture(deployContractsFixture);

const price = 100;
const quantity = 10;
await orderBook.limitOrders([
{
side: OrderSide.Buy,
tokenId,
price,
quantity,
},
{
side: OrderSide.Buy,
tokenId,
price,
quantity,
},
]);
// Selling should work
await orderBook.limitOrders([
{
side: OrderSide.Sell,
tokenId,
price,
quantity: 1,
},
]);

// Remove the tokenId
await orderBook.setTokenIdInfos([tokenId], [{tick: 0, minQuantity: 20}]);
// Cancel should work
const orderId = 1;
const preBalance = await brush.balanceOf(owner.address);
await orderBook.cancelOrders([orderId], [{side: OrderSide.Buy, tokenId, price}]);

// Selling should no longer work
await expect(
orderBook.limitOrders([
{
side: OrderSide.Sell,
tokenId,
price,
quantity: 1,
},
]),
)
.to.be.revertedWithCustomError(orderBook, "TokenDoesntExist")
.withArgs(tokenId);
expect(await brush.balanceOf(owner.address)).to.eq(preBalance + BigInt(price * (quantity - 1)));
});
});

it("Consume a segment and whole price level with a tombstone offset, and check it works as expected when re-added to the tree", async function () {
Expand Down

0 comments on commit ef8d16f

Please sign in to comment.