Skip to content

feat(swapper): add Fynd POC integration - #12528

Open
Masha-lla wants to merge 3 commits into
shapeshift:developfrom
Masha-lla:codex/poc-fynd-swapper
Open

feat(swapper): add Fynd POC integration#12528
Masha-lla wants to merge 3 commits into
shapeshift:developfrom
Masha-lla:codex/poc-fynd-swapper

Conversation

@Masha-lla

@Masha-lla Masha-lla commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Description

This proof of concept adds Fynd as an Ethereum same-chain swapper for exact-input trades.

  • registers Fynd behind VITE_FEATURE_FYND_SWAP
  • supports ETH and ERC-20 rate and quote requests through the Fynd /info and /quote APIs
  • maps Fynd routes, fees, gas estimates, approvals, and encoded EVM transactions into ShapeShift trade models
  • adds a development-only Vite proxy so the hosted API key remains server-side and hosted API CORS does not block local browser testing
  • adds the Fynd icon, CSP configuration, and focused fee calculation tests

This is intentionally a POC. It currently targets Ethereum mainnet only, omits affiliate fee signing, and does not enable Fynd in production.

Issue (if applicable)

N/A — exploratory POC based on the Fynd integration proposal.

Risk

High if enabled: this introduces a new EVM transaction source and approval target. The feature remains disabled in production and should not be merged for production use without a security review, transaction regression testing, and two approvals.

Affected behavior is limited to Ethereum exact-input swaps routed through Fynd when the feature flag is enabled. Existing swappers remain unchanged.

Testing

Engineering

Validated locally with the feature flag enabled and a server-side hosted Fynd API key:

  1. Run pnpm run dev:web:localhost.
  2. Open the trade page on http://127.0.0.1:3000.
  3. Quote ETH to USDC and USDC to ETH.
  4. Confirm the selected protocol is Fynd • ekubo_v3, output amounts are populated, and network fees are displayed.

Automated checks:

  • pnpm exec eslint vite.config.mts packages/swapper/src/swappers/FyndSwapper packages/swapper/src/constants.ts packages/swapper/src/types.ts packages/public-api/src/config.ts src/config.ts src/state/helpers.ts src/state/slices/preferencesSlice/preferencesSlice.ts src/test/mocks/store.ts src/components/MultiHopTrade/components/TradeInput/components/SwapperIcon/SwapperIcon.tsx --fix
  • pnpm exec tsc --noEmit -p packages/swapper/tsconfig.esm.json
  • pnpm exec vitest run packages/swapper/src/swappers/FyndSwapper/utils/helpers.test.ts

The root type-check is currently blocked by pre-existing missing package build artifacts (TS6305) after the monorepo clean step; the swapper-specific type-check passes.

No transaction was signed or broadcast during browser verification.

Operations

  • 🏁 My feature is behind a flag and doesn't require operations testing (yet)

Screenshots (if applicable)

N/A

Summary by CodeRabbit

  • New Features
    • Added optional Fynd swap support for Ethereum trades.
    • Fynd provides quotes, rates, transaction details, fee estimates, and swap status updates.
    • Added feature-flag and environment configuration, disabled by default.
    • Added Fynd branding to swapper selection displays.
  • Bug Fixes
    • Added validation and error handling for unsupported trades, invalid responses, and failed quotes.
  • Tests
    • Added coverage for Fynd fee calculations and response validation.

@coderabbitai

coderabbitai Bot commented Aug 5, 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: 11c2ce91-3322-42ac-9e66-592ef6be2c63

📥 Commits

Reviewing files that changed from the base of the PR and between 312bf51 and 462f7ee.

📒 Files selected for processing (3)
  • packages/swapper/src/swappers/FyndSwapper/utils/fyndService.ts
  • packages/swapper/src/swappers/FyndSwapper/utils/validation.test.ts
  • packages/swapper/src/swappers/FyndSwapper/utils/validation.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/swapper/src/swappers/FyndSwapper/utils/validation.test.ts
  • packages/swapper/src/swappers/FyndSwapper/utils/fyndService.ts
  • packages/swapper/src/swappers/FyndSwapper/utils/validation.ts

