Skip to content

Commit

Permalink
Clearing a partially filled segment when all orders are consumed seem…
Browse files Browse the repository at this point in the history
…s to give better gas utilization
  • Loading branch information
0xSamWitch committed Jan 29, 2024
1 parent 846a6fc commit 312bf5c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions contracts/SamWitchOrderBook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -584,19 +584,19 @@ contract SamWitchOrderBook is ISamWitchOrderBook, ERC1155Holder, UUPSUpgradeable
}

if (eatIntoLastOrder || numOrdersWithinLastSegmentFullyConsumed != 0) {
// Clear the orders for this many
// This segment wasn't completely filled before
if (numOrdersWithinLastSegmentFullyConsumed != 0) {
for (uint i; i < numOrdersWithinLastSegmentFullyConsumed; ++i) {
packed &= _clearOrderMask(i);
}
}
if (uint(packed) == 0) {
// All orders in the segment are consumed, delete from tree
tree[_tokenId].remove(bestPrice);
packedOrders.pop();
} else {
packedOrders[lastSegment] = packed;
}

packedOrders[lastSegment] = packed;

if (eatIntoLastOrder) {
break;
}
Expand Down

0 comments on commit 312bf5c

Please sign in to comment.