-
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,99 @@ | ||||||||||||||
| --- | ||||||||||||||
| 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 progmatic 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. | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing article: "surrounding settlement contract" → "surrounding the settlement contract". -Wrappers are smart contracts that "wrap" the settlement process, executing custom logic surrounding settlement contract.
+Wrappers are smart contracts that "wrap" the settlement process, executing custom logic surrounding the settlement contract.📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| 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. | ||||||||||||||
|
|
||||||||||||||
| ### Wrapper Authentication | ||||||||||||||
|
|
||||||||||||||
| For security, all wrappers must be approved through CoW Protocol's `GPv2AllowlistAuthenticator` before they can be used. This ensures that only audited and wrappers can interact with the settlement contract, protecting users, solver, and the protocol from malicious contracts. Unlike [hooks](./cow-hooks.mdx), Wrapper functionality can revert the execution of a transaction, ensuring sensitive user operations such as cross-chain operations can be guarenteed to be completed. | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix spelling error. "guarenteed" should be "guaranteed". ✍️ Proposed fix-For security, all wrappers must be approved through CoW Protocol's `GPv2AllowlistAuthenticator` before they can be used. This ensures that only audited and wrappers can interact with the settlement contract, protecting users, solver, and the protocol from malicious contracts. Unlike [hooks](./cow-hooks.mdx), Wrapper functionality can revert the execution of a transaction, ensuring sensitive user operations such as cross-chain operations can be guarenteed to be completed.
+For security, all wrappers must be approved through CoW Protocol's `GPv2AllowlistAuthenticator` before they can be used. This ensures that only audited wrappers can interact with the settlement contract, protecting users, solvers, and the protocol from malicious contracts. Unlike [hooks](./cow-hooks.mdx), wrapper functionality can revert the execution of a transaction, ensuring sensitive user operations such as cross-chain operations can be guaranteed to be completed.Note: Also fixed "solver" → "solvers", removed extra space before "wrappers", and capitalization of "Wrapper functionality" → "wrapper functionality" for consistency. 📝 Committable suggestion
Suggested change
🧰 Tools🪛 LanguageTool[grammar] ~17-~17: Ensure spelling is correct (QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1) 🤖 Prompt for AI Agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line doesn't make sense; "This ensures that only audited and wrappers" also double space after "and"
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. solver ---> solvers
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. title for Wrapper or lower case wrapper?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cross-chain operations can be guarenteed to be completed. --> can be completed safely. |
||||||||||||||
|
|
||||||||||||||
| ### Wrapper Nesting | ||||||||||||||
|
|
||||||||||||||
| One of the powerful features of wrappers is their ability to be nested. Multiple wrappers can be chained together in a single settlement transaction, allowing different orders in the same batch to each use their required wrapper functionality. For example, one order might need a flash loan wrapper while another needs a leverage wrapper—both can be executed in the same settlement through wrapper nesting. | ||||||||||||||
|
|
||||||||||||||
| ## 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. | ||||||||||||||
|
|
||||||||||||||
| ### Progmatic Orders | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix spelling error. "Progmatic" should be "Programmatic". ✍️ Proposed fix-### Progmatic Orders
+### Programmatic Orders📝 Committable suggestion
Suggested change
🧰 Tools🪛 LanguageTool[grammar] ~44-~44: Ensure spelling is correct (QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1) 🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| 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) | ||||||||||||||
|
Comment on lines
+52
to
+54
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent hyphenation: "Cross chain" should be "Cross-chain". Line 17 already uses "cross-chain" correctly. Line 53 should match: -- Cross chain transfers (pre- or post- transfer)
+- Cross-chain transfers (pre- or post-transfer)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| 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 functionality that must not be skipped that is also approved. | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. making wrappers ideal for functionality that must not be skipped that is also approved. ---> making wrappers ideal for transactions requiring more robust checks. |
||||||||||||||
|
|
||||||||||||||
| ## 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 the 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. | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add hyphen to compound adjective. "high quality" should be hyphenated when used as a compound adjective before a noun. ✍️ Proposed fix-Wrappers cannot be deployed and used immediately—they must be approved by the 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.
+Wrappers cannot be deployed and used immediately—they must be approved by the 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.📝 Committable suggestion
Suggested change
🧰 Tools🪛 LanguageTool[grammar] ~74-~74: Use a hyphen to join words. (QB_NEW_EN_HYPHEN) 🤖 Prompt for AI Agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they must be approved by the CoW DAO through the allowlist authenticator --> they must be approved by CoW DAO through the allowlist authenticator. |
||||||||||||||
|
|
||||||||||||||
| ### Execution Not Enforced by the on-chain Protocol | ||||||||||||||
|
|
||||||||||||||
| Despite official rules enforcing the execution of wrappers when required by the user, a solver could still not 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. | ||||||||||||||
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.
Fix spelling errors.
"progmatic" should be "programmatic" and the sentence has punctuation issues (double dash should be em dash or comma).
✍️ Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 LanguageTool
[grammar] ~7-~7: Ensure spelling is correct
Context: ...e flash loans, leveraged positions, and progmatic orders--all while preserving the securi...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
🤖 Prompt for AI Agents