feat(relay): add api key and upgrade status endpoint to v3 - #12533
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR adds Relay API key configuration across environment and swapper settings. Relay quote, status, and indexing requests use authentication when configured. Relay polling uses API v3 and recognizes additional status values. ChangesRelay API updates
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant SwapperConfig
participant getRelayRequestConfig
participant RelaySwapper
participant RelayAPI
SwapperConfig->>getRelayRequestConfig: Provide VITE_RELAY_API_KEY
getRelayRequestConfig->>RelaySwapper: Return x-api-key configuration
RelaySwapper->>RelayAPI: Send quote, status, or indexing request
RelayAPI-->>RelaySwapper: Return trade or status data
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/swapper/src/swappers/RelaySwapper/endpoints.ts (1)
105-119: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winMap Relay processing states that should return
TxStatus.Pending.
waitingis a valid Relay v3 status and currently returnsTxStatus.Unknown. Map it toTxStatus.Pending, and cover the Relay status table in tests even ifdelayedis not part of this endpoint’s current response set.🤖 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/swapper/src/swappers/RelaySwapper/endpoints.ts` around lines 105 - 119, Update the status mapping in the RelaySwapper endpoint’s status conversion to include the valid Relay v3 waiting state in the TxStatus.Pending branch. Add or update tests covering the Relay status table, including delayed as a documented status case even if the endpoint does not currently return it.
🧹 Nitpick comments (2)
packages/swapper/src/swappers/RelaySwapper/utils/types.ts (1)
39-51: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse a string enum for Relay status values.
This change expands an inline string union for a status field. Define a descriptive
RelayIntentStatusstring enum with the same wire values, then use it inRelayStatus, the endpoint switch, andgetLatestRelayStatusMessage.Verify public consumers before changing the exported type.
As per coding guidelines, TypeScript statuses must use descriptive string enums.
🤖 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/swapper/src/swappers/RelaySwapper/utils/types.ts` around lines 39 - 51, Replace the inline status union in RelayStatus with an exported descriptive string enum named RelayIntentStatus, preserving all existing wire values. Update the endpoint switch and getLatestRelayStatusMessage to use the enum members, and verify public consumers remain compatible with the exported type.Source: Coding guidelines
packages/swapper/src/types.ts (1)
88-88: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winModel the optional API key consistently.
getRelayRequestConfigomits the header when the key is absent, butSwapperConfigrequiresVITE_RELAY_API_KEY. If an environment parser omits this value, the type does not match runtime behavior and config object construction can fail type-checking.Either mark the property optional or normalize missing values to
''at everySwapperConfigboundary. Verify all configuration factories.Possible type fix
- VITE_RELAY_API_KEY: string + VITE_RELAY_API_KEY?: stringAs per coding guidelines, properties that might not be present must use
?.🤖 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/swapper/src/types.ts` at line 88, Update the SwapperConfig declaration for VITE_RELAY_API_KEY to be optional, matching getRelayRequestConfig behavior when the key is absent. Review all SwapperConfig factories and boundaries to ensure omitted environment values remain valid without forcing empty-string normalization.Source: Coding guidelines
🤖 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 @.env:
- Line 333: Remove the non-empty VITE_RELAY_API_KEY value from the tracked .env
file, leaving it unset or using the repository’s approved placeholder format.
Rotate the exposed credential if it is live; only retain a value after
confirming Relay explicitly supports browser-public keys.
In
`@packages/swapper/src/swappers/RelaySwapper/utils/getLatestRelayStatusMessage.ts`:
- Around line 13-18: Replace the inline Relay status literals in
getLatestRelayStatusMessage with a shared descriptive TypeScript string enum for
v3 wire statuses, reusing or defining it alongside the Relay status symbols.
Preserve the exact values "depositing", "submitted", "success", and "failure",
and compare statusValue against the enum members throughout the switch.
In `@packages/swapper/src/swappers/RelaySwapper/utils/relayService.ts`:
- Around line 21-24: Remove client-side use of VITE_RELAY_API_KEY from
getRelayRequestConfig and keep Relay API-key header injection exclusively in a
server-side proxy or server-only service. Update callers such as RelaySwapper to
use that server-side path, and verify the client bundle contains neither the key
configuration nor relayService code.
In `@src/vite-env.d.ts`:
- Line 122: Update the VITE_RELAY_API_KEY declaration in the Vite environment
type definitions to mark the property optional, matching the missing-value
handling in config.ts while retaining its string value type.
---
Outside diff comments:
In `@packages/swapper/src/swappers/RelaySwapper/endpoints.ts`:
- Around line 105-119: Update the status mapping in the RelaySwapper endpoint’s
status conversion to include the valid Relay v3 waiting state in the
TxStatus.Pending branch. Add or update tests covering the Relay status table,
including delayed as a documented status case even if the endpoint does not
currently return it.
---
Nitpick comments:
In `@packages/swapper/src/swappers/RelaySwapper/utils/types.ts`:
- Around line 39-51: Replace the inline status union in RelayStatus with an
exported descriptive string enum named RelayIntentStatus, preserving all
existing wire values. Update the endpoint switch and getLatestRelayStatusMessage
to use the enum members, and verify public consumers remain compatible with the
exported type.
In `@packages/swapper/src/types.ts`:
- Line 88: Update the SwapperConfig declaration for VITE_RELAY_API_KEY to be
optional, matching getRelayRequestConfig behavior when the key is absent. Review
all SwapperConfig factories and boundaries to ensure omitted environment values
remain valid without forcing empty-string normalization.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5fbdf0cd-3272-4238-a066-eab7b72f0594
📒 Files selected for processing (13)
.envpackages/public-api/.env.examplepackages/public-api/src/config.tspackages/public-api/src/env.tspackages/swapper/src/swappers/RelaySwapper/endpoints.tspackages/swapper/src/swappers/RelaySwapper/utils/fetchRelayTrade.tspackages/swapper/src/swappers/RelaySwapper/utils/getLatestRelayStatusMessage.tspackages/swapper/src/swappers/RelaySwapper/utils/notifyTransactionIndexing.tspackages/swapper/src/swappers/RelaySwapper/utils/relayService.tspackages/swapper/src/swappers/RelaySwapper/utils/types.tspackages/swapper/src/types.tssrc/config.tssrc/vite-env.d.ts
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…peshift/web into feat/relay-api-key-status-v3
Description
Adds our Relay API key and upgrades the intents status endpoint from v2 to v3.
API key — passed via the
x-api-keyheader (per Relay docs, used for authentication and higher rate limits) on all Relay requests:/quote/v2,/transactions/single, and the status poll. NewVITE_RELAY_API_KEYconfig var plumbed through web config,SwapperConfig, and public-api (RELAY_API_KEY, optional). Header is only attached when the key is set.Status v3 —
/intents/status/v2→/intents/status/v3, withRelayStatusaligned to the v3 response per Relay's OpenAPI spec:time→updatedAt(not consumed by us)failure, notfailed— previously failed swaps fell through toUnknownand would poll indefinitely instead of surfacing as failed. Now correctly mapped toFailed.depositingandsubmittedmapped toPendingwith the "Deposit detected, processing swap..." message.Note: there is no
/quote/v3— quote remains on v2 (confirmed against Relay's OpenAPI spec).Issue (if applicable)
closes #
Risk
Low risk — Relay swaps only. No transaction construction changes; affects quote/status request headers and status polling interpretation. The
failurestatus fix changes failed-swap reporting fromUnknowntoFailed, which is the intended behavior.Testing
Engineering
api.relay.link/documentation/json):x-api-keyheader param,/intents/status/v3response shape (updatedAt, status enum incl.depositing/submitted), and confirmedfailure(notfailed) is the spec value in both v2 and v3.Confirmed, with the status request hitting/intents/status/v3with thex-api-keyheader.Operations
Screenshots (if applicable)
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes