From d3a02122142f365c20a5c99a7146873c519463dd Mon Sep 17 00:00:00 2001 From: Matej Poklemba Date: Wed, 3 Apr 2024 15:14:32 +0200 Subject: [PATCH] `cancelSellOrder` gas optimization --- .../contracts/orderbook/OrderbookDex.sol | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/contracts/evm-contracts/contracts/orderbook/OrderbookDex.sol b/packages/contracts/evm-contracts/contracts/orderbook/OrderbookDex.sol index 810edb55d..b06bb93b6 100644 --- a/packages/contracts/evm-contracts/contracts/orderbook/OrderbookDex.sol +++ b/packages/contracts/evm-contracts/contracts/orderbook/OrderbookDex.sol @@ -181,18 +181,13 @@ contract OrderbookDex is IOrderbookDex, ERC1155Holder, ReentrancyGuard { /// @dev MUST change the `assetAmount` parameter for the specified order to `0`. /// MUST emit `OrderCancelled` event. function cancelSellOrder(uint256 orderId) public virtual { - Order memory order = orders[msg.sender][orderId]; + Order storage order = orders[msg.sender][orderId]; + uint256 assetAmount = order.assetAmount; if (order.assetAmount == 0) { revert OrderDoesNotExist(orderId); } - orders[msg.sender][orderId].assetAmount = 0; - asset.safeTransferFrom( - address(this), - msg.sender, - order.assetId, - order.assetAmount, - bytes("") - ); + order.assetAmount = 0; + asset.safeTransferFrom(address(this), msg.sender, order.assetId, assetAmount, bytes("")); emit OrderCancelled(msg.sender, orderId); }