📝 Walkthrough

Walkthrough

Fynd is added as an Ethereum swapper with quote, rate, fee, transaction, API, and status handling. Shared registries, exports, feature flags, environment configuration, CSP rules, development proxying, and the swapper icon are updated.

Changes

Fynd swapper

Layer / File(s) Summary
Contracts, validation, and calculations
packages/swapper/src/swappers/FyndSwapper/types.ts, packages/swapper/src/swappers/FyndSwapper/utils/*
Adds Fynd response contracts, Ethereum support, validation, asset conversion, fee calculations, trade context, and tests.
API service and response handling
packages/swapper/src/swappers/FyndSwapper/utils/fyndService.ts, packages/swapper/src/swappers/FyndSwapper/utils/fetchFromFynd.ts
Adds cached API access, router lookup, quote and rate requests, and response error handling.
Quote, rate, and execution workflows
packages/swapper/src/swappers/FyndSwapper/getTradeQuote/*, packages/swapper/src/swappers/FyndSwapper/getTradeRate/*, packages/swapper/src/swappers/FyndSwapper/utils/getFyndStepData.ts, packages/swapper/src/swappers/FyndSwapper/endpoints.ts, packages/swapper/src/swappers/FyndSwapper/FyndSwapper.ts
Builds quotes, rates, transaction steps, network fees, protocol fees, status handling, and shared EVM execution.
Registration and exports
packages/swapper/src/types.ts, packages/swapper/src/constants.ts, packages/swapper/src/index.ts, packages/swapper/src/swappers/FyndSwapper/index.ts, packages/public-api/src/config.ts
Registers Fynd, adds public types and exports, applies default slippage, and adds the Ethereum base URL configuration.
Feature configuration and application wiring
.env*, src/config.ts, src/state/*, src/vite-env.d.ts, vite.config.mts, headers/csps/*, src/components/.../SwapperIcon.tsx, src/test/mocks/store.ts
Adds environment validation, feature gating, enabled-swapper selection, proxying, CSP access, mock state, and icon rendering.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant TradeRequest
  participant getTradeQuote
  participant fetchFromFynd
  participant FyndAPI
  participant getFyndStepData
  participant EVMExecutor
  TradeRequest->>getTradeQuote: submit trade input
  getTradeQuote->>fetchFromFynd: request Fynd quote
  fetchFromFynd->>FyndAPI: retrieve router and quote
  FyndAPI-->>fetchFromFynd: return quote response
  fetchFromFynd-->>getTradeQuote: return validated quote
  getTradeQuote->>getFyndStepData: build transaction and fees
  getFyndStepData-->>getTradeQuote: return transaction step
  TradeRequest->>EVMExecutor: execute transaction
Loading

Possibly related issues

  • Panora swapper #12494 — Both changes add a feature-gated aggregator swapper with configuration, CSP, registration, validation, and UI integration.

Possibly related PRs

  • shapeshift/web#12275 — Both changes wire a new swapper through configuration, CSP registration, exports, feature flags, icons, and quote/rate workflows.
  • shapeshift/web#12492 — Both changes add a feature-flagged swapper with configuration, CSP registration, exports, registration, and quote/rate APIs.

Poem

A rabbit checks each route and fee,
Then hops through Fynd’s API.
Ethereum steps are built with care,
Feature flags guard what’s there.
Quotes return, transactions run.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: adding the Fynd proof-of-concept swapper integration.
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 unit tests (beta)
  • Create PR with unit tests

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.

@Masha-lla
Masha-lla marked this pull request as ready for review August 5, 2026 15:00
@Masha-lla
Masha-lla requested a review from a team as a code owner August 5, 2026 15:00

@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: 5

🧹 Nitpick comments (2)
packages/swapper/src/swappers/FyndSwapper/getTradeRate/getTradeRate.ts (1)

59-72: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Destructure the step data once.

Line 70 calls maybeStepData.unwrap() a second time inside the object literal. Destructure it after the error check, as getTradeQuote does.

♻️ Proposed refactor
   if (maybeStepData.isErr()) return Err(maybeStepData.unwrapErr())
+  const { networkFeeCryptoBaseUnit } = maybeStepData.unwrap()
 
   const tradeRate: TradeRate = {
     ...tradeCommon,
     quoteOrRate: 'rate',
     receiveAddress: input.receiveAddress,
     steps: [
       {
         ...stepCommon,
         accountNumber: input.accountNumber,
-        feeData: {
-          networkFeeCryptoBaseUnit: maybeStepData.unwrap().networkFeeCryptoBaseUnit,
-          protocolFees,
-        },
+        feeData: { networkFeeCryptoBaseUnit, protocolFees },
       },
     ] as SingleHopTradeRateSteps,
   }
🤖 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/FyndSwapper/getTradeRate/getTradeRate.ts`
around lines 59 - 72, In the getTradeRate flow, after the maybeStepData.isErr()
check, destructure the successful step data once and use that local value for
networkFeeCryptoBaseUnit in the tradeRate object instead of calling
maybeStepData.unwrap() again. Keep the existing error propagation and tradeRate
construction unchanged.
packages/swapper/src/swappers/FyndSwapper/utils/helpers.ts (1)

20-24: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use action-oriented function names.

The current names describe a conversion pattern or implementation pattern instead of the action.

  • packages/swapper/src/swappers/FyndSwapper/utils/helpers.ts#L20-L24: rename assetIdToFyndToken to convertAssetIdToFyndToken.
  • packages/swapper/src/swappers/FyndSwapper/utils/fyndService.ts#L8-L18: rename fyndServiceFactory to createFyndService.

As per coding guidelines, “Use verb prefixes for functions that perform actions.”

🤖 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/FyndSwapper/utils/helpers.ts` around lines 20 -
24, Rename assetIdToFyndToken to convertAssetIdToFyndToken in
packages/swapper/src/swappers/FyndSwapper/utils/helpers.ts and update all
references. Rename fyndServiceFactory to createFyndService in
packages/swapper/src/swappers/FyndSwapper/utils/fyndService.ts and update all
references.

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 `@packages/swapper/src/constants.ts`:
- Around line 108-111: Update the swappers registry entry for SwapperName.Fynd
to conditionally include the combined fyndSwapper and fyndApi exports only when
VITE_FEATURE_FYND_SWAP is enabled. Add or reuse the public API
environment/config flag used by constants.ts, and ensure disabled configurations
omit the Fynd entry entirely rather than merely hiding it in UI selectors.

In `@packages/swapper/src/swappers/FyndSwapper/getTradeQuote/getTradeQuote.ts`:
- Around line 45-52: Update the validation in getTradeQuote so quotes are
rejected only when quote.transaction is missing; allow absent fee_breakdown so
getFyndTradeContext can apply its existing router and client fee fallbacks. Keep
the executable-step construction unchanged, or, if the quote contract guarantees
fee_breakdown, remove that fallback in getFyndTradeContext and align both paths
to require it.

In `@packages/swapper/src/swappers/FyndSwapper/utils/fetchFromFynd.ts`:
- Around line 44-47: Update fetchFromFynd to runtime-validate both
FyndInfoResponse and FyndQuoteResponse before using or returning quote data:
require an Ethereum info response with a valid router_address, require
transaction and fee_breakdown, and require all quote amounts and fees to be
numeric and non-negative. Convert every rejected shape to
TradeQuoteError.InvalidResponse, and add tests covering each invalid response
case.

In `@packages/swapper/src/swappers/FyndSwapper/utils/getFyndStepData.ts`:
- Around line 29-35: Update the rate branch in getFyndStepData to use the shared
getEvmNetworkFeeCryptoBaseUnit path, passing the provider gas_estimate as
gasLimit and preserving the provider gas price handling so null values are not
silently converted into a zero network fee; alternatively, explicitly reject
null gas prices instead of defaulting them.

In `@packages/swapper/src/swappers/FyndSwapper/utils/helpers.ts`:
- Around line 20-88: Add explicit return types to assetIdToFyndToken,
assertValidTrade, calculateFyndRouterFee, calculateFyndAmounts,
calculateFyndRate, and isNativeFyndSell in helpers.ts, using a named object type
for calculateFyndAmounts; add the SwapErrorRight return type to
quoteStatusToError in fetchFromFynd.ts. Then run pnpm run lint --fix and pnpm
run type-check.

---

Nitpick comments:
In `@packages/swapper/src/swappers/FyndSwapper/getTradeRate/getTradeRate.ts`:
- Around line 59-72: In the getTradeRate flow, after the maybeStepData.isErr()
check, destructure the successful step data once and use that local value for
networkFeeCryptoBaseUnit in the tradeRate object instead of calling
maybeStepData.unwrap() again. Keep the existing error propagation and tradeRate
construction unchanged.

In `@packages/swapper/src/swappers/FyndSwapper/utils/helpers.ts`:
- Around line 20-24: Rename assetIdToFyndToken to convertAssetIdToFyndToken in
packages/swapper/src/swappers/FyndSwapper/utils/helpers.ts and update all
references. Rename fyndServiceFactory to createFyndService in
packages/swapper/src/swappers/FyndSwapper/utils/fyndService.ts and update all
references.
🪄 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: fdc11f3c-03d1-4114-9f2a-d1d93cb65f8b

📥 Commits

Reviewing files that changed from the base of the PR and between 32ecf2b and 4939cbb.

⛔ Files ignored due to path filters (1)
  • src/components/MultiHopTrade/components/TradeInput/components/SwapperIcon/fynd-icon.svg is excluded by !**/*.svg
