Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not allowing zero sell amount orders #27

Merged
merged 2 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/CoWSwapEthFlow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ contract CoWSwapEthFlow is
revert IncorrectEthAmount();
}

if (0 == order.sellAmount) {
revert NotAllowedZeroSellAmount();
}

EthFlowOrder.OnchainData memory onchainData = EthFlowOrder.OnchainData(
msg.sender,
order.validTo
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/ICoWSwapEthFlow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ interface ICoWSwapEthFlow {
/// @dev Error thrown when trying to create an order without sending the expected amount of ETH to this contract.
error IncorrectEthAmount();

/// @dev Error thrown when trying to create an order with a sell amount == 0
error NotAllowedZeroSellAmount();

/// @dev Error thrown if trying to delete an order while not allowed.
error NotAllowedToDeleteOrder(bytes32 orderHash);

Expand Down
20 changes: 20 additions & 0 deletions test/CoWSwapEthFlow.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,26 @@ contract TestOrderCreation is EthFlowTestSetup, ICoWSwapOnchainOrders {
ethFlow.createOrder{value: sellAmount + feeAmount - 1}(order);
}

function testRevertOrderCreationIfSellAmountIsZero() public {
uint256 sellAmount = 0 ether;
uint256 feeAmount = 1 ether;
EthFlowOrder.Data memory order = EthFlowOrder.Data(
IERC20(address(0)),
address(0),
sellAmount,
0,
bytes32(0),
feeAmount,
0,
false,
0
);
assertEq(order.sellAmount, sellAmount);

vm.expectRevert(ICoWSwapEthFlow.NotAllowedZeroSellAmount.selector);
ethFlow.createOrder{value: sellAmount + feeAmount}(order);
}

function testRevertIfCreatingAnOrderWithTheSameHashTwice() public {
uint256 sellAmount = 41 ether;
uint256 feeAmount = 1 ether;
Expand Down