Skip to content

feat(trading): add signer-less presign calldata - #965

Open
raq0x wants to merge 1 commit into
mainfrom
feat/presign-calldata
Open

feat(trading): add signer-less presign calldata#965
raq0x wants to merge 1 commit into
mainfrom
feat/presign-calldata

Conversation

@raq0x

@raq0x raq0x commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Adds a signerless pre-sign path (the P1 milestone): build the setPreSignature(orderUid, true) calldata for a PRESIGN order without handing a signer to the SDK, so a Safe, multisig, or custody stack can submit the transaction itself.

getPreSignTransaction already covered pre-signing, but it resolves an SDK signer and estimates gas with it — which doesn't fit setups where the SDK never holds a signer and the submitting stack estimates gas in its own execution context.

Fixes FE-439
Project: https://linear.app/cowswap/project/sdk-external-signer-less-order-signing-b006c53af4e0

const { orderId } = await sdk.postSwapOrder(parameters, {
  quoteRequest: { signingScheme: SigningScheme.PRESIGN },
})

// no signer, no RPC call, no gas estimate
const preSignCallData = sdk.getPreSignCallData({ orderUid: orderId })

await yourSafeOrCustodyStack.submitTransaction(preSignCallData)
  • sdk.getPreSignCallData({ orderUid, chainId?, env?, settlementContractOverride? }) — returns { to, data, value }, synchronously. chainId/env fall back to the trader params and order-book context; no signer or appCode needed. Also available standalone as getPreSignCallData(chainId, orderUid, options?), plus a PreSignCallData type.
  • An adapter is still required (ABI encoding is adapter-specific), but it may be signer-less. The transaction must be executed by the owner encoded in the order UID.
  • getPreSignTransaction now builds to/data from the same helper; output unchanged.

Summary by CodeRabbit

  • New Features

    • Added signerless pre-signature calldata generation for externally submitted transactions.
    • Supports custom settlement contracts and staging or production environments.
    • Exposes the new capability through the Trading SDK for Safe, multisig, and custody workflows.
    • Improved settlement contract selection and validation when chain details are unavailable.
  • Documentation

    • Clarified when to use raw calldata versus signer-based pre-sign transactions.
    • Updated swap and limit order examples to use the order ID and smart-contract wallet as owner.
    • Added guidance for externally submitting generated transaction data.

@raq0x
raq0x requested a review from a team August 7, 2026 07:48
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The trading package adds getPreSignCallData for unsigned pre-signature calldata. It centralizes settlement contract resolution, integrates the helper into TradingSdk, preserves signer-based transaction generation, adds signerless adapter tests, and updates smart-contract wallet documentation.

Changes

Signerless pre-signature calldata

Layer / File(s) Summary
Calldata construction and settlement resolution
packages/trading/src/getPreSignCallData.ts, packages/trading/src/getSettlementContract.ts, packages/trading/src/getPreSignTransaction.ts
The package encodes setPreSignature(orderUid, true) with zero value. Settlement address overrides and environment selection use the exported resolver. Signer-based transactions reuse the calldata and retain gas estimation.
TradingSdk signerless API and validation
packages/trading/src/tradingSdk.ts, packages/trading/src/index.ts, packages/trading/tests/setup.ts, packages/trading/src/tradingSdk.test.ts, packages/trading/src/getPreSignCallData.test.ts
TradingSdk.getPreSignCallData resolves chain and settlement settings, validates that a chain ID exists, and returns unsigned calldata. Tests cover signerless adapters, overrides, staging addresses, order-book configuration, and validation errors.
Smart-contract wallet usage documentation
packages/trading/README.md, packages/trading/src/README.md
The documentation distinguishes external calldata submission from signer-based pre-sign transactions. Swap and limit-order examples use orderUid and set the smart-contract wallet as the order owner.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ExternalWalletStack
  participant TradingSdk
  participant getPreSignCallData
  participant SettlementContract
  ExternalWalletStack->>TradingSdk: Request pre-sign calldata
  TradingSdk->>getPreSignCallData: Resolve order and settlement configuration
  getPreSignCallData->>SettlementContract: Encode setPreSignature(orderUid, true)
  SettlementContract-->>TradingSdk: Return unsigned transaction data
  TradingSdk-->>ExternalWalletStack: Submit calldata for execution
Loading

Possibly related PRs

Suggested reviewers: shoom3301, azebuado

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding signer-less pre-sign calldata support to trading.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/presign-calldata

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.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

📦 GitHub Packages Published

Last updated: Aug 7, 2026, 07:51:20 AM UTC