📒 Files selected for processing (29)
  • .env
  • .env.development
  • .env.production
  • headers/csps/defi/swappers/Fynd.ts
  • headers/csps/index.ts
  • packages/public-api/src/config.ts
  • packages/swapper/src/constants.ts
  • packages/swapper/src/index.ts
  • packages/swapper/src/swappers/FyndSwapper/FyndSwapper.ts
  • packages/swapper/src/swappers/FyndSwapper/endpoints.ts
  • packages/swapper/src/swappers/FyndSwapper/getTradeQuote/getTradeQuote.ts
  • packages/swapper/src/swappers/FyndSwapper/getTradeRate/getTradeRate.ts
  • packages/swapper/src/swappers/FyndSwapper/index.ts
  • packages/swapper/src/swappers/FyndSwapper/types.ts
  • packages/swapper/src/swappers/FyndSwapper/utils/constants.ts
  • packages/swapper/src/swappers/FyndSwapper/utils/fetchFromFynd.ts
  • packages/swapper/src/swappers/FyndSwapper/utils/fyndService.ts
  • packages/swapper/src/swappers/FyndSwapper/utils/getFyndStepData.ts
  • packages/swapper/src/swappers/FyndSwapper/utils/getFyndTradeContext.ts
  • packages/swapper/src/swappers/FyndSwapper/utils/helpers.test.ts
  • packages/swapper/src/swappers/FyndSwapper/utils/helpers.ts
  • packages/swapper/src/types.ts
  • src/components/MultiHopTrade/components/TradeInput/components/SwapperIcon/SwapperIcon.tsx
  • src/config.ts
  • src/state/helpers.ts
  • src/state/slices/preferencesSlice/preferencesSlice.ts
  • src/test/mocks/store.ts
  • src/vite-env.d.ts
  • vite.config.mts

