Skip to content

fix(swap-service): pass the BOB Gateway API key through to the swapper - #58

Merged
kaladinlight merged 1 commit into
developfrom
fix/bob-gateway-api-key
Aug 28, 2026
Merged

fix(swap-service): pass the BOB Gateway API key through to the swapper#58
kaladinlight merged 1 commit into
developfrom
fix/bob-gateway-api-key

Conversation

@kaladinlight

Copy link
Copy Markdown
Member

Description

getSwapperConfig() passed a placeholder empty string for VITE_BOB_GATEWAY_API_KEY, so the BOB SDK omitted the auth header entirely:

// @gobob/bob-sdk/dist/gateway/client.js:27
headers: apiKey ? { Authorization: `Bearer ${apiKey}` } : undefined,

Every gateway call therefore went out unauthenticated and came back 403 Forbidden with an HTML body, surfacing as GatewayError: Non-JSON response: HTTP 403 Forbidden in the status poller.

This wires the key through env.ts and getSwapperConfig(), matching how the other swapper keys are declared, and documents it in .env.example.

Validated with z.string().length(32) rather than .min(1) because the SDK hard-rejects any other length at client construction, where it would surface as an unhandled throw rather than a startup error:

if (apiKey && apiKey.length !== 32) throw new Error('apiKey must be exactly 32 characters')

VITE_BOB_GATEWAY_API_KEY must be set in Railway before this merges — it is a required variable, so the service will refuse to start without it.

Two config placeholders remain empty and are deliberately out of scope: VITE_ACROSS_INTEGRATOR_ID (may affect Across affiliate attribution) and VITE_TRON_GRID_API_KEY (Sun.io falls back to TronGrid's public rate limits).

Testing

  • 68/68 existing tests pass.
  • Confirmed the failure mode against the live API: unauthenticated requests to /v3/get-order/{id} return 403 with a Cloudflare HTML body, matching the observed error signature exactly.
  • Loaded src/env.ts directly under ts-node to check schema behaviour, since the test suite mocks the env module wholesale and would not catch a bad schema:
    • with the key present, config resolves it at length 32
    • with it absent, boot fails with Invalid environment variables: ... at VITE_BOB_GATEWAY_API_KEY

The key itself could not be verified end to end from a dev machine — Cloudflare blocks that IP for all requests to gateway-api-mainnet.gobob.xyz, including unauthenticated ones to public endpoints, so the request never reaches the API. Worth watching the first deploy: if BOB swaps still log Non-JSON response: HTTP 403, the block is on the source IP rather than the credential, and BOB would need to allowlist it.

🤖 Generated with Claude Code

The key was a placeholder empty string, so the BOB SDK omitted the
Authorization header and every gateway call was rejected. Validated at
32 characters because the SDK throws on any other length.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@kaladinlight
kaladinlight enabled auto-merge (squash) August 28, 2026 21:25
@kaladinlight
kaladinlight merged commit c2773a8 into develop Aug 28, 2026
1 check passed
@kaladinlight
kaladinlight deleted the fix/bob-gateway-api-key branch August 28, 2026 21:27
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