-
Notifications
You must be signed in to change notification settings - Fork 24
docs: add comprehensive generalized wrappers documentation #595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kaze-cow
wants to merge
11
commits into
main
Choose a base branch
from
add-wrapper
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,142
−0
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9e9d980
docs: add comprehensive generalized wrappers documentation
kaze-cow 4248b8f
fix compile errors
kaze-cow 8e0fcdd
try to clean up wording of the wrapper description
kaze-cow 44a2d3b
wording for guarenteed execution
kaze-cow 5563ab8
fix wordings
kaze-cow ad8f9e6
use protocol terminology
kaze-cow 3e58601
fix more wording for CoW team
kaze-cow aba6279
fix wording in periphery guide
kaze-cow 9678bb8
actually embed the code since the gist embed script doesn't seem to work
kaze-cow e65d348
fix ai comments
kaze-cow 2bc9013
other ai fixes misc
kaze-cow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| --- | ||
| sidebar_position: 7 | ||
| --- | ||
|
|
||
| # Generalized Wrappers | ||
|
|
||
| Generalized wrappers is a new framework to allow custom logic to execute before and/or after order settlement on CoW Protocol. They enable complex DeFi workflows—like flash loans, leveraged positions, and programmatic orders—all while preserving the security and assurances granted by CoW Protocol. | ||
|
|
||
| ## What are Wrappers? | ||
|
|
||
| Wrappers are smart contracts that "wrap" the settlement process, executing custom logic surrounding settlement contract. When a solver executes a settlement that includes a wrapper, they call the wrapper contract instead of the settlement contract directly. The wrapper calls the settlement contract on behalf of the solver. | ||
|
|
||
| This mechanism extends CoW Protocol's functionality in a modular way, allowing new features and integrations to be added without modifying the core settlement contract or requiring any changes to solver implementations. | ||
|
|
||
| ## Use Cases | ||
|
|
||
| Wrappers enable a wide variety of advanced trading and DeFi operations: | ||
|
|
||
| ### Leverage Positions | ||
|
|
||
| By wrapping the execution context of a CoW settlement, protocols implementing leveraged position opening capabilities can be supported. | ||
|
|
||
| As the flagship GW implementation, Euler demonstrates a quintessential implementation of this use case. The wrapper: | ||
|
|
||
| 1. Coordinates with Euler's Ethereum Vault Connector (EVC) batch execution system | ||
| 2. Executes the necessary EVC batch operations before settlement | ||
| 3. Performs the settlement to acquire the leveraged asset | ||
| 4. Completes the position setup after settlement | ||
|
|
||
| This enables users to open leveraged positions on Euler through a single CoW Protocol order, with all the complexity handled by the wrapper. Leveraged positions are associated with high-volume trading, so CoW benefits from increased revenue from such integrations. | ||
|
|
||
| ### Flash Loan Integration | ||
|
|
||
| Currently, CoW Protocol uses a dedicated `FlashLoanRouter` contract for flash loan functionality. However, this implementation comes with additional implementation effort from both the solvers and the CoW Protocol backend infrastructure. With generalized wrappers, flash loan integration becomes simpler and more flexible. | ||
|
|
||
| ### Programmatic Orders | ||
|
|
||
| By introducing a wrapped order type combined with [composable-cow](../../reference/contracts/periphery/composable_cow.md) conditional order generators, it is possible for any account (EOA or smart contract wallet) to authorize delayed orders that can be triggered at a specified time. The wrapper contract provides the signing authentication, the conditional order contract controls the logic for when the order can execute, and the CoW Settlement contract protects the execution of the swap generated by the conditional order. | ||
|
|
||
| ### Protocol-Approved Hooks | ||
|
|
||
| Unlike [CoW Hooks](./cow-hooks.mdx), which can revert even if the order is executed successfully, wrappers provide a way to enforce required pre- and post-settlement operations. Since wrappers are protocol-approved through the allowlist authenticator, they can implement critical functionality that must execute: | ||
|
|
||
| - Compliance checks (e.g., OFAC screening) | ||
| - Cross chain transfers (pre- or post- transfer) | ||
| - Deposit in a vault or other wrapper contract (swap and stake) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| The key difference from hooks is that if a wrapper is required for an order, the settlement cannot proceed without it—making wrappers ideal for transactions requiring robust execution. | ||
|
|
||
| ## Considerations | ||
|
|
||
| While wrappers are powerful, there are important considerations to keep in mind: | ||
|
|
||
| ### Gas Overhead | ||
|
|
||
| Wrappers add gas overhead to settlement transactions. Benchmarks show that even an empty wrapper (one that does nothing but pass through to settlement) adds approximately 22,272 gas, or about 11.4% overhead. The actual overhead depends on: | ||
|
|
||
| - The complexity of the wrapper's logic | ||
| - The size of the settlement data being passed through | ||
| - The number of nested wrappers in the chain | ||
|
|
||
| For many use cases, this overhead is acceptable given the functionality unlocked, but it's an important factor in deciding whether to use a wrapper. | ||
|
|
||
| ### Requires Protocol Approval | ||
|
|
||
| Wrappers cannot be deployed and used immediately—they must be approved by CoW DAO through the allowlist authenticator. This approval process ensures high-quality wrapper implementations and safety for solvers, but means there's a roadblock for developers looking to extend CoW Protocol. Developers should plan for this approval process when building wrapper-based integrations. | ||
|
|
||
| ### On-Chain Protocol Does Not Enforce Execution | ||
|
|
||
| Despite official rules enforcing the execution of wrappers when required by the user, a solver may choose not to execute a wrapper with an order. This means wrappers must be designed defensively: | ||
|
|
||
| - If a wrapper is strictly required, the order should fail to settle without it | ||
| - Wrappers should validate all input data and fail in cases where a user's funds could be at risk | ||
|
|
||
| ### Encoding Complexity | ||
|
|
||
| To improve gas performance, wrapper data is encoded in a condensed format. Constructing wrapper calldata correctly can be complex, especially when nesting multiple wrappers. While the protocol provides helper contracts like `CowWrapperHelper` to simplify this, developers need to understand the encoding scheme to build robust integrations. | ||
|
|
||
| ## Getting Started | ||
|
|
||
| Wrappers are a powerful tool for advanced integrations on CoW Protocol. To start building with wrappers: | ||
|
|
||
| - **For developers**: See the [Integration Guide](../../integrate/wrappers.mdx) for implementation details, code examples, and security guidelines | ||
| - **For technical specs**: Consult the [Technical Reference](../../reference/contracts/periphery/wrapper.mdx) for detailed contract documentation and API specifications | ||
|
|
||
| To learn more about wrappers and see example implementations: | ||
|
|
||
| - [Euler Integration Contracts Repository](https://github.com/cowprotocol/euler-integration-contracts) - Contains the `CowWrapper` abstract contract and example implementations | ||
| - [Services Repository PR #3700](https://github.com/cowprotocol/services/pull/3700) - Backend integration implementation. Good reference for solvers looking to support wrappers. | ||
|
|
||
| Wrappers represent a significant evolution in CoW Protocol's capabilities, enabling complex DeFi workflows while maintaining security and simplicity for solvers. As more wrappers are developed and approved, they will continue to expand what's possible with intent-based trading. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing article: "surrounding settlement contract" → "surrounding the settlement contract".
📝 Committable suggestion
🤖 Prompt for AI Agents