Comment on lines +108 to +111
[SwapperName.Fynd]: {
...fyndSwapper,
...fyndApi,
},

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.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C 8 'SwapperName\.Fynd|VITE_FEATURE_FYND_SWAP|fyndApi|fyndSwapper' \
  src packages/public-api packages/swapper

Repository: shapeshift/web

Length of output: 22478


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== swapper registry consumers =="
rg -n "swapperRegistry\)|getSwapper\(|executeEvmTransaction\(|getUnsignedEvmTransaction\(|getTradeQuote\(|getTradeRate\(|checkTradeStatus\(|getEvmTransactionFees\(" packages src --glob '*.ts' --glob '*.tsx' | head -n 240

echo
echo "== constants outline/section =="
cat -n packages/swapper/src/constants.ts | sed -n '1,220p'

echo
echo "== public API files =="
git ls-files packages/public-api | sort

Repository: shapeshift/web

Length of output: 18303


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== selector helpers around Fynd =="
cat -n src/state/helpers.ts | sed -n '1,130p'
echo
echo "== preferences slice around Fynd =="
cat -n src/state/slices/preferencesSlice/preferencesSlice.ts | sed -n '210,255p'

echo
echo "== feature flag references concise =="
rg -n "FyndSwap|VITE_FEATURE_FYND_SWAP|SwapperName\.Fynd|getAvailable.*Swapper|is.*Swapper" src packages/swapper packages/public-api --glob '*.ts' --glob '*.tsx' | head -n 240

