Skip to content

fix: match permit deadline to order validTo for CoW limit orders#2888

Open
mgrabina wants to merge 1 commit intomainfrom
fix/permit-deadline-match-order-validity
Open

fix: match permit deadline to order validTo for CoW limit orders#2888
mgrabina wants to merge 1 commit intomainfrom
fix/permit-deadline-match-order-validity

Conversation

@mgrabina
Copy link
Contributor

Summary

  • The ERC20 permit deadline in useSwapTokenApproval was hardcoded to 1 hour (Date.now() + 3600), while CoW Protocol order validTo can be set up to 1 year by the user
  • When a user creates a limit order with a long expiry (e.g. "One day", "One week", "One year"), the permit baked into the post-hook calldata expires after 1 hour, making the order permanently unfillable — solvers simulate the settlement, the permit() call reverts, and they skip the order
  • This fix passes the order's validTo timestamp as the permit deadline, ensuring the permit stays valid for the order's entire lifetime

Root cause (traced from a real stuck order)

Order: 0xcaa1f0...
Simulation: Tenderly

  1. Collateral swap order (WBTC→USDT on Arbitrum) created Feb 7 with validTo = Feb 2027
  2. Permit deadline = Feb 7 + 1 hour ≈ Feb 7 15:43 UTC
  3. Solvers attempt settlement on Feb 27 → post-hook calls aWBTC.permit()reverts (deadline passed)
  4. Without the permit, adapter can't withdraw aWBTC → can't repay flash loan → "ERC20: transfer amount exceeds balance"
  5. Order sits open with 0 fills forever

Changes

  • Added optional validTo param to SwapTokenApprovalParams
  • When validTo is provided, it's used as the permit deadline instead of the 1-hour default
  • All 4 CoW action components now pass validTo to the approval hook
  • Paraswap components are unaffected (no validTo, param is optional, falls back to 1 hour)

Test plan

  • Create a collateral swap limit order with "One day" expiry — verify the permit deadline in the signed data matches the order's validTo
  • Create a plain swap limit order with "One week" expiry — same verification
  • Create a debt swap limit order — verify permit deadline matches
  • Create a repay-with-collateral limit order — verify permit deadline matches
  • Paraswap swaps still work normally (no regression)
  • Verify an order created with this fix can be filled by solvers after >1 hour

🤖 Generated with Claude Code

The permit deadline was hardcoded to 1 hour while CoW order validTo can
be up to 1 year. This caused orders with long expiries to become
permanently unfillable once the permit expired, since the post-hook's
permit() call would revert and solvers would skip the order.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Feb 27, 2026

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

Project Deployment Actions Updated (UTC)
interface Building Building Preview, Comment Feb 27, 2026 6:26pm

Request Review

@github-actions
Copy link

@github-actions
Copy link

📦 Next.js Bundle Analysis for aave-ui

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

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