Skip to content

fix: refresh expired swap quotes before signing - #260

Open
0xApotheosis wants to merge 1 commit into
mainfrom
fix/swap-quote-expiry
Open

fix: refresh expired swap quotes before signing#260
0xApotheosis wants to merge 1 commit into
mainfrom
fix/swap-quote-expiry

Conversation

@0xApotheosis

@0xApotheosis 0xApotheosis commented Sep 8, 2026

Copy link
Copy Markdown
Member

Description

Refreshes swap quotes after network switching and after any token approval confirms, instead of submitting the original calldata after a delay. Refreshed amounts, provider, spender and network fees are shown in the card; changed terms require acceptance before continuing. Allowance is checked against each refreshed spender.

Bebop quotes retain their expiry. Relay uses a conservative 60-second window from request start. Missing, expired and nearly expired quotes cannot reach the wallet request. Refreshes preserve the exact assets, sell amount and accounts, including swaps originally specified in USD.

Verification

Use the local frontend and backend with working provider keys and an EVM wallet. Request swap 100 USDC on Base for FOX on Ethereum with sufficient USDC and gas.

  1. Delay the network switch for over a minute. After switching, check that /api/swap/refresh supplies a new transaction and deadline. The card must show the refreshed quote.
  2. For deterministic review checks, override a local /api/swap/refresh response to change swapData.buyAmountCryptoPrecision. The card must wait for Accept updated quote; Cancel swap must stop execution. Do not sign transactions from modified responses.
  3. Leave the review open past expiresAt, then accept. Expect another refresh before any wallet request. Override the refresh response to HTTP 502: expect an error, with no fallback to the old transaction.
  4. With an ERC-20 requiring approval, confirm the approval and inspect the next refresh. If the spender changes, allowance must be checked for the new spender. This check requires signing the approval transaction; reject the final swap request if you only want to test preparation.
  5. Disconnect or change the wallet while reviewing a quote. Continuing must stop with a wallet-change error.

Confirmed: a live unsigned Relay quote for Base USDC → Ethereum FOX returned a valid deadline with ~59 seconds remaining. Deterministic execution tests cover approval refresh, spender changes, acceptance after expiry, cancellation, provider failures, changed swap identity and wallet changes. Wallet UI checks above have not been exercised; browser access was unavailable.

Deployment / limitation

This PR contains both backend and frontend changes; no separate PR is required. The new frontend calls /api/swap/refresh, so the backend should be live before the frontend is promoted. If the frontend deploys first, swap preparation temporarily fails at quote refresh until the backend deploy completes; it never falls back to the old transaction.

The final guard runs immediately before wallet signing with a 10-second buffer. An EVM wallet can still hold its own signing dialog open past the deadline; the app cannot revoke a request already handed to it.

@vercel

vercel Bot commented Sep 8, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
shapeshift-agentic Ready Ready Preview Sep 8, 2026 3:13am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 43 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 7086934c-204c-4dd2-bae5-dba5e0dd23b3

📥 Commits

Reviewing files that changed from the base of the PR and between fe86029 and 42e6f7e.

📒 Files selected for processing (17)
  • apps/agentic-chat/src/components/tools/InitiateSwapUI.tsx
  • apps/agentic-chat/src/components/tools/useSwapExecution.tsx
  • apps/agentic-chat/src/services/swapService.ts
  • apps/agentic-chat/src/utils/__tests__/prepareFreshSwap.test.ts
  • apps/agentic-chat/src/utils/chains/evm/transaction.ts
  • apps/agentic-chat/src/utils/chains/solana/transaction.ts
  • apps/agentic-chat/src/utils/chains/types.ts
  • apps/agentic-chat/src/utils/ensureAllowance.ts
  • apps/agentic-chat/src/utils/prepareFreshSwap.ts
  • apps/agentic-chat/src/utils/sendTransaction.ts
  • apps/agentic-chat/src/utils/swapExecutor.ts
  • apps/agentic-server/src/lib/schemas/swapSchemas.ts
  • apps/agentic-server/src/server.ts
  • apps/agentic-server/src/tools/initiateSwap.ts
  • apps/agentic-server/src/utils/getBebopRate/getBebopRate.ts
  • apps/agentic-server/src/utils/getRelayRate/getRelayRate.ts
  • packages/types/src/rate.ts

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.

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.

1 participant