Skip to content

Commit a401718

Browse files
Merge pull request #50 from consenlabs/v5.3.0-PVE002
validate order in cancelLimitOrder()
2 parents eeb8f5b + 04f5fc1 commit a401718

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

contracts/LimitOrder.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,10 @@ contract LimitOrder is ILimitOrder, BaseLibEIP712, SignatureValidator, Reentranc
485485
* Cancel limit order
486486
*/
487487
function cancelLimitOrder(LimitOrderLibEIP712.Order calldata _order, bytes calldata _cancelOrderMakerSig) external override onlyUserProxy nonReentrant {
488+
require(_order.expiry > uint64(block.timestamp), "LimitOrder: Order is expired");
489+
bytes32 orderHash = getEIP712Hash(LimitOrderLibEIP712._getOrderStructHash(_order));
490+
bool isCancelled = LibOrderStorage.getStorage().orderHashToCancelled[orderHash];
491+
require(!isCancelled, "LimitOrder: Order is cancelled already");
488492
{
489493
LimitOrderLibEIP712.Order memory cancelledOrder = _order;
490494
cancelledOrder.takerTokenAmount = 0;
@@ -494,9 +498,7 @@ contract LimitOrder is ILimitOrder, BaseLibEIP712, SignatureValidator, Reentranc
494498
}
495499

496500
// Set cancelled state to storage
497-
bytes32 orderHash = getEIP712Hash(LimitOrderLibEIP712._getOrderStructHash(_order));
498501
LibOrderStorage.getStorage().orderHashToCancelled[orderHash] = true;
499-
500502
emit OrderCancelled(orderHash, _order.maker);
501503
}
502504

contracts/test/forkMainnet/LimitOrder.t.sol

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,28 @@ contract LimitOrderTest is StrategySharedSetup {
11121112
userProxy.toLimitOrder(cancelPayload);
11131113
}
11141114

1115+
function testCannotCancelExpiredOrder() public {
1116+
LimitOrderLibEIP712.Order memory expiredOrder = DEFAULT_ORDER;
1117+
expiredOrder.expiry = 0;
1118+
1119+
bytes memory payload = _genCancelLimitOrderPayload(expiredOrder, _signOrder(userPrivateKey, expiredOrder, SignatureValidator.SignatureType.EIP712));
1120+
vm.expectRevert("LimitOrder: Order is expired");
1121+
vm.prank(user, user); // Only EOA
1122+
userProxy.toLimitOrder(payload);
1123+
}
1124+
1125+
function testCannotCancelTwice() public {
1126+
LimitOrderLibEIP712.Order memory zeroOrder = DEFAULT_ORDER;
1127+
zeroOrder.takerTokenAmount = 0;
1128+
1129+
bytes memory payload = _genCancelLimitOrderPayload(DEFAULT_ORDER, _signOrder(makerPrivateKey, zeroOrder, SignatureValidator.SignatureType.EIP712));
1130+
vm.prank(user, user); // Only EOA
1131+
userProxy.toLimitOrder(payload);
1132+
vm.expectRevert("LimitOrder: Order is cancelled already");
1133+
vm.prank(user, user); // Only EOA
1134+
userProxy.toLimitOrder(payload);
1135+
}
1136+
11151137
/*********************************
11161138
* Helpers *
11171139
*********************************/

0 commit comments

Comments
 (0)