Repository: shapeshift/web

Length of output: 19607


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== swapper registry exported/use site =="
cat -n packages/swapper/src/swapper.ts | sed -n '1,110p'

echo
echo "== public-api swapper deps and index =="
cat -n packages/public-api/src/swapperDeps.ts | sed -n '1,220p'
echo
cat -n packages/public-api/src/index.ts | sed -n '1,220p'

echo
echo "== public-api route quote/rate/index =="
cat -n packages/public-api/src/routes/quote/getQuote.ts | sed -n '1,180p'
echo
cat -n packages/public-api/src/routes/rates/getRates.ts | sed -n '1,180p'
echo
cat -n packages/public-api/src/routes/quote/index.ts | sed -n '1,180p'
echo
cat -n packages/public-api/src/routes/rates/index.ts | sed -n '1,180p'

echo
echo "== public-api registry/status =="
cat -n packages/public-api/src/registry.ts | sed -n '1,220p'
echo
cat -n packages/public-api/src/routes/status/getSwapStatus.ts | sed -n '1,220p'
echo
cat -n packages/public-api/src/routes/status/index.ts | sed -n '1,220p'

Repository: shapeshift/web

Length of output: 39202


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== public-api env/config =="
cat -n packages/public-api/src/env.ts | sed -n '1,220p'
echo
echo "== public-api config feature constants =="
cat -n packages/public-api/src/config.ts | sed -n '1,260p'
echo
echo "== public-api constants enabled swapper env =="
cat -n packages/public-api/src/constants.ts | sed -n '1,220p'

echo
echo "== public-api docs mentioning Fynd/swapper names =="
rg -n "SwapperName|Fynd|enabled|ENABLED|quote/status/rates" packages/public-api/docs --glob '*.md'

Repository: shapeshift/web

Length of output: 9015


Security And Privacy (CWE-16)

Reachability: Internal · Exploitability: Moderate

Reachability path
● Entry
  packages/swapper/src/swappers/FyndSwapper/getTradeQuote/getTradeQuote.ts:19
  getTradeQuote
│
▼
● Sink
  packages/swapper/src/constants.ts

Gate the Fynd registry entry with VITE_FEATURE_FYND_SWAP.

packages/swapper/src/constants.ts exports fyndSwapper and fyndApi directly into swappers[SwapperName.Fynd], making quote/rate/unsigned transaction methods reachable through public API paths. Add public-API env/config support for this flag and skip exporting Fynd unless it is enabled, instead of relying only on app selectors/UI gating.

