Skip to content

docs: add comprehensive generalized wrappers documentation#595

Open
kaze-cow wants to merge 11 commits intomainfrom
add-wrapper
Open

docs: add comprehensive generalized wrappers documentation#595
kaze-cow wants to merge 11 commits intomainfrom
add-wrapper

Conversation

@kaze-cow
Copy link

@kaze-cow kaze-cow commented Feb 12, 2026

Description

Add complete documentation for CoW Protocol's generalized wrappers feature across three audience-specific files:

Changes

  • concepts/order-types/wrappers.md: High-level overview explaining what wrappers are, use cases (Euler leverage, flash loans, TWAP, protocol hooks), benefits, and considerations
  • integrate/wrappers.mdx: Practical integration guide with three sections:
    • For Order Creators: How to add wrappers to orders via appData
    • For Wrapper Developers: Building custom wrapper contracts with security requirements and implementation examples
    • For Solvers: Encoding wrapper settlements and handling wrapper execution
  • reference/contracts/periphery/wrapper.mdx: Smart contract reference focused on ICowWrapper interface, CowWrapper abstract contract, implementation patterns, and on-chain behavior

Summary by CodeRabbit

  • Documentation
    • Added comprehensive docs for Generalized Wrappers: concepts, architecture, lifecycle, and quick-start examples.
    • New integration guide for building, encoding, chaining, validation, solver behavior, execution/authentication, and troubleshooting.
    • Reference material covering interfaces/flow, data-format specs, on-chain utilities, testing guidance, security considerations, gas trade-offs, and example implementations.

Add complete documentation for CoW Protocol's generalized wrappers feature
across three audience-specific files:

- concepts/order-types/wrappers.md: High-level overview explaining what
  wrappers are, use cases (Euler leverage, flash loans, TWAP, protocol hooks),
  benefits, and considerations

- integrate/wrappers.mdx: Practical integration guide with three sections:
  * For Order Creators: How to add wrappers to orders via appData
  * For Wrapper Developers: Building custom wrapper contracts with security
    requirements and implementation examples
  * For Solvers: Encoding wrapper settlements and handling wrapper execution

- reference/contracts/periphery/wrapper.mdx: Smart contract reference focused
  on ICowWrapper interface, CowWrapper abstract contract, implementation
  patterns, and on-chain behavior

Each file serves a distinct purpose and audience while cross-linking to
provide comprehensive coverage of the wrapper system.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@kaze-cow kaze-cow requested a review from anxolin February 12, 2026 15:58
@kaze-cow kaze-cow self-assigned this Feb 12, 2026
@kaze-cow kaze-cow requested a review from a team as a code owner February 12, 2026 15:58
@vercel
Copy link

vercel bot commented Feb 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview Feb 17, 2026 3:49am

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 12, 2026

Warning

Rate limit exceeded

@kaze-cow has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 54 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

Adds three new documentation pages introducing Generalized Wrappers for the CoW Protocol: a conceptual overview, an integration guide, and a technical reference describing wrapper architecture, data encoding, execution flow, and security considerations.

Changes

Cohort / File(s) Summary
Concepts Doc
docs/cow-protocol/concepts/order-types/wrappers.md
New conceptual overview defining wrappers, use cases (leverage, flash loans, programmatic/conditional orders), differences from hooks, considerations (gas, allowlist authentication, encoding complexity), examples and references.
Integration Guide
docs/cow-protocol/integrate/wrappers.mdx
New integration guide describing building wrappers (inherit CowWrapper, implement _wrap and parseWrapperData), formatting appData.wrappers (target, data, is_omittable), validation via CowWrapperHelper, encoding strategies, solver/driver integration, troubleshooting, and testing tips.
Reference / Periphery
docs/cow-protocol/reference/contracts/periphery/wrapper.mdx
New technical reference detailing interfaces and base contracts (ICowWrapper, CowWrapper, authentication interfaces), wrappedSettle lifecycle and chain encoding (length-prefixed per-wrapper data, next-wrapper addresses), helper utilities, example implementations (EmptyWrapper, FlashLoanWrapper), events, limitations, and security notes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  rect rgba(200,220,255,0.5)
    participant User
    participant Solver
    participant Authenticator
    participant WrapperA as Wrapper (A)
    participant WrapperB as Wrapper (B)
    participant Settlement as SettlementContract
    participant External as ExternalProtocol
  end

  User->>Solver: submit order + appData.wrappers
  Solver->>Authenticator: validate wrapper allowlist
  Authenticator-->>Solver: allow / deny
  alt allowed
    Solver->>WrapperA: call wrappedSettle(dataA, next=WrapperB)
    WrapperA->>WrapperA: _wrap pre-settlement logic
    WrapperA->>WrapperB: _next(pass remaining data)
    WrapperB->>WrapperB: _wrap pre/post logic
    WrapperB->>Settlement: _next -> call settlement target
    Settlement->>External: execute settlement (swaps, transfers)
    External-->>Settlement: settlement result
    Settlement-->>WrapperB: return
    WrapperB->>WrapperA: return (post-settle)
    WrapperA-->>Solver: final return
  else denied
    Authenticator-->>Solver: revert / reject
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Suggested reviewers

  • pretf00d
  • MartinquaXD

