Skip to content

Commit

Permalink
Make nft/token private to save gas and remove unused nonces state var…
Browse files Browse the repository at this point in the history
…iable
  • Loading branch information
0xSamWitch committed Jan 27, 2024
1 parent 467dcea commit 06b523a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
9 changes: 4 additions & 5 deletions contracts/SamWitchOrderBook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ contract SamWitchOrderBook is ISamWitchOrderBook, ERC1155Holder, UUPSUpgradeable
uint8 private constant NUM_ORDERS_PER_SEGMENT = 4;

// state
IERC1155 public nft;
IBrushToken public token;
IERC1155 private nft;
IBrushToken private token;

address private devAddr;
uint16 private devFee; // Base 10000
Expand All @@ -56,8 +56,6 @@ contract SamWitchOrderBook is ISamWitchOrderBook, ERC1155Holder, UUPSUpgradeable
uint80[1_099_511_627_776] private brushClaimable; // Can pack 3 brush claimables into 1 word
mapping(uint40 orderId => mapping(uint tokenId => uint amount)) private tokenIdsClaimable;

mapping(address => uint) public nonces;

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
Expand Down Expand Up @@ -576,10 +574,11 @@ contract SamWitchOrderBook is ISamWitchOrderBook, ERC1155Holder, UUPSUpgradeable
}

if (numSegmentsFullyConsumed != 0) {
uint tombstoneOffset = node.tombstoneOffset;
tree[_tokenId].edit(bestPrice, uint32(numSegmentsFullyConsumed));

// Consumed all orders at this price level, so remove it from the tree
if (numSegmentsFullyConsumed == packedOrders.length - node.tombstoneOffset) {
if (numSegmentsFullyConsumed == packedOrders.length - tombstoneOffset) {
tree[_tokenId].remove(bestPrice); // TODO: A ranged delete would be nice
}
}
Expand Down
1 change: 0 additions & 1 deletion test/SamWitchOrderBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,6 @@ describe("SamWitchOrderBook", function () {
expect(await orderBook.nodeExists(OrderSide.Buy, tokenId, price)).to.be.false;

// Re-add it, should start in the next segment
console.log("Re-add");
await orderBook.limitOrders([limitOrder]);
const node = await orderBook.getNode(OrderSide.Buy, tokenId, price);
expect(node.tombstoneOffset).to.eq(1);
Expand Down

0 comments on commit 06b523a

Please sign in to comment.