Skip to content

fix(twap): approve prod vault relayer regardless of environment#7695

Merged
kernelwhisperer merged 7 commits into
cowprotocol:developfrom
tenderdeve:fix/7690-twap-allowance-prod-relayer
Jul 6, 2026
Merged

fix(twap): approve prod vault relayer regardless of environment#7695
kernelwhisperer merged 7 commits into
cowprotocol:developfrom
tenderdeve:fix/7690-twap-allowance-prod-relayer

Conversation

@tenderdeve

@tenderdeve tenderdeve commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #7690.

TWAP orders are always settled against the production CoW Protocol settlement contract, regardless of which environment (prod / barn) the frontend is configured against. The TWAP spender override, however, was using the environment-aware COW_PROTOCOL_VAULT_RELAYER_ADDRESS from @cowprotocol/common-utils, which resolves to the staging vault relayer when running on the barn backend env.

As a result, on the barn-deployed app, allowances granted from the TWAP page targeted the staging vault relayer, while the TWAP order itself was created against the production ComposableCoW / settlement — leaving the order unfillable due to insufficient allowance against the production relayer.

Fix

  • Add a prod-only re-export COW_PROTOCOL_VAULT_RELAYER_ADDRESS_PROD in @cowprotocol/common-utils for the explicit "always-prod" case.
  • Switch the TWAP spender override (apps/cowswap-frontend/src/modules/twap/updaters/index.tsx) to use this prod-only constant, so TWAP allowances always target the production relayer regardless of the current environment. This also matches the existing intent already documented in the inline comment above the spender computation.

No other consumers of the environment-aware constant are touched — only the TWAP flow is bound to the production settlement contract.

Test plan

  • Build the dev (barn) app
  • Connect to a Safe wallet via WC (or open inside Safe)
  • Pick a not-approved token to sell on the TWAP page
  • Verify the approve tx targets the production vault relayer (not the staging one)
  • Verify the TWAP order can be filled
  • Regression: on the prod app, behavior is unchanged (prod relayer in both cases)

Summary by CodeRabbit

  • Bug Fixes
    • Improved TWAP order approval setup to consistently use the production vault relayer addresses, avoiding mismatches across environments.
    • Added and reused dedicated production vault relayer address constants so the trade spender override is derived correctly when chain information is available.

TWAP orders are always settled against the production CoW Protocol
settlement contract, but the spender override was using the
environment-aware COW_PROTOCOL_VAULT_RELAYER_ADDRESS from
@cowprotocol/common-utils, which resolves to the staging vault
relayer on the barn backend env. As a result, allowances granted on
the barn-deployed app targeted the staging relayer and TWAP orders
were unfillable on Safe due to insufficient allowance against the
prod relayer.

Add a prod-only re-export, COW_PROTOCOL_VAULT_RELAYER_ADDRESS_PROD,
in @cowprotocol/common-utils and use it for the TWAP spender
override, so TWAP allowances always target the production relayer
regardless of the current environment.

Closes cowprotocol#7690
@vercel

vercel Bot commented Jun 22, 2026

Copy link
Copy Markdown

@tenderdeve is attempting to deploy a commit to the cow-dev Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3bcfa714-442c-41a3-a337-397a9ffb6f0f

📥 Commits

Reviewing files that changed from the base of the PR and between 57fc1a4 and 9d3af6f.

📒 Files selected for processing (1)
  • libs/common-utils/src/cowProtocolContracts.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • libs/common-utils/src/cowProtocolContracts.ts

Walkthrough

Adds a production-only vault relayer constant in common utils and switches TWAP allowance wiring to use it for spenderAddress.

Changes

TWAP prod vault relayer address fix

Layer / File(s) Summary
Define the prod relayer constant
libs/common-utils/src/cowProtocolContracts.ts
Aliases the cow-sdk prod vault relayer import, exports COW_PROTOCOL_VAULT_RELAYER_ADDRESS_PROD, and routes the non-barn branch of COW_PROTOCOL_VAULT_RELAYER_ADDRESS through that production value.
Use the prod relayer in TWAP
apps/cowswap-frontend/src/modules/twap/updaters/index.tsx
Updates the TWAP updater import and spenderAddress derivation to read from COW_PROTOCOL_VAULT_RELAYER_ADDRESS_PROD.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Possibly related PRs

  • cowprotocol/cowswap#7557: Also changes how COW_PROTOCOL_VAULT_RELAYER_ADDRESS is sourced and exposed for frontend use.