Poem

🐇 I hop through wrappers, layer by layer,
Pre-checks and post-hooks handled with care,
Data rounds the chain and next calls fly free,
Settlements settle, modular and spry,
A rabbit's cheer for tidy DeFi glee!

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main change: adding comprehensive documentation for generalized wrappers, which aligns perfectly with the three new documentation files in the changeset.
Description check ✅ Passed The description follows the template structure with a clear description and detailed changes section listing all three documentation files with specific scope for each, providing comprehensive context for reviewers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add-wrapper

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 14

🤖 Fix all issues with AI agents
In `@docs/cow-protocol/concepts/order-types/wrappers.md`:
- Line 44: Fix the spelling in the header "### Progmatic Orders" by changing it
to "### Programmatic Orders" in the docs file; locate the header string
"Progmatic Orders" and replace it with "Programmatic Orders" so the section
title is correct.
- Line 7: Fix the typos and punctuation in the "Generalized wrappers" sentence:
change "progmatic" to "programmatic" and replace the double dash "--" with an em
dash "—" (or a comma) so the sentence reads cleanly (e.g., "...like flash loans,
leveraged positions, and programmatic orders— all while preserving..."). Update
the sentence in the wrappers.md content where "Generalized wrappers is a new
framework..." appears.
- Line 17: Fix typos and minor wording in the paragraph: change "guarenteed" to
"guaranteed", remove the extra space before "wrappers" so it reads "audited and
wrappers" properly as "audited wrappers" (or "audited and wrappers" -> remove
stray "and" if intended), change "solver" to plural "solvers", and lowercase
"Wrapper functionality" to "wrapper functionality" for consistency; update the
sentence in the docs content (the paragraph referencing
GPv2AllowlistAuthenticator and settlement contract) accordingly.
- Line 74: Update the phrase "high quality wrapper implementations" to use a
hyphenated compound adjective: change it to "high-quality wrapper
implementations" in the sentence describing the approval process by the
allowlist authenticator and CoW DAO (the sentence beginning "Wrappers cannot be
deployed..."). Ensure the hyphen is added only when "high-quality" directly
modifies "wrapper implementations."
- Line 92: Update the broken link pointing to
../../reference/contracts/periphery/wrapper.md by changing its extension to .mdx
(../../reference/contracts/periphery/wrapper.mdx) in the text "**For technical
specs**" inside the wrapper documentation; locate the markdown link string
"../../reference/contracts/periphery/wrapper.md" and replace ".md" with ".mdx"
so it points to the correct Technical Reference file (wrapper.mdx).

In `@docs/cow-protocol/integrate/wrappers.mdx`:
- Line 131: Replace the placeholder link in the sentence "Wrappers are specified
in the order's [`appData`](TODO) under the `wrappers` field" with the actual
documentation path for appData: locate the appData docs by searching the repo
for the "appData" heading or file (the page that documents order.appData), then
update the TODO to that MDX/URL (use a relative docs path or absolute docs URL
consistent with other links in docs/cow-protocol/integrate/wrappers.mdx) so the
link points directly to the appData section.
- Line 320: Replace the misspelled word "simpulate" with "simulate" in the
sentence that reads "Account for wrapper gas overhead in your bids. The easiest
way to do this is to simpulate the wrapper transaction against an empty
settlement." so it reads "...simulate the wrapper transaction against an empty
settlement."; locate that exact sentence to make the single-word correction.
- Line 164: Update the incorrect documentation link: change the path string in
the sentence referencing GPv2AllowlistAuthenticator from
../references/contracts/core/allowlist.md to
../reference/contracts/core/allowlist.md so the link points to the existing
reference directory and continues to mention GPv2AllowlistAuthenticator for
context.
- Line 343: Update the broken link in docs/cow-protocol/integrate/wrappers.mdx
by changing the reference from "../reference/contracts/periphery/wrapper.md" to
"../reference/contracts/periphery/wrapper.mdx" so it points to the actual
wrapper.mdx file; locate the link text "**[Contracts
Reference](../reference/contracts/periphery/wrapper.md)**" and replace the .md
extension with .mdx.
- Line 8: The navigation link in docs/cow-protocol/integrate/wrappers.mdx has
mismatched bold markers around the link text ("Executing Wrappers as a Solver"
with anchor "#for-solvers") causing formatting issues; fix it by making the bold
markers balanced — either wrap the entire link and trailing description in
**...** or remove the leading ** so the link uses normal markdown; update the
line containing the "[Executing Wrappers as a Solver](`#for-solvers`) - Everything
solvers need to know to execute wrapper orders" text to have correct opening and
closing bold markers.
- Around line 254-257: The docs use two different names for the same
value—chainedWrapperData vs wrapperData—causing confusion in the call to
wrapperContract.interface.encodeFunctionData("wrappedSettle"); make the names
consistent by either (A) changing the second parameter in the encodeFunctionData
call from chainedWrapperData to wrapperData, or (B) updating the earlier
function that returns wrapperData to return/mention chainedWrapperData instead;
ensure the comment "From step 3" and the variable name used in wrappedSettle's
argument list (wrapperData/chainedWrapperData) match exactly.

