Skip to main content

CoWUidGenerator

A helper contract for calculating the same EIP-712 signature hash for a given user order that the GPv2SettlementContract expects.

Architectureโ€‹

This contract is a simple helper contract that:

  • References the CoW Protocol settlement contractโ€™s domainSeparator.
  • Constructs a Gnosis Protocol v2 (CoW) order data struct on-chain.
  • Determines whether the order is a sell or buy order based on isSell.
  • Computes the EIP-712 hash that matches what the CoW Protocol uses to verify user signatures off-chain.

Data Types and Storageโ€‹

GPv2SettlementContractโ€‹

An interface for the CoW Protocol settlement contract.

interface GPv2SettlementContract {
function domainSeparator() external view returns (bytes32);
}

Functionsโ€‹

getUidโ€‹

Constructs an order, determines if it is a sell or buy order, then computes the same EIP-712 hash used by CoW Protocol for verifying signatures. Returns both the EIP-712 digest and the ABI-encoded order.

tip

Note: The digest being returned is only the order digest, not the actual order uid. In order to get the order uid this must be concatenated with the address of the order owner and the timestamp until which the order is valid (reference).

getUid(
address sellToken,
address buyToken,
address receiver,
uint256 sellAmount,
uint256 buyAmount,
uint32 validTo,
bytes32 appData,
uint256 feeAmount,
bool isSell,
bool partiallyFillable)
public view returns (bytes32 hash, bytes memory encoded)
ParameterDescription
sellTokenThe token address being sold if the order is a sell order, or the token that the user owes if the order is a buy order
buyTokenThe token the user will receive if the order is a sell order, or the token the user wants to buy if if the order is a buy order
receiverThe address to receive the bought tokens
sellAmountThe amount of sellToken being transferred (cannot be 0)
buyAmountThe amount of buyToken being transferred (cannot be 0)
validToTimestamp after which the order expires
appDataOptional field used by users/dapps/wallets to attach meta-information to orders
feeAmountAmount of fee to be charged (currently hardcoded to 0)
isSellIndicates whether the order is a buy or sell
partiallyFillableIndicates whether the order is partially fillable or fill-or-kill

Indexingโ€‹

Nil

Off-chainโ€‹

Nil