TheDocumentation Index
Fetch the complete documentation index at: https://cowswap-mintlify-docs-audit-1776071666.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Hook struct defines the parameters for user-specified hooks that execute during CoW Protocol settlements.
Definition
HooksTrampoline and specifies the parameters needed for a single hook call execution.
Fields
target
| Property | Value |
|---|---|
| Type | address |
| Required | Yes |
- Must be a valid Ethereum address
- Can be an EOA or a contract
- The call executes regardless of whether code exists at the address
callData
| Property | Value |
|---|---|
| Type | bytes |
| Required | Yes |
- Can be empty (for plain ETH transfers)
- Should be ABI-encoded for function calls
- Use
abi.encodeWithSignature()orabi.encodeWithSelector()for encoding
gasLimit
| Property | Value |
|---|---|
| Type | uint256 |
| Required | Yes |
- Must be sufficient for the hook execution
- Accounts for the 63/64 gas forwarding rule
- If insufficient gas remains, the trampoline reverts
- Setting too high risks reversion; setting too low causes hook failure
Code Examples
Basic Hook Construction
Hook with Parameters
Multiple Hooks Array
Empty Call Data Hook
Using Selector for Efficiency
Gas Limit Considerations
Due to the EVM’s 63/64 rule for gas forwarding, the actual available gas to the hook may be slightly less than specified.
Calculating Gas Limits
- Estimate execution cost through testing
- Add 10-20% buffer as a safety margin
- Account for the trampoline’s
gasleft() * 63 / 64calculation - Consider that failed hooks consume the gas limit without blocking the settlement
Common Patterns
Pre-Settlement Hook
Post-Settlement Hook
Conditional Hook
Best Practices
- Test gas usage on testnets, measuring actual consumption
- Handle reverts gracefully in hook target design
- Minimize complexity to reduce gas costs and failure risk
- Validate inputs in hook target parameters
- Emit events for tracking execution and debugging
Related
- HooksTrampoline Contract — Contract API reference
- Errors — Error types and handling
- Usage Guide — Implementation guide