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

Use arbitrary data instead of quoteId #21

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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: 2 additions & 2 deletions src/CoWSwapEthFlow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ contract CoWSwapEthFlow is

// The data event field includes extra information needed to settle orders with the CoW Swap API.
bytes memory data = abi.encodePacked(
order.quoteId,
onchainData.validTo
onchainData.validTo,
order.extraData
);

orderHash = broadcastOrder(
Expand Down
11 changes: 6 additions & 5 deletions src/libraries/EthFlowOrder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ library EthFlowOrder {
uint32 validTo;
/// @dev Flag indicating whether the order is fill-or-kill or can be filled partially.
bool partiallyFillable;
/// @dev quoteId The quote id obtained from the CoW Swap API to lock in the current price. It is not directly
/// used by any onchain component but is part of the information emitted onchain on order creation and may be
/// required for an order to be automatically picked up by the CoW Swap orderbook.
int64 quoteId;
/// @dev extraData The extra data that is not directly used by any onchain component but is part of the
/// information emitted onchain on order creation and may be required for an order to be automatically picked up
/// by the CoW Swap orderbook. An example of this may be the quote id obtained from the CoW Swap API in order to
/// lock in the current price.
bytes extraData;
}

/// @dev An order that is owned by this address is an order that has not yet been assigned.
Expand Down Expand Up @@ -75,7 +76,7 @@ library EthFlowOrder {
}

// Note that not all fields from `order` are used in creating the corresponding CoW Swap order.
// For example, validTo and quoteId are ignored.
// For example, validTo and extraData are ignored.
return
GPv2Order.Data(
wrappedNativeToken, // IERC20 sellToken
Expand Down
20 changes: 10 additions & 10 deletions test/CoWSwapEthFlow.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ contract TestOrderCreation is EthFlowTestSetup, ICoWSwapOnchainOrders {
feeAmount,
0,
false,
0
hex""
);
assertEq(order.sellAmount, sellAmount);

Expand All @@ -187,7 +187,7 @@ contract TestOrderCreation is EthFlowTestSetup, ICoWSwapOnchainOrders {
feeAmount,
FillWithSameByte.toUint32(0x07),
true,
FillWithSameByte.toInt64(0x08)
FillWithSameByte.toVector(0x08, 42)
);
assertEq(order.sellAmount, sellAmount);
assertEq(order.feeAmount, feeAmount);
Expand Down Expand Up @@ -226,7 +226,7 @@ contract TestOrderCreation is EthFlowTestSetup, ICoWSwapOnchainOrders {
feeAmount,
FillWithSameByte.toUint32(0x07),
true,
FillWithSameByte.toInt64(0x08)
FillWithSameByte.toVector(0x08, 42)
);
assertEq(order.sellAmount, sellAmount);
assertEq(order.feeAmount, feeAmount);
Expand All @@ -245,7 +245,7 @@ contract TestOrderCreation is EthFlowTestSetup, ICoWSwapOnchainOrders {
uint256 sellAmount = 41 ether;
uint256 feeAmount = 1 ether;
uint32 validTo = FillWithSameByte.toUint32(0x01);
int64 quoteId = 1337;
bytes memory extraData = hex"1337";
EthFlowOrder.Data memory order = EthFlowOrder.Data(
IERC20(FillWithSameByte.toAddress(0x02)),
FillWithSameByte.toAddress(0x03),
Expand All @@ -255,7 +255,7 @@ contract TestOrderCreation is EthFlowTestSetup, ICoWSwapOnchainOrders {
feeAmount,
validTo,
true,
quoteId
extraData
);
assertEq(order.sellAmount, sellAmount);
assertEq(order.feeAmount, feeAmount);
Expand All @@ -274,7 +274,7 @@ contract TestOrderCreation is EthFlowTestSetup, ICoWSwapOnchainOrders {
executor,
order.toCoWSwapOrder(wrappedNativeToken),
signature,
abi.encodePacked(quoteId, validTo)
abi.encodePacked(validTo, extraData)
);
vm.prank(executor);
ethFlow.createOrder{value: sellAmount + feeAmount}(order);
Expand All @@ -293,7 +293,7 @@ contract TestOrderCreation is EthFlowTestSetup, ICoWSwapOnchainOrders {
feeAmount,
validTo,
true,
FillWithSameByte.toInt64(0x07)
FillWithSameByte.toVector(0x07, 42)
);
assertEq(order.sellAmount, sellAmount);
assertEq(order.feeAmount, feeAmount);
Expand Down Expand Up @@ -327,7 +327,7 @@ contract TestOrderCreation is EthFlowTestSetup, ICoWSwapOnchainOrders {
feeAmount,
FillWithSameByte.toUint32(0x05),
false,
FillWithSameByte.toInt64(0x06)
FillWithSameByte.toVector(0x06, 42)
);
assertEq(order.sellAmount, sellAmount);
assertEq(order.feeAmount, feeAmount);
Expand All @@ -348,7 +348,7 @@ contract OrderDeletion is EthFlowTestSetup {
FillWithSameByte.toUint128(0x06), // using uint128 to avoid triggering multiplication overflow
FillWithSameByte.toUint32(0x07),
true,
FillWithSameByte.toInt64(0x08)
FillWithSameByte.toVector(0x08, 42)
);
require(
order.validTo > block.timestamp,
Expand Down Expand Up @@ -624,7 +624,7 @@ contract SignatureVerification is EthFlowTestSetup {
FillWithSameByte.toUint256(0x16),
FillWithSameByte.toUint32(0x17),
true,
FillWithSameByte.toInt64(0x18)
FillWithSameByte.toVector(0x18, 42)
);
require(
order.validTo > block.timestamp,
Expand Down
4 changes: 2 additions & 2 deletions test/EthFlowOrder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract TestCoWSwapOnchainOrders is Test {
FillWithSameByte.toUint256(0x06),
FillWithSameByte.toUint32(0x07),
true,
FillWithSameByte.toInt64(0x08)
FillWithSameByte.toVector(0x08, 42)
);
IERC20 wrappedNativeToken = IERC20(FillWithSameByte.toAddress(0x42));

Expand Down Expand Up @@ -59,7 +59,7 @@ contract TestCoWSwapOnchainOrders is Test {
FillWithSameByte.toUint256(0x06),
FillWithSameByte.toUint32(0x07),
true,
FillWithSameByte.toInt64(0x08)
FillWithSameByte.toVector(0x08, 42)
);
assertEq(ethFlowOrder.receiver, GPv2Order.RECEIVER_SAME_AS_OWNER);

Expand Down
15 changes: 11 additions & 4 deletions test/FillWithSameByte.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ library FillWithSameByte {
return bytes32(repeatByte(b, 32));
}

function toInt64(uint8 b) public pure returns (int64) {
return int64(int256(repeatByte(b, 8)));
}

function toUint32(uint8 b) public pure returns (uint32) {
return uint32(repeatByte(b, 4));
}
Expand All @@ -26,6 +22,17 @@ library FillWithSameByte {
return repeatByte(b, 32);
}

function toVector(uint8 b, uint256 times)
public
pure
returns (bytes memory result)
{
result = new bytes(times);
for (uint256 i = 0; i < times; i++) {
result[i] = bytes1(b);
}
}

function repeatByte(uint8 b, uint8 times) internal pure returns (uint256) {
uint256 n = 0;
for (uint8 i = 0; i < times; i++) {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/TradingWithCoWSwap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ contract TradingWithCowSwap is DeploymentSetUp {
feeAmount,
31337, //validTo
false, //partiallyFillable
424242 //quoteId
hex"424242" //extraData
);
assertLt(block.timestamp, order.validTo);

Expand Down Expand Up @@ -121,7 +121,7 @@ contract TradingWithCowSwap is DeploymentSetUp {
feeAmount,
31337, //validTo
true, //partiallyFillable
424242 //quoteId
hex"424242" //extraData
);
assertLt(block.timestamp, order.validTo);

Expand Down