fix(sdk): accept null for optional fields in swapApprovalResponseSchema#269
Conversation
`/swap/approval` now serializes `approvalTxns`, `steps.originSwap`, `steps.destinationSwap`, and `swapTx` as explicit `null` (rather than omitting them) for cases where they don't apply — e.g. bridgeable-to- bridgeable routes return `null` for the swap legs. Zod's `.optional()` accepts `undefined` but rejects `null`, so `getSwapQuote` was throwing `Invalid swap approval response` on every same-token bridge quote. Switch the four affected fields to `.nullish()`. Downstream consumers (`executeSwapQuote`) already coerce these via truthiness checks, so runtime behavior is unchanged. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 21c3029 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Remember to bump the patch version of the package. |
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Bumped |
|
@droplet-rl no need to bump the package version. it will be bumped by the changeset PR. also fix the failing test. Scroll is not supported by us anymore |
This reverts commit bea34fa.
Scroll is no longer a supported chain. Caused "Could not find chainInfo for chain with id 534352" failures in client.test.ts. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Done. Reverted the version bump (will let the changeset PR handle it) and dropped Scroll from |
Summary
swapApprovalResponseSchemarejects valid/swap/approvalresponses on every bridgeable-to-bridgeable route — Zod's.optional()acceptsundefinedbut notnull, and the API now serializesapprovalTxns,steps.originSwap,steps.destinationSwap, andswapTxas explicitnullwhen they don't apply..nullish(). Consumers (executeSwapQuote) already coerce via truthiness, so runtime behavior is unchanged.Context
Reported by Fun (Connor McEwen) in
#funon 2026-06-10.getSwapQuotethrowsInvalid swap approval response. Error: ...on quotes like Arbitrum USDC → Optimism USDC (no swap legs). Verified against liveapp.across.to/api/swap/approval:Root cause on the server side: across-protocol/quote-api#2645 ("epic: hyperliquid withdrawals") flipped these fields from
undefinedtonullinapi/swap/_utils.ts:buildBaseSwapResponseJson. A surgical revert of those four lines is being pursued inquote-api; this SDK patch is the integrator-side defense so future server changes that null vs. omit don't break clients again.Test plan
pnpm build(tsc) — cleanpnpm lint— only pre-existing warning unrelated to this changenullfor the four fields) —swapApprovalResponseSchema.safeParsereturnssuccess: trueexecuteSwapQuote) still treatnullthe same asundefined(they do —if (!swapQuote.swapTx)andif (swapQuote.approvalTxns && ...))🤖 Generated with Claude Code