Skip to content

fix: enable Solana swaps via Chainflip with correct decimals#91

Merged
0xApotheosis merged 4 commits intodevelopfrom
fix/solana-rates-blocked
Jan 27, 2026
Merged

fix: enable Solana swaps via Chainflip with correct decimals#91
0xApotheosis merged 4 commits intodevelopfrom
fix/solana-rates-blocked

Conversation

@0xApotheosis
Copy link
Member

@0xApotheosis 0xApotheosis commented Jan 26, 2026

Summary

  • Enable SOL ↔ ETH/BTC swaps that were previously blocked
  • Fix amount calculation to use correct native decimals for each asset
  • Fix output display to show human-readable amounts instead of scientific notation

Root Cause

Multiple issues were preventing Solana swaps from working:

  1. Blocking logic: An if-block was returning "No rate available" for SOL↔ETH and SOL→BTC pairs before even calling Chainflip
  2. Wrong decimals for API requests: The amount calculation used fromToken.decimals[toToken.symbol] which looked up decimals based on the destination token instead of using the source token's native decimals
  3. Scientific notation in URL: JavaScript's 10 ** 18 can produce 1e+18 when stringified, which Chainflip couldn't parse
  4. Wrong decimals for output display: The output amount used THORChain decimals instead of Chainflip native decimals

Changes

1. Remove blocking logic

Removed the if-block that blocked SOL↔ETH and SOL→BTC pairs - Chainflip now supports these.

2. Add getChainflipAssetId helper

Maps token/chain combinations to correct Chainflip asset identifiers:

  • SOL → Sol.Sol
  • BTC → Btc.Btc
  • ETH → Eth.Eth
  • USDT → Usdt.Eth

3. Add getChainflipDecimals helper

Returns correct native decimals for Chainflip assets:

  • SOL: 9 decimals
  • BTC: 8 decimals
  • ETH: 18 decimals
  • USDT: 6 decimals

4. Use BigInt for amount formatting

const amountInBaseUnits = BigInt(Math.round(numericAmount * 10 ** decimals)).toString()

Ensures the amount is formatted as a proper integer string (e.g., "1000000000") instead of scientific notation ("1e+9").

5. Fix output display decimals

Use getChainflipDecimals(toToken) for Chainflip swaps to correctly format the received amount.

Test Plan

  • SOL → ETH: Enter 1 SOL, verify quote returns ~0.04 ETH
  • ETH → SOL: Enter 1 ETH, verify quote returns ~23 SOL
  • SOL → BTC: Enter 1 SOL, verify quote returns ~0.0014 BTC
  • ETH → BTC: Verify THORChain still works for non-Solana pairs
  • Output amounts display correctly (not in scientific notation)

🤖 Generated with Claude Code

@vercel
Copy link

vercel bot commented Jan 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
website-frontend Ready Ready Preview, Comment Jan 27, 2026 0:38am

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 26, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/solana-rates-blocked

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.

- Remove outdated blocking logic that prevented SOL→BTC, SOL→ETH, and
  ETH→SOL pairs from fetching quotes
- Add getChainflipAssetId helper to map token/chain combinations to
  correct Chainflip asset identifiers (e.g., ETH on any chain maps to
  Eth.Eth since Chainflip only supports ETH on Ethereum mainnet)

Chainflip now supports all these pairs and returns valid quotes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SOL → ETH swaps were failing because the amount calculation used the
destination token's decimals instead of the source token's native
decimals. Added getChainflipDecimals helper to return correct decimals
for each asset (SOL=9, BTC=8, ETH=18, USDT=6).

Co-Authored-By: Claude <noreply@anthropic.com>
@0xApotheosis 0xApotheosis changed the title fix: remove outdated blocking logic for Solana pairs fix: correct decimals for Chainflip Solana swap quotes Jan 27, 2026
JavaScript's Number type can produce scientific notation (1e+18) for
large numbers when converted to string, which the Chainflip API may
not parse correctly. Using BigInt ensures the amount is formatted as
a proper integer string (1000000000000000000).

Co-Authored-By: Claude <noreply@anthropic.com>
For Chainflip swaps (Solana involved), use getChainflipDecimals for
the destination token. For THORChain swaps, use the existing decimals
lookup. This fixes the output showing in scientific notation.

Co-Authored-By: Claude <noreply@anthropic.com>
@0xApotheosis 0xApotheosis changed the title fix: correct decimals for Chainflip Solana swap quotes fix: enable Solana swaps via Chainflip with correct decimals Jan 27, 2026
@0xApotheosis 0xApotheosis marked this pull request as ready for review January 27, 2026 00:42
@0xApotheosis 0xApotheosis merged commit dbbd7fc into develop Jan 27, 2026
4 checks passed
@0xApotheosis 0xApotheosis deleted the fix/solana-rates-blocked branch January 27, 2026 00:42
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