The following packages have been published to GitHub Packages with pre-release version pr-965-b5c07690:

  • @cowprotocol/cow-sdk@9.2.6-pr-965-b5c07690.0
  • @cowprotocol/sdk-app-data@6.0.0-pr-965-b5c07690.0
  • @cowprotocol/sdk-bridging@4.4.2-pr-965-b5c07690.0
  • @cowprotocol/sdk-common@0.12.1-pr-965-b5c07690.0
  • @cowprotocol/sdk-composable@1.3.0-pr-965-b5c07690.0
  • @cowprotocol/sdk-config@2.4.0-pr-965-b5c07690.0
  • @cowprotocol/sdk-contracts-ts@3.3.3-pr-965-b5c07690.0
  • @cowprotocol/sdk-cow-shed@0.4.5-pr-965-b5c07690.0
  • @cowprotocol/sdk-ethers-v5-adapter@0.4.11-pr-965-b5c07690.0
  • @cowprotocol/sdk-ethers-v6-adapter@0.4.11-pr-965-b5c07690.0
  • @cowprotocol/sdk-flash-loans@3.3.3-pr-965-b5c07690.0
  • @cowprotocol/sdk-order-book@4.0.2-pr-965-b5c07690.0
  • @cowprotocol/sdk-order-signing@1.1.6-pr-965-b5c07690.0
  • @cowprotocol/sdk-subgraph@1.2.1-pr-965-b5c07690.0
  • @cowprotocol/sdk-trading@2.2.6-pr-965-b5c07690.0
  • @cowprotocol/sdk-viem-adapter@0.3.26-pr-965-b5c07690.0
  • @cowprotocol/sdk-weiroll@0.2.2-pr-965-b5c07690.0

Installation

These packages require authentication to install from GitHub Packages. First, create a .npmrc file:

# Create .npmrc file in your project root
echo "@cowprotocol:registry=https://npm.pkg.github.com" > .npmrc
echo "//npm.pkg.github.com/:_authToken=YOUR_GITHUB_TOKEN" >> .npmrc

To get your GitHub token:

  1. Go to https://github.com/settings/tokens
  2. Click "Generate new token (classic)"
  3. Check only the "read:packages" scope
  4. Copy the token and replace YOUR_GITHUB_TOKEN in the .npmrc file

Then install any of the packages above, either by exact version (i.e. @cowprotocol/cow-sdk@9.2.6-pr-965-b5c07690.0) or more conveniently by using the tag (@cowprotocol/cow-sdk@pr-965):

# Yarn
yarn add npm:@cowprotocol/cow-sdk@pr-965

# pnpm
pnpm install npm:@cowprotocol/cow-sdk@pr-965

# NPM
npm install npm:@cowprotocol/cow-sdk@pr-965

Update to the latest version (only if you used the tag)

Every commit will publish a new package. To upgrade to the latest version, run:

# Yarn
yarn upgrade @cowprotocol/cow-sdk

# pnpm
pnpm update @cowprotocol/cow-sdk

# NPM
npm update @cowprotocol/cow-sdk

View Packages

You can view the published packages at: https://github.com/cowprotocol/cow-sdk/packages

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/trading/src/README.md`:
- Around line 379-390: Update the “Build pre-sign calldata without a signer”
example to configure the required global adapter before calling
TradingSdk.getPreSignCallData, or explicitly state that callers must configure
one first; preserve the signerless behavior and submission flow.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b08110c4-5d9b-4110-99ef-db59659467a0

📥 Commits

Reviewing files that changed from the base of the PR and between 8a756e8 and b5c0769.

📒 Files selected for processing (10)
  • packages/trading/README.md
  • packages/trading/src/README.md
  • packages/trading/src/getPreSignCallData.test.ts
  • packages/trading/src/getPreSignCallData.ts
  • packages/trading/src/getPreSignTransaction.ts
  • packages/trading/src/getSettlementContract.ts
  • packages/trading/src/index.ts
  • packages/trading/src/tradingSdk.test.ts
  • packages/trading/src/tradingSdk.ts
  • packages/trading/tests/setup.ts

Comment on lines +379 to +390
#### Build pre-sign calldata without a signer

For a Safe, multisig, or custody flow, request the raw transaction data and submit it through your own stack:

```typescript
const preSignCallData = sdk.getPreSignCallData({ orderUid: orderId })

// Returns { to, data, value } and does not estimate gas.
await yourMultisigOrCustodyStack.submitTransaction(preSignCallData)
```

The helper does not access a signer or make an RPC call. The final transaction must be executed by the order owner encoded in the order UID—for a Safe-owned order, the Safe itself must call the settlement contract.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Configure an adapter in this signerless flow.

getPreSignCallData still calls getGlobalAdapter() for ABI encoding. The shown TradingSdk setup does not configure an adapter. Add signerless adapter setup to the example, or state that callers must configure a global adapter before this call.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/trading/src/README.md` around lines 379 - 390, Update the “Build
pre-sign calldata without a signer” example to configure the required global
adapter before calling TradingSdk.getPreSignCallData, or explicitly state that
callers must configure one first; preserve the signerless behavior and
submission flow.

@linear-code

linear-code Bot commented Aug 7, 2026

Copy link
Copy Markdown

FE-439

@azebuado
azebuado requested review from azebuado and shoom3301 August 10, 2026 15:20

@azebuado azebuado left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good!

Only one question: would it make sense to update also the examples as you did in the previous PR, to show how to use it with various providers like viem and ethers?

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