Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

CoWSwapCloneWithAppData

Git Source

Inherits: IERC1271, Clone

Variant of CoWSwapClone that enforces a fixed CoW Protocol appData hash for order validation. The hash is supplied when the implementation is deployed so every clone derived from it inherits the same metadata and remains backward-compatible with the existing adapter cloning flow. The clone should be initialized with the following packed bytes, in this exact order:

  • sellToken (address): The address of the token to be sold.
  • buyToken (address): The address of the token to be bought.
  • sellAmount (uint256): The amount of the sell token.
  • buyAmount (uint256): The minimum amount of the buy token.
  • validTo (uint64): The timestamp until which the order is valid.
  • operator (address): The address of the operator allowed to manage the trade.
  • receiver (address): The address that will receive the bought tokens. To use this contract, deploy the implementation with the desired appData hash, then create clones using the ClonesWithImmutableArgs library with the above immutable arguments packed into a single bytes array. After deployment, call initialize() to set up the necessary token approvals.

State Variables

appDataHash

CONSTANTS ///

The appData hash that is submitted for the orders.

bytes32 public immutable appDataHash;

_ERC1271_MAGIC_VALUE

bytes4 internal constant _ERC1271_MAGIC_VALUE = 0x1626ba7e;

_ERC1271_NON_MAGIC_VALUE

bytes4 internal constant _ERC1271_NON_MAGIC_VALUE = 0xffffffff;

_COW_SETTLEMENT_DOMAIN_SEPARATOR

The domain separator of GPv2Settlement contract used for orderDigest calculation.

bytes32 internal constant _COW_SETTLEMENT_DOMAIN_SEPARATOR =
    0xc078f884a2676e1345748b1feace7b0abee5d00ecadb6e574dcdd109a63e8943;

_VAULT_RELAYER

Address of the GPv2VaultRelayer. https://docs.cow.fi/cow-protocol/reference/contracts/core

address internal constant _VAULT_RELAYER = 0xC92E8bdf79f0507f65a392b0ab4667716BFE0110;

Functions

constructor

constructor(bytes32 appDataHash_) payable;

initialize

Initializes the CoWSwap clone by approving the vault relayer to spend the maximum amount of the sell token.

This function should be called after the clone is deployed to set up the necessary token approvals.

function initialize() external payable;

isValidSignature

Validates the signature of an order by comparing the order digest and verifying all order parameters.

function isValidSignature(bytes32 orderDigest, bytes calldata encodedOrder) external view override returns (bytes4);

Parameters

NameTypeDescription
orderDigestbytes32The digest of the order to validate.
encodedOrderbytesThe ABI-encoded GPv2Order.Data to validate.

Returns

NameTypeDescription
<none>bytes4A magic value if the signature is valid, otherwise a non-magic value.

claim

Claims the sell and buy tokens. Calling this function before the trade has settled will cancel the trade. Only the operator or the receiver can claim the tokens.

function claim() external payable returns (uint256 claimedSellAmount, uint256 claimedBuyAmount);

Returns

NameTypeDescription
claimedSellAmountuint256The amount of sell tokens claimed.
claimedBuyAmountuint256The amount of buy tokens claimed.

sellToken

Returns the address of the sell token.

function sellToken() public pure returns (address);

Returns

NameTypeDescription
<none>addressThe address of the sell token.

buyToken

Returns the address of the buy token.

function buyToken() public pure returns (address);

Returns

NameTypeDescription
<none>addressThe address of the buy token.

sellAmount

Returns the number of sell tokens included in the order.

function sellAmount() public pure returns (uint256);

Returns

NameTypeDescription
<none>uint256The amount of sell tokens.

minBuyAmount

Returns the minimum number of buy tokens that must be received for the order to be valid.

function minBuyAmount() public pure returns (uint256);

Returns

NameTypeDescription
<none>uint256The minimum acceptable buy amount.

validTo

Returns the timestamp until which the order is valid.

function validTo() public pure returns (uint32);

Returns

NameTypeDescription
<none>uint32The Unix timestamp (seconds) for the order expiry.

receiver

Returns the address of the receiver.

function receiver() public pure returns (address);

Returns

NameTypeDescription
<none>addressThe address of the receiver.

operator

Returns the address of the operator who can claim the tokens after the trade has settled. The operator can also cancel the trade before it has settled by calling the claim function before the trade has settled.

function operator() public pure returns (address);

Returns

NameTypeDescription
<none>addressThe address of the operator.

Events

CoWSwapCloneCreated

EVENTS ///

event CoWSwapCloneCreated(
    address indexed sellToken,
    address indexed buyToken,
    uint256 sellAmount,
    uint256 minBuyAmount,
    uint32 validTo,
    address indexed receiver,
    address operator
);

OrderClaimed

event OrderClaimed(address indexed operator, uint256 claimedSellAmount, uint256 claimedBuyAmount);

Errors

CallerIsNotOperatorOrReceiver

ERRORS ///

error CallerIsNotOperatorOrReceiver();