Documentation Index
Fetch the complete documentation index at: https://cowswap-mintlify-docs-quality-audit-1774257282.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Architecture
The main settlement contract for CoW Protocol allows for custom interactions to be executed before and after the settlement logic. This is primarily used by solvers to access on-chain liquidity for settling batch auctions, but it can also be made available to users to perform custom actions, hereafter referred to as hooks. However, executing hooks from the settlement contract is not ideal for two reasons:- Hooks may be malicious and drain the protocol fees
- Hooks may revert, causing the settlement contract to revert, disrupting the settlement process
HooksTrampoline contract serves as a reference implementation that helps isolate the settlement contract and provide protection.
Therefore executing users’ hooks can be visualized as follows:
Guarantees and Invariants
- The trampoline contract is not upgradable
- Hooks are only executed during the course of a settlement on CoW Protocol
- Enough gas is forwarded to the hooks to execute the logic
Relying on the trampoline contract address
Solvers may use theHooksTrampoline contract to execute hooks, as it offers a pragmatic way to meet many of the security guarantees required of hook execution while still keeping the settlement submission logic relatively simple. However, the protocol does not mandate any specific implementation. In fact, solvers are not required to use an intermediary contract at all if they can ensure the security of their hooks by other means, they may do so and save gas.
Data Types and Storage
Hook
Hooks are passed to the trampoline contract as a Hook struct:
| Field | Description |
|---|---|
target | Address of the contract to call |
callData | Data to pass to the contract |
gasLimit | Maximum amount of gas to use for the call |
Functions
For settlement
execute
This function is called by the settlement contract during the course of settlement as an interaction to execute the user’s hooks.
| Parameter | Description |
|---|---|
hooks | Array of hooks to execute |