Suggested reviewers

  • limitofzero
  • kernelwhisperer
  • elena-zh

Poem

🐰 Hop to prod, the key is set,
No barn-bound address to forget.
TWAP gets its allowance bright,
And fills its orders just right.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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
Title check ✅ Passed The title clearly summarizes the main change: TWAP approvals now target the production vault relayer regardless of environment.
Description check ✅ Passed The description includes a summary, fix details, and a test plan, which covers the repository's required sections well enough.
Linked Issues check ✅ Passed The changes directly address #7690 by making TWAP allowances target the production settlement contract in barn and prod.
Out of Scope Changes check ✅ Passed The PR stays focused on the TWAP approval path and the shared relayer constant, with no clear unrelated code changes.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

// Use this when allowances must always target the production relayer
// regardless of the current environment (e.g. TWAP, which is always
// settled against the production settlement contract).
export const COW_PROTOCOL_VAULT_RELAYER_ADDRESS_PROD: AddressPerChain =

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.

Nitpick: we have 2 names for the same variable, let's keep using COW_PROTOCOL_VAULT_RELAYER_ADDRESS_PROD, get rid of COW_PROTOCOL_VAULT_RELAYER_ADDRESS_PROD_SDK. Did you do this because of the type casting to AddressPerChain?

Addresses @kernelwhisperer's feedback on cowprotocol#7695 — rename the SDK import
alias to an internal underscore-prefixed name so COW_PROTOCOL_VAULT_RELAYER_ADDRESS_PROD
is the only PROD-named export. The cast to AddressPerChain is still needed
because the SDK's type differs from AddressPerChain.
@tenderdeve

Copy link
Copy Markdown
Contributor Author

@kernelwhisperer updated in e81f214 — renamed the SDK import alias to _COW_PROTOCOL_VAULT_RELAYER_ADDRESS_PROD (internal underscore-prefixed) so COW_PROTOCOL_VAULT_RELAYER_ADDRESS_PROD is the only PROD-named export. The as AddressPerChain cast is still needed because the SDK's type differs from AddressPerChain (same pattern as the settlement contract just above).

@elena-zh elena-zh added the trigger-preview Add to a fork PR to trigger CF-pages preview. See https://github.com/cowprotocol/cowswap/pull/7615 label Jun 23, 2026
@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Cloudflare Pages preview mirror

Preview branch URL: https://github.com/cowprotocol/cowswap/tree/cf-preview/pr-7695
Mirror PR: #7704
Cloudflare Pages preview links will be posted on the mirror PR by the Cloudflare Pages GitHub integration once builds complete.

Source fork branch: tenderdeve/cowswap:fix/7690-twap-allowance-prod-relayer
Approval target SHA: 241f605b1dce
Last mirrored SHA: e81f2148821c
Last comment update: @kernelwhisperer at 2026-07-06T10:19:55.477Z

  • Sync Cloudflare preview to approval target commit

@elena-zh elena-zh 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.

LGTM, thanks

Drop the duplicate prod relayer identifier. Define
COW_PROTOCOL_VAULT_RELAYER_ADDRESS_PROD once (the AddressPerChain cast
target) and reuse it for the env-aware export, so the SDK import is now
plain raw plumbing referenced a single time.

Addresses @kernelwhisperer's review feedback.
@tenderdeve

Copy link
Copy Markdown
Contributor Author

@kernelwhisperer good catch — yes, the second identifier only existed to apply the AddressPerChain cast (the SDK types the relayer as Record<SupportedChainId, string>, but the spender consumer expects Address). Consolidated in 9d3af6f: COW_PROTOCOL_VAULT_RELAYER_ADDRESS_PROD is now the single canonical name and the cast target; the env-aware export reuses it, and the SDK import is just raw plumbing referenced once. Typecheck + lint pass.

@elena-zh
elena-zh requested a review from kernelwhisperer June 30, 2026 08:14
@kernelwhisperer
kernelwhisperer enabled auto-merge (squash) July 6, 2026 10:19
@kernelwhisperer

Copy link
Copy Markdown
Contributor

The as AddressPerChain cast is still needed because the SDK's type differs from AddressPerChain (same pattern as the settlement contract just above).

I think it's worth looking into the the sdk type is not AddressPerChain... anyway, approved!

@kernelwhisperer
kernelwhisperer merged commit 41cead4 into cowprotocol:develop Jul 6, 2026
12 of 20 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TWAP: allowances should target the prod settlement contract

3 participants