Skip to content

feat(relay): add api key and upgrade status endpoint to v3 - #12533

Merged
kaladinlight merged 5 commits into
developfrom
feat/relay-api-key-status-v3
Aug 7, 2026
Merged

feat(relay): add api key and upgrade status endpoint to v3#12533
kaladinlight merged 5 commits into
developfrom
feat/relay-api-key-status-v3

Conversation

@kaladinlight

@kaladinlight kaladinlight commented Aug 6, 2026

Copy link
Copy Markdown
Member

Description

Adds our Relay API key and upgrades the intents status endpoint from v2 to v3.

API key — passed via the x-api-key header (per Relay docs, used for authentication and higher rate limits) on all Relay requests: /quote/v2, /transactions/single, and the status poll. New VITE_RELAY_API_KEY config 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, with RelayStatus aligned to the v3 response per Relay's OpenAPI spec:

  • timeupdatedAt (not consumed by us)
  • Status enum corrected: Relay returns failure, not failed — previously failed swaps fell through to Unknown and would poll indefinitely instead of surfacing as failed. Now correctly mapped to Failed.
  • New intermediate states depositing and submitted mapped to Pending with 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

What protocols, transaction types, wallets or contract interactions might be affected by this PR?

Low risk — Relay swaps only. No transaction construction changes; affects quote/status request headers and status polling interpretation. The failure status fix changes failed-swap reporting from Unknown to Failed, which is the intended behavior.

Testing

Engineering

  • Verified against Relay's OpenAPI spec (api.relay.link/documentation/json): x-api-key header param, /intents/status/v3 response shape (updatedAt, status enum incl. depositing/submitted), and confirmed failure (not failed) is the spec value in both v2 and v3.
  • Execute a Relay swap and confirm quotes return and status transitions through to Confirmed, with the status request hitting /intents/status/v3 with the x-api-key header.

Operations

  • Perform a cross-chain Relay swap (e.g. ETH → an L2) and confirm quotes load and the swap completes with correct status messaging in the action center.

Screenshots (if applicable)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added optional Relay API authentication for quotes, transaction status checks, and transaction indexing.
    • Added support for additional Relay transaction statuses, including depositing, submitted, and failure.
  • Bug Fixes

    • Improved mapping of Relay statuses to pending, failed, and deposit-detected swap states.
    • Updated Relay status checks to use the latest endpoint and response format.
    • Improved reliability of authenticated Relay requests.

@kaladinlight
kaladinlight requested a review from a team as a code owner August 6, 2026 20:33
@coderabbitai

coderabbitai Bot commented Aug 6, 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f02a3df0-fe26-494e-820e-e9176590b666

📥 Commits

Reviewing files that changed from the base of the PR and between 0523955 and 321e795.

📒 Files selected for processing (1)
  • packages/swapper/src/swappers/RelaySwapper/utils/relayService.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/swapper/src/swappers/RelaySwapper/utils/relayService.ts

📝 Walkthrough

Walkthrough

The 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.

Changes

Relay API updates

Layer / File(s) Summary
Relay API key configuration
.env, packages/public-api/.env.example, packages/public-api/src/env.ts, packages/public-api/src/config.ts, packages/swapper/src/types.ts, src/config.ts, src/vite-env.d.ts
Adds Relay API key entries, validation, server mapping, and swapper type declarations.
Authenticated Relay requests
packages/swapper/src/swappers/RelaySwapper/utils/relayService.ts, packages/swapper/src/swappers/RelaySwapper/utils/fetchRelayTrade.ts, packages/swapper/src/swappers/RelaySwapper/endpoints.ts, packages/swapper/src/swappers/RelaySwapper/utils/notifyTransactionIndexing.ts
Adds shared x-api-key request configuration. Quote, status, and transaction-indexing requests use the configuration. Status polling changes to API v3.
Relay status contract and messages
packages/swapper/src/swappers/RelaySwapper/utils/types.ts, packages/swapper/src/swappers/RelaySwapper/endpoints.ts, packages/swapper/src/swappers/RelaySwapper/utils/getLatestRelayStatusMessage.ts
Adds depositing and submitted, replaces failed with failure, and renames time to updatedAt.

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
Loading

Poem

A rabbit checks the Relay key,
Then sends each request securely.
New statuses hop into the queue,
V3 polling follows through.
Failure names now match the way.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the two main changes: Relay API key support and the upgrade to the v3 status endpoint.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/relay-api-key-status-v3

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.

@coderabbitai coderabbitai Bot 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.

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 win

Map Relay processing states that should return TxStatus.Pending.

waiting is a valid Relay v3 status and currently returns TxStatus.Unknown. Map it to TxStatus.Pending, and cover the Relay status table in tests even if delayed is 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 win

Use a string enum for Relay status values.

This change expands an inline string union for a status field. Define a descriptive RelayIntentStatus string enum with the same wire values, then use it in RelayStatus, the endpoint switch, and getLatestRelayStatusMessage.

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 win

Model the optional API key consistently.

getRelayRequestConfig omits the header when the key is absent, but SwapperConfig requires VITE_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 every SwapperConfig boundary. Verify all configuration factories.

Possible type fix
-  VITE_RELAY_API_KEY: string
+  VITE_RELAY_API_KEY?: string

As 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

📥 Commits

Reviewing files that changed from the base of the PR and between b38ae59 and 5c25782.

📒 Files selected for processing (13)
  • .env
  • packages/public-api/.env.example
  • packages/public-api/src/config.ts
  • packages/public-api/src/env.ts
  • packages/swapper/src/swappers/RelaySwapper/endpoints.ts
  • packages/swapper/src/swappers/RelaySwapper/utils/fetchRelayTrade.ts
  • packages/swapper/src/swappers/RelaySwapper/utils/getLatestRelayStatusMessage.ts
  • packages/swapper/src/swappers/RelaySwapper/utils/notifyTransactionIndexing.ts
  • packages/swapper/src/swappers/RelaySwapper/utils/relayService.ts
  • packages/swapper/src/swappers/RelaySwapper/utils/types.ts
  • packages/swapper/src/types.ts
  • src/config.ts
  • src/vite-env.d.ts

Comment thread .env
Comment thread packages/swapper/src/swappers/RelaySwapper/utils/relayService.ts Outdated
Comment thread src/vite-env.d.ts
@kaladinlight
kaladinlight enabled auto-merge (squash) August 7, 2026 14:07
@kaladinlight
kaladinlight merged commit 2b2e498 into develop Aug 7, 2026
4 checks passed
@kaladinlight
kaladinlight deleted the feat/relay-api-key-status-v3 branch August 7, 2026 16:07
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