Skip to content

Commit

Permalink
Make helper return a valid CoW Swap signature
Browse files Browse the repository at this point in the history
  • Loading branch information
fedgiac committed Jul 8, 2024
1 parent f94df4d commit bbe367a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
9 changes: 7 additions & 2 deletions src/ConstantProductHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ contract ConstantProductHelper is ICOWAMMPoolHelper, LegacyHelper {
revert InvalidArrayLength();
}

bytes memory eip1271sig;
if (!isLegacy(pool)) {
// Standalone CoW AMMs (**non-Gnosis Safe Wallets**)
if (!isCanonical(pool)) {
Expand Down Expand Up @@ -93,7 +94,7 @@ contract ConstantProductHelper is ICOWAMMPoolHelper, LegacyHelper {
})
);

sig = abi.encode(_order);
eip1271sig = abi.encode(_order);

preInteractions = new GPv2Interaction.Data[](1);
preInteractions[0] = GPv2Interaction.Data({
Expand All @@ -102,8 +103,12 @@ contract ConstantProductHelper is ICOWAMMPoolHelper, LegacyHelper {
callData: abi.encodeCall(ConstantProduct.commit, (_order.hash(SETTLEMENT.domainSeparator())))
});
} else {
(_order, preInteractions, postInteractions, sig) = legacyOrder(pool, prices);
(_order, preInteractions, postInteractions, eip1271sig) = legacyOrder(pool, prices);
}

// A ERC-1271 signature on CoW Protocol is composed of two parts: the
// signer address and the valid ERC-1271 signature data for that signer.
sig = abi.encodePacked(pool, eip1271sig);
}

/// @dev Take advantage of the mapping on the factory that is set to the owner's address for canonical pools.
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/ICOWAMMPoolHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ interface ICOWAMMPoolHelper {
* @return order The CoW Protocol JIT order
* @return preInteractions The array array for any **PRE** interactions (empty if none)
* @return postInteractions The array array for any **POST** interactions (empty if none)
* @return sig The ERC-1271 signature for the order
* @return sig A valid CoW-Protocol signature for the resulting order using
* the ERC-1271 signature scheme.
*/
function order(address pool, uint256[] calldata prices)
external
Expand Down
6 changes: 0 additions & 6 deletions test/fork/ConstantProductHelper.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@ contract ConstantProductHelperForkedTest is ForkedTest {
GPv2Interaction.Data[] memory postInteractions;
bytes memory sig;
(ammOrder, preInteractions, postInteractions, sig) = helper.order(wethUsdcAmm, prices);
// The signature is valid for the contract but not for the
// settlement contract. We need to prepend the verifying contract
// address.
// TODO: update the helper so that it already includes the address in
// the signature.
sig = abi.encodePacked(wethUsdcAmm, sig);
trades[0] = orderToFullTrade(ammOrder, tokens, GPv2Signing.Scheme.Eip1271, sig);

// We expect a commit interaction in both pre and post interactions
Expand Down

0 comments on commit bbe367a

Please sign in to comment.