🤖 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/constants.ts` around lines 108 - 111, Update the
swappers registry entry for SwapperName.Fynd to conditionally include the
combined fyndSwapper and fyndApi exports only when VITE_FEATURE_FYND_SWAP is
enabled. Add or reuse the public API environment/config flag used by
constants.ts, and ensure disabled configurations omit the Fynd entry entirely
rather than merely hiding it in UI selectors.

Comment thread packages/swapper/src/swappers/FyndSwapper/getTradeQuote/getTradeQuote.ts Outdated
Comment thread packages/swapper/src/swappers/FyndSwapper/utils/fetchFromFynd.ts Outdated
Comment on lines +29 to +35
if (args.type === 'rate') {
return Ok({
networkFeeCryptoBaseUnit: bnOrZero(args.gasEstimate)
.times(args.gasPrice ?? '0')
.toFixed(),
})
}

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the rate-mode argument shape of getEvmNetworkFeeCryptoBaseUnit and how other swappers use it.
fd 'getEvmNetworkFeeCryptoBaseUnit.ts' --exec cat -n
rg -nP -C6 'getEvmNetworkFeeCryptoBaseUnit\(\{' packages/swapper/src

Repository: shapeshift/web

Length of output: 39041


🏁 Script executed:

#!/bin/bash
# Inspect the Fynd step-data implementation and the Fynd types that define gas estimates and prices.
fd getFyndStepData.ts packages/swapper/src/swappers/FyndSwapper --exec cat -n
rg -n "gasPrice|gas_estimate|gas_price|gasEstimate|getFyndStepData" packages/swapper/src/swappers/FyndSwapper packages/swapper/src -C 3

Repository: shapeshift/web

Length of output: 44312


Use the shared EVM rate fee path for Fynd.

quote.gas_price can be null, which makes getFyndStepData return a zero network fee. Call getEvmNetworkFeeCryptoBaseUnit from the rate branch using the provider gas_estimate as gasLimit, or reject null instead of defaulting it to '0'.

🤖 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/FyndSwapper/utils/getFyndStepData.ts` around
lines 29 - 35, Update the rate branch in getFyndStepData to use the shared
getEvmNetworkFeeCryptoBaseUnit path, passing the provider gas_estimate as
gasLimit and preserving the provider gas price handling so null values are not
silently converted into a zero network fee; alternatively, explicitly reject
null gas prices instead of defaulting them.

Comment thread packages/swapper/src/swappers/FyndSwapper/utils/helpers.ts Outdated

@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: 2

🧹 Nitpick comments (3)
packages/swapper/src/swappers/FyndSwapper/utils/validation.test.ts (1)

6-39: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Type and rename the test fixtures.

Rename transaction, feeBreakdown, order, and response to descriptive UPPER_SNAKE_CASE constants. Define named fixture types from the Fynd response contracts.

Rename value to invalidInfoResponse. Add explicit callback parameter types for both it.each handlers.

As per coding guidelines, Use UPPER_SNAKE_CASE for constants and configuration values with descriptive names, ALWAYS use explicit types for object shapes using interfaces or type aliases in TypeScript, and Avoid non-descriptive variable names like data, item, obj, and single-letter variable names except in loops.

Also applies to: 53-83

🤖 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/FyndSwapper/utils/validation.test.ts` around
lines 6 - 39, Rename the test fixtures transaction, feeBreakdown, order,
response, and value to descriptive UPPER_SNAKE_CASE constants, using
invalidInfoResponse for value. Define named interfaces or type aliases based on
the Fynd response contracts for each fixture’s object shape, apply those types
explicitly, and add explicit callback parameter types to both it.each handlers.

Source: Coding guidelines

packages/swapper/src/swappers/FyndSwapper/utils/validation.ts (1)

50-56: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Keep external response arrays typed as unknown[].

Array.isArray() narrows value.swaps and value.orders to any[]. The swap and order callback parameters then bypass the required external-payload type safety.

Add an isUnknownArray guard or explicitly narrow the arrays to unknown[]. Make isValidOrder a type guard before the final response cast.

As per coding guidelines, NEVER use any type unless absolutely necessary in TypeScript, ALWAYS use explicit types for function parameters and return values in TypeScript, and ALWAYS create custom type guards for complex types in TypeScript.

Also applies to: 115-127

🤖 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/FyndSwapper/utils/validation.ts` around lines
50 - 56, Update isValidRoute and isValidOrder to prevent Array.isArray from
producing any[]: narrow swaps and orders to unknown[] using an isUnknownArray
guard or equivalent explicit narrowing, and annotate callback parameters
explicitly. Make isValidOrder a type guard so the final external response cast
is safely based on validated data.