In `@docs/cow-protocol/reference/contracts/periphery/wrapper.mdx`:
- Line 477: Replace the misspelled word "reccomended" with "recommended" in the
sentence that reads "It is reccomended to use
[Cannon](https://usecannon.com/learn) to make it easy to redeploy your
wrappers." (search for the exact string "reccomended" in the wrapper.mdx content
to locate the spot).
- Line 283: Fix the spelling mistake in the documentation: change "reccomended"
to "recommended" in the sentence mentioning ICowWrapper and CowWrapper so it
reads "It is strongly recommended to **NOT** implement `ICowWrapper` directly.
The `CowWrapper` abstract contract provides:". Update the phrase near the
references to ICowWrapper and CowWrapper accordingly.
- Around line 129-134: Fix the malformed Markdown code block under the
"Example:" section by converting the loose fenced text into a proper fenced code
block: ensure the "Example:" label is followed by a fenced block using ```text,
include the two lines "[0x0005][0xAABBCCDDEE][0x1234...ABCD][0x0003][0x112233]"
and "↑len    ↑data         ↑next wrapper  ↑len   ↑data" exactly as shown, and
close the block with ``` so the snippet displays correctly in the docs reference
for wrapper.mdx.
🧹 Nitpick comments (1)
docs/cow-protocol/reference/contracts/periphery/wrapper.mdx (1)

43-43: Clarify incomplete phrase.

"allowing CoW orders" appears incomplete. Perhaps it should be "allowing multiple CoW orders to use different wrappers in the same batch" or similar?

📝 Suggested clarification
-3. **Nested Support**: Multiple wrappers chain by encoding addresses sequentially, allowing CoW orders
+3. **Nested Support**: Multiple wrappers chain by encoding addresses sequentially, allowing multiple orders with different wrappers in the same settlement batch


### 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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.
🧰 Tools
🪛 LanguageTool

[grammar] ~17-~17: Ensure spelling is correct
Context: ...s such as cross-chain operations can be guarenteed to be completed. ### Wrapper Nesting ...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

