Skip to content

chore(swap-service): use relayTokenToAssetId from @shapeshiftoss/swapper#40

Merged
kaladinlight merged 1 commit into
developfrom
chore/swap-relay-token-to-asset-id
May 18, 2026
Merged

chore(swap-service): use relayTokenToAssetId from @shapeshiftoss/swapper#40
kaladinlight merged 1 commit into
developfrom
chore/swap-relay-token-to-asset-id

Conversation

@kaladinlight
Copy link
Copy Markdown
Member

@kaladinlight kaladinlight commented May 18, 2026

Description

Replaces the inline appFeeCurrencyObjectAssetId construction in the Relay verifier with the canonical relayTokenToAssetId helper now exported from @shapeshiftoss/swapper (bumped 17.7.0 → 17.7.3). The helper correctly handles non-EVM chains (BTC/Solana/Tron) and Relay's numeric-chainId mapping — both of which the inline implementation got wrong.

Also adds relayTokenToAssetId to the test-side mock of @shapeshiftoss/swapper in verification/__tests__/setup.ts and tightens the local RelayToken interface to non-optional fields (matching the package contract).

Testing

  • cd apps/swap-service && npx jest src/verification/__tests__/relay.test.ts — existing relay tests still pass (native ETH, ERC20 USDT, missing currency cases)

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced error handling in swap verification for affiliate fee processing.
  • Chores

    • Updated swap service dependency version.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

Warning

Rate limit exceeded

@kaladinlight has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 54 minutes and 14 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cfcd6223-303a-48c5-94fc-a06c77e4243a

📥 Commits

Reviewing files that changed from the base of the PR and between ee5e045 and 660dc03.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (4)
  • apps/swap-service/src/verification/__tests__/setup.ts
  • apps/swap-service/src/verification/swap-verification.service.ts
  • apps/swap-service/src/verification/types.ts
  • package.json
📝 Walkthrough

Walkthrough

SwapVerificationService is refactored to use the external relayTokenToAssetId utility for deriving affiliate fee asset IDs, replacing inline manual parsing. RelayToken fields are now required, the service imports and applies the utility in verifyRelay with error handling, and tests mock the utility behavior. The dependency version is updated to match.

Changes

Relay Verification Refactoring

Layer / File(s) Summary
RelayToken type contract
apps/swap-service/src/verification/types.ts
chainId, address, symbol, name, and decimals are now required fields instead of optional on RelayToken.
Swap verification service refactoring
apps/swap-service/src/verification/swap-verification.service.ts
relayTokenToAssetId is imported and used in verifyRelay to compute actualAffiliateFeeAssetId from appFeeCurrencyObject with try/catch error handling, replacing inline native/ERC20 address-to-eip155 mapping logic.
Test mock and dependency update
apps/swap-service/src/verification/__tests__/setup.ts, package.json
Test setup mocks relayTokenToAssetId to return native or ERC20 eip155 asset IDs; @shapeshiftoss/swapper is bumped from 17.7.0 to 17.7.3.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • shapeshift/microservices#39: Both PRs modify SwapVerificationService.verifyRelay—this PR refactors actualAffiliateFeeAssetId derivation using relayTokenToAssetId, while the related PR adjusts relay pending reason handling.

Poem

🐰 A utility hops in with grace,
Replacing inline parsing's case,
Types grow strict, no optionals now,
Tests mock true—we'll show you how,
Cleaner code, a simpler place! 🎯

🚥 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 accurately describes the main change: replacing inline assetId construction with the relayTokenToAssetId helper from @shapeshiftoss/swapper.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/swap-relay-token-to-asset-id

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
apps/swap-service/src/verification/swap-verification.service.ts (1)

193-197: ⚡ Quick win

Log relay token conversion failures before fallback.

Line 193 currently swallows conversion errors silently; add a warning so malformed Relay payloads are observable during verification.

Proposed patch
-      try {
-        return relayTokenToAssetId(currency)
-      } catch {
-        return undefined
-      }
+      try {
+        return relayTokenToAssetId(currency)
+      } catch (e) {
+        this.logger.warn(
+          `Relay - failed to derive affiliate fee assetId for relayId=${relayId}: ${
+            e instanceof Error ? e.message : 'Unknown error'
+          }`,
+        )
+        return undefined
+      }
🤖 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 `@apps/swap-service/src/verification/swap-verification.service.ts` around lines
193 - 197, The catch block that swallows errors from
relayTokenToAssetId(currency) must log a warning before returning undefined;
update the try/catch in swap-verification.service.ts (the call to
relayTokenToAssetId and the surrounding verification logic) to catch (err) and
call the appropriate logger (e.g., this.logger.warn or processLogger.warn) with
a message that includes the error, the malformed currency payload, and context
("relay token conversion failed for currency") so failures are observable, then
return undefined as the fallback.
apps/swap-service/src/verification/__tests__/setup.ts (1)

63-68: ⚡ Quick win

Update the mock to match the real relayTokenToAssetId behavior to catch regressions for non-EVM chains.

The current stub only handles EVM tokens (returning eip155:chainId/slip44:60 or eip155:chainId/erc20:address), but the real implementation from @shapeshiftoss/swapper supports BTC, Solana, and Tron formats. Tests currently cover only Ethereum mainnet (chainId 1), so they won't catch breaks in non-EVM token mapping if this PR expands relay support to other chains.

🤖 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 `@apps/swap-service/src/verification/__tests__/setup.ts` around lines 63 - 68,
The mock implementation of relayTokenToAssetId only covers EVM (isNative ->
eip155:.../slip44:60 or erc20:...), so update the stub in setup.ts to mirror the
real `@shapeshiftoss/swapper` logic used in production: detect chain/network and
return BTC (e.g., slip44-based or proper btc asset id), Solana (solana:<pubkey>
format), Tron (tron:<address>), and EVM variants (eip155:.../slip44:60 or
eip155:.../erc20:lowercased) as the real function does; ensure you use the same
token shape/fields and lowercasing where appropriate so tests will catch
regressions for non-EVM chains when calling relayTokenToAssetId.
🤖 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.

Nitpick comments:
In `@apps/swap-service/src/verification/__tests__/setup.ts`:
- Around line 63-68: The mock implementation of relayTokenToAssetId only covers
EVM (isNative -> eip155:.../slip44:60 or erc20:...), so update the stub in
setup.ts to mirror the real `@shapeshiftoss/swapper` logic used in production:
detect chain/network and return BTC (e.g., slip44-based or proper btc asset id),
Solana (solana:<pubkey> format), Tron (tron:<address>), and EVM variants
(eip155:.../slip44:60 or eip155:.../erc20:lowercased) as the real function does;
ensure you use the same token shape/fields and lowercasing where appropriate so
tests will catch regressions for non-EVM chains when calling
relayTokenToAssetId.

In `@apps/swap-service/src/verification/swap-verification.service.ts`:
- Around line 193-197: The catch block that swallows errors from
relayTokenToAssetId(currency) must log a warning before returning undefined;
update the try/catch in swap-verification.service.ts (the call to
relayTokenToAssetId and the surrounding verification logic) to catch (err) and
call the appropriate logger (e.g., this.logger.warn or processLogger.warn) with
a message that includes the error, the malformed currency payload, and context
("relay token conversion failed for currency") so failures are observable, then
return undefined as the fallback.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b280e754-c69e-4ad7-bc04-57180729ca3a

📥 Commits

Reviewing files that changed from the base of the PR and between 4cac300 and ee5e045.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (4)
  • apps/swap-service/src/verification/__tests__/setup.ts
  • apps/swap-service/src/verification/swap-verification.service.ts
  • apps/swap-service/src/verification/types.ts
  • package.json

Replaces inline assetId construction with the canonical helper from the
swapper package (bumped to 17.7.3), which handles non-EVM chains and
Relay's chain-id mapping correctly. Adds the function to the test mock.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@kaladinlight kaladinlight force-pushed the chore/swap-relay-token-to-asset-id branch from ee5e045 to 660dc03 Compare May 18, 2026 19:17
@kaladinlight kaladinlight enabled auto-merge (squash) May 18, 2026 19:18
@kaladinlight kaladinlight merged commit 75bf563 into develop May 18, 2026
2 checks passed
@kaladinlight kaladinlight deleted the chore/swap-relay-token-to-asset-id branch May 18, 2026 19:19
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