Source: Coding guidelines

packages/swapper/src/swappers/FyndSwapper/utils/fyndService.ts (1)

8-8: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use a named service configuration type.

Replace the inline { baseUrl: string } parameter type with a descriptive FyndServiceConfig type.

As per coding guidelines, ALWAYS use explicit types for object shapes using interfaces or type aliases in TypeScript.

🤖 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/FyndSwapper/utils/fyndService.ts` at line 8,
Introduce a named FyndServiceConfig type alias or interface for the service
options object, then update createFyndService to use FyndServiceConfig instead
of the inline { baseUrl: string } parameter type.

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 `@packages/swapper/src/swappers/FyndSwapper/utils/validation.ts`:
- Around line 42-48: Extend the fee-breakdown validation and successful-quote
path around isValidFeeBreakdown and calculateFyndAmounts to ensure router_fee
plus client_fee does not exceed amount_out; reject such quotes before amount
calculation can produce a negative buyAmountAfterFeesCryptoBaseUnit. Add a
regression test covering a quote whose combined fees exceed the quoted output.
- Around line 24-25: Update isNonNegativeNumericString to accept only non-empty
strings representing non-negative decimal integers in base-unit fields. Reject
fractional and exponent notation such as “0.5” and “1.23e-1” before the
bn(value) checks, while preserving acceptance of valid unsigned integer strings.

---

Nitpick comments:
In `@packages/swapper/src/swappers/FyndSwapper/utils/fyndService.ts`:
- Line 8: Introduce a named FyndServiceConfig type alias or interface for the
service options object, then update createFyndService to use FyndServiceConfig
instead of the inline { baseUrl: string } parameter type.

In `@packages/swapper/src/swappers/FyndSwapper/utils/validation.test.ts`:
- Around line 6-39: Rename the test fixtures transaction, feeBreakdown, order,
response, and value to descriptive UPPER_SNAKE_CASE constants, using
invalidInfoResponse for value. Define named interfaces or type aliases based on
the Fynd response contracts for each fixture’s object shape, apply those types
explicitly, and add explicit callback parameter types to both it.each handlers.

In `@packages/swapper/src/swappers/FyndSwapper/utils/validation.ts`:
- Around line 50-56: Update isValidRoute and isValidOrder to prevent
Array.isArray from producing any[]: narrow swaps and orders to unknown[] using
an isUnknownArray guard or equivalent explicit narrowing, and annotate callback
parameters explicitly. Make isValidOrder a type guard so the final external
response cast is safely based on validated data.
🪄 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: c50935c0-3c0d-4e9f-8715-589432acc8cf

📥 Commits

Reviewing files that changed from the base of the PR and between 4939cbb and 312bf51.

📒 Files selected for processing (8)
  • packages/swapper/src/swappers/FyndSwapper/getTradeQuote/getTradeQuote.ts
  • packages/swapper/src/swappers/FyndSwapper/getTradeRate/getTradeRate.ts
  • packages/swapper/src/swappers/FyndSwapper/utils/fetchFromFynd.ts
  • packages/swapper/src/swappers/FyndSwapper/utils/fyndService.ts
  • packages/swapper/src/swappers/FyndSwapper/utils/getFyndStepData.ts
  • packages/swapper/src/swappers/FyndSwapper/utils/helpers.ts
  • packages/swapper/src/swappers/FyndSwapper/utils/validation.test.ts
  • packages/swapper/src/swappers/FyndSwapper/utils/validation.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/swapper/src/swappers/FyndSwapper/getTradeQuote/getTradeQuote.ts
  • packages/swapper/src/swappers/FyndSwapper/utils/fetchFromFynd.ts
  • packages/swapper/src/swappers/FyndSwapper/utils/getFyndStepData.ts

Comment thread packages/swapper/src/swappers/FyndSwapper/utils/validation.ts Outdated
Comment thread packages/swapper/src/swappers/FyndSwapper/utils/validation.ts Outdated
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