🤖 Prompt for AI Agents
In `@docs/cow-protocol/concepts/order-types/wrappers.md` at line 17, Fix typos and
minor wording in the paragraph: change "guarenteed" to "guaranteed", remove the
extra space before "wrappers" so it reads "audited and wrappers" properly as
"audited wrappers" (or "audited and wrappers" -> remove stray "and" if
intended), change "solver" to plural "solvers", and lowercase "Wrapper
functionality" to "wrapper functionality" for consistency; update the sentence
in the docs content (the paragraph referencing GPv2AllowlistAuthenticator and
settlement contract) accordingly.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Fix all issues with AI agents
In `@docs/cow-protocol/concepts/order-types/wrappers.md`:
- Line 11: In the sentence starting "Wrappers are smart contracts that 'wrap'
the settlement process..." replace "surrounding settlement contract" with
"surrounding the settlement contract" so the phrase reads "executing custom
logic surrounding the settlement contract" to correct the missing article;
locate the phrase in wrappers.md and update that sentence accordingly.
- Around line 52-54: Replace the inconsistent "Cross chain transfers (pre- or
post- transfer)" phrase with a hyphenated form: "Cross-chain transfers (pre- or
post-transfer)" so it matches the existing "cross-chain" usage and also
hyphenates "post-transfer"; update the exact line containing the phrase "Cross
chain transfers" in the document.

In `@docs/cow-protocol/integrate/wrappers.mdx`:
- Around line 12-16: Multiple subsection headings (e.g., "Overview", "Adding
Wrappers to Orders", "Detecting Wrapper Orders" and other similar entries) are
incorrectly using "##" and therefore sit at the same level as the three main
audience headings ("For Wrapper Developers", "For Order Creators…", "For
Solvers"); change these subsection headings from "##" to "###" so they become
children of their respective audience sections (update every occurrence
referenced in the comment such as the "Overview", "Adding Wrappers to Orders",
"Detecting Wrapper Orders" headings and the other instances mentioned) to
restore proper heading hierarchy and TOC nesting.
- Around line 217-237: The encodeWrapperData function assumes wrapper.data
always exists and uses wrapper.data.length and slice, which breaks when
WrapperCall.data is optional; update encodeWrapperData to normalize data per
wrapper (e.g., const data = wrapper.data ?? '0x'; if (data === '') data = '0x'),
compute dataLength safely as Math.max(0, (data.length - 2) / 2), generate
lengthHex from that number, and only append data.slice(2) when dataLength > 0;
apply these changes in the encodeWrapperData function so it handles undefined or
empty wrapper.data without throwing.
🧹 Nitpick comments (1)
docs/cow-protocol/integrate/wrappers.mdx (1)

298-314: Wrapper accumulation example blindly collects duplicates.

The conceptual example pushes all wrappers from all orders without deduplication. If two orders reference the same wrapper, it would appear twice. Consider adding a comment or dedup logic to clarify expected behavior for readers.


## 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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.
Wrappers are smart contracts that "wrap" the settlement process, executing custom logic surrounding the 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.
🤖 Prompt for AI Agents
In `@docs/cow-protocol/concepts/order-types/wrappers.md` at line 11, In the
sentence starting "Wrappers are smart contracts that 'wrap' the settlement
process..." replace "surrounding settlement contract" with "surrounding the
settlement contract" so the phrase reads "executing custom logic surrounding the
settlement contract" to correct the missing article; locate the phrase in
wrappers.md and update that sentence accordingly.

Comment on lines +217 to +237
function encodeWrapperData(wrappers: WrapperCall[]): string {
let wrapperData = '0x';

for (const [index, wrapper] of wrappers.entries()) {
// Skip first wrapper's address (it's the transaction target)
if (index !== 0) {
// Add wrapper address (20 bytes, without 0x prefix)
wrapperData += wrapper.target.slice(2);
}

// Encode data length as u16 big-endian (2 bytes)
const dataLength = (wrapper.data.length - 2) / 2; // Remove '0x' and convert to byte length
const lengthHex = dataLength.toString(16).padStart(4, '0');
wrapperData += lengthHex;

// Add wrapper data (without 0x prefix)
wrapperData += wrapper.data.slice(2);
}

return wrapperData;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Encoding function doesn't handle optional/empty data field.

The WrapperCall interface (line 43) declares data as optional (data?: string), but this encoding function unconditionally accesses wrapper.data.length and wrapper.data.slice(2). If data is undefined or an empty string, this will throw at runtime.

Proposed fix
 function encodeWrapperData(wrappers: WrapperCall[]): string {
     let wrapperData = '0x';
 
     for (const [index, wrapper] of wrappers.entries()) {
         // Skip first wrapper's address (it's the transaction target)
         if (index !== 0) {
             // Add wrapper address (20 bytes, without 0x prefix)
             wrapperData += wrapper.target.slice(2);
         }
 
+        const rawData = wrapper.data ?? '0x';
         // Encode data length as u16 big-endian (2 bytes)
-        const dataLength = (wrapper.data.length - 2) / 2; // Remove '0x' and convert to byte length
+        const dataLength = (rawData.length - 2) / 2; // Remove '0x' and convert to byte length
         const lengthHex = dataLength.toString(16).padStart(4, '0');
         wrapperData += lengthHex;
 
         // Add wrapper data (without 0x prefix)
-        wrapperData += wrapper.data.slice(2);
+        wrapperData += rawData.slice(2);
     }
 
     return wrapperData;
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function encodeWrapperData(wrappers: WrapperCall[]): string {
let wrapperData = '0x';
for (const [index, wrapper] of wrappers.entries()) {
// Skip first wrapper's address (it's the transaction target)
if (index !== 0) {
// Add wrapper address (20 bytes, without 0x prefix)
wrapperData += wrapper.target.slice(2);
}
// Encode data length as u16 big-endian (2 bytes)
const dataLength = (wrapper.data.length - 2) / 2; // Remove '0x' and convert to byte length
const lengthHex = dataLength.toString(16).padStart(4, '0');
wrapperData += lengthHex;
// Add wrapper data (without 0x prefix)
wrapperData += wrapper.data.slice(2);
}
return wrapperData;
}
function encodeWrapperData(wrappers: WrapperCall[]): string {
let wrapperData = '0x';
for (const [index, wrapper] of wrappers.entries()) {
// Skip first wrapper's address (it's the transaction target)
if (index !== 0) {
// Add wrapper address (20 bytes, without 0x prefix)
wrapperData += wrapper.target.slice(2);
}
const rawData = wrapper.data ?? '0x';
// Encode data length as u16 big-endian (2 bytes)
const dataLength = (rawData.length - 2) / 2; // Remove '0x' and convert to byte length
const lengthHex = dataLength.toString(16).padStart(4, '0');
wrapperData += lengthHex;
// Add wrapper data (without 0x prefix)
wrapperData += rawData.slice(2);
}
return wrapperData;
}
🤖 Prompt for AI Agents
In `@docs/cow-protocol/integrate/wrappers.mdx` around lines 217 - 237, The
encodeWrapperData function assumes wrapper.data always exists and uses
wrapper.data.length and slice, which breaks when WrapperCall.data is optional;
update encodeWrapperData to normalize data per wrapper (e.g., const data =
wrapper.data ?? '0x'; if (data === '') data = '0x'), compute dataLength safely
as Math.max(0, (data.length - 2) / 2), generate lengthHex from that number, and
only append data.slice(2) when dataLength > 0; apply these changes in the
encodeWrapperData function so it handles undefined or empty wrapper.data without
throwing.


## Detecting Wrapper Orders

Wrappers are specified in the order's [`appData`](../reference/core/auctions/schema.md) under the `wrappers` field:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

order's ---> orders

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the grammar is it is now is correct here. The appData is "possessed" by the order.

Copy link
Contributor

@pretf00d pretf00d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left comments

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/cow-protocol/integrate/wrappers.mdx`:
- Line 101: Update the plural possessive in the sentence following the wrapper
sequence description: replace "other user's orders" with "other users' orders"
in the line that reads "The wrappers execute in sequence: Wrapper1 → Wrapper2 →
Settlement → Wrapper2 (post) → Wrapper1 (post). Note that wrappers from other
user's orders may be interspersed, though this should generally not affect the
execution of the order." Leave the rest of the sentence and punctuation
unchanged.

In `@docs/cow-protocol/reference/contracts/periphery/wrapper.mdx`:
- Around line 465-473: Docs reference the wrong function name: update all
occurrences of parseWrapperData in this document and examples to the actual
interface/contract method validateWrapperData to match ICowWrapper and
CowWrapper; search for "parseWrapperData" (example blocks at the current
examples) and replace with "validateWrapperData", ensuring the signature text
and examples use the exact method name validateWrapperData so implementations
compile against the ICowWrapper interface.
- Around line 265-301: The examples use the wrong function signatures; update
every example wrapper (e.g., MyWrapper, EmptyWrapper, FlashLoanWrapper and the
`_wrap` sections) to match the CowWrapper contract: implement `_wrap(bytes
calldata settleData, bytes calldata wrapperData, bytes calldata
remainingWrapperData)` and call `_next(bytes calldata settleData, bytes calldata
remainingWrapperData)` when forwarding, ensuring you pass through the incoming
settleData and remainingWrapperData arguments; keep `parseWrapperData` as-is but
verify any references to wrapperData vs remainingWrapperData are consistent with
these three- and two-argument signatures.
- Around line 309-321: The example for wrappedSettle is inconsistent with the
actual contract: update the snippet to match the real implementation by (1)
using AUTHENTICATOR.isSolver(msg.sender) instead of
GPv2Authentication(SETTLEMENT).isSolver(...), (2) replacing the generic string
revert with the custom error NotASolver(msg.sender), (3) calling _wrap with the
correct parameters (pass settleData and the other expected args rather than
wrapperData), and (4) including the length-prefix parsing logic that extracts
the chained wrapper payloads from settleData; alternatively remove this
redundant snippet and add a cross-reference to the authoritative wrappedSettle
implementation shown earlier.
- Line 399: Doc text incorrectly states "last 20 bytes" for extracting the next
target address; update the sentence to say "first 20 bytes" to match the _next()
implementation that reads remainingWrapperData[:20]; locate the mention in
wrapper.mdx and replace "last 20 bytes" with "first 20 bytes" (or equivalent
phrasing) so documentation matches the _next() behavior.
- Line 462: Remove the non-functional external gist script embed "<script
src=\"https://gist.github.com/kaze-cow/8c8a49f3305519948b1ec868c7efa5b9.js\"></script>"
from wrapper.mdx and either paste the helper contract code directly into the MDX
as a fenced code block (e.g., a Solidity or JavaScript code block) or replace it
with a standard link and short explanation; locate the string
"https://gist.github.com/kaze-cow/8c8a49f3305519948b1ec868c7efa5b9.js" in the
file and remove or replace that tag accordingly.
- Around line 409-414: The encoding diagram wrongly includes a trailing
"Settlement (20 B)" inside wrapperData; update the diagram so wrapperData only
contains the concatenation of wrapper entries (wrap1, Addr2, wrap2, etc.)
without a final settlement address, and show settleData (the initial settle
calldata) separately pointing to the settlement target derived from the
SETTLEMENT immutable; align the visual layout with the contract NatSpec and the
_next() function behavior (which omits appending the settlement address) by
removing the final Settlement field and ensuring labels reference wrapperData
and settleData consistently.

---

Duplicate comments:
In `@docs/cow-protocol/concepts/order-types/wrappers.md`:
- Line 45: Update the phrase "Cross chain transfers (pre- or post- transfer)" to
use consistent hyphenation by changing it to "Cross-chain transfers (pre- or
post-transfer)"; locate the exact text "Cross chain transfers (pre- or post-
transfer)" in wrappers.md and replace accordingly to maintain consistent style
across the document.
- Line 36: Typo in the markdown header "### Progmatic Orders": change the header
text to "### Programmatic Orders" (update the string "Progmatic Orders" to
"Programmatic Orders" in the header line so the section title is spelled
correctly).
- Line 11: Fix the grammar in the sentence inside wrappers.md: change "executing
custom logic surrounding settlement contract" to "executing custom logic
surrounding the settlement contract" (i.e., insert the missing article "the") so
the paragraph reads correctly in the Wrappers description.
- Line 7: Fix the typo and dash style in the sentence starting "Generalized
wrappers is a new framework..." by replacing "progmatic" with "programmatic" and
changing the double hyphen "--" to an em dash "—" so the phrase reads "...like
flash loans, leveraged positions, and programmatic orders— all while
preserving..."; update that exact sentence in wrappers.md to use the corrected
word and the em dash.
- Line 66: Update the phrasing in the sentence that currently reads "high
quality wrapper implementations" to use a compound adjective: change it to
"high-quality wrapper implementations" so the adjective properly modifies the
noun; locate the sentence starting "Wrappers cannot be deployed and used
immediately—they must be approved..." and replace only the "high quality" token
with "high-quality".

In `@docs/cow-protocol/integrate/wrappers.mdx`:
- Around line 254-257: The snippet calling
wrapperContract.interface.encodeFunctionData("wrappedSettle", [settleData,
chainedWrapperData]) uses a different variable name than Step 3, which returns
wrapperData; change the second argument to wrapperData (or consistently rename
Step 3's output to chainedWrapperData) so the variable name matches across steps
and avoids confusion when locating the wrappedSettle call in
wrapperContract.interface.encodeFunctionData.
- Line 16: Multiple subsection headings (e.g., "Overview", "Adding Wrappers to
Orders", "Detecting Wrapper Orders", and others listed) are using the same level
'##' as the top-level audience sections which flattens the TOC; change those
subsection headings from '##' to '###' so they are nested under their respective
audience '##' sections (search for the literal headings "Overview", "Adding
Wrappers to Orders", "Detecting Wrapper Orders", etc., and replace their leading
'##' with '###'), and verify all occurrences mentioned (lines referenced in the
review) are updated consistently.
- Around line 217-237: The encodeWrapperData function reads wrapper.data without
handling it being optional; update encodeWrapperData so it treats missing or
empty wrapper.data as '0x' (zero-length) before using .length or .slice, compute
dataLength as 0 in that case, and append no payload bytes but still write the
2-byte length (0x0000) when needed; specifically guard uses of
wrapper.data.length and wrapper.data.slice(2) (refer to WrapperCall.data and
encodeWrapperData) by normalizing wrapper.data to a safe string or branching on
its presence.
- Line 320: Fix the typo in the docs sentence that currently reads "The easiest
way to do this is to simpulate the wrapper transaction against an empty
settlement." — change "simpulate" to "simulate" so the sentence reads "The
easiest way to do this is to simulate the wrapper transaction against an empty
settlement." Update this in the integrate/wrappers.mdx content where that
sentence appears.

In `@docs/cow-protocol/reference/contracts/periphery/wrapper.mdx`:
- Around line 336-341: The markdown block under the "Example:" line uses
mismatched/nested triple backticks causing render issues; fix by replacing the
bare opening ``` after "Example:" and the mismatched closing fences with a
single properly fenced code block that encloses the example line (the bracketed
hex sample like [0x0005][0xAABBCCDDEE][0x1234...ABCD][0x0003][0x112233]) so the
entire snippet is within one pair of triple backticks and renders correctly.
- Line 684: Fix the typo in the sentence starting "When settlement contract
upgrades, all wrappers must be redeployed." — change "reccomended" to
"recommended" in that line so it reads: "It is recommended to use
[Cannon](https://usecannon.com/learn) to make it easy to redeploy your
wrappers." Ensure only the single word is corrected and punctuation remains
unchanged.
- Line 490: Fix the spelling typo in the documentation: change "reccomended" to
"recommended" in the sentence referencing ICowWrapper and CowWrapper (the line
that reads "It is strongly reccomended to **NOT** implement `ICowWrapper`
directly. The `CowWrapper` abstract contract provides:"). Ensure the corrected
word appears wherever this misspelling occurs in the docs covering
ICowWrapper/CowWrapper.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
docs/cow-protocol/integrate/wrappers.mdx (1)

298-314: Conceptual example blindly pushes duplicate wrappers.

If multiple orders reference the same wrapper contract, this code will accumulate duplicates. Worth adding a note or dedup logic so solvers don't encode the same wrapper multiple times.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/cow-protocol/integrate/wrappers.mdx` around lines 298 - 314, The example
collects wrappers into solution.wrappers by pushing order.appData.wrappers
directly, which can produce duplicates; before calling
encodeWrapperSettlement(solution) deduplicate wrappers (e.g., track seen wrapper
identifiers/addresses while iterating or replace solution.wrappers with a unique
list) so each wrapper contract is encoded only once; ensure you use the
wrapper's unique key (address or id) when deduping and preserve required
ordering if order matters.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/cow-protocol/concepts/order-types/wrappers.md`:
- Around line 68-70: The heading "Execution Not Enforced by the on-chain
Protocol" should be renamed for consistent title casing and clarity (e.g.,
"On-Chain Protocol Does Not Enforce Execution"); update the heading text
accordingly and replace the ambiguous phrase "a solver could still not execute a
wrapper with an order" with a clearer wording such as "a solver may choose not
to execute a wrapper with an order" to reflect intent; ensure you update the
heading and sentence in the "Execution Not Enforced by the on-chain Protocol"
block (search for that exact heading and the sentence) so casing and meaning
match other headings like "Requires Protocol Approval."

In `@docs/cow-protocol/integrate/wrappers.mdx`:
- Around line 166-168: Summary: The phrase "CoW Protocol provided driver" is
missing a hyphen in the compound adjective; change it to "CoW Protocol-provided
driver". Locate the sentence in the "### 3. Include Wrappers in the Solution"
section of docs/cow-protocol/integrate/wrappers.mdx and update the phrase "CoW
Protocol provided driver" to "CoW Protocol-provided driver" so the compound
modifier is correctly hyphenated.

---

Duplicate comments:
In `@docs/cow-protocol/concepts/order-types/wrappers.md`:
- Line 11: Update the sentence that reads "Wrappers are smart contracts that
"wrap" the settlement process, executing custom logic surrounding settlement
contract." to include the missing article so it reads "...executing custom logic
surrounding the settlement contract." Locate the sentence beginning with
"Wrappers are smart contracts..." in the Wrappers documentation and replace
"surrounding settlement contract" with "surrounding the settlement contract" to
correct the grammar.
- Around line 44-46: The list item has inconsistent hyphenation: locate the
phrases "Cross chain" and "post- transfer" in the wrappers.md content and change
them to "Cross-chain" and "post-transfer" respectively (ensure no extra spaces
around the hyphen), updating the markdown list entry so the phrasing reads
"Cross-chain transfers (pre- or post-transfer)" for consistency.

In `@docs/cow-protocol/integrate/wrappers.mdx`:
- Line 16: Subsections under the three audience sections are using the same
heading level (##) which flattens the TOC; update each affected subsection
heading (Overview, Adding Wrappers to Orders, Detecting Wrapper Orders, Solver
Requirements, Encoding Wrapper Settlements, Accumulating Wrappers in Solutions,
Testing and Validation, Common Issues) to the next-level heading (###) so they
become children of the audience sections; locate those headings in
docs/cow-protocol/integrate/wrappers.mdx (search for the exact subsection
titles) and replace the leading "##" with "###" for each listed heading.
- Line 101: The sentence uses the singular possessive "other user's orders" but
should be plural possessive; update the phrase to "other users' orders" in the
wrappers description (the line containing "The wrappers execute in sequence:
Wrapper1 → Wrapper2 → Settlement → Wrapper2 (post) → Wrapper1 (post). Note that
wrappers from other user's orders may be interspersed...") to correct the plural
possessive form.
- Around line 217-237: encodeWrapperData assumes WrapperCall.data is always
present; update it to handle optional/empty data (WrapperCall.data?: string) by
treating absent or "0x" as zero-length payload: compute dataLength as
wrapper.data ? (wrapper.data.length - 2) / 2 : 0, produce the 2-byte big-endian
length accordingly, and only append wrapper.data.slice(2) when dataLength > 0;
keep existing address-handling logic and unchanged output format.

---

Nitpick comments:
In `@docs/cow-protocol/integrate/wrappers.mdx`:
- Around line 298-314: The example collects wrappers into solution.wrappers by
pushing order.appData.wrappers directly, which can produce duplicates; before
calling encodeWrapperSettlement(solution) deduplicate wrappers (e.g., track seen
wrapper identifiers/addresses while iterating or replace solution.wrappers with
a unique list) so each wrapper contract is encoded only once; ensure you use the
wrapper's unique key (address or id) when deduping and preserve required
ordering if order matters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants