Expand description
§cow-sdk-contracts
Low-level CoW Protocol contract helpers: order hashing and UID packing, EIP-712 / EIP-1271 signature codecs and on-chain verification, fail-closed on-chain event decoding, the settlement / eth-flow / token ABI bindings, deployment metadata, and the opt-in COW Shed account-abstraction module.
⚠️ Alpha —
0.1.0-alpha. Pre-release and not security-audited; the public API may change before0.1.0. It is published as a pre-release, so Cargo selects it only when you opt in (cow-sdk-contracts = "0.1.0-alpha.10"). Review it yourself before relying on it with real funds.
This crate owns the deterministic building blocks used by higher-level crates
such as cow-sdk-signing and
cow-sdk-trading. Most end-user
code reaches these helpers through
cow-sdk; depend on this crate directly
when you are writing contract-level tooling, encoders, or verifiers that do not
need the full trading facade.
§What it provides
- Order hashing and UID codec —
hash_orderandhash_order_cancellation(s)EIP-712 digests,order_eip712_type_hash, and the 56-byte UID codec (compute_order_uid,pack_order_uid_params,extract_order_uid_params). - Signature codecs and recovery — a closed-construction
RecoverableSignature(ECDSA recovery, ERC-2098 round-trip, EIP-191 prehash), theSignatureenum, theSigningSchemeenum, and EIP-1271 payload encode/decode. - On-chain EIP-1271 verification —
verify_eip1271_signature(_cached)through an injectedProvider, with an optionalEip1271Cache. - Fail-closed event decoding —
OrderPlacement/OrderInvalidation, settlement, and eth-flow log decoders that validate the topic set and field lengths before ABI decode and return a typed error rather than panicking on hostile input. - ABI bindings and calldata — eth-flow create/invalidate, ERC-20, and wrapped-native (WETH) wrap/unwrap interactions.
- Deployment registry —
Registry::addressresolves Settlement, VaultRelayer, and EthFlow across the supported chains and prod/staging from committed const addresses, no RPC. - (feature
cow-shed) account-abstraction proxy derivation, EIP-712 hook signing, andexecuteHookscalldata via theCowShedHooksorchestrator. - (feature
composable) the ComposableCoW + TWAP module: the conditional-order id and create/createWithContext/remove encoders, theTwapDatabuilder, theMultiplexermerkle helper, and the puretiming_atschedule classifier.
§Install
[dependencies]
cow-sdk-contracts = "0.1.0-alpha.10"§Example
use cow_sdk_contracts::{ContractId, Registry};
use cow_sdk_core::{CowEnv, SupportedChainId};
// Resolve the canonical settlement contract for a chain and environment.
let settlement = Registry::default()
.address(ContractId::Settlement, SupportedChainId::Mainnet, CowEnv::Prod)
.unwrap();
assert_eq!(
settlement.to_hex_string(),
"0x9008d19f58aabd9ed0d60971565aa8510560ab41",
);From there, hash_order produces an order’s EIP-712 digest, the signature
codecs recover and encode EOA and EIP-1271 signatures, and the event decoders
parse settlement and on-chain-order logs fail-closed. See the
crate documentation for the full surface.
§Features
All off by default:
cow-shed— the COW Shed account-abstraction module (cow_shed): deterministic proxy derivation, EIP-712 hook signing, andexecuteHookscalldata, with theCowShedHooksorchestrator.composable— the ComposableCoW + TWAP module behind the off-by-defaultcomposablefeature: the conditional-order id and create/createWithContext/remove encoders, theTwapDatabuilder, the hand-rolledMultiplexermerkle helper, and the puretiming_atschedule classifier.tracing— structured spans through thetracingfacade.
§Primitive layer
Address, Hash32, OrderUid, and AppDataHash come from cow-sdk-core as
#[repr(transparent)] newtypes over the matching alloy_primitives types per
ADR 0052;
conversion at the alloy seam is zero-cost. EIP-712 domain separators and message
hashes route through alloy_sol_types.
§Where this fits
This crate is the deterministic, provider-agnostic building-block layer. It does
not own the user-domain OrderData (that is
cow-sdk-core; this crate hashes over
it), it carries no RPC client (verification takes a cow_sdk_core::Provider
parameter), it does not implement the solver settle path (out of scope —
order-lifecycle only), and it does no HTTP or order submission
(cow-sdk-orderbook) or order
building (cow-sdk-trading).
§Where to next
§License
Licensed under GPL-3.0-or-later. See the workspace
LICENSE
file for the full text.
Low-level CoW Protocol contract helpers for order hashing, signature
codecs and on-chain verification, ABI bindings, fail-closed event decoding,
and deployment metadata.
Re-exports§
pub use deployments::ContractId;pub use deployments::DeploymentChainId;pub use deployments::DeploymentEnv;pub use deployments::Registry;pub use errors::ContractsError;pub use eth_flow::EthFlowEvent;pub use eth_flow::EthFlowOnchainData;pub use eth_flow::EthFlowOrderData;pub use eth_flow::ICoWSwapEthFlowEvents;pub use eth_flow::OnchainOrderRefund;pub use eth_flow::decode_eth_flow_log;pub use eth_flow::decode_order_refund;pub use eth_flow::encode_create_order_calldata;pub use eth_flow::encode_invalidate_order_calldata;pub use eth_flow::parse_eth_flow_onchain_data;pub use interaction::Interaction;pub use interaction::InteractionLike;pub use interaction::normalize_interaction;pub use interaction::normalize_interactions;pub use onchain_orders::ICoWSwapOnchainOrders;pub use onchain_orders::OnchainOrderInvalidation;pub use onchain_orders::OnchainOrderPlacement;pub use onchain_orders::OnchainSigningScheme;pub use onchain_orders::decode_order_invalidation;pub use onchain_orders::decode_order_placement;pub use order::BUY_ETH_ADDRESS;pub use order::CANCELLATIONS_TYPE_FIELDS;pub use order::GPv2OrderCancellations;pub use order::ORDER_TYPE_FIELDS;pub use order::ORDER_UID_LENGTH;pub use order::OrderCancellations;pub use order::OrderTypeField;pub use order::OrderUidParams;pub use order::compute_order_uid;pub use order::extract_order_uid_params;pub use order::hash_order;pub use order::hash_order_cancellation;pub use order::hash_order_cancellations;pub use order::order_eip712_type_hash;pub use order::pack_order_uid_params;pub use settlement::IGPv2SettlementEvents;pub use settlement::SettlementEvent;pub use settlement::decode_settlement_log;pub use settlement::encode_invalidate_order;pub use settlement::encode_set_pre_signature;pub use signature::Eip1271SignatureData;pub use signature::Eip1271VerificationRequest;pub use signature::IERC1271;pub use signature::MAX_SIGNATURE_HEX_BYTES;pub use signature::RecoverableSignature;pub use signature::Signature;pub use signature::SigningScheme;pub use signature::decode_eip1271_signature_data;pub use signature::decode_signing_scheme;pub use signature::encode_eip1271_signature_data;pub use signature::encode_signing_scheme;pub use signature::verify_eip1271_signature;pub use tokens::IERC20;pub use tokens::IWrappedNativeToken;pub use tokens::approve_transaction;pub use tokens::encode_approve;pub use tokens::unwrap_interaction;pub use tokens::unwrap_transaction;pub use tokens::wrap_interaction;pub use tokens::wrap_transaction;pub use tx::UnsignedTransaction;pub use tx::ethflow_create_order_transaction;pub use tx::ethflow_invalidate_order_transaction;pub use tx::invalidate_order_transaction;pub use tx::pre_sign_transaction;pub use tx::resolve_contract_address;pub use tx::resolve_eth_flow_address;pub use tx::resolve_settlement_address;pub use verify::Eip1271Cache;pub use verify::NoopEip1271Cache;pub use verify::verify_eip1271_signature_cached;
Modules§
- composable
composable - Composable conditional orders (
ComposableCoWframework + TWAP). - cow_
shed cow-shed - COW Shed account-abstraction proxy, EIP-712, and hook-signing helpers.
- deployments
- Chain-keyed registry of canonical CoW Protocol contract deployments.
Const-backed registry of canonical
CoWProtocol contract deployments. - errors
- Contract crate error types.
- eth_
flow - Typed
CoWSwapEthFlowcall-data encoders generated from the upstream Solidity surface via thealloy::sol!macro. Typed ABI bindings for theCoWSwapEthFlowcontract. - hex_
field - Hex decode helpers for
0x-prefixed payloads inside the contracts boundary. - interaction
- Typed interaction models and normalization helpers.
- onchain_
orders - Typed
CoWSwapOnchainOrdersevent bindings and a fail-closed log decoder. Typed bindings and a fail-closed decoder for theCoWSwapOnchainOrdersevent surface. - order
- Order hashing, UID packing, and normalization helpers.
Order hashing, UID packing, EIP-712 metadata, and the
GPv2typed-datasol!bindings. - settlement
- Typed
GPv2SettlementABI binding and a fail-closed settlement event-log decoder.GPv2SettlementABI binding and fail-closed event decoding. - signature
- Signature codecs and EIP-1271 verification helpers.
- tokens
- Typed ERC-20 and wrapped-native (WETH9-family) token bindings and wrap / unwrap interaction helpers. Typed ABI bindings for the ERC-20 and wrapped-native token surfaces.
- tx
- Gas-free on-chain transaction builders with override-or-registry resolution. Gas-free on-chain transaction builders over the canonical contract bindings.
- verify
- Cache-aware EIP-1271 signature verification path. On-chain EIP-1271 signature verification with optional caching.
Functions§
- buy_
balance_ from_ marker - Resolves a buy-token balance destination from its
GPv2marker hash. - buy_
balance_ name - Returns the settlement flag label for a supported buy-token balance destination.
- order_
kind_ from_ marker - Resolves an order kind from its
GPv2marker hash. - order_
kind_ name - Returns the EIP-712 type-string label for a supported order kind.
- sell_
balance_ from_ marker - Resolves a sell-token balance source from its
GPv2marker hash. - sell_
balance_ name - Returns the settlement flag label for a supported sell-token balance source.