Generalized wrappers are under active development and the API may change. The flagship implementation is the Euler/EVC integration.
How wrappers work
When a settlement uses wrappers, the solver does not callsettle() on the settlement contract. Instead, the solver calls wrappedSettle() on the first wrapper in the chain. The execution flow is nested:
- The solver calls
wrappedSettle(settleData, chainedWrapperData)on the outermost wrapper. - The wrapper runs its pre-settlement logic.
- The wrapper calls
_next(), which either chains to the next wrapper or calls the settlement contract. - After settlement returns, the wrapper runs its post-settlement logic.
How wrappers are specified
Wrappers are specified in the order’sappData via a wrappers array. Each entry contains a target (the wrapper contract address) and an optional data field for wrapper-specific parameters.
This is distinct from hooks, which are specified per-order in the metadata.hooks field.
Authentication and security
Only allowlisted wrapper contracts can call the settlement contract. Allowlisting is governed by CoW DAO through theGPv2AllowlistAuthenticator. Before a wrapper can be added to the allowlist, it must be audited by a well-known security provider.
Wrapper implementations should treat all parameters as untrusted. Because wrappers are nested, a wrapper further down the chain could modify the settlement data before it reaches the settlement contract. Defensive design is required.
Gas overhead
An empty wrapper (one that performs no custom logic) adds approximately 22,272 gas (~11.4% overhead) on a single Uniswap V3 trade. Real-world wrappers will add more depending on the complexity of their pre- and post-settlement logic.How wrappers differ from hooks
| Hooks | Wrappers | |
|---|---|---|
| Scope | Per-order; run alongside a specific order | Per-settlement; can inspect and modify the entire settlement |
| Executed by | The settlement contract | The solver, before calling settlement |
| Approval | No DAO approval required | Must be allowlisted by CoW DAO |
| Entry point | Settlement contract’s settle() | Wrapper’s wrappedSettle() |
Use cases
- Leveraged positions: The flagship use case. The Euler/EVC integration uses wrappers to open, modify, and close leveraged positions atomically as part of a CoW Protocol settlement.
- Flash loan integration: Wrappers can take flash loans before settlement and repay them after, providing capital efficiency for solvers.
- Programmatic order execution: Wrappers enable programmatic order patterns for all wallet types, not just smart contract wallets.
Implementation
The abstractCowWrapper contract that wrapper implementations extend lives in the Euler integration contracts repository. Wrapper developers inherit from this base contract and implement their custom pre- and